Chombo + EB  3.2
AmrAdaptor.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _AMRADAPTOR_H
12 #define _AMRADAPTOR_H
13 
14 #include "ChomboSundialsAdaptor.H"
15 
16 #include "LevelData.H"
17 #include "FArrayBox.H"
18 
19 /// Data holder for %AMR hierarchy data to interact with SUNDIALS.
20 /**
21  This class supports most of the operations needed by SUNDIALS nvector,
22  mapped onto an %AMR hierarchy of LevelData<FArrayBox>. It works in parallel
23  and serial, and uses masks to make sure covered cells on coarse levels don't
24  contribute to calculations needed by SUNDIALS. It is dumb, in that if any of
25  the %AMR hierarchy is regridded or redefined, this must be redefined as well.
26 
27  Note that many of the SUNDIALS NVector operations allow the object itself to
28  be passed for an in-place update, check each function.
29  */
31 {
32 
33 public:
34  ///
35  /**
36  Constructor.
37  */
39 
40  ///
41  /**
42  Destructor.
43  */
44  virtual ~AmrAdaptor() {
45  int nlvl = m_amrData.size();
46  for (int lvl=0; lvl < nlvl; lvl++)
47  {
48  if (m_ownData && (m_amrData[lvl] != NULL))
49  delete m_amrData[lvl];
50  if (m_amrMask[lvl] != NULL)
51  delete m_amrMask[lvl];
52  }
53  };
54 
55  ///
56  /**
57  Factory.
58  */
60 
61  ///
62  /**
63  Define from an existing %AMR hierarchy.
64  <ul>
65  <li> amrData: vector of pointers to all the %LevelData<FArrayBox> in the hierarchy
66  <li> refRatio: vector of integer refinement ratios between levels
67  <li> finestLevel: finest active AMR level (may not be using all available levels)
68  <li> ownData: (true) delete pointers in destructor
69  </ul>
70  Redefines and calculates masks. Calls delete on amrData and masks pointers in destructor.
71  */
72  void define(Vector<LevelData<FArrayBox>*> amrData, Vector<int> refRatio,
73  int finestLevel, bool ownData);
74 
75  ///
76  /**
77  Get the %AMR data pointers.
78  */
80 
81  ///
82  /**
83  Get the refinement ratios.
84  */
85  Vector<int> getRefRatio() { return this->m_refRatio; };
86 
87  ///
88  /**
89  Get the finest active AMR level
90  */
91  size_t getFinestLevel() {return this->m_finestLevel;}
92 
93  ///
94  /**
95  Get the flag for owning data deallocation
96  */
97  bool getOwnData() { return this->m_ownData; };
98 
99  ///
100  /**
101  SUNDIALS operation - calculates a*x+b*y and puts in this instance's data
102  */
104  Real a, Real b);
105  ///
106  /**
107  SUNDIALS operation - sets this instance's data to c
108  */
109  virtual void setConst(Real c);
110  ///
111  /**
112  SUNDIALS operation - sets this instance's data to x*y
113  */
114  virtual void prod(ChomboSundialsAdaptor& ax, ChomboSundialsAdaptor& ay);
115  ///
116  /**
117  SUNDIALS operation - sets this instance's data to x/y
118  */
119  virtual void div(ChomboSundialsAdaptor& ax, ChomboSundialsAdaptor& ay);
120  ///
121  /**
122  SUNDIALS operation - sets this instance's data to c*x
123  */
124  virtual void scale(ChomboSundialsAdaptor& ax, Real c);
125  ///
126  /**
127  SUNDIALS operation - sets this instance's data to abs(x)
128  */
129  virtual void abs(ChomboSundialsAdaptor& ax);
130  ///
131  /**
132  SUNDIALS operation - sets this instance's data to 1/x
133  */
134  virtual void inv(ChomboSundialsAdaptor& ax);
135  ///
136  /**
137  SUNDIALS operation - sets this instance's data to x+b
138  */
139  virtual void addConst(ChomboSundialsAdaptor& ax, Real b);
140  ///
141  /**
142  SUNDIALS operation - returns MPI-sum dot product across all ranks,
143  sum(data^T * input), masked for covered cells
144  */
145  virtual Real dotProd(ChomboSundialsAdaptor& ax);
146  ///
147  /**
148  SUNDIALS operation - returns MPI-reduce across all ranks' data max norm,
149  masked for covered cells
150  */
151  virtual Real maxNorm();
152  ///
153  /**
154  SUNDIALS operation - returns MPI-reduce across all ranks' data
155  weighted RMS (root mean square) norm, masked for covered cells
156  */
157  virtual Real wRMSNorm(ChomboSundialsAdaptor& aw);
158  ///
159  /**
160  SUNDIALS operation - not implemented, Aborts
161  */
163  ///
164  /**
165  SUNDIALS operation - returns MPI-reduce across all ranks' data min,
166  masked for covered cells
167  */
168  virtual Real min();
169  ///
170  /**
171  SUNDIALS operation - not implemented, Aborts
172  */
173  virtual Real wL2Norm(ChomboSundialsAdaptor& aw);
174  ///
175  /**
176  SUNDIALS operation - not implemented, Aborts
177  */
178  virtual void compare(ChomboSundialsAdaptor& ax, Real b);
179  ///
180  /**
181  SUNDIALS operation - not implemented, Aborts
182  */
183  virtual bool invTest(ChomboSundialsAdaptor& ax);
184  ///
185  /**
186  SUNDIALS operation - not implemented, Aborts
187  */
189  ///
190  /**
191  SUNDIALS operation - not implemented, Aborts
192  */
193  virtual Real minQuotient(ChomboSundialsAdaptor& adenom);
194  ///
195  /**
196  SUNDIALS operation - returns the total number of *uncovered* %AMR cells
197  multiplied by the number of components
198  */
199  virtual unsigned long getLength();
200  ///
201  /**
202  SUNDIALS operation - returns MPI-reduce across all ranks' data L1 norm
203  (sum abs values), no dx or refinement ratio, masked for covered cells
204  */
205  virtual Real l1Norm();
206  ///
207  /**
208  Not implemented, Aborts
209  */
210  virtual void print();
211  ///
212  /**
213  Not implemented, Aborts
214  */
215  virtual void printFile(FILE* outfile);
216 #if CH_USE_HDF5
217  ///
218  /**
219  Not implemented, Aborts
220  */
221  virtual void printFileHDF(const char* filename);
222 #endif
223  ///
224  /**
225  Not implemented, Aborts
226  */
227  virtual bool copyTo(ChomboSundialsAdaptor& a);
228  ///
229  /**
230  Not implemented, Aborts
231  */
232  virtual void exchange();
233 
234 
235  // Member variables
236  //! Pointers to %AMR hierarchy data
238  //! %AMR hierarchy refinement ratios between levels
240  //! finest active AMR level
242  //! %AMR mask, 1 for uncovered values, 0 for covered values
243  Vector<LevelData<FArrayBox>*> m_amrMask; // To help with efficient ops
244  //! Cached nvector length, sum of all unmasked values, across all ranks
245  unsigned long m_length = -1;
246  //! Number of components in the %LevelData<FArrayBox>'s
247  int m_comp = -1;
248  //! If true, will call delete in destructor
249  bool m_ownData = false;
250 
251 private:
252 };
253 
254 #endif
Vector< LevelData< FArrayBox > * > getData()
Definition: AmrAdaptor.H:79
virtual void compare(ChomboSundialsAdaptor &ax, Real b)
void define(Vector< LevelData< FArrayBox > *> amrData, Vector< int > refRatio, int finestLevel, bool ownData)
virtual bool constrMask(ChomboSundialsAdaptor &ac, ChomboSundialsAdaptor &am)
virtual Real dotProd(ChomboSundialsAdaptor &ax)
virtual void setConst(Real c)
bool getOwnData()
Definition: AmrAdaptor.H:97
virtual void prod(ChomboSundialsAdaptor &ax, ChomboSundialsAdaptor &ay)
virtual void linearSum(ChomboSundialsAdaptor &x, ChomboSundialsAdaptor &y, Real a, Real b)
virtual bool copyTo(ChomboSundialsAdaptor &a)
virtual unsigned long getLength()
one dimensional dynamic array
Definition: Vector.H:53
virtual void abs(ChomboSundialsAdaptor &ax)
virtual ChomboSundialsAdaptor * newAdaptor()
virtual void printFileHDF(const char *filename)
Vector< LevelData< FArrayBox > * > m_amrData
Pointers to AMR hierarchy data.
Definition: AmrAdaptor.H:237
Virtual base class contract to interact with SUNDIALS.
Definition: ChomboSundialsAdaptor.H:26
Data holder for AMR hierarchy data to interact with SUNDIALS.
Definition: AmrAdaptor.H:30
unsigned long m_length
Cached nvector length, sum of all unmasked values, across all ranks.
Definition: AmrAdaptor.H:245
virtual Real wL2Norm(ChomboSundialsAdaptor &aw)
virtual Real l1Norm()
virtual ~AmrAdaptor()
Definition: AmrAdaptor.H:44
virtual void inv(ChomboSundialsAdaptor &ax)
Vector< int > m_refRatio
AMR hierarchy refinement ratios between levels
Definition: AmrAdaptor.H:239
virtual void div(ChomboSundialsAdaptor &ax, ChomboSundialsAdaptor &ay)
virtual Real min()
virtual Real minQuotient(ChomboSundialsAdaptor &adenom)
virtual void exchange()
double Real
Definition: REAL.H:33
virtual void print()
size_t size() const
Definition: Vector.H:192
bool m_ownData
If true, will call delete in destructor.
Definition: AmrAdaptor.H:249
AmrAdaptor()
Definition: AmrAdaptor.H:38
virtual void printFile(FILE *outfile)
size_t getFinestLevel()
Definition: AmrAdaptor.H:91
virtual Real maxNorm()
Vector< int > getRefRatio()
Definition: AmrAdaptor.H:85
int m_comp
Number of components in the LevelData<FArrayBox>&#39;s.
Definition: AmrAdaptor.H:247
Vector< LevelData< FArrayBox > * > m_amrMask
AMR mask, 1 for uncovered values, 0 for covered values
Definition: AmrAdaptor.H:243
virtual void scale(ChomboSundialsAdaptor &ax, Real c)
virtual bool invTest(ChomboSundialsAdaptor &ax)
virtual Real wRMSNorm(ChomboSundialsAdaptor &aw)
virtual void addConst(ChomboSundialsAdaptor &ax, Real b)
virtual Real wRMSNormMask(ChomboSundialsAdaptor &aw, ChomboSundialsAdaptor &aid)
size_t m_finestLevel
finest active AMR level
Definition: AmrAdaptor.H:241