Chombo + EB  3.2
SimpleAdaptor.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 _SIMPLEADAPTOR_H
12 #define _SIMPLEADAPTOR_H
13 
14 #include "ChomboSundialsAdaptor.H"
15 
16 #include "LevelData.H"
17 #include "FArrayBox.H"
18 
19 /// Class to interface a LevelData<FArrayBox> with SUNDIALS
20 /**
21  This class implements all the required NVector methods for
22  SUNDIALS to call on a LevelData<FArrayBox>, works in parallel.
23  Output available using HDF5.
24 
25  Calling context must allocate memory in the LevelData, and then
26  set the public Data member variable and others. This will call
27  *delete* on Data in the destructor.
28 
29  Note that many of the SUNDIALS NVector operations allow the object
30  itself to be passed for an in-place update, check each function.
31  */
33 {
34 
35 public:
36  ///
37  /**
38  Constructor
39  */
41  ///
42  /**
43  Destructor - calls delete on Data pointer.
44  */
45  virtual ~SimpleAdaptor()
46  {
47  if (m_ownData && (m_data != NULL))
48  delete m_data;
49  };
50 
51  ///
52  /**
53  Define from an existing %LevelData<FArrayBox>.
54  <ul>
55  <li> lvlData: pointers to the %LevelData<FArrayBox>
56  <li> ownData: (true) delete pointer in destructor
57  </ul>
58  */
59  void define(LevelData<FArrayBox>* lvlData, bool ownData);
60 
61  ///
62  /**
63  Get the %LevelData<FArrayBox> data pointer.
64  */
65  LevelData<FArrayBox>* getData() { return this->m_data; };
66 
67  ///
68  /**
69  Get the flag for owning data deallocation
70  */
71  bool getOwnData() { return this->m_ownData; };
72 
73  ///
74  /**
75  SUNDIALS operation - calculates a*x+b*y and puts in this instance's data
76  */
78  Real a, Real b);
79  ///
80  /**
81  SUNDIALS operation - sets this instance's data to c
82  */
83  virtual void setConst(Real c);
84  ///
85  /**
86  SUNDIALS operation - sets this instance's data to x*y
87  */
88  virtual void prod(ChomboSundialsAdaptor& ax, ChomboSundialsAdaptor& ay);
89  ///
90  /**
91  SUNDIALS operation - sets this instance's data to x/y
92  */
93  virtual void div(ChomboSundialsAdaptor& ax, ChomboSundialsAdaptor& ay);
94  ///
95  /**
96  SUNDIALS operation - sets this instance's data to c*x
97  */
98  virtual void scale(ChomboSundialsAdaptor& ax, Real c);
99  ///
100  /**
101  SUNDIALS operation - sets this instance's data to abs(x)
102  */
103  virtual void abs(ChomboSundialsAdaptor& ax);
104  ///
105  /**
106  SUNDIALS operation - sets this instance's data to 1/x
107  */
108  virtual void inv(ChomboSundialsAdaptor& ax);
109  ///
110  /**
111  SUNDIALS operation - sets this instance's data to x+b
112  */
113  virtual void addConst(ChomboSundialsAdaptor& ax, Real b);
114  ///
115  /**
116  SUNDIALS operation - returns MPI-sum dot product sum(data^T * input)
117  across all MPI ranks
118  */
119  virtual Real dotProd(ChomboSundialsAdaptor& ax);
120  ///
121  /**
122  SUNDIALS operation - returns MPI-reduce across all MPI ranks' data max norm
123  */
124  virtual Real maxNorm();
125  ///
126  /**
127  SUNDIALS operation - returns MPI-reduce across all ranks' data
128  weighted RMS (root mean square) norm
129  */
130  virtual Real wRMSNorm(ChomboSundialsAdaptor& aw);
131  ///
132  /**
133  SUNDIALS operation - not implemented, Aborts
134  */
136  ///
137  /**
138  SUNDIALS operation - returns MPI-reduce across all ranks' data min
139  */
140  virtual Real min();
141  ///
142  /**
143  SUNDIALS operation - returns MPI-reduce L1 norm (sum abs values)
144  */
145  virtual Real l1Norm();
146  ///
147  /**
148  SUNDIALS operation - not implemented, Aborts
149  */
150  virtual Real wL2Norm(ChomboSundialsAdaptor& aw);
151  ///
152  /**
153  SUNDIALS operation - not implemented, Aborts
154  */
155  virtual void compare(ChomboSundialsAdaptor& ax, Real b);
156  ///
157  /**
158  SUNDIALS operation - not implemented, Aborts
159  */
160  virtual bool invTest(ChomboSundialsAdaptor& ax);
161  ///
162  /**
163  SUNDIALS operation - not implemented, Aborts
164  */
166  ///
167  /**
168  SUNDIALS operation - not implemented, Aborts
169  */
170  virtual Real minQuotient(ChomboSundialsAdaptor& adenom);
171 
172  ///
173  /**
174  SUNDIALS operation - returns the total number of interior cells
175  multiplied by the number of components
176  */
177  virtual unsigned long getLength();
178  ///
179  /**
180  Call exchange on the underlying LevelData<FArrayBox>
181  */
182  virtual void exchange()
183  {
185  }
186  ///
187  /**
188  Calls dumpLDFPar - careful, very verbose
189  */
190  virtual void print();
191  ///
192  /**
193  SUNDIALS operation - not implemented, Aborts
194  */
195  virtual void printFile(FILE* outfile);
196 #ifdef CH_USE_HDF5
197  ///
198  /**
199  Calls writeLevelname to produce HDF5 output
200  */
201  virtual void printFileHDF(const char* filename);
202 #endif
203 
204  ///
205  /**
206  Uses MPI to copy values from this to arg, only if DBLs are the same.
207  Returns true if the copy was succesful, false otherwise.
208  */
209  virtual bool copyTo(ChomboSundialsAdaptor& a)
210  {
211  SimpleAdaptor* sa = dynamic_cast<SimpleAdaptor*>(&a);
212  if (sa == NULL) return false;
213  if (!(m_data->disjointBoxLayout() == sa->m_data->disjointBoxLayout()))
214  return false;
215  m_data->copyTo(*sa->m_data);
216  return true;
217  }
218 
219  ///
220  /**
221  Factory, creates a clone of this and allocates new data (not copied).
222  */
224  {
225  SimpleAdaptor* adaptor = new SimpleAdaptor();
226  adaptor->m_dp = m_dp;
227  adaptor->m_nComp = m_nComp;
228  adaptor->m_ghost = m_ghost;
229  adaptor->m_data = new LevelData<FArrayBox>;
230  adaptor->m_data->define(m_dp, m_nComp, m_ghost);
231  adaptor->m_ownData = true;
232  return adaptor;
233  }
234 
235 private:
236  // Private Member variables
237  //! Pointer to LevelData<FArrayBox> data this wraps
239  //! DisjointBoxLayout of the %LevelData<FArrayBox>
241  //! Number of components in the %LevelData<FArrayBox>
242  int m_nComp;
243  //! Number of ghost cells in the %LevelData<FArrayBox>
245  //! If true, will call delete in destructor
246  bool m_ownData = false;
247 
248 };
249 
250 #endif
virtual void prod(ChomboSundialsAdaptor &ax, ChomboSundialsAdaptor &ay)
virtual Real l1Norm()
Interval interval() const
Definition: BoxLayoutData.H:312
virtual Real min()
virtual void inv(ChomboSundialsAdaptor &ax)
virtual void addConst(ChomboSundialsAdaptor &ax, Real b)
virtual void printFile(FILE *outfile)
virtual bool invTest(ChomboSundialsAdaptor &ax)
virtual ~SimpleAdaptor()
Definition: SimpleAdaptor.H:45
virtual Real minQuotient(ChomboSundialsAdaptor &adenom)
virtual unsigned long getLength()
virtual void print()
bool m_ownData
If true, will call delete in destructor.
Definition: SimpleAdaptor.H:246
Virtual base class contract to interact with SUNDIALS.
Definition: ChomboSundialsAdaptor.H:26
LevelData< FArrayBox > * getData()
Definition: SimpleAdaptor.H:65
virtual void printFileHDF(const char *filename)
bool getOwnData()
Definition: SimpleAdaptor.H:71
virtual Real wRMSNormMask(ChomboSundialsAdaptor &aw, ChomboSundialsAdaptor &aid)
virtual ChomboSundialsAdaptor * newAdaptor()
Definition: SimpleAdaptor.H:223
virtual void exchange(void)
Simplest case – do all components.
Definition: LevelDataI.H:470
virtual Real dotProd(ChomboSundialsAdaptor &ax)
virtual void exchange()
Definition: SimpleAdaptor.H:182
virtual void compare(ChomboSundialsAdaptor &ax, Real b)
int m_nComp
Number of components in the LevelData<FArrayBox>
Definition: SimpleAdaptor.H:242
double Real
Definition: REAL.H:33
virtual void define(const DisjointBoxLayout &dp, int comps, const IntVect &ghost=IntVect::Zero, const DataFactory< T > &a_factory=DefaultDataFactory< T >())
Definition: LevelDataI.H:93
virtual void copyTo(const Interval &srcComps, BoxLayoutData< T > &dest, const Interval &destComps) const
Definition: LevelDataI.H:221
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
LevelData< FArrayBox > * m_data
Pointer to LevelData<FArrayBox> data this wraps.
Definition: SimpleAdaptor.H:238
virtual void abs(ChomboSundialsAdaptor &ax)
SimpleAdaptor()
Definition: SimpleAdaptor.H:40
IntVect m_ghost
Number of ghost cells in the LevelData<FArrayBox>
Definition: SimpleAdaptor.H:244
virtual void setConst(Real c)
virtual void div(ChomboSundialsAdaptor &ax, ChomboSundialsAdaptor &ay)
DisjointBoxLayout m_dp
DisjointBoxLayout of the LevelData<FArrayBox>
Definition: SimpleAdaptor.H:240
virtual void linearSum(ChomboSundialsAdaptor &x, ChomboSundialsAdaptor &y, Real a, Real b)
virtual Real maxNorm()
const DisjointBoxLayout & disjointBoxLayout() const
Definition: LevelData.H:225
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
virtual bool constrMask(ChomboSundialsAdaptor &ac, ChomboSundialsAdaptor &am)
Class to interface a LevelData<FArrayBox> with SUNDIALS.
Definition: SimpleAdaptor.H:32
virtual Real wRMSNorm(ChomboSundialsAdaptor &aw)
virtual void scale(ChomboSundialsAdaptor &ax, Real c)
virtual Real wL2Norm(ChomboSundialsAdaptor &aw)
void define(LevelData< FArrayBox > *lvlData, bool ownData)
virtual bool copyTo(ChomboSundialsAdaptor &a)
Definition: SimpleAdaptor.H:209