aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Requirements
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-04-04 12:05:04 -0400
committerErik Schnetter <schnetter@gmail.com>2013-04-04 12:05:04 -0400
commitf203c7178b5d44f4654991d5ccd2fcd8c1ce5af3 (patch)
tree654f779aa9b423aa4556e9e0ec799b77663e1071 /Carpet/Requirements
parent314d48a230714aca56fc9f27e7d6e7ca160cfb00 (diff)
Requirements: Simplify logic to detect changes in gridpoint_t
Introduce operator^ (exclusive-or) for gridpoint_t. Use it when determining whether the state changed.
Diffstat (limited to 'Carpet/Requirements')
-rw-r--r--Carpet/Requirements/src/Requirements.hh6
-rw-r--r--Carpet/Requirements/src/gridpoint.cc75
-rw-r--r--Carpet/Requirements/src/gridpoint.hh47
3 files changed, 68 insertions, 60 deletions
diff --git a/Carpet/Requirements/src/Requirements.hh b/Carpet/Requirements/src/Requirements.hh
index 94a45cdac..9b235a7e1 100644
--- a/Carpet/Requirements/src/Requirements.hh
+++ b/Carpet/Requirements/src/Requirements.hh
@@ -13,12 +13,6 @@ namespace Requirements {
namespace valid {
enum valid_t { nowhere, interior, everywhere };
}
-
- enum zones_t { BIT_INTERIOR = 1,
- BIT_BOUNDARY = 2,
- BIT_GHOSTZONES = 4,
- BIT_BOUNDARY_GHOSTZONES = 8
- };
// Set up basic grid structure
void Setup(int maps);
diff --git a/Carpet/Requirements/src/gridpoint.cc b/Carpet/Requirements/src/gridpoint.cc
index 57973811a..644357ab7 100644
--- a/Carpet/Requirements/src/gridpoint.cc
+++ b/Carpet/Requirements/src/gridpoint.cc
@@ -10,44 +10,36 @@
namespace Requirements {
using namespace std;
-
+
bool gridpoint_t::there_was_an_error = false;
bool gridpoint_t::there_was_a_warning = false;
// Accessors
- bool gridpoint_t::interior() const { return i_interior; }
- bool gridpoint_t::boundary() const { return i_boundary; }
- bool gridpoint_t::ghostzones() const { return i_ghostzones; }
- bool gridpoint_t::boundary_ghostzones() const { return i_boundary_ghostzones; }
- void gridpoint_t::set_interior(bool b, location_t &l)
+ void gridpoint_t::set_interior(bool b, const location_t &l)
{
- if (i_interior == b)
- return;
+ const gridpoint_t oldgp = *this;
i_interior = b;
- output_location(l, BIT_INTERIOR);
+ output_location(oldgp, l);
}
- void gridpoint_t::set_boundary(bool b, location_t &l)
+ void gridpoint_t::set_boundary(bool b, const location_t &l)
{
- if (i_boundary == b)
- return;
+ const gridpoint_t oldgp = *this;
i_boundary = b;
- output_location(l, BIT_BOUNDARY);
+ output_location(oldgp, l);
}
- void gridpoint_t::set_ghostzones(bool b, location_t &l)
+ void gridpoint_t::set_ghostzones(bool b, const location_t &l)
{
- if (i_ghostzones == b)
- return;
+ const gridpoint_t oldgp = *this;
i_ghostzones = b;
- output_location(l, BIT_GHOSTZONES);
+ output_location(oldgp, l);
}
- void gridpoint_t::set_boundary_ghostzones(bool b, location_t &l)
+ void gridpoint_t::set_boundary_ghostzones(bool b, const location_t &l)
{
- if (i_boundary_ghostzones == b)
- return;
+ const gridpoint_t oldgp = *this;
i_boundary_ghostzones = b;
- output_location(l, BIT_BOUNDARY_GHOSTZONES);
+ output_location(oldgp, l);
}
-
+
// Check that all the parts of the grid variables read by a function
// are valid. This will be called before the function is executed.
void gridpoint_t::check_state(clause_t const& clause,
@@ -150,31 +142,22 @@ namespace Requirements {
// Update this object to reflect the fact that some parts of some
// variables are now valid after a function has been called
- void gridpoint_t::update_state(clause_t const& clause, location_t &loc)
+ void gridpoint_t::update_state(clause_t const& clause, const location_t &loc)
{
- int where = 0;
+ const gridpoint_t oldgp = *this;
if (clause.everywhere or clause.interior) {
- if (!i_interior)
- where |= BIT_INTERIOR;
i_interior = true;
}
if (clause.everywhere or clause.boundary) {
- if (!i_boundary)
- where |= BIT_BOUNDARY;
i_boundary = true;
}
if (clause.everywhere) {
- if (!i_ghostzones)
- where |= BIT_GHOSTZONES;
i_ghostzones = true;
}
if (clause.everywhere or clause.boundary_ghostzones) {
- if (!i_boundary_ghostzones)
- where |= BIT_BOUNDARY_GHOSTZONES;
i_boundary_ghostzones = true;
}
- if (where)
- output_location(loc, where);
+ output_location(oldgp, loc);
}
void gridpoint_t::output(ostream& os) const
@@ -188,17 +171,25 @@ namespace Requirements {
}
// Some readable and parsable debug output
- void gridpoint_t::output_location(location_t& l, int changed) const
+ void gridpoint_t::output_location(const gridpoint_t& oldgp,
+ const location_t& l) const
{
DECLARE_CCTK_PARAMETERS;
-
- cout << "LOC: " << l << " "
- << ( (changed&BIT_INTERIOR) ?"(IN:":"(in:" ) << i_interior
- << ( (changed&BIT_BOUNDARY) ?",BO:":",bo:" ) << i_boundary
- << ( (changed&BIT_GHOSTZONES) ?",GH:":",gh:" ) << i_ghostzones
- << ( (changed&BIT_BOUNDARY_GHOSTZONES)?",BG:":",bg:" ) << i_boundary_ghostzones
- << ") " << l.info << "\n";
if (not output_changes) return;
+
+ const gridpoint_t difference = *this ^ oldgp;
+ if (difference.empty()) return;
+
+ cout << "LOC: " << l << " ("
+ << (difference.interior() ? "IN" : "in" ) << ":"
+ << interior() << ","
+ << (difference.boundary() ? "BO" : "bo" ) << ":"
+ << boundary() << ","
+ << (difference.ghostzones() ? "GH" : "gh" ) << ":"
+ << ghostzones() << ","
+ << (difference.boundary_ghostzones() ? "BG" : "bg" ) << ":"
+ << boundary_ghostzones() << ") "
+ << l.info << "\n";
}
}
diff --git a/Carpet/Requirements/src/gridpoint.hh b/Carpet/Requirements/src/gridpoint.hh
index 14dc6a1ec..a64e2abfc 100644
--- a/Carpet/Requirements/src/gridpoint.hh
+++ b/Carpet/Requirements/src/gridpoint.hh
@@ -16,11 +16,20 @@ namespace Requirements {
// Currently only works with unigrid.
class gridpoint_t {
bool i_interior, i_boundary, i_ghostzones, i_boundary_ghostzones;
- public:
+ public:
gridpoint_t():
i_interior(false), i_boundary(false), i_ghostzones(false),
i_boundary_ghostzones(false)
{}
+ gridpoint_t(bool interior_,
+ bool boundary_,
+ bool ghostzones_,
+ bool boundary_ghostzones_):
+ i_interior(interior_),
+ i_boundary(boundary_),
+ i_ghostzones(ghostzones_),
+ i_boundary_ghostzones(boundary_ghostzones_)
+ {}
// Construct an object with information about which points are
// valid, assuming that a function with the given clause has just
@@ -31,15 +40,16 @@ namespace Requirements {
i_ghostzones(clause.everywhere),
i_boundary_ghostzones(clause.everywhere or clause.boundary_ghostzones)
{}
+
// Accessors
- bool interior() const;
- bool boundary() const;
- bool ghostzones() const;
- bool boundary_ghostzones() const;
- void set_interior(bool b, location_t &l);
- void set_boundary(bool b, location_t &l);
- void set_ghostzones(bool b, location_t &l);
- void set_boundary_ghostzones(bool b, location_t &l);
+ bool interior() const { return i_interior; }
+ bool boundary() const { return i_boundary; }
+ bool ghostzones() const { return i_ghostzones; }
+ bool boundary_ghostzones() const { return i_boundary_ghostzones; }
+ void set_interior(bool b, const location_t &l);
+ void set_boundary(bool b, const location_t &l);
+ void set_ghostzones(bool b, const location_t &l);
+ void set_boundary_ghostzones(bool b, const location_t &l);
void check_state(clause_t const& clause,
cFunctionData const* function_data,
@@ -50,12 +60,25 @@ namespace Requirements {
void report_warning(cFunctionData const* function_data,
int vi, int rl, int m, int tl,
char const* what, char const* where) const;
- void update_state(clause_t const& clause, location_t &loc);
-
+ void update_state(clause_t const& clause, const location_t &loc);
+
+ // Operators
+ bool empty() const
+ {
+ return i_interior or i_boundary or i_ghostzones or i_boundary_ghostzones;
+ }
+ gridpoint_t operator^(const gridpoint_t& gp) const
+ {
+ return gridpoint_t(i_interior ^ gp.i_interior,
+ i_boundary ^ gp.i_boundary,
+ i_ghostzones ^ gp.i_ghostzones,
+ i_boundary_ghostzones ^ gp.i_boundary_ghostzones);
+ }
+
// Input/Output helpers
void input (istream& is);
void output (ostream& os) const;
- void output_location (location_t &l, int changed) const;
+ void output_location(const gridpoint_t& oldgp, const location_t& l) const;
static bool there_was_an_error;
static bool there_was_a_warning;