Flumy [Free API]
Process based model for meandering chanelized systems
GridReal.hpp
1 #ifndef GRID_REAL_HH
2 #define GRID_REAL_HH
3 
4 #include "MCRCProgramming.hpp"
5 #include "flumy_export.hpp"
6 
7 #include "GridParams.hpp"
8 
9 class iTracer;
10 
11 enum GridFileFormat {
12  GFF_ERROR = -1,
13  GFF_F2G = 0,
14  GFF_GSLIB = 1,
15  GFF_CPS3 = 2,
16  GFF_UNDEFINED = 3
17 };
18 
23 class FLUMY_EXPORT GridReal : public GridParams {
24 
25 public :
26 
30  GridReal(const MP_real & dx,
31  const MP_real & dy,
32  const MP_int & nx,
33  const MP_int & ny,
34  const MP_real & ox = 0.,
35  const MP_real & oy = 0.,
36  const MP_real & val = MP_UNKNOWN_REAL_VALUE);
38  GridReal(const MP_real & dx,
39  const MP_real & dy,
40  const MP_real & dz,
41  const MP_int & nx,
42  const MP_int & ny,
43  const MP_int & nz,
44  const MP_real & ox = 0.,
45  const MP_real & oy = 0.,
46  const MP_real & oz = 0.,
47  const MP_real & val = MP_UNKNOWN_REAL_VALUE);
49  GridReal(const std::vector<std::vector<MP_real> >& values);
52  GridReal(const GridParams& grid);
55  GridReal(const GridParams& grid, const MP_real & val);
57  GridReal(const GridReal& grid);
59  virtual ~GridReal() {}
61  GridReal& operator= (const GridReal& gridc);
63  virtual void reset(const GridParams & grid) override;
65  virtual void reset(const MP_real & dx,
66  const MP_real & dy,
67  const MP_int & nx,
68  const MP_int & ny,
69  const MP_real & ox = 0.,
70  const MP_real & oy = 0.,
71  const MP_real & val = MP_UNKNOWN_REAL_VALUE);
73  virtual void reset(const MP_real & dx,
74  const MP_real & dy,
75  const MP_real & dz,
76  const MP_int & nx,
77  const MP_int & ny,
78  const MP_int & nz,
79  const MP_real & ox = 0.,
80  const MP_real & oy = 0.,
81  const MP_real & oz = 0.,
82  const MP_real & val = MP_UNKNOWN_REAL_VALUE);
84  virtual bool check(MP_real & val, bool correct = true) const;
86  virtual void fill(const MP_real & val);
88  virtual void fill_2D(const std::vector<std::vector<MP_real> >& values);
91  virtual void fill_yxz(const MP_int size, const MP_real values[]);
94  virtual void fill_zyx(const MP_int size, const MP_real values[]);
97  virtual bool get_at(MP_int& size, MP_real values[]) const;
99  virtual bool set_at(const MP_int & ix, const MP_int & iy, const MP_real & val);
101  virtual bool set_at(const MP_int & ix, const MP_int & iy, const MP_int & iz, const MP_real & val);
103  virtual bool get_at(const MP_int & ix, const MP_int & iy, MP_real & val) const;
105  virtual bool get_at(const MP_int & ix, const MP_int & iy, RealList & val) const;
107  virtual bool get_at(const MP_int & ix, const MP_int & iy, const MP_int & iz, MP_real & val) const;
109  virtual bool write(const MP_string& filename,
110  const iTracer* tracer,
111  const GridFileFormat& format = GFF_F2G,
112  const MP_string& order = MP_DEFAULT_CELLS_ORDER) const;
114  virtual bool read(const MP_string& filename);
116  const RealList& get_values() const { return _values; }
118  RealList get_values_zyx() const;
120  MP_real get_mean() const;
122  MP_real get_min() const { return _min; }
124  MP_real get_max() const { return _max; }
126  MP_real get_min(MP_int& ix, MP_int& iy) const;
128  MP_real get_max(MP_int& ix, MP_int& iy) const;
130  MP_int get_nb_positive() const;
132  MP_int get_nb_negative() const;
134  bool add_variable(GridReal* aux);
136  void set_name(const MP_string& name) { _name = name; }
138  const MP_string& get_name() const { return _name; }
140  void set_undef_string(const MP_string& undef) { _undef_string = undef; }
142  const MP_string& get_undef_string() const { return _undef_string; }
144  void set_undef_value(const MP_real undef) { _undef_value = undef; }
146  const MP_real& get_undef_value() const { return _undef_value; }
148  static bool is_order_valid(const MP_string& order);
150  static bool is_order_valid(const MP_string& order,
151  MP_string& order1,
152  MP_string& order2,
153  MP_string& order3);
155  static bool is_order_valid(const MP_string& order1,
156  const MP_string& order2,
157  const MP_string& order3);
159  static GridFileFormat get_format(const MP_string& filename);
161  static MP_string get_format_label(const GridFileFormat& format);
163  const MP_string& last_error() const { return _last_error; }
164 
165 protected :
167  RealList _values;
169  MP_real _min;
170  MP_real _max;
172  MP_int _ixmin;
173  MP_int _iymin;
174  MP_int _ixmax;
175  MP_int _iymax;
177  std::vector<GridReal*> _aux;
179  MP_string _name;
181  MP_string _undef_string;
183  MP_real _undef_value;
185  mutable MP_string _last_error;
186 
188  bool write_gslib(const MP_string& filename,
189  const iTracer* tracer) const;
191  bool write_ascii(const MP_string& filename,
192  const iTracer* tracer) const;
194  bool write_f2g(const MP_string& filename,
195  const iTracer* tracer,
196  const MP_string& order = MP_DEFAULT_CELLS_ORDER) const;
198  bool write_values(std::ofstream & os,
199  const iTracer* tracer,
200  const MP_string& order = MP_DEFAULT_CELLS_ORDER) const;
202  bool read_cps3(const MP_string& filename);
204  bool read_gslib(const MP_string& filename);
206  bool read_ascii(const MP_string& filename);
208  bool read_f2g(const MP_string& filename);
209 };
210 
211 #endif /* GRID_REAL_HH */
Base class for 3D grid description.
Definition: GridParams.hpp:28
GridParams & operator=(const GridParams &)
Operator =.
Base class for 2D grid containing real values.
Definition: GridReal.hpp:23
virtual bool read(const MP_string &filename)
Read all grid node values from a file (see User Manual Appendices for the file format)
static bool is_order_valid(const MP_string &order, MP_string &order1, MP_string &order2, MP_string &order3)
Test if an "order string" is valid.
MP_real get_max() const
Retrieve the grid max value (keep get_ prefix to avoid conflict under windows)
Definition: GridReal.hpp:124
MP_real _min
Minimum and maximum of values.
Definition: GridReal.hpp:169
MP_int _iymin
Definition: GridReal.hpp:173
MP_real get_mean() const
Retrieve the grid mean value.
bool write_f2g(const MP_string &filename, const iTracer *tracer, const MP_string &order=MP_DEFAULT_CELLS_ORDER) const
Write all grid node values into an F2F formated file (see User Manual Appendices for the file format)
virtual bool get_at(const MP_int &ix, const MP_int &iy, RealList &val) const
Retrieve the vertical values list at node [ix,iy].
GridReal(const GridReal &grid)
Copy constructor.
const MP_real & get_undef_value() const
Return the undefined value of the variable.
Definition: GridReal.hpp:146
MP_real get_min() const
Retrieve the grid min value (keep get_ prefix to avoid conflict under windows)
Definition: GridReal.hpp:122
MP_string _last_error
Last error message.
Definition: GridReal.hpp:185
GridReal(const GridParams &grid, const MP_real &val)
Constructor build from another grid (use it to copy another grid parameters). This is not a copy con...
std::vector< GridReal * > _aux
Auxiliary grids (at any time, these grids must contain the same number of elements)
Definition: GridReal.hpp:177
virtual bool get_at(const MP_int &ix, const MP_int &iy, const MP_int &iz, MP_real &val) const
Retrieve the node[ix,iy,iz] value of the grid.
MP_string _undef_string
Undefined string.
Definition: GridReal.hpp:181
virtual void fill_2D(const std::vector< std::vector< MP_real > > &values)
Fill the grid with a 2D array of real values.
bool read_cps3(const MP_string &filename)
Read all grid node values from a CPS-3 formated file (see User Manual Appendices for the file format)
static GridFileFormat get_format(const MP_string &filename)
Return the Ascii format of the given grid file.
const MP_string & get_undef_string() const
Return the undefined string of the variable.
Definition: GridReal.hpp:142
MP_int _ixmax
Definition: GridReal.hpp:174
const MP_string & last_error() const
Return last error message.
Definition: GridReal.hpp:163
virtual void fill(const MP_real &val)
Fill the grid with a new real value.
GridReal(const MP_real &dx, const MP_real &dy, const MP_real &dz, const MP_int &nx, const MP_int &ny, const MP_int &nz, const MP_real &ox=0., const MP_real &oy=0., const MP_real &oz=0., const MP_real &val=MP_UNKNOWN_REAL_VALUE)
Constructor from 3D grid parameters which fills the grid with the given real value.
GridReal(const std::vector< std::vector< MP_real > > &values)
Constructor from a 2D array of real values.
MP_real get_max(MP_int &ix, MP_int &iy) const
Retrieve the grid max value and location (keep get_ prefix to avoid conflict under windows)
virtual void fill_zyx(const MP_int size, const MP_real values[])
Fill the grid with an array of real values (sorted by y then x then z, e.g. iz increasing first) Size...
GridReal(const MP_real &dx, const MP_real &dy, const MP_int &nx, const MP_int &ny, const MP_real &ox=0., const MP_real &oy=0., const MP_real &val=MP_UNKNOWN_REAL_VALUE)
Constructor from 2D grid parameters which fills the grid with the given real value.
void set_name(const MP_string &name)
Set the variable name.
Definition: GridReal.hpp:136
MP_real _max
Definition: GridReal.hpp:170
bool read_f2g(const MP_string &filename)
Read all grid node values from an F2G formatted file (see User Manual Appendices for the file format)
MP_int _iymax
Definition: GridReal.hpp:175
bool write_ascii(const MP_string &filename, const iTracer *tracer) const
Write all grid node values into an ASCII formated file (see User Manual Appendices for the file forma...
void set_undef_string(const MP_string &undef)
Set the undefined string.
Definition: GridReal.hpp:140
bool write_gslib(const MP_string &filename, const iTracer *tracer) const
Write all grid node values into an GSLIB formated file (see User Manual Appendices for the file forma...
virtual bool write(const MP_string &filename, const iTracer *tracer, const GridFileFormat &format=GFF_F2G, const MP_string &order=MP_DEFAULT_CELLS_ORDER) const
Write all grid node values into a file (see User Manual Appendices for the file format)
RealList _values
Grid values (at any time, vector size should be _nx*_ny*_nz)
Definition: GridReal.hpp:167
virtual bool set_at(const MP_int &ix, const MP_int &iy, const MP_int &iz, const MP_real &val)
Set the node[ix,iy,iz] value of the grid.
RealList get_values_zyx() const
Retrieve all grid values in a vector (order is +Z +Y +X, e.g. iz increasing first) (same as getRegula...
const MP_string & get_name() const
Return the name of the variable.
Definition: GridReal.hpp:138
void set_undef_value(const MP_real undef)
Set the undefined value.
Definition: GridReal.hpp:144
MP_string _name
Variable name.
Definition: GridReal.hpp:179
static bool is_order_valid(const MP_string &order)
Test if an "order string" is valid.
bool add_variable(GridReal *aux)
Add an auxiliary variable to the current grid (grids must be compatible)
virtual bool get_at(MP_int &size, MP_real values[]) const
Retrieve the grid values in an array of real values (sorted by z then x then y) Size of the array mus...
virtual void reset(const GridParams &grid) override
Reset 2D grid parameters to new values.
MP_real _undef_value
Undefined value.
Definition: GridReal.hpp:183
virtual void reset(const MP_real &dx, const MP_real &dy, const MP_real &dz, const MP_int &nx, const MP_int &ny, const MP_int &nz, const MP_real &ox=0., const MP_real &oy=0., const MP_real &oz=0., const MP_real &val=MP_UNKNOWN_REAL_VALUE)
Reset 3D grid parameters to new values and fill the grid with a new real value.
bool write_values(std::ofstream &os, const iTracer *tracer, const MP_string &order=MP_DEFAULT_CELLS_ORDER) const
Write values in the given output stream and in the given order.
virtual bool set_at(const MP_int &ix, const MP_int &iy, const MP_real &val)
Set the node[ix,iy] value of the grid (if grid is 3D, fill all pillar nodes)
bool read_ascii(const MP_string &filename)
Read all grid node values from an ASCII formated file (see User Manual Appendices for the file format...
virtual void reset(const MP_real &dx, const MP_real &dy, const MP_int &nx, const MP_int &ny, const MP_real &ox=0., const MP_real &oy=0., const MP_real &val=MP_UNKNOWN_REAL_VALUE)
Reset 2D grid parameters to new values and fill the grid with a new real value.
GridReal(const GridParams &grid)
Constructor build from another grid (use it to copy another grid parameters). This is not a copy con...
static bool is_order_valid(const MP_string &order1, const MP_string &order2, const MP_string &order3)
Test if an "order string" is valid.
virtual bool check(MP_real &val, bool correct=true) const
Check the input value (and correct it if needed)
GridReal()
Default constructor.
bool read_gslib(const MP_string &filename)
Read all grid node values from a GSLIB formated file (see User Manual Appendices for the file format)
virtual bool get_at(const MP_int &ix, const MP_int &iy, MP_real &val) const
Retrieve the node[ix,iy] value of the grid (if grid is 3D, retrieve first pillar node)
virtual ~GridReal()
Destructor.
Definition: GridReal.hpp:59
MP_real get_min(MP_int &ix, MP_int &iy) const
Retrieve the grid min value and location (keep get_ prefix to avoid conflict under windows)
static MP_string get_format_label(const GridFileFormat &format)
Return the Ascii format label for the given format id.
MP_int _ixmin
Minimum and maximum location.
Definition: GridReal.hpp:172
MP_int get_nb_negative() const
Retrieve the number of negative cells.
virtual void fill_yxz(const MP_int size, const MP_real values[])
Fill the grid with an array of real values (sorted by z then x then y, e.g. iy increasing first) Size...
const RealList & get_values() const
Retrieve all grid values in a vector (order is +X +Y +Z, e.g. ix increasing first)
Definition: GridReal.hpp:116
MP_int get_nb_positive() const
Retrieve the number of positive cells.