Chombo + EB + MF  3.2
AMRDataFileIF.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 _AMRDATAFILEIF_H_
12 #define _AMRDATAFILEIF_H_
13 
14 #include <iostream>
15 #include <fstream>
16 using std::istream;
17 using std::ifstream;
18 
19 #include "MayDay.H"
20 #include "RealVect.H"
21 #include "IntVectSet.H"
22 #include "FArrayBox.H"
23 #include "LevelData.H"
24 #include "Vector.H"
25 #include "RefCountedPtr.H"
26 
27 #include "BaseIF.H"
28 
29 #include "NamespaceHeader.H"
30 
31 ///
32 /**
33  This implicit function reads data from a Chombo AMR HDF5 file and produces function values
34  from the data read. The data lies on an AMR hierarchy of rectilinear grids specified in the file.
35  Function values within the data region are
36  obtained using trilinear interpolation. Function values outside the data
37  region are the maximum value of the data read.
38 
39  */
40 
41 class AMRDataFileIF: public BaseIF
42 {
43 public:
44  ///
45 
46  ///
47  /**
48  Constructor specifying filename (a_filename), level set value (a_value), and whether
49  inside the domain is where data is less than the level set value
50  (a_inside). Data is read from the file named, which must be a Chombo AMR HDF5 file.
51  */
52  AMRDataFileIF(const char* const a_filename,
53  const Real& a_value,
54  const bool& a_inside,
55  const bool& a_useCubicInterp = false);
56 
57 
58  /// Copy constructor
59  AMRDataFileIF(const AMRDataFileIF& a_inputIF);
60 
61  ///
62  /**
63  This is used by the factory (see below) to create a new object. All
64  objects created in this way share a refcounted pointer to their data.
65 
66  Constructor specifying a refcounted pointer to the data (a_real_data
67  or a_char_data), the no data value (a_noDataValue), the spacing
68  (a_spacing), the physical origin (a_origin), the number of grid points
69  in each direction (a_num), a level set value (a_value), and whether
70  inside the domain is where data is less than the level set value
71  (a_inside).
72  */
74  const RefCountedPtr<BaseFab<unsigned char> > a_char_data,
75  const Real& a_noDataValue,
76  const Box& a_baseDomain,
77  const Vector<RealVect>& a_spacing,
78  const RealVect& a_origin,
79  const Vector<int>& a_refRatio,
80  const Real& a_value,
81  const bool& a_inside,
82  const bool& a_useCubicInterp = false);
83 
84  /// Destructor
85  virtual ~AMRDataFileIF();
86 
87  ///
88  /**
89  Return the header information
90  */
91  virtual void GetHeader(Box& a_baseDomain,
92  Vector<RealVect>& a_vectDx,
93  RealVect& a_origin) const;
94 
95  ///
96  /**
97  Return the parameter information
98  */
99  virtual void GetParams(Real& a_value,
100  bool& a_inside,
101  bool& a_useCubicInterp) const;
102 
103  ///
104  /**
105  Set the parameter information
106  */
107  virtual void SetParams(const Real& a_value,
108  const bool& a_inside,
109  const bool& a_useCubicInterp = false);
110 
111  ///
112  /**
113  value to use when we are outside
114  */
115  virtual void SetNoDataValue(const Real& a_value);
116 
117  ///
118  /**
119  Return the value of the function at a_point using trilinear interpolation
120  of the data. If a_point is outside the data then return the maximum data
121  value.
122  */
123  virtual Real value(const RealVect& a_point) const;
124 
125  virtual Real value(const IndexTM<Real,GLOBALDIM>& a_point) const;
126 
127  virtual Real value(const IndexTM<int,GLOBALDIM> & a_partialDerivative,
128  const IndexTM<Real,GLOBALDIM>& a_point) const;
129 
130  virtual BaseIF* newImplicitFunction() const;
131 
132  void GetFullHeader(Box& a_baseDomain,
133  Vector<RealVect>& a_vectDx,
134  RealVect& a_origin)
135  {
136  a_baseDomain = m_baseDomain;
137  a_vectDx = m_vectDx;
138  a_origin = m_origin;
139  }
140 
142  {
143  return m_real_data;
144  }
145 
147  {
148  return m_char_data;
149  }
150 
151 protected:
152  void ReadData(Real& a_maxValue,
153  const char* const a_filename);
154 
155  void MakeCorners(void);
156 
157  Box m_baseDomain; // number of grid points in each direction
158  Vector<RealVect> m_vectDx; // grid spacing (in physical coordinates)
159  RealVect m_origin; // grid origin (in physical coordinates)
160 
161  Real m_value; // level set value
162  bool m_inside; // inside less than flag
163 
166 
167  // the data - copies all share this
168  RefCountedPtr<Vector<LevelData<FArrayBox>* > > m_real_data; // Real data stored as Real
169  RefCountedPtr<BaseFab<unsigned char> > m_char_data; // Char data stored as unsigned char's
170 
171  Real m_noDataValue; // no data value
172 
173  IntVectSet m_cornersLinear; // corners of a 1x1 box for linear interpolation
174  IntVectSet m_cornersCubic; // corners of a 4x4 box for cubic interpolation
175 
177 
178 private:
180  {
181  MayDay::Abort("AMRDataFileIF uses strong construction");
182  }
183 
184  void operator=(const AMRDataFileIF& a_inputIF)
185  {
186  MayDay::Abort("AMRDataFileIF doesn't allow assignment");
187  }
188 };
189 
190 #include "NamespaceFooter.H"
191 #endif
Real m_value
Definition: AMRDataFileIF.H:161
virtual BaseIF * newImplicitFunction() const
A reference-counting handle class.
Definition: RefCountedPtr.H:173
void operator=(const AMRDataFileIF &a_inputIF)
Definition: AMRDataFileIF.H:184
An irregular domain on an integer lattice.
Definition: IntVectSet.H:44
Real m_noDataValue
Definition: AMRDataFileIF.H:171
IntVectSet m_cornersLinear
Definition: AMRDataFileIF.H:173
one dimensional dynamic array
Definition: Vector.H:53
bool m_inside
Definition: AMRDataFileIF.H:162
Box m_baseDomain
Definition: AMRDataFileIF.H:157
RefCountedPtr< Vector< LevelData< FArrayBox > *> > m_real_data
Definition: AMRDataFileIF.H:168
Vector< RealVect > m_vectDx
Definition: AMRDataFileIF.H:158
RefCountedPtr< BaseFab< unsigned char > > GetCharData(void)
Definition: AMRDataFileIF.H:146
bool m_useCubicInterp
Definition: AMRDataFileIF.H:176
Definition: BaseIF.H:32
double Real
Definition: REAL.H:33
virtual void GetHeader(Box &a_baseDomain, Vector< RealVect > &a_vectDx, RealVect &a_origin) const
Vector< int > m_refRatio
Definition: AMRDataFileIF.H:164
virtual void GetParams(Real &a_value, bool &a_inside, bool &a_useCubicInterp) const
RealVect m_origin
Definition: AMRDataFileIF.H:159
AMRDataFileIF()
Definition: AMRDataFileIF.H:179
IntVectSet m_cornersCubic
Definition: AMRDataFileIF.H:174
RefCountedPtr< BaseFab< unsigned char > > m_char_data
Definition: AMRDataFileIF.H:169
void MakeCorners(void)
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
Definition: AMRDataFileIF.H:41
int m_numLevels
Definition: AMRDataFileIF.H:165
virtual Real value(const RealVect &a_point) const
virtual void SetParams(const Real &a_value, const bool &a_inside, const bool &a_useCubicInterp=false)
RefCountedPtr< FArrayBox > GetRealData(void)
Definition: AMRDataFileIF.H:141
virtual ~AMRDataFileIF()
Destructor.
void ReadData(Real &a_maxValue, const char *const a_filename)
virtual void SetNoDataValue(const Real &a_value)
void GetFullHeader(Box &a_baseDomain, Vector< RealVect > &a_vectDx, RealVect &a_origin)
Definition: AMRDataFileIF.H:132
static void Abort(const char *const a_msg=m_nullString)
Print out message to cerr and exit via abort() (if serial) or MPI_Abort() (if parallel).