Block-Structured AMR Software Framework
AMReX_AmrData.H
Go to the documentation of this file.
1 // ---------------------------------------------------------------
2 // AmrData.H
3 // ---------------------------------------------------------------
4 #ifndef AMREX_AMRDATA_H_
5 #define AMREX_AMRDATA_H_
6 #include <AMReX_Config.H>
7 
9 #include <AMReX_Array.H>
10 #include <AMReX_Vector.H>
11 #include <AMReX_MultiFab.H>
12 #include <AMReX_VisMF.H>
13 
14 #include <iosfwd>
15 #include <string>
16 
17 namespace amrex {
18 
19 class AmrData {
20 
21  protected:
22  // List of grids at each level, level 0 being coarsest.
23  Vector<Vector<MultiFab *> > dataGrids; // [level][component]
24  Vector<Vector<std::vector<bool> > > dataGridsDefined; // [level][component][index]
25  Vector<Vector<VisMF *> > visMF; // [level][whichMultiFab]
28 
29  int finestLevel; // most refined level available
30  Vector<int> refRatio; // refinement ratio between level L and L+1
31  Vector< Vector<Real> > dxLevel; // [level][dim]; // grid spacing
34  Vector<Box> maxDomain; // max problem domain size
36  Real time;
39  int nComp, nGrow;
40  int nRegions; // number of boundary regions
41  int boundaryWidth; // number of zones in the boundary regions
42  int coordSys;
43  Vector< Vector< FArrayBox *> > regions; // [lev][nReg] ptrs to bndry data
44  BoxArray fabBoxArray; // used only for fileType == Amrvis::FAB
45  std::string plotFileVersion;
46 
49  int vCartGrid; // ---- the CartGrid version
50  bool bTerrain;
52 
53  public:
54  AmrData();
55  ~AmrData();
56 
57  bool ReadData(const std::string &filename, Amrvis::FileType filetype);
58  bool ReadNonPlotfileData(const std::string &filename, Amrvis::FileType filetype);
59 
60  const Vector<std::string> &PlotVarNames() const { return plotVars; }
61 
62  int FinestLevel() const { return finestLevel; }
63  const Vector<int> &RefRatio() const { return refRatio; }
64  const BoxArray &boxArray(int level) const {
65  if(fileType == Amrvis::FAB || (fileType == Amrvis::MULTIFAB && level == 0)) {
66  return fabBoxArray;
67  } else {
68  // use visMF[][0]: all boxArrays are
69  // guaranteed to be the same for each MultiFab
70  return visMF[level][0]->boxArray();
71  }
72  }
73 
74  const DistributionMapping& DistributionMap (int level) const {
75  if(fileType == Amrvis::FAB || (fileType == Amrvis::MULTIFAB && level == 0)) {
76  return dataGrids[0][0]->DistributionMap();
77  } else {
78  return dataGrids[level][0]->DistributionMap();
79  }
80  }
81 
82  // limits of interior region of computational domain at each level
83  const Vector<Box> &ProbDomain() const { return probDomain; }
84  // physical size of computational domain
85  const Vector<Real> &ProbSize() const { return probSize; }
86  const Vector<Real> &ProbLo() const { return probLo; }
87  const Vector<Real> &ProbHi() const { return probHi; }
88 
89  // return physical location of cell at index ix, level lev
90  // cellLoc = location of cell center
91  // loNodeLoc = location of node (vertex) on lower left hand corner
92  // hiNodeLoc = location of node (vertex) on upper right hand corner
93  void CellLoc(int lev, IntVect ix, Vector<Real> &pos) const;
94  void LoNodeLoc(int lev, IntVect ix, Vector<Real> &pos) const;
95  void HiNodeLoc(int lev, IntVect ix, Vector<Real> &pos) const;
96 
97  // Return grid spacing at level iLevel
98  Vector<Real> CellSize(int iLevel) const { return dxLevel[iLevel]; }
99 
100  // find the IntVect given a physical location
101  // returns the intvect, the finest level it is contained on,
102  // and the intvect at the given finest level
103  void IntVectFromLocation(const int finestFillLevel, const Vector<Real> &location,
104  IntVect &ivLoc, int &ivLevel, IntVect &ivFinestFillLev) const;
105 
106  const Vector< Vector< Vector<Real> > > &GridLocLo() const { return gridLocLo; }
107  const Vector< Vector< Vector<Real> > > &GridLocHi() const { return gridLocHi; }
108  const Vector< Vector<Real> > &DxLevel() const { return dxLevel; }
109  const Vector<int> &LevelSteps() const { return levelSteps; }
110 
111  int NComp() const { return nComp; }
112  int BoundaryWidth() const { return boundaryWidth; }
113  int NGrow() const { return nGrow; }
114  int CoordSys() const { return coordSys; }
115  Real Time() const { return time; }
116  const std::string &PlotFileVersion() const { return plotFileVersion; }
117 
118  // fill a databox using conservative interpolation
119  void FillVar(FArrayBox *destFab, const Box &destBox,
120  int finestFillLevel, const std::string &varName, int procWithFabs);
121  void FillVar(Vector<FArrayBox *> &destFabs, const Vector<Box> &destBoxes,
122  int finestFillLevel, const std::string &varName, int procWithFabs);
123  void FillVar(MultiFab &destMultiFab, int finestFillLevel,
124  const Vector<std::string> &varNames, const Vector<int> &destFillComps);
125  void FillVar(MultiFab &destMultiFab, int finestFillLevel,
126  const std::string &varname, int destcomp = 0);
127 
128  const std::string &GetFileName() const { return fileName; }
129 
132  bool CartGrid() const { return bCartGrid; }
133  bool GetShowBody() const { return bShowBody; }
134  void SetShowBody(bool tf) { bShowBody = tf; }
135  int CartGridVersion() const { return vCartGrid; }
136  Real VfEps(int level) const { return vfEps[level]; }
137  void SetVfEps(Real *newvfeps, int finestlev);
138  bool Terrain() const { return bTerrain; }
139 
140  void SetBoundaryWidth(int width) { boundaryWidth = width; }
141 
142  bool CanDerive(const std::string &name) const;
143  bool CanDerive(const Vector<std::string> &names) const;
144  int NumDeriveFunc() const;
145  void ListDeriveFunc(std::ostream &os) const;
146  int StateNumber(const std::string &statename) const;
147 
148  // return the finest level <= startLevel that fully contains box b
149  // b is defined on startLevel
150  int FinestContainingLevel(const Box &b, int startLevel) const;
151 
152  // return the finest level <= startLevel that intersects box b
153  // b is defined on startLevel
154  int FinestIntersectingLevel(const Box &b, int startLevel) const;
155 
156  // number of grids at level which intersect b
157  int NIntersectingGrids(int level, const Box &b) const;
158  MultiFab &GetGrids(int level, int componentIndex);
159  MultiFab &GetGrids(int level, int componentIndex, const Box &onBox);
160 
161  void FlushGrids(); // Clear all internal field data
162  void FlushGrids(int componentIndex); // Clear all internal field data associated with this component
163 
164  // calculate the min and max values of derived on onBox at level
165  // return false if onBox did not intersect any grids
166  bool MinMax(const Box &onBox, const std::string &derived, int level,
167  Real &dataMin, Real &dataMax);
168 
169  static void SetVerbose(bool tf) { verbose = tf; }
170  static bool Verbose() { return verbose; }
171  static void SetSkipPltLines(int spl) { skipPltLines = spl; }
172  static void SetStaticBoundaryWidth(int bw) { sBoundaryWidth = bw; }
173 
174  private:
175  std::string fileName;
177  static bool verbose;
178  static int skipPltLines;
179  static int sBoundaryWidth;
180 
181  // fill on interior by piecewise constant interpolation
182  void FillInterior(FArrayBox &dest, int level, const Box &subbox);
183  void PcInterp(FArrayBox &fine, const FArrayBox &crse,
184  const Box &subbox, int lrat);
185  FArrayBox *ReadGrid(std::istream &is, int numVar);
186  bool DefineFab(int level, int componentIndex, int fabIndex);
187 };
188 
189 }
190 
191 #endif
Array4< Real > fine
Definition: AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
Definition: AMReX_AmrData.H:19
int CoordSys() const
Definition: AMReX_AmrData.H:114
static int sBoundaryWidth
Definition: AMReX_AmrData.H:179
Vector< Real > probSize
Definition: AMReX_AmrData.H:35
const Vector< Vector< Vector< Real > > > & GridLocHi() const
Definition: AMReX_AmrData.H:107
void LoNodeLoc(int lev, IntVect ix, Vector< Real > &pos) const
Definition: AMReX_AmrData.cpp:976
bool ReadNonPlotfileData(const std::string &filename, Amrvis::FileType filetype)
Definition: AMReX_AmrData.cpp:741
int NumDeriveFunc() const
Definition: AMReX_AmrData.cpp:1516
void ListDeriveFunc(std::ostream &os) const
Definition: AMReX_AmrData.cpp:1553
Vector< Real > afEps
Definition: AMReX_AmrData.H:38
static bool verbose
Definition: AMReX_AmrData.H:177
int FinestLevel() const
Definition: AMReX_AmrData.H:62
const Vector< Real > & ProbLo() const
Definition: AMReX_AmrData.H:86
Vector< Real > probLo
Definition: AMReX_AmrData.H:35
const Vector< Vector< Vector< Real > > > & GridLocLo() const
Definition: AMReX_AmrData.H:106
Vector< int > compIndexToVisMFComponentMap
Definition: AMReX_AmrData.H:27
Vector< Vector< Vector< Real > > > gridLocLo
Definition: AMReX_AmrData.H:32
void SetFileType(Amrvis::FileType type)
Vector< Vector< FArrayBox * > > regions
Definition: AMReX_AmrData.H:43
bool CartGrid() const
Definition: AMReX_AmrData.H:132
Real VfEps(int level) const
Definition: AMReX_AmrData.H:136
const Vector< Box > & ProbDomain() const
Definition: AMReX_AmrData.H:83
Real Time() const
Definition: AMReX_AmrData.H:115
const Vector< Real > & ProbHi() const
Definition: AMReX_AmrData.H:87
static void SetStaticBoundaryWidth(int bw)
Definition: AMReX_AmrData.H:172
FArrayBox * ReadGrid(std::istream &is, int numVar)
Definition: AMReX_AmrData.cpp:1922
Amrvis::FileType fileType
Definition: AMReX_AmrData.H:47
int BoundaryWidth() const
Definition: AMReX_AmrData.H:112
Amrvis::FileType GetFileType() const
Definition: AMReX_AmrData.H:131
Vector< Vector< VisMF * > > visMF
Definition: AMReX_AmrData.H:25
std::string plotFileVersion
Definition: AMReX_AmrData.H:45
int nRegions
Definition: AMReX_AmrData.H:40
int finestLevel
Definition: AMReX_AmrData.H:29
Vector< Real > CellSize(int iLevel) const
Definition: AMReX_AmrData.H:98
std::string fileName
Definition: AMReX_AmrData.H:175
const Vector< Vector< Real > > & DxLevel() const
Definition: AMReX_AmrData.H:108
int coordSys
Definition: AMReX_AmrData.H:42
int NIntersectingGrids(int level, const Box &b) const
Definition: AMReX_AmrData.cpp:1561
MultiFab & GetGrids(int level, int componentIndex)
Definition: AMReX_AmrData.cpp:1627
const Vector< int > & RefRatio() const
Definition: AMReX_AmrData.H:63
Vector< Vector< Vector< Real > > > gridLocHi
Definition: AMReX_AmrData.H:32
Vector< Box > probDomain
Definition: AMReX_AmrData.H:33
void PcInterp(FArrayBox &fine, const FArrayBox &crse, const Box &subbox, int lrat)
Definition: AMReX_AmrData.cpp:1898
static Amrvis::FileType defaultFileType
Definition: AMReX_AmrData.H:176
bool Terrain() const
Definition: AMReX_AmrData.H:138
Vector< Box > maxDomain
Definition: AMReX_AmrData.H:34
Vector< Vector< MultiFab * > > dataGrids
Definition: AMReX_AmrData.H:23
AmrData()
Definition: AMReX_AmrData.cpp:44
int StateNumber(const std::string &statename) const
Definition: AMReX_AmrData.cpp:1883
static void SetVerbose(bool tf)
Definition: AMReX_AmrData.H:169
int NGrow() const
Definition: AMReX_AmrData.H:113
int vCartGrid
Definition: AMReX_AmrData.H:49
int FinestIntersectingLevel(const Box &b, int startLevel) const
Definition: AMReX_AmrData.cpp:1602
bool GetShowBody() const
Definition: AMReX_AmrData.H:133
Vector< int > levelSteps
Definition: AMReX_AmrData.H:51
void FillVar(FArrayBox *destFab, const Box &destBox, int finestFillLevel, const std::string &varName, int procWithFabs)
Definition: AMReX_AmrData.cpp:1022
const DistributionMapping & DistributionMap(int level) const
Definition: AMReX_AmrData.H:74
void HiNodeLoc(int lev, IntVect ix, Vector< Real > &pos) const
Definition: AMReX_AmrData.cpp:985
Vector< Real > vfEps
Definition: AMReX_AmrData.H:38
const BoxArray & boxArray(int level) const
Definition: AMReX_AmrData.H:64
int nComp
Definition: AMReX_AmrData.H:39
~AmrData()
Definition: AMReX_AmrData.cpp:55
void FlushGrids()
Definition: AMReX_AmrData.cpp:1669
Vector< int > refRatio
Definition: AMReX_AmrData.H:30
int nGrow
Definition: AMReX_AmrData.H:39
const Vector< std::string > & PlotVarNames() const
Definition: AMReX_AmrData.H:60
const std::string & GetFileName() const
Definition: AMReX_AmrData.H:128
void CellLoc(int lev, IntVect ix, Vector< Real > &pos) const
Definition: AMReX_AmrData.cpp:967
void SetVfEps(Real *newvfeps, int finestlev)
bool bCartGrid
Definition: AMReX_AmrData.H:48
void IntVectFromLocation(const int finestFillLevel, const Vector< Real > &location, IntVect &ivLoc, int &ivLevel, IntVect &ivFinestFillLev) const
Definition: AMReX_AmrData.cpp:994
Vector< std::string > plotVars
Definition: AMReX_AmrData.H:37
int CartGridVersion() const
Definition: AMReX_AmrData.H:135
int FinestContainingLevel(const Box &b, int startLevel) const
Definition: AMReX_AmrData.cpp:1581
Vector< Real > probHi
Definition: AMReX_AmrData.H:35
void SetShowBody(bool tf)
Definition: AMReX_AmrData.H:134
bool bShowBody
Definition: AMReX_AmrData.H:48
void SetBoundaryWidth(int width)
Definition: AMReX_AmrData.H:140
bool DefineFab(int level, int componentIndex, int fabIndex)
Definition: AMReX_AmrData.cpp:1654
Vector< Vector< Real > > dxLevel
Definition: AMReX_AmrData.H:31
int NComp() const
Definition: AMReX_AmrData.H:111
Vector< int > compIndexToVisMFMap
Definition: AMReX_AmrData.H:26
static void SetSkipPltLines(int spl)
Definition: AMReX_AmrData.H:171
bool ReadData(const std::string &filename, Amrvis::FileType filetype)
Definition: AMReX_AmrData.cpp:91
const Vector< int > & LevelSteps() const
Definition: AMReX_AmrData.H:109
static int skipPltLines
Definition: AMReX_AmrData.H:178
const Vector< Real > & ProbSize() const
Definition: AMReX_AmrData.H:85
bool MinMax(const Box &onBox, const std::string &derived, int level, Real &dataMin, Real &dataMax)
Definition: AMReX_AmrData.cpp:1702
Real time
Definition: AMReX_AmrData.H:36
Vector< Vector< std::vector< bool > > > dataGridsDefined
Definition: AMReX_AmrData.H:24
bool CanDerive(const std::string &name) const
Definition: AMReX_AmrData.cpp:1525
static bool Verbose()
Definition: AMReX_AmrData.H:170
bool bTerrain
Definition: AMReX_AmrData.H:50
void FillInterior(FArrayBox &dest, int level, const Box &subbox)
Definition: AMReX_AmrData.cpp:1510
BoxArray fabBoxArray
Definition: AMReX_AmrData.H:44
int boundaryWidth
Definition: AMReX_AmrData.H:41
const std::string & PlotFileVersion() const
Definition: AMReX_AmrData.H:116
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:549
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
FileType
Definition: AMReX_AmrvisConstants.H:86
@ MULTIFAB
Definition: AMReX_AmrvisConstants.H:86
@ FAB
Definition: AMReX_AmrvisConstants.H:86
constexpr int ix
Definition: AMReX_Interp_2D_C.H:32
Definition: AMReX_Amr.cpp:49