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 /// Copies from a subsection of one box into another. 00120 /** 00121 Assumes the boxes are both in the same index space, and that 00122 box R is completely contained in both the src and destination 00123 boxes. This function required by BoxLayoutData 00124 */ 00125 void copy(const Box& R, const Interval& Cdest, const FluxBox& src, 00126 const Interval& Csrc); 00127 00128 /// Modifies this FluxBox by copying the contents of \em src into it. 00129 /** 00130 This, the most general form 00131 of copy, specifies the contents of any sub-box srcbox 00132 in `FluxBox' src may be copied into a (possibly 00133 different) destbox in the destination `FluxBox'. Note 00134 that although the srcbox and the destbox may be 00135 disjoint, they must be the same size and shape. If the 00136 sizes differ, the copy is undefined and a runtime error 00137 results. This copy function is the only one of the 00138 copy functions to allow a copy between differing 00139 boxes. The user also specifies how many components are 00140 copied, starting at component srccomp in src and stored 00141 starting at component destcomp. The results are 00142 UNDEFINED if the src and dest FluxBoxes are the same and 00143 the srcbox and destbox overlap. 00144 */ 00145 void copy (const Box& srcbox, 00146 const Interval& destcomps, 00147 const Box& destbox, 00148 const FluxBox& src, 00149 const Interval& srccomps); 00150 00151 /// Modifies this FluxBox to its additive inverse. 00152 /** 00153 Modifies this FluxBox by replacing each value with its additive 00154 inverse, for the given range of components and within the given subbox. 00155 Returns *this. 00156 */ 00157 FluxBox& negate (const Box& subbox, 00158 int comp=0, 00159 int numcomp=1); 00160 00161 /// Modifies this FluxBox to its additive inverse. 00162 /** 00163 Modifies this FluxBox by replacing each value with its additive 00164 inverse, for the given range of components over the whole domain of 00165 the FluxBox. Returns *this. 00166 */ 00167 FluxBox& negate (int comp, 00168 int numcomp=1); 00169 00170 /// Modifies this FluxBox to its additive inverse. 00171 /** 00172 Modifies this FluxBox by replacing each value with its additive 00173 inverse for all components over the whole domain of the FluxBox. 00174 Returns *this. 00175 */ 00176 FluxBox& negate (); 00177 00178 /// Modifies this FluxBox by adding src in the CELL-CENTERED sub-box 00179 /** 00180 Modifies this FluxBox by pointwise addition of values in the argument 00181 FArrayBox. Adds src's components (a_srccomp : a_srccomp+a_numcomp-1) 00182 to this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00183 where the domain of this FluxBox intersects the a_subbox. The actual 00184 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00185 NOTE: 00186 a_subbox must be contained in the cell-centered Box of this FluxBox. 00187 Returns *this 00188 */ 00189 FluxBox& plus(const FluxBox& a_src, 00190 const Box& a_subbox, 00191 int a_srccomp, 00192 int a_destcomp, 00193 int a_numcomp = 1); 00194 00195 /// Modifies this FluxBox by subtracting src in the CELL-CENTERED sub-box 00196 /** 00197 Modifies this FluxBox by pointwise addition of values in the argument 00198 FArrayBox. Subtracts src's components (a_srccomp : a_srccomp+a_numcomp-1) 00199 from this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00200 where the domain of this FluxBox intersects the a_subbox. The actual 00201 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00202 NOTE: 00203 a_subbox must be contained in the cell-centered Box of this FluxBox. 00204 Returns *this 00205 */ 00206 FluxBox& minus(const FluxBox& a_src, 00207 const Box& a_subbox, 00208 int a_srccomp, 00209 int a_destcomp, 00210 int a_numcomp = 1); 00211 00212 /// Modifies this FluxBox by multiplying src in the CELL-CENTERED sub-box 00213 /** 00214 Modifies this FluxBox by pointwise multiplication of values in the 00215 argument FArrayBox. Multiplies src's components 00216 (a_srccomp : a_srccomp+a_numcomp-1) with this FluxBox's components 00217 (a_destcomp : a_destcomp+numcomp-1) where the domain of this FluxBox 00218 intersects the a_subbox. The actual directionally-dependent subbox 00219 is a_subbox.surroundingNodes(dir); 00220 NOTE: 00221 a_subbox must be contained in the cell-centered Box of this FluxBox. 00222 Returns *this 00223 */ 00224 FluxBox& mult(const FluxBox& a_src, 00225 const Box& a_subbox, 00226 int a_srccomp, 00227 int a_destcomp, 00228 int a_numcomp = 1); 00229 00230 /// Modifies this FluxBox by dividing src in the CELL-CENTERED sub-box 00231 /** 00232 Modifies this FluxBox by pointwise division of values in the argument 00233 FArrayBox. Divides src's components (a_srccomp : a_srccomp+a_numcomp-1) 00234 into this FluxBox's components (a_destcomp : a_destcomp+numcomp-1) 00235 where the domain of this FluxBox intersects the a_subbox. The actual 00236 directionally-dependent subbox is a_subbox.surroundingNodes(dir); 00237 NOTE: 00238 a_subbox must be contained in the cell-centered Box of this FluxBox. 00239 Returns *this 00240 */ 00241 FluxBox& divide(const FluxBox& a_src, 00242 const Box& a_subbox, 00243 int a_srccomp, 00244 int a_destcomp, 00245 int a_numcomp = 1); 00246 00247 /// Modifies this FluxBox by adding the scalar Real r to all values. 00248 FluxBox& operator+= (Real r); 00249 00250 /// Modifies this FluxBox by incrementing with the argument FluxBox. 00251 /** 00252 Modifies this FluxBox by pointwise addition of the values of the 00253 argument FluxBox. You might come to grief if the domains of the 00254 FArrayBoxes don't match, just as in FArrayBox::plus(). 00255 */ 00256 FluxBox& operator+= (const FluxBox& f); 00257 00258 /// Modifies this FluxBox by subtracting the scalar Real r to all values. 00259 FluxBox& operator-= (Real r); 00260 00261 /// Modifies this FluxBox by decrementing with the argument FluxBox. 00262 /** 00263 Modifies this FluxBox by pointwise subtraction of the values of the 00264 argument FluxBox. You might come to grief if the domains of the 00265 FluxBoxes don't match, just as in FArrayBox::minus(). 00266 */ 00267 FluxBox& operator-= (const FluxBox& f); 00268 00269 /// Modifies this FluxBox by multiplying all values by the scalar Real r. 00270 FluxBox& operator*= (Real r); 00271 00272 /// Modifies this FluxBox by multiplying by the argument FluxBox. 00273 /** 00274 Modifies this FluxBox by pointwise multiplication of the values by the 00275 argument FluxBox. You might come to grief if the domains of the 00276 FluxBoxes don't match, just as in FArrayBox::mult(). 00277 */ 00278 FluxBox& operator*= (const FluxBox& f); 00279 00280 /// Modifies this FluxBox by shifting its domain box. 00281 FluxBox& shift (const IntVect& v); 00282 00283 // Linearization Functions 00284 00285 /// Returns size of linearized data over \em bx. 00286 /** 00287 Returns size, in number of bytes, of a flat linear 00288 representation of data in components comps in faces around 00289 cell-centered box R 00290 */ 00291 int size(const Box& bx, const Interval& comps) const; 00292 00293 /// Writes a linear representation of this FluxBox 00294 /** 00295 Write a linear representaion of the internal data for 00296 the faces surrounding cell-centered box R. Assumes that sufficient 00297 memory for the buffer has already been allocated by the caller 00298 */ 00299 void linearOut(void*buf, const Box& R, const Interval& comps) const; 00300 00301 /// like linearOut, but returns current position in the buffer 00302 void* linearOut2(void*buf, const Box& R, const Interval& comps) const; 00303 00304 /// Read a linear representation of the data over the Box \rm R 00305 /** 00306 Reads in the output of linearOut 00307 */ 00308 void linearIn(void*buf, const Box& R, const Interval& comps); 00309 00310 /// like linearInt, but returns current position in the buffer 00311 void* linearIn2(void*buf, const Box& R, const Interval& comps); 00312 00313 /// Helper function for linearization 00314 static int preAllocatable() 00315 { 00316 return 0; 00317 } 00318 00319 00320 protected: 00321 /** 00322 Cell-centered Box over which this FluxBox is defined 00323 */ 00324 Box m_bx; 00325 00326 /** 00327 Number of variables on each face 00328 */ 00329 int m_nvar; 00330 00331 /** 00332 CH_SPACEDIM FArrayBoxes which hold fluxes 00333 */ 00334 Vector<FArrayBox*> m_fluxes; 00335 00336 00337 private: 00338 // these are disallowed 00339 00340 /// Disallowed 00341 FluxBox (const FluxBox&); 00342 /// Disallowed 00343 FluxBox& operator = (const FluxBox&); 00344 00345 }; 00346 00347 #include "NamespaceFooter.H" 00348 #endif