From 6fed65225be5d09e75a9981bb8d228557bd6a1b8 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Fri, 12 Jan 2007 20:41:00 +0000 Subject: CarpetLib: Add new datatype region_t The new datatype region_t combines an extent (a bbox), an outer boundary descriptor, a refinement descriptor, and a processor number: struct region_t { ibbox extent; // extent b2vect outer_boundaries; // outer boundaries b2vect refinement_boundaries; // refinement boundaries int map; // map to which this // region belongs int processor; // processor number }; These quantities are often used together, and combining them into a single datatype simplifies the code significantly. Adapt gh, dh, etc. to use this new datatype. This is a major API change. darcs-hash:20070112204130-dae7b-92cad546187b0fe499e8cfc38b2e26614a4f608c.gz --- Carpet/CarpetLib/interface.ccl | 1 + Carpet/CarpetLib/src/defs.cc | 31 ++++--------- Carpet/CarpetLib/src/defs.hh | 11 ----- Carpet/CarpetLib/src/dh.cc | 10 ++-- Carpet/CarpetLib/src/ggf.cc | 4 +- Carpet/CarpetLib/src/gh.cc | 92 +++++++++++++------------------------ Carpet/CarpetLib/src/gh.hh | 83 +++++++++++++++------------------ Carpet/CarpetLib/src/make.code.defn | 1 + Carpet/CarpetLib/src/region.cc | 86 ++++++++++++++++++++++++++++++++++ Carpet/CarpetLib/src/region.hh | 38 +++++++++++++++ 10 files changed, 210 insertions(+), 147 deletions(-) create mode 100644 Carpet/CarpetLib/src/region.cc create mode 100644 Carpet/CarpetLib/src/region.hh (limited to 'Carpet') diff --git a/Carpet/CarpetLib/interface.ccl b/Carpet/CarpetLib/interface.ccl index 1b3da8365..98a160bf9 100644 --- a/Carpet/CarpetLib/interface.ccl +++ b/Carpet/CarpetLib/interface.ccl @@ -7,6 +7,7 @@ includes header: dist.hh in dist.hh includes header: bbox.hh in bbox.hh includes header: bboxset.hh in bboxset.hh +includes header: region.hh in region.hh includes header: vect.hh in vect.hh includes header: commstate.hh in commstate.hh diff --git a/Carpet/CarpetLib/src/defs.cc b/Carpet/CarpetLib/src/defs.cc index 9b9715d47..09a078141 100644 --- a/Carpet/CarpetLib/src/defs.cc +++ b/Carpet/CarpetLib/src/defs.cc @@ -10,33 +10,13 @@ #include "bbox.hh" #include "defs.hh" +#include "region.hh" #include "vect.hh" using namespace std; -istream& operator>> (istream& is, grid_structure_t& gs) -{ - skipws (is); - consume (is, '{'); - is >> gs.bbss; - skipws (is); - consume (is, ';'); - is >> gs.obss; - skipws (is); - consume (is, '}'); - return is; -} - -ostream& operator<< (ostream& os, grid_structure_t const& gs) -{ - os << "{" << gs.bbss << ";" << gs.obss << "}"; - return os; -} - - - template inline T ipow_helper (T x, unsigned int y) { @@ -183,25 +163,30 @@ template CCTK_REAL ipow (CCTK_REAL x, int y); template vect ipow (vect x, int y); template istream& input (istream& os, vector& v); -template istream& input (istream& os, vector& v); template istream& input (istream& os, vector >& v); template istream& input (istream& os, vector >& v); template istream& input (istream& os, vector > >& v); template istream& input (istream& os, vector > >& v); +template istream& input (istream& os, vector& v); +template istream& input (istream& os, vector >& v); +template istream& input (istream& os, vector > >& v); template istream& input (istream& os, vector >& v); template istream& input (istream& os, vector,3> >& v); template istream& input (istream& os, vector,3> > >& v); template ostream& output (ostream& os, const list >& l); +template ostream& output (ostream& os, const list& l); template ostream& output (ostream& os, const set >& s); template ostream& output (ostream& os, const set >& s); template ostream& output (ostream& os, const stack >& s); template ostream& output (ostream& os, const vector& v); template ostream& output (ostream& os, const vector& v); template ostream& output (ostream& os, const vector& v); -template ostream& output (ostream& os, const vector& v); template ostream& output (ostream& os, const vector >& v); template ostream& output (ostream& os, const vector >& v); +template ostream& output (ostream& os, const vector& v); +template ostream& output (ostream& os, const vector >& v); +template ostream& output (ostream& os, const vector > >& v); template ostream& output (ostream& os, const vector > >& v); template ostream& output (ostream& os, const vector >& v); template ostream& output (ostream& os, const vector >& v); diff --git a/Carpet/CarpetLib/src/defs.hh b/Carpet/CarpetLib/src/defs.hh index 57d57a6b5..21272b58e 100644 --- a/Carpet/CarpetLib/src/defs.hh +++ b/Carpet/CarpetLib/src/defs.hh @@ -52,17 +52,6 @@ typedef vect,2> i2vect; -// Grid structure description -struct grid_structure_t { - vector > bbss; // refinement regions [reflevel][component] - vector > obss; // outer boundaries [reflevel][component] -}; - -istream& operator>> (istream& is, grid_structure_t& gs); -ostream& operator<< (ostream& os, grid_structure_t const& gs); - - - // A general type enum centering { vertex_centered, cell_centered }; diff --git a/Carpet/CarpetLib/src/dh.cc b/Carpet/CarpetLib/src/dh.cc index 59eff7286..8c2fe6cfd 100644 --- a/Carpet/CarpetLib/src/dh.cc +++ b/Carpet/CarpetLib/src/dh.cc @@ -112,7 +112,7 @@ void dh::allocate_bboxes () for (int rl=0; rlallocate - (d.boxes.at(ml).at(rl).at(c).exterior, h.proc(rl,c)); + (d.boxes.at(ml).at(rl).at(c).exterior, h.processor(rl,c)); } // for tl } // for c @@ -130,7 +130,7 @@ void ggf::recompose_allocate (const int rl) for (int tl=0; tlallocate - (d.boxes.at(ml).at(rl).at(c).exterior, h.proc(rl,c)); + (d.boxes.at(ml).at(rl).at(c).exterior, h.processor(rl,c)); } // for tl } // for c } // for ml diff --git a/Carpet/CarpetLib/src/gh.cc b/Carpet/CarpetLib/src/gh.cc index 95b216a08..eb523551c 100644 --- a/Carpet/CarpetLib/src/gh.cc +++ b/Carpet/CarpetLib/src/gh.cc @@ -37,26 +37,18 @@ gh::gh (const vector & reffacts_, const centering refcent_, gh::~gh () { } // Modifiers -void gh::regrid (const mexts& exts, - const rbnds& outer_bounds, - const rprocs& procs) +void gh::regrid (mregs const & regs) { DECLARE_CCTK_PARAMETERS; // Save the old grid hierarchy - _oldextents = _extents; - _oldouter_boundaries = _outer_boundaries; - _oldprocessors = _processors; - - _extents = exts; - _outer_boundaries = outer_bounds; - _processors = procs; + _oldregions = _regions; + _regions = regs; // Consistency checks // nota bene: there might be 0 refinement levels. - check_processor_number_consistency (); check_multigrid_consistency (); check_component_consistency (); check_base_grid_extent (); @@ -83,8 +75,8 @@ bool gh::recompose (const int rl, const bool do_prolongate) { // Handle changes in number of mglevels - if (_oldextents.size() != _extents.size()) { - _oldextents.resize (_extents.size()); + if (_oldregions.size() != _regions.size()) { + _oldregions.resize (_regions.size()); } bool const do_recompose = level_did_change(rl); @@ -98,13 +90,10 @@ bool gh::recompose (const int rl, // Overwrite old with new grid hierarchy for (int ml=0; ml=0 and rl= (int)_oldextents.at(ml).size()) return true; - if (_extents.at(ml).at(rl).size() != _oldextents.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 c=0; c::const_iterator d = dhs.begin(); diff --git a/Carpet/CarpetLib/src/gh.hh b/Carpet/CarpetLib/src/gh.hh index a3e943785..cc9d148f2 100644 --- a/Carpet/CarpetLib/src/gh.hh +++ b/Carpet/CarpetLib/src/gh.hh @@ -10,6 +10,7 @@ #include "bboxset.hh" #include "defs.hh" #include "dist.hh" +#include "region.hh" #include "vect.hh" using namespace std; @@ -33,15 +34,9 @@ class gh { public: // Types - typedef vector cexts; // ... for each component - typedef vector rexts; // ... for each refinement level - typedef vector mexts; // ... for each multigrid level - - typedef vector cbnds; // ... for each component - typedef vector rbnds; // ... for each refinement level - - typedef vector cprocs; // ... for each component - typedef vector rprocs; // ... for each refinement level + typedef vector cregs; // ... for each component + typedef vector rregs; // ... for each refinement level + typedef vector mregs; // ... for each multigrid level public: // should be readonly @@ -54,18 +49,14 @@ public: // should be readonly const ibbox baseextent; - private: vector > _bases; // [ml][rl] - // TODO: invent structure for this - mexts _extents; // extents of all grids - rbnds _outer_boundaries; // boundary descriptions of all grids - rprocs _processors; // processor numbers of all grids - - mexts _oldextents; // a copy, used during regridding - rbnds _oldouter_boundaries; - rprocs _oldprocessors; - + + // Extents and properties of all grids + mregs _regions; + // A copy, used during regridding + mregs _oldregions; + list ths; // list of all time hierarchies list dhs; // list of all data hierarchies @@ -80,65 +71,64 @@ public: virtual ~gh (); // Modifiers - void regrid (const mexts& exts, - const rbnds& outer_bounds, - const rprocs& procs); + void regrid (mregs const & regs); bool recompose (const int rl, const bool do_prolongate); private: bool level_did_change (const int rl) const; + // Accessors + public: - const mexts & extents() const + mregs const & regions () const { - return _extents; + return _regions; } - const rbnds & outer_boundaries() const + const vector > & bases() const + { + return _bases; + } + + ibbox extent (const int m, const int rl, const int c) const { - return _outer_boundaries; + return _regions.at(m).at(rl).at(c).extent; + } + + b2vect outer_boundaries (const int rl, const int c) const + { + return _regions.at(0).at(rl).at(c).outer_boundaries; } - const rprocs & processors() const + b2vect refinement_boundaries (const int rl, const int c) const { - return _processors; + return _regions.at(0).at(rl).at(c).refinement_boundaries; } - const vector > & bases() const + int processor (const int rl, const int c) const { - return _bases; + return _regions.at(0).at(rl).at(c).processor; } - - // Accessors + int mglevels () const { - return (int)_extents.size(); + return (int)_regions.size(); } int reflevels () const { if (mglevels() == 0) return 0; - return (int)_extents.at(0).size(); + return (int)_regions.at(0).size(); } int components (const int rl) const { - return (int)_extents.at(0).at(rl).size(); - } - - bbvect outer_boundary (const int rl, const int c) const - { - return _outer_boundaries.at(rl).at(c); - } - - int proc (const int rl, const int c) const - { - return _processors.at(rl).at(c); + return (int)_regions.at(0).at(rl).size(); } bool is_local (const int rl, const int c) const { - return proc(rl,c) == dist::rank(); + return processor(rl,c) == dist::rank(); } int local_components (const int rl) const; @@ -155,7 +145,6 @@ public: virtual ostream& output (ostream& os) const; private: - void check_processor_number_consistency (); void check_multigrid_consistency (); void check_component_consistency (); void check_base_grid_extent (); diff --git a/Carpet/CarpetLib/src/make.code.defn b/Carpet/CarpetLib/src/make.code.defn index 7a846f845..6c85dc167 100644 --- a/Carpet/CarpetLib/src/make.code.defn +++ b/Carpet/CarpetLib/src/make.code.defn @@ -13,6 +13,7 @@ SRCS = bbox.cc \ ggf.cc \ gh.cc \ mem.cc \ + region.cc \ th.cc \ vect.cc \ checkindex.c \ diff --git a/Carpet/CarpetLib/src/region.cc b/Carpet/CarpetLib/src/region.cc new file mode 100644 index 000000000..db9ef302e --- /dev/null +++ b/Carpet/CarpetLib/src/region.cc @@ -0,0 +1,86 @@ +#include + +#include "defs.hh" +#include "region.hh" + +using namespace std; + + + +bool +operator== (region_t const & a, region_t const & b) +{ + return + a.extent == b.extent and + all (all (a.outer_boundaries == b.outer_boundaries)) and + all (all (a.refinement_boundaries == b.refinement_boundaries)) and + a.map == b.map and + a.processor == b.processor; +} + + + +istream & +operator>> (istream & is, region_t & reg) +{ + skipws (is); + consume (is, "region_t"); + skipws (is); + consume (is, '('); + + skipws (is); + consume (is, "extent"); + skipws (is); + consume (is, '='); + is >> reg.extent; + skipws (is); + consume (is, ','); + + skipws (is); + consume (is, "outer_boundaries"); + skipws (is); + consume (is, '='); + is >> reg.outer_boundaries; + skipws (is); + consume (is, ','); + + skipws (is); + consume (is, "refinement_boundaries"); + skipws (is); + consume (is, '='); + is >> reg.refinement_boundaries; + skipws (is); + consume (is, ','); + + skipws (is); + consume (is, "map"); + skipws (is); + consume (is, '='); + is >> reg.map; + skipws (is); + consume (is, ','); + + skipws (is); + consume (is, "processor"); + skipws (is); + consume (is, '='); + is >> reg.processor; + skipws (is); + consume (is, ')'); + + return is; +} + + + +ostream & +operator<< (ostream & os, region_t const & reg) +{ + os << "region_t(" + << "extent=" << reg.extent << "," + << "outer_boundaries=" << reg.outer_boundaries << "," + << "refinement_boundaries=" << reg.refinement_boundaries << "," + << "map=" << reg.map << "," + << "processor=" << reg.processor << ")"; + return os; +} diff --git a/Carpet/CarpetLib/src/region.hh b/Carpet/CarpetLib/src/region.hh new file mode 100644 index 000000000..73bc48ea0 --- /dev/null +++ b/Carpet/CarpetLib/src/region.hh @@ -0,0 +1,38 @@ +#ifndef REGION_HH +#define REGION_HH + +#include + +#include "defs.hh" +#include "bbox.hh" +#include "vect.hh" + + + +// Region description +struct region_t { + ibbox extent; // extent + b2vect outer_boundaries; // outer boundaries + b2vect refinement_boundaries; // refinement boundaries + int map; // map to which this + // region belongs + int processor; // processor number +}; + + + +bool operator== (region_t const & a, region_t const & b); +inline +bool operator!= (region_t const & a, region_t const & b) +{ + return not operator== (a, b); +} + + + +istream & operator>> (istream & is, region_t & reg); +ostream & operator<< (ostream & os, region_t const & reg); + + + +#endif // #ifndef REGION_HH -- cgit v1.2.3