Overture  Version 25
GenericGridCollection.h
Go to the documentation of this file.
1 #ifndef _GenericGridCollection
2 #define _GenericGridCollection
3 
4 //
5 // Who to blame: Geoff Chesshire and WDH
6 //
7 
8 #include "GenericGrid.h"
9 #ifdef USE_STL
10 #include "RCVector.h"
11 #else
12 #include "ListOfGenericGrid.h"
14 #endif // USE_STL
15 #include "GCMath.h"
16 #include "GridDistribution.h"
17 
18 #ifndef OV_USE_OLD_STL_HEADERS
19 #include <vector>
20 #else
21 #include <vector.h>
22 #endif
23 
25 class LoadBalancer;
26 
27 //
28 // Class for reference-counted data.
29 //
31  public ReferenceCounting {
32  public:
33  enum {
34  THEbaseGrid = 1 << 20, // bit 20
35  THErefinementLevel = THEbaseGrid << 1, // bit 21
38  THEdomain = THEmultigridLevel << 1, // bit 24 -- added 060815 *wdh*
47  | THEbaseGrid
54  };
56 #ifdef USE_STL
58  RCVector<GenericGrid> grid;
61  RCVector<GenericGridCollection> baseGrid;
64  RCVector<GenericGridCollection> refinementLevel;
67  RCVector<GenericGridCollection> componentGrid;
70  RCVector<GenericGridCollection> multigridLevel;
73  RCVector<GenericGridCollection> domain;
75 #else
94 #endif // USE_STL
95  std::vector<aString> domainName;
96  bool keepGridDistributionOnCopy; // used to copy a grid collection to a different parallel distrubution.
99 
100  GenericGridCollectionData(const Integer numberOfGrids_ = 0);
102  const GenericGridCollectionData& x,
103  const CopyType ct = DEEP);
104  virtual ~GenericGridCollectionData();
106  inline GenericGrid& operator[](const Integer& i) { return grid[i]; }
107  inline const GenericGrid& operator[](const Integer& i) const
108  { return grid[i]; }
109  void reference(const GenericGridCollectionData& x);
110  virtual void breakReference();
111  virtual void consistencyCheck() const;
112  // get the name of a domain
113  const aString & getDomainName(int domain) const;
114  // set the name of a domain
115  void setDomainName(int domain, const aString & name );
116  virtual Integer get(
117  const GenericDataBase& db,
118  const aString& name);
119 
120  virtual Integer put(GenericDataBase& db,
121  const aString& name,
122  int geometryToPut = -1 // by default put computedGeometry
123  ) const;
124 
125  inline Integer update(
126  const Integer what = THEusualSuspects,
127  const Integer how = COMPUTEtheUsual)
128  { return update(*this, what, how); }
129  virtual Integer update(
131  const Integer what = THEusualSuspects,
132  const Integer how = COMPUTEtheUsual);
133  virtual void destroy(const Integer what = NOTHING);
134  virtual void geometryHasChanged(const Integer what = ~NOTHING);
135  virtual Integer addRefinement(
136  const Integer& level,
137  const Integer k = 0 );
138 
139  virtual Integer addRefinements(
140  const Integer level,
141  const Integer k,
142  const Integer numberToAdd );
143 
144  virtual void deleteRefinement(const Integer& k);
145  virtual void deleteRefinementLevels(const Integer level = 0);
146  virtual void referenceRefinementLevels(
148  const Integer level = INTEGER_MAX);
150  const Integer& level,
151  const Integer k = 0);
152  virtual void deleteMultigridCoarsening(const Integer& k);
153  virtual void deleteMultigridLevels(const Integer level = 0);
154  virtual void setNumberOfGrids(const Integer& numberOfGrids_);
155  void initialize(const Integer& numberOfGrids_);
156 
157  protected:
159  {
166 
168  const Integer& what,
169  Integer& numberOfCollections,
170 #ifdef USE_STL
171  RCVector<GenericGridCollection>& list,
172 #else
174 #endif // USE_STL
175  IntegerArray& number);
176 //
177 // Virtual member functions used only through class ReferenceCounting:
178 //
179  private:
180  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
181  { return operator=((GenericGridCollectionData&)x); }
182  inline virtual void reference(const ReferenceCounting& x)
184  inline virtual ReferenceCounting* virtualConstructor(
185  const CopyType ct = DEEP) const
186  { return new GenericGridCollectionData(*this, ct); }
187  aString className;
188  public:
189  inline virtual aString getClassName() const { return className; }
190 };
191 
193  public ReferenceCounting {
194  public:
195 // Public constants:
196 
197 // Constants to be ORed to form the first argument of update() and destroy():
198  enum {
208  };
209 
210 // Constants to be ORed to form the second argument of update():
211  enum {
215  };
216 
217 // Public data:
218 #ifdef USE_STL
219 // List of grids.
220  RCVector<GenericGrid> grid;
221  const IntegerArray gridNumber;
222 
223 // Collections of grids having the same base grid.
224  RCVector<GenericGridCollection> baseGrid;
226 
227 // Collections of grids having the same refinement level.
228  RCVector<GenericGridCollection> refinementLevel;
230 
231 // Collections of multigrid coarsenings of the same component grid
232  RCVector<GenericGridCollection> componentGrid;
234 
235 // Collections of grids having the same multigrid level.
236  RCVector<GenericGridCollection> multigridLevel;
238 
239 // Collections of grids having the same domain
240  RCVector<GenericGridCollection> domain;
242 #else
243 // List of grids.
246 
247 // Collections of grids having the same base grid.
250 
251 // Collections of grids having the same refinement level.
254 
255 // Collections of multigrid coarsenings of the same component grid
258 
259 // Collections of grids having the same multigrid level.
262 
263 // Collections of grids having the same domain
266 #endif // USE_STL
267 //
268 // Public member functions for access to data:
269 //
270 // This is a mask that indicates which geometrical data has been computed.
271 // This must be reset to zero to invalidate the data when the geometry changes.
272 //
273  inline const Integer& computedGeometry() const
274  { return rcData->computedGeometry; }
275 //
276 // The number of grids in the grid list.
277 //
278  inline const Integer& numberOfGrids() const { return rcData->numberOfGrids; }
279 //
280 // The number of GridCollections in baseGrid.
281 //
282  inline const Integer& numberOfBaseGrids() const
283  { return rcData->numberOfBaseGrids; }
284 //
285 // The number of GridCollections in refinementLevel.
286 //
287  inline const Integer& numberOfRefinementLevels() const
288  { return rcData->numberOfRefinementLevels; }
289 //
290 // The number of GridCollections in componentGrid.
291 //
292  inline const Integer& numberOfComponentGrids() const
293  { return rcData->numberOfComponentGrids; }
294 //
295 // The number of GridCollections in multigridLevel.
296 //
297  inline const Integer& numberOfMultigridLevels() const
298  { return rcData->numberOfMultigridLevels; }
299 //
300 // The number of domains
301 //
302  inline const Integer& numberOfDomains() const
303  { return rcData->numberOfDomains; }
304 //
305 // Public member functions:
306 //
307 // Default constructor.
308 //
309 // Create a GenericGridCollection with the given number of dimensions
310 // and number of component grids.
311 //
312  GenericGridCollection(const Integer numberOfGrids_ = 0);
313 //
314 // Copy constructor. (Does deep copy by default.)
315 //
317  const GenericGridCollection& x,
318  const CopyType ct = DEEP);
319 //
320 // Destructor.
321 //
322  virtual ~GenericGridCollection();
323 //
324 // Assignment operator. (Does a deep copy.)
325 //
327 //
328 // Get a reference to a component grid using C or Fortran indexing.
329 //
330  inline GenericGrid& operator[](const Integer& i) { return grid[i]; }
331  inline const GenericGrid& operator[](const Integer& i) const
332  { return grid[i]; }
333 //
334 // Make a reference. (Does a shallow copy.)
335 //
336  void reference(const GenericGridCollection& x);
338 //
339 // Break a reference. (Replaces with a deep copy.)
340 //
341  virtual void breakReference();
342 //
343 // Check that the data structure is self-consistent.
344 //
345  virtual void consistencyCheck() const;
346 
347  // get the name of a domain
348  const aString & getDomainName(int domain) const;
349 
350  // set the name of a domain
351  void setDomainName(int domain, const aString & name );
352 
353  // suppy a LoadBalancer to use when reading in grids
354  void setLoadBalancer( LoadBalancer & loadBalancer );
355 
356 //
357 // "Get" and "put" database operations.
358 //
359  virtual Integer get(
360  const GenericDataBase& db,
361  const aString& name);
362 
363  virtual Integer put(GenericDataBase& db,
364  const aString& name,
365  int geometryToPut = -1 // by default put computedGeometry
366  ) const;
367 //
368 // Set references to reference-counted data.
369 //
370  void updateReferences(const Integer what = EVERYTHING);
371 //
372 // Update the grid.
373 //
374  inline Integer update(
375  const Integer what = THEusualSuspects,
376  const Integer how = COMPUTEtheUsual)
377  { return update(*this, what, how); }
378 //
379 // Update the grid, sharing the data of another grid.
380 //
381  virtual Integer update(
383  const Integer what = THEusualSuspects,
384  const Integer how = COMPUTEtheUsual);
385 //
386 // Destroy optional grid data.
387 //
388  virtual void destroy(const Integer what = NOTHING);
389 //
390 // Mark all of the geometric data out-of-date.
391 //
392  inline void geometryHasChanged(const Integer what = ~NOTHING)
393  { rcData->geometryHasChanged(what); }
394 //
395 // Add a refinement grid to the collection.
396 //
397  virtual Integer addRefinement(
398  const Integer& level, // The refinement level number.
399  const Integer k = 0); // The index of an ancestor of the refinement grid.
400 //
401 // Delete all multigrid levels of refinement grid k.
402 //
403  virtual void deleteRefinement(const Integer& k);
404 //
405 // Delete all grids with refinement level greater than the given level.
406 //
407  virtual void deleteRefinementLevels(const Integer level = 0);
408 //
409 // Reference x[i] for refinementLevelNumber(i) <= level.
410 // Delete all other grids.
411 //
412  virtual void referenceRefinementLevels(
414  const Integer level = INTEGER_MAX);
415 //
416 // Add a multigrid coarsening of grid k.
417 //
419  const Integer& level, // The multigrid level number.
420  const Integer k = 0); // The index of the corresponding grid
421  // at any finer multigrid level.
422 //
423 // Delete grid k, a multigrid coarsening, and all of its multigrid coarsenings.
424 //
425  virtual void deleteMultigridCoarsening(const Integer& k);
426 //
427 // Delete all of the grids with multigrid level greater than the given level.
428 //
429  virtual void deleteMultigridLevels(const Integer level = 0);
430 //
431 // Set the number of grids.
432 //
433  virtual void setNumberOfGrids(const Integer& numberOfGrids_);
434 
435 // Specify whether to keep the parallel distribution when copying gridCollections.
436  void keepGridDistributionOnCopy(const bool trueOrFalse=true);
437 
438 //
439 // Initialize the GenericGridCollection with the given number of grids.
440 // These grids have their gridNumbers, baseGridNumbers and componentGridNumbers
441 // set to [0, ..., numberOfGrids_-1], and their refinementLevelNumbers and
442 // multigridLevelNumbers set to zero.
443 //
444  virtual void initialize(
445  const Integer& numberOfGrids_);
446 //
447 // Comparison function. Returns true if x is the same grid as *this.
448 //
449  inline Logical operator==(const GenericGridCollection& x) const
450  { return x.rcData == rcData; }
451  inline Logical operator!=(const GenericGridCollection& x) const
452  { return x.rcData != rcData; }
453 //
454 // Return the index of x in *this, or return -1 if x is not in *this.
455 //
456  inline Integer getIndex(const GenericGrid& x) const {
457  for (Integer i=0; i<numberOfGrids(); i++) if (grid[i] == x) return i;
458  return -1;
459  }
460 
461  // Here is the master grid.
463 //
464 // Pointer to reference-counted data.
465 //
469  inline const GenericGridCollectionData* operator->() const
470  { return rcData; }
472  inline const GenericGridCollectionData& operator*() const
473  { return *rcData; }
474 
475  protected:
477 
478 //
479 // Virtual member functions used only through class ReferenceCounting:
480 //
481  private:
482  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
483  { return operator=((GenericGridCollection&)x); }
484  inline virtual void reference(const ReferenceCounting& x)
486  inline virtual ReferenceCounting* virtualConstructor(
487  const CopyType ct = DEEP) const
488  { return new GenericGridCollection(*this, ct); }
489  aString className;
490  public:
491  inline virtual aString getClassName() const { return className; }
492 };
493 //
494 // Stream output operator.
495 //
496 ostream& operator<<(ostream& s, const GenericGridCollection& g);
497 
498 #endif // _GenericGridCollection