BISICLES AMR ice sheet model  0.9
UnstructuredIO.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 // UnstructuredIO.H
12 // Operations related to reading and writing data from/to valid regions
13 // of AMR Hierarchies
14 //===========================================================================
15 #ifndef _UNSTRUCTUREDIO_H_
16 #define _UNSTRUCTUREDIO_H_
17 
18 #include "RealVect.H"
19 #include "FArrayBox.H"
20 #include "LevelData.H"
21 #include "BoxIterator.H"
22 #include "netcdf.h"
23 #include <set>
24 #include "Transformation.H"
25 #include "NamespaceHeader.H"
26 
28 {
29 
30 public:
31  typedef std::set<std::pair<int, Box> > LevelBoxSet ;
32 private:
33 
34  int m_nComp;
35  Vector<RealVect> m_dx;
36  RealVect m_x0;
37  Real m_time;
38  int m_nLevel;
39  Vector<int> m_ratio;
40  Vector<int> m_level;
41  LevelBoxSet m_levelBoxSet;
42  Vector<Vector<int> > m_iv;
43  Vector<Vector< Real > > m_field;
44  Vector<Vector<Real > > m_x;
45  Box m_crseDomain;
46  bool m_isDefined;
47 
48 public:
49 
50 
51 
52  UnstructuredData(int a_nComp, const RealVect& a_crseDx, const Box& a_crseDomain,
53  const Vector<int>& a_ratio, const Real& a_time, const RealVect& a_x0 = RealVect::Zero );
54 
55  void define(int a_nComp, const RealVect& a_crseDx, const Box& a_crseDomain,
56  const Vector<int>& a_ratio, const Real& a_time, const RealVect& a_x0 = RealVect::Zero );
57 
58  UnstructuredData():m_isDefined(false){}
59 
60  void resize(int a_size);
61 
62 
63  void append(int a_lev, const Box& a_box, const IntVect& a_iv,
64  const Vector<Real>& a_data);
65 
66  int nComp() const
67  {
68  return m_nComp;
69  }
70 
71  size_t nCell() const
72  {
73  return m_level.size();
74  }
75 
76  size_t nLevel() const
77  {
78  return m_nLevel;
79  }
80 
81  Box domain(int a_lev) const
82  {
83  if (a_lev == 0)
84  return m_crseDomain;
85  else
86  return domain(a_lev - 1).refine(m_ratio[a_lev-1]);
87  }
88 
89  Real time() const
90  {
91  return m_time;
92  }
93 
94  Real& time()
95  {
96  return m_time;
97  }
98 
99 
100  const Vector<int>& ratio() const
101  {
102  return m_ratio;
103  }
104 
105  const Vector<RealVect>& dx() const
106  {
107  return m_dx;
108  }
109 
110 
111  const Vector<int>& level() const
112  {
113  return m_level;
114  }
115 
116  Vector<int>& level()
117  {
118  return m_level;
119  }
120 
121  const LevelBoxSet& levelBoxSet() const
122  {
123  return m_levelBoxSet;
124  }
125 
126  LevelBoxSet& levelBoxSet()
127  {
128  return m_levelBoxSet;
129  }
130 
131  const Vector<int>& iv(int a_dir) const
132  {
133  return m_iv[a_dir];
134  }
135 
136  Vector<int>& iv(int a_dir)
137  {
138  return m_iv[a_dir];
139  }
140 
141  const Vector<Real>& field(int a_comp) const
142  {
143  return m_field[a_comp];
144  }
145 
146  Vector<Real>& field(int a_comp)
147  {
148  return m_field[a_comp];
149  }
150 
151  const Vector<Real>& x(int a_dir) const
152  {
153  return m_x[a_dir];
154  }
155 
157 
161  void computeNodeCoord(Vector<Real>& a_nodeCoord, int a_dir, const IntVect& a_node) const;
162 
163 };
164 
165 namespace UnstructuredIO
166 {
167 
169  void BStoUS( UnstructuredData& a_usData ,
170  const Vector<LevelData<FArrayBox>*>& a_bsData,
171  const Vector<int>& a_ratio,
172  bool a_validOnly);
173 
175  void USToBS ( Vector<LevelData<FArrayBox>*>& a_bsdata,
176  const UnstructuredData& a_usData);
177 
178 
179 
180  int defineCFDimension(int a_ncID, size_t a_len, const std::string& a_name);
181 
182  int defineCFVar(int a_ncID, int a_nDim, int* a_dimID, nc_type a_type,
183  const std::string& a_name,
184  const std::string& a_unit,
185  const std::string& a_stdName,
186  const std::string& a_longName);
187 
188  void readCFVar(int a_ncID, const std::string& a_name,Vector<int>& a_data);
189 
190  void readCFVar(int a_ncID, int a_varID ,Vector<int>& a_data);
191 
192  void readCFVar(int a_ncID, const std::string& a_name,Vector<Real>& a_data);
193 
194  void readCFVar(int a_ncID, int a_varID ,Vector<Real>& a_data);
195 
196  void writeCFVar(int a_ncID, const std::string& a_name, const Vector<int>& a_data);
197 
198  void writeCFVar(int a_ncID, const std::string& a_name, const Vector<Real>& a_data);
199 
201  void writeCF ( const std::string&, const UnstructuredData& ,
202  const Vector<std::string>&, const std::string&,
203  const Transformation&);
204 
206  void readCF ( UnstructuredData&, Vector<std::string>&,
207  const std::string&);
208 
209 
210 
211 }
212 
213 #include "NamespaceFooter.H"
214 #endif
UnstructuredData()
Definition: UnstructuredIO.H:58
void USToBS(Vector< LevelData< FArrayBox > *> &a_bsdata, const UnstructuredData &a_usData)
build block structed data from valid data
Definition: UnstructuredIO.cpp:128
void resize(int a_size)
Definition: UnstructuredIO.cpp:50
int nComp() const
Definition: UnstructuredIO.H:66
void writeCF(const std::string &, const UnstructuredData &, const Vector< std::string > &, const std::string &, const Transformation &)
write UnstructuredData to a NetCDF-CF file
Definition: UnstructuredIO.cpp:498
void readCF(UnstructuredData &, Vector< std::string > &, const std::string &)
read UnstructuredData from a NetCDF-CF file
Definition: UnstructuredIO.cpp:276
const LevelBoxSet & levelBoxSet() const
Definition: UnstructuredIO.H:121
const Vector< RealVect > & dx() const
Definition: UnstructuredIO.H:105
void define(int a_nComp, const RealVect &a_crseDx, const Box &a_crseDomain, const Vector< int > &a_ratio, const Real &a_time, const RealVect &a_x0=RealVect::Zero)
Definition: UnstructuredIO.cpp:30
int defineCFDimension(int a_ncID, size_t a_len, const std::string &a_name)
Definition: UnstructuredIO.cpp:900
size_t nCell() const
Definition: UnstructuredIO.H:71
Definition: UnstructuredIO.H:165
void computeNodeCoord(Vector< Real > &a_nodeCoord, int a_dir, const IntVect &a_node) const
fill a_nodeCoord with the a_dir co-ordinate of node a_node.
Definition: UnstructuredIO.cpp:106
const Vector< Real > & field(int a_comp) const
Definition: UnstructuredIO.H:141
const Vector< int > & level() const
Definition: UnstructuredIO.H:111
const Vector< int > & ratio() const
Definition: UnstructuredIO.H:100
void readCFVar(int a_ncID, int a_varID, Vector< Real > &a_data)
Definition: UnstructuredIO.cpp:1005
Vector< int > & iv(int a_dir)
Definition: UnstructuredIO.H:136
const Vector< int > & iv(int a_dir) const
Definition: UnstructuredIO.H:131
abstract class for co-ordinate Transformations.
Definition: Transformation.H:25
Vector< int > & level()
Definition: UnstructuredIO.H:116
Definition: UnstructuredIO.H:27
std::set< std::pair< int, Box > > LevelBoxSet
Definition: UnstructuredIO.H:31
const Vector< Real > & x(int a_dir) const
Definition: UnstructuredIO.H:151
Vector< Real > & field(int a_comp)
Definition: UnstructuredIO.H:146
Real time() const
Definition: UnstructuredIO.H:89
Real & time()
Definition: UnstructuredIO.H:94
Box domain(int a_lev) const
Definition: UnstructuredIO.H:81
int defineCFVar(int a_ncID, int a_nDim, int *a_dimID, nc_type a_type, const std::string &a_name, const std::string &a_unit, const std::string &a_stdName, const std::string &a_longName)
Definition: UnstructuredIO.cpp:916
LevelBoxSet & levelBoxSet()
Definition: UnstructuredIO.H:126
void append(int a_lev, const Box &a_box, const IntVect &a_iv, const Vector< Real > &a_data)
Definition: UnstructuredIO.cpp:73
void writeCFVar(int a_ncID, const std::string &a_name, const Vector< Real > &a_data)
Definition: UnstructuredIO.cpp:1038
size_t nLevel() const
Definition: UnstructuredIO.H:76
void BStoUS(UnstructuredData &a_usData, const Vector< LevelData< FArrayBox > *> &a_bsData, const Vector< int > &a_ratio, bool a_validOnly)
populate a UnstructuredData from a Vector<LevelData<FArrayBox>*>
Definition: UnstructuredIO.cpp:198