Overture  Version 25
GenericGrid.h
Go to the documentation of this file.
1 #ifndef _GenericGrid
2 #define _GenericGrid
3 
4 //
5 // Who to blame: Geoff Chesshire and WDH
6 //
7 
8 #include <limits.h>
9 #include "ReferenceCounting.h"
10 #include "GenericGridFunction.h"
11 #include "GenericDataBase.h"
12 
13 //
14 // Class for reference-counted data.
15 //
17  public ReferenceCounting {
18  public:
19  enum {
20  ENDtheGenericGridData = 1, // bit 0
21  NOTHING = 0,
22  THEusualSuspects = INT_MIN, // (sign bit)
26  COMPUTEfailed = INT_MIN // (sign bit)
27  };
31  const GenericGridData& x,
32  const CopyType ct = DEEP);
33  virtual ~GenericGridData();
34 
36 
37  virtual GenericGridData& equals(const GenericGridData& x, int option=0); // equals operator with options
38 
39  void reference(const GenericGridData& x);
40  virtual void breakReference();
41  virtual void consistencyCheck() const;
42 
43  virtual Integer get(const GenericDataBase& db,
44  const aString& name,
45  bool getMapping=true ); // for AMR grids we may not get the mapping.
46 
47  virtual Integer put(GenericDataBase& db,
48  const aString& name,
49  bool putMapping = true, // for AMR grids we may not save the mapping.
50  int geometryToPut = -1 ) const; // by default put computedGeometry
51 
52  virtual void specifyProcesses(const Range& range);
53 
54  inline Integer update(
55  const Integer what = THEusualSuspects,
56  const Integer how = COMPUTEtheUsual)
57  { return update(*this, what, how); }
58  virtual Integer update(
59  GenericGridData& x,
60  const Integer what = THEusualSuspects,
61  const Integer how = COMPUTEtheUsual);
62  virtual void destroy(const Integer what = NOTHING);
63  virtual void geometryHasChanged(const Integer what = ~NOTHING);
64  void initialize();
65 //
66 // Virtual member functions used only through class ReferenceCounting:
67 //
68  private:
69  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
70  { return operator=((GenericGridData&)x); }
71  inline virtual void reference(const ReferenceCounting& x)
72  { reference((GenericGridData&)x); }
73  inline virtual ReferenceCounting* virtualConstructor(
74  const CopyType ct = DEEP) const
75  { return new GenericGridData(*this, ct); }
76  aString className;
77  public:
78  inline virtual aString getClassName() const { return className; }
79 };
80 
82  public ReferenceCounting {
83  public:
84 // Public constants:
85 
87  {
90  };
91 
92 // Constants to be ORed to form the first argument of update() and destroy():
93  enum {
97  };
98 
99 // Constants to be ORed to form the second argument of update():
100  enum {
104  };
105 //
106 // Public member functions for access to data:
107 //
108 // This is a mask that indicates which geometrical data has been computed.
109 // This must be reset to zero to invalidate the data when the geometry changes.
110 //
111  inline const Integer& computedGeometry() const
112  { return rcData->computedGeometry; }
113 //
114 // Public member functions.
115 //
116 // Default constructor.
117 //
118 // Create a GenericGrid.
119 //
120  GenericGrid();
121 //
122 // Copy constructor. (Does a deep copy by default.)
123 //
124  GenericGrid(
125  const GenericGrid& x,
126  const CopyType ct = DEEP);
127 //
128 // Destructor.
129 //
130  virtual ~GenericGrid();
131 //
132 // Assignment operator. (Does a deep copy.)
133 //
134  GenericGrid& operator=(const GenericGrid& x);
135 
136  GenericGrid& equals(const GenericGrid& x, int option=0); // equals operator with options
137 
138 //
139 // Make a reference. (Does a shallow copy.)
140 //
141  void reference(const GenericGrid& x);
142  void reference(GenericGridData& x);
143 //
144 // Break a reference. (Replaces with a deep copy.)
145 //
146  virtual void breakReference();
147 //
148 // Check that the data structure is self-consistent.
149 //
150  virtual void consistencyCheck() const;
151 //
152 // "Get" and "put" database operations.
153 //
154  virtual Integer get(const GenericDataBase& db,
155  const aString& name,
156  bool getMapping=true ); // for AMR grids we may not get the mapping.
157 
158  virtual Integer put(GenericDataBase& db,
159  const aString& name,
160  bool putMapping = true, // for AMR grids we may not save the mapping.
161  int geometryToPut = -1 ) const; // by default put computedGeometry
162 //
163 // Specify the set of processes over which GridFunctions are distributed.
164 // We now support only the specification of a contiguous range of process IDs.
165 //
166  virtual void specifyProcesses(const Range& range);
167 
168 //
169 // Set references to reference-counted data.
170 //
171  void updateReferences(const Integer what = EVERYTHING);
172 //
173 // Update the grid.
174 //
175  inline Integer update(
176  const Integer what = THEusualSuspects,
177  const Integer how = COMPUTEtheUsual)
178  { return update(*this, what, how); }
179 //
180 // Update the grid, sharing the data of another grid.
181 //
182  virtual Integer update(
183  GenericGrid& x,
184  const Integer what = THEusualSuspects,
185  const Integer how = COMPUTEtheUsual);
186 //
187 // Destroy optional grid data.
188 //
189  virtual void destroy(const Integer what = NOTHING);
190 //
191 // Mark all of the geometric data out-of-date.
192 //
193  inline void geometryHasChanged(const Integer what = ~NOTHING)
194  { rcData->geometryHasChanged(what); }
195 //
196 // Initialize the GenericGrid.
197 //
198  virtual void initialize();
199 //
200 // Comparison function. Returns true if x is the same grid as *this.
201 //
202  inline Logical operator==(const GenericGrid& x) const
203  { return x.rcData == rcData; }
204  inline Logical operator!=(const GenericGrid& x) const
205  { return x.rcData != rcData; }
206 //
207 // Pointer to reference-counted data.
208 //
211  inline GenericGridData* operator->() { return rcData; }
212  inline const GenericGridData* operator->() const { return rcData; }
213  inline GenericGridData& operator*() { return *rcData; }
214  inline const GenericGridData& operator*() const { return *rcData; }
215 //
216 // Virtual member functions used only through class ReferenceCounting:
217 //
218  private:
219  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
220  { return operator=((GenericGrid&)x); }
221  inline virtual void reference(const ReferenceCounting& x)
222  { reference((GenericGrid&)x); }
223  inline virtual ReferenceCounting* virtualConstructor(
224  const CopyType ct = DEEP) const
225  { return new GenericGrid(*this, ct); }
226  aString className;
227  public:
228  inline virtual aString getClassName() const { return className; }
229 };
230 //
231 // Stream output Operator.
232 //
233 ostream& operator<<(ostream& s, const GenericGrid& g);
234 
235 #endif // _GenericGrid