00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _FLUXBOX_H_ 00012 #define _FLUXBOX_H_ 00013 00014 #include "Box.H" 00015 #include "Vector.H" 00016 #include "FArrayBox.H" 00017 #include "NamespaceHeader.H" 00018 00019 /// A FArrayBox-like container for face-centered fluxes 00020 /** This is a class to contain face-centered fluxes on a box. 00021 */ 00022 class FluxBox 00023 { 00024 00025 public: 00026 /// Default constructor 00027 FluxBox(); 00028 00029 /// Constructs FluxBox on cell-centered box with n components 00030 FluxBox(const Box& bx, int n=1); 00031 00032 /// Constructs FluxBox aliasing SpaceDim memory pointers for the FArrayBox 00033 FluxBox(const Box& a_bx, const int a_nComp, D_DECL6(Real *const a_alias0, 00034 Real *const a_alias1, 00035 Real *const a_alias2, 00036 Real *const a_alias3, 00037 Real *const a_alias4, 00038 Real *const a_alias5)); 00039 00040 /// Destructor 00041 ~FluxBox(); 00042 00043 /// Resize FluxBox similar to BaseFab::resize() 00044 void resize(const Box& bx, int n=1); 00045 00046 /// Define function 00047 void define(const Box& bx, int n=1); 00048 00049 void define(const FluxBox& a_fb) 00050 { 00051 define(a_fb.box(), a_fb.nComp()); 00052 } 00053 00054 /// Returns the FluxBox to the undefined state 00055 void clear(); 00056 00057 // access functions 00058 00059 /// Number of components 00060 int nComp() const; 00061 00062 /// Returns cell-centered box which defines fluxBox 00063 const Box& box() const; 00064 00065 /// Returns face-centered flux in direction \em dir 00066 FArrayBox& getFlux(const int dir); 00067 00068 /// Returns const reference to face-centered flux in direction \em dir 00069 const FArrayBox& getFlux(const int dir) const; 00070 00071 /// Returns FArrayBox in direction dir 00072 FArrayBox& operator[] (const int dir); 00073 00074 /// Constant version 00075 const FArrayBox& operator[] (const int dir) const; 00076 00077 // data modification functions 00078 00079 /// Set all fluxes to val 00080 void setVal(const Real val); 00081 00082 /// Set fluxes in direction dir to val 00083 void setVal(const Real val, const int dir); 00084 00085 /// More specific setVal 00086 void setVal(const Real val, const int dir, const int startComp, 00087 const int nComp); 00088 00089 /// Sets fluxes on faces surrounding cell-centered box bx 00090 void setVal(const Real val, const Box& bx); 00091 00092 /// Most specific setVal 00093 /** 00094 Sets fluxes on faces surrounding cell-centered box bx 00095 */ 00096 void setVal(const Real val, const Box& bx, const int dir, 00097 const int startComp, const int nComp); 00098 00099 /// Copy from src to this FluxBox -- sizes must be identical 00100 void copy(const FluxBox& src); 00101 00102 /// Copy on overlap, for all directions 00103 void copy(const FluxBox& src, const int srcComp, 00104 const int destComp, const int numComp); 00105 00106 /// Copy on overlap of FluxBoxes, in direction dir 00107 void copy(const FluxBox& src, const int dir, const int srcComp, 00108 const int destComp, const int numComp); 00109 00110 /** 00111 Modifies this FluxBox by copying the contents of the argument src 00112 into it. A copy within the intersecting region of the domains of the 00113 two FluxBoxes and the specified Box a_destbox is performed. All 00114 components are copied. 00115 */ 00116 void copy(const FluxBox& a_src, 00117 const Box& a_destbox); 00118 00119 00120 /// Copies from a subsection of one box into another. 00121 /** 00122 Assumes the boxes are both in the same index space, and that 00123 box R is completely contained in both the src and destination 00124 boxes. This function required by BoxLayoutData 00125 */ 00126 void copy(const Box& R, const Interval& Cdest, const FluxBox& src, 00127 const Interval& Csrc); 00128 00129 /// Modifies this FluxBox by copying the contents of \em src into it. 00130 /** 00131 This, the most general form 00132 of copy, specifies the contents of any sub-box srcbox 00133 in `FluxBox' src may be copied into a (possibly 00134 different) destbox in the destination `FluxBox'. Note 00135 that although the srcbox and the destbox may be 00136 disjoint, they must be the same size and shape. If the 00137 sizes differ, the copy is undefined and a runtime error 00138 results. This copy function is the only one of the 00139 copy functions to allow a copy between differing 00140 boxes. The user also specifies how many components are 00141 copied, starting at component srccomp in src and stored 00142 starting at component destcomp. The results are 00143 UNDEFINED if the src and dest FluxBoxes are the same and 00144 the srcbox and destbox overlap. 00145 */ 00146 void copy (const Box& srcbox, 00147 const Interval& destcomps, 00148 const Box& destbox, 00149 const FluxBox& src, 00150 const Interval& srccomps); 00151 00152 /// Modifies this FluxBox to its additive inverse. 00153 /** 00154 Modifies this FluxBox by replacing each value with its additive 00155 inverse, for the given range of components and within the given subbox. 00156 Returns *this. 00157 */ 00158 FluxBox& negate (const Box& subbox, 00159 int comp=0, 00160 int numcomp=1); 00161 00162 /// Modifies this FluxBox to its additive inverse. 00163 /** 00164 Modifies this FluxBox by replacing each value with its additive 00165 inverse, for the given range of components over the whole domain of 00166 the FluxBox. Returns *this. 00167 */ 00168 FluxBox& negate (int comp, 00169 int numcomp=1); 00170 00171 /// Modifies this FluxBox to its additive inverse. 00172 /** 00173 Modifies this FluxBox by replacing each value with its additive 00174 inverse for all components over the whole domain of the FluxBox. 00175 Returns *this. 00176 */ 00177 FluxBox& negate (); 00178 00179 00180 /// Modifies this FluxBox by adding src in the CELL-CENTERED sub-box 00181 /** 00182 Modifies this FluxBox by pointwise addition of values in the argument 00183 FArrayBox. Adds src's components (a_srccomp : a_srccomp+a_numcomp-1) 00184 to this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00185 where the domain of this FluxBox intersects the a_subbox. The actual 00186 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00187 NOTE: 00188 a_subbox must be contained in the cell-centered Box of this FluxBox. 00189 Returns *this 00190 */ 00191 FluxBox& plus(const FluxBox& a_src, 00192 const Box& a_subbox, 00193 int a_srccomp, 00194 int a_destcomp, 00195 int a_numcomp = 1); 00196 00197 00198 /// Modifies this FluxBox by subtracting src in the CELL-CENTERED sub-box 00199 /** 00200 Modifies this FluxBox by pointwise addition of values in the argument 00201 FArrayBox. Subtracts src's components (a_srccomp : a_srccomp+a_numcomp-1) 00202 from this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00203 where the domain of this FluxBox intersects the a_subbox. The actual 00204 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00205 NOTE: 00206 a_subbox must be contained in the cell-centered Box of this FluxBox. 00207 Returns *this 00208 */ 00209 FluxBox& minus(const FluxBox& a_src, 00210 const Box& a_subbox, 00211 int a_srccomp, 00212 int a_destcomp, 00213 int a_numcomp = 1); 00214 00215 00216 /// Modifies this FluxBox by multiplying src in the CELL-CENTERED sub-box 00217 /** 00218 Modifies this FluxBox by pointwise multiplication of values in the 00219 argument FArrayBox. Multiplies src's components 00220 (a_srccomp : a_srccomp+a_numcomp-1) with this FluxBox's components 00221 (a_destcomp : a_destcomp+numcomp-1) where the domain of this FluxBox 00222 intersects the a_subbox. The actual directionally-dependent subbox 00223 is a_subbox.surroundingNodes(dir); 00224 NOTE: 00225 a_subbox must be contained in the cell-centered Box of this FluxBox. 00226 Returns *this 00227 */ 00228 FluxBox& mult(const FluxBox& a_src, 00229 const Box& a_subbox, 00230 int a_srccomp, 00231 int a_destcomp, 00232 int a_numcomp = 1); 00233 00234 00235 /// Modifies this FluxBox by dividing src in the CELL-CENTERED sub-box 00236 /** 00237 Modifies this FluxBox by pointwise division of values in the argument 00238 FArrayBox. Divides src's components (a_srccomp : a_srccomp+a_numcomp-1) 00239 into this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00240 where the domain of this FluxBox intersects the a_subbox. The actual 00241 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00242 NOTE: 00243 a_subbox must be contained in the cell-centered Box of this FluxBox. 00244 Returns *this 00245 */ 00246 FluxBox& divide(const FluxBox& a_src, 00247 const Box& a_subbox, 00248 int a_srccomp, 00249 int a_destcomp, 00250 int a_numcomp = 1); 00251 00252 /// Modifies this FluxBox by adding the scalar Real r to all values. 00253 FluxBox& operator+= (Real r); 00254 00255 /// Modifies this FluxBox by incrementing with the argument FluxBox. 00256 /** 00257 Modifies this FluxBox by pointwise addition of the values of the 00258 argument FluxBox. You might come to grief if the domains of the 00259 FArrayBoxes don't match, just as in FArrayBox::plus(). 00260 */ 00261 FluxBox& operator+= (const FluxBox& f); 00262 00263 /// Modifies this FluxBox by subtracting the scalar Real r to all values. 00264 FluxBox& operator-= (Real r); 00265 00266 /// Modifies this FluxBox by decrementing with the argument FluxBox. 00267 /** 00268 Modifies this FluxBox by pointwise subtraction of the values of the 00269 argument FluxBox. You might come to grief if the domains of the 00270 FluxBoxes don't match, just as in FArrayBox::minus(). 00271 */ 00272 FluxBox& operator-= (const FluxBox& f); 00273 00274 /// Modifies this FluxBox by multiplying all values by the scalar Real r. 00275 FluxBox& operator*= (Real r); 00276 00277 /// Modifies this FluxBox by multiplying by the argument FluxBox. 00278 /** 00279 Modifies this FluxBox by pointwise multiplication of the values by the 00280 argument FluxBox. You might come to grief if the domains of the 00281 FluxBoxes don't match, just as in FArrayBox::mult(). 00282 */ 00283 FluxBox& operator*= (const FluxBox& f); 00284 00285 /// Modifies this FluxBox by shifting its domain box. 00286 FluxBox& shift (const IntVect& v); 00287 00288 // Linearization Functions 00289 00290 /// Returns size of linearized data over \em bx. 00291 /** 00292 Returns size, in number of bytes, of a flat linear 00293 representation of data in components comps in faces around 00294 cell-centered box R 00295 */ 00296 int size(const Box& bx, const Interval& comps) const; 00297 00298 /// Writes a linear representation of this FluxBox 00299 /** 00300 Write a linear representaion of the internal data for 00301 the faces surrounding cell-centered box R. Assumes that sufficient 00302 memory for the buffer has already been allocated by the caller 00303 */ 00304 void linearOut(void*buf, const Box& R, const Interval& comps) const; 00305 00306 /// like linearOut, but returns current position in the buffer 00307 void* linearOut2(void*buf, const Box& R, const Interval& comps) const; 00308 00309 /// Read a linear representation of the data over the Box \rm R 00310 /** 00311 Reads in the output of linearOut 00312 */ 00313 void linearIn(void*buf, const Box& R, const Interval& comps); 00314 00315 /// like linearInt, but returns current position in the buffer 00316 void* linearIn2(void*buf, const Box& R, const Interval& comps); 00317 00318 /// Helper function for linearization 00319 static int preAllocatable() 00320 { 00321 return 0; 00322 } 00323 00324 00325 protected: 00326 /** 00327 Cell-centered Box over which this FluxBox is defined 00328 */ 00329 Box m_bx; 00330 00331 /** 00332 Number of variables on each face 00333 */ 00334 int m_nvar; 00335 00336 /** 00337 CH_SPACEDIM FArrayBoxes which hold fluxes 00338 */ 00339 Vector<FArrayBox*> m_fluxes; 00340 00341 00342 private: 00343 // these are disallowed 00344 00345 /// Disallowed 00346 FluxBox (const FluxBox&); 00347 /// Disallowed 00348 FluxBox& operator = (const FluxBox&); 00349 00350 }; 00351 00352 #include "NamespaceFooter.H" 00353 #endif
1.5.5