From e5218dae7b905bb330f48dcbc78ad0f744a164c0 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 19 Apr 2007 01:45:00 +0000 Subject: CarpetLib: Various gh changes Store boundary widths in gh class. Do not calculate base extents, have them passed in instead. darcs-hash:20070419014532-dae7b-26e78ee0f9e196337a32df895e9bf54b30db21df.gz --- Carpet/CarpetLib/src/gh.cc | 396 ++++++++++++++++++++++++--------------------- Carpet/CarpetLib/src/gh.hh | 87 ++++------ 2 files changed, 250 insertions(+), 233 deletions(-) (limited to 'Carpet/CarpetLib/src') diff --git a/Carpet/CarpetLib/src/gh.cc b/Carpet/CarpetLib/src/gh.cc index 1fa06ee2d..e85d010d8 100644 --- a/Carpet/CarpetLib/src/gh.cc +++ b/Carpet/CarpetLib/src/gh.cc @@ -18,46 +18,163 @@ using namespace std; // Constructors -gh::gh (const vector & reffacts_, const centering refcent_, - const int mgfact_, const centering mgcent_, - const ibbox baseextent_) +gh:: +gh (vector const & reffacts_, centering const refcent_, + int const mgfact_, centering const mgcent_, + vector > const & baseextents_, + i2vect const & boundary_width_) : reffacts(reffacts_), refcent(refcent_), mgfact(mgfact_), mgcent(mgcent_), - baseextent(baseextent_) + baseextents(baseextents_), + boundary_width(boundary_width_) { assert (reffacts.size() >= 1); assert (all (reffacts.front() == 1)); - for (size_t n = 1; n < reffacts.size(); ++ n) { - assert (all (reffacts.AT(n) >= reffacts.AT(n-1))); - assert (all (reffacts.AT(n) % reffacts.AT(n-1) == 0)); + for (int rl = 1; rl < (int)reffacts.size(); ++ rl) { + assert (all (reffacts.AT(rl) >= reffacts.AT(rl-1))); + assert (all (reffacts.AT(rl) % reffacts.AT(rl-1) == 0)); + } + assert (refcent == vertex_centered or refcent == cell_centered); + + assert (mgfact >= 1); + assert (mgcent == vertex_centered or mgcent == cell_centered); + + assert (baseextents.size() >= 1); + assert (baseextents.AT(0).size() >= 1); + assert (baseextents.AT(0).size() == reffacts.size()); + for (int ml = 1; ml < (int)baseextents.size(); ++ ml) { + assert (baseextents.AT(ml).size() == baseextents.AT(ml-1).size()); + } + for (int ml = 0; ml < (int)baseextents.size(); ++ ml) { + for (int rl = 1; rl < (int)baseextents.AT(ml).size(); ++ rl) { + ibbox const & cbox = baseextents.AT(ml).AT(rl-1); + ibbox const & fbox = baseextents.AT(ml).AT(rl); + assert (all (cbox.stride() * reffacts.AT(rl-1) == + fbox.stride() * reffacts.AT(rl))); + } + } + + assert (all (all (boundary_width >= 0))); + for (int ml = 0; ml < (int)baseextents.size(); ++ ml) { + for (int rl = 0; rl < (int)baseextents.AT(ml).size(); ++ rl) { + ibbox const & box = baseextents.AT(ml).AT(rl); + assert (all (box.shape() / box.stride() > + boundary_width[0] + boundary_width[1])); + } } - assert (all (baseextent.stride() % reffacts.AT(reffacts.size()-1) == 0)); } // Destructors -gh::~gh () { } +gh:: +~gh () +{ +} + + // Modifiers -void gh::regrid (mregs const & regs) +void +gh:: +regrid (mregs const & regs) { DECLARE_CCTK_PARAMETERS; - // Save the old grid hierarchy - _oldregions.clear (); - swap (_oldregions, _regions); - _regions = regs; + // Save the grid hierarchy + oldregions.clear (); + swap (oldregions, regions); + regions = regs; + + // Consistency checks - // nota bene: there might be 0 refinement levels. + // Note: there may be zero refinement levels - check_multigrid_consistency (); - check_component_consistency (); - check_base_grid_extent (); - check_refinement_levels (); + // Check multigrid consistency + assert (mglevels()>0); + for (int ml=1; ml0); + for (int c=0; c=0 and rl= (int)_oldregions.AT(ml).size()) return true; - if (_regions.AT(ml).AT(rl).size() != _oldregions.AT(ml).AT(rl).size()) { + if (rl >= (int)oldregions.AT(ml).size()) return true; + if (regions.AT(ml).AT(rl).size() != oldregions.AT(ml).AT(rl).size()) { return true; } for (int c=0; c0); - for (int ml=1; ml0); - for (int c=0; c0) { - for (int c=0; c::const_iterator d = dhs.begin(); - d != dhs.end(); ++d) { - os << sep; - (*d)->output(os); - sep = ","; + bool isfirst = true; + for (list::const_iterator + d = dhs.begin(); d != dhs.end(); ++ d, isfirst = false) + { + if (not isfirst) os << ","; + os << *d; + } } os << "}"; return os; diff --git a/Carpet/CarpetLib/src/gh.hh b/Carpet/CarpetLib/src/gh.hh index 619aeebf0..6346e1509 100644 --- a/Carpet/CarpetLib/src/gh.hh +++ b/Carpet/CarpetLib/src/gh.hh @@ -22,9 +22,6 @@ class dh; class th; class gh; -// Output -ostream& operator<< (ostream& os, const gh& h); - // A refinement hierarchy, where higher levels are finer than the base @@ -47,15 +44,11 @@ public: // should be readonly const int mgfact; // default multigrid factor const centering mgcent; // default (vertex or cell centered) - const ibbox baseextent; - -private: - vector > _bases; // [ml][rl] + vector > baseextents; // [ml][rl] + const i2vect boundary_width; - // Extents and properties of all grids - mregs _regions; - // A copy, used during regridding - mregs _oldregions; + mregs regions; // extents and properties of all grids + mregs oldregions; // a copy, used during regridding list ths; // list of all time hierarchies list dhs; // list of all data hierarchies @@ -63,67 +56,60 @@ private: public: // Constructors - gh (const vector & reffacts, const centering refcent, - const int mgfact, const centering mgcent, - const ibbox baseextent); + gh (vector const & reffacts, centering refcent, + int mgfact, centering mgcent, + vector > const & baseextents, + i2vect const & boundary_width); // Destructors ~gh (); // Modifiers void regrid (mregs const & regs); - bool recompose (const int rl, - const bool do_prolongate); + bool recompose (int rl, bool do_prolongate); + private: - bool level_did_change (const int rl) const; + + bool level_did_change (int rl) const; // Accessors public: - mregs const & regions () const - { - return _regions; - } - - const vector > & bases() const - { - return _bases; - } - ibbox extent (const int m, const int rl, const int c) const + ibbox const & extent (const int ml, const int rl, const int c) const { - return _regions.AT(m).AT(rl).AT(c).extent; + return regions.AT(ml).AT(rl).AT(c).extent; } - b2vect outer_boundaries (const int rl, const int c) const + ibbox const & baseextent (const int ml, const int rl) const { - return _regions.AT(0).AT(rl).AT(c).outer_boundaries; + return baseextents.AT(ml).AT(rl); } - - b2vect refinement_boundaries (const int rl, const int c) const + + b2vect const & outer_boundaries (const int rl, const int c) const { - return _regions.AT(0).AT(rl).AT(c).refinement_boundaries; + return regions.AT(0).AT(rl).AT(c).outer_boundaries; } - + int processor (const int rl, const int c) const { - return _regions.AT(0).AT(rl).AT(c).processor; + return regions.AT(0).AT(rl).AT(c).processor; } int mglevels () const { - return (int)_regions.size(); + return (int)regions.size(); } int reflevels () const { if (mglevels() == 0) return 0; - return (int)_regions.AT(0).size(); + return (int)regions.AT(0).size(); } int components (const int rl) const { - return (int)_regions.AT(0).AT(rl).size(); + return (int)regions.AT(0).AT(rl).size(); } bool is_local (const int rl, const int c) const @@ -134,32 +120,27 @@ public: int local_components (const int rl) const; // Time hierarchy management - void add (th* t); - void remove (th* t); + void add (th * t); + void remove (th * t); // Data hierarchy management - void add (dh* d); - void remove (dh* d); + void add (dh * d); + void remove (dh * d); // Output - ostream& output (ostream& os) const; + ostream & output (ostream & os) const; private: - void check_multigrid_consistency (); - void check_component_consistency (); - void check_base_grid_extent (); - void check_refinement_levels (); - void calculate_base_extents_of_all_levels (); - void do_output_bboxes (ostream& os) const; - void do_output_bases (ostream& os) const; + void do_output_bboxes (ostream & os) const; + void do_output_bases (ostream & os) const; }; -inline ostream& operator<< (ostream& os, const gh& h) { - h.output(os); - return os; +inline ostream & operator<< (ostream & os, gh const & h) +{ + return h.output(os); } -- cgit v1.2.3