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