aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Requirements/src/gridpoint.hh
blob: ead8a733856f9a8a376ea2c5b7834c5ab5ebe3d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef GRIDPOINT_HH
#define GRIDPOINT_HH

#include <iostream>

#include <cctk_Schedule.h>

#include <clause.hh>
#include <location.hh>

using namespace std;

namespace Requirements {
  
  // Represents which have valid information and which do not.
  // This will later be indexed by rl, map etc.
  // Currently only works with unigrid.
  class gridpoint_t {
    bool i_interior, i_boundary, i_ghostzones, i_boundary_ghostzones;
  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
    // been run
    gridpoint_t(clause_t const& clause):
      i_interior(clause.everywhere or clause.interior),
      i_boundary(clause.everywhere or clause.boundary),
      i_ghostzones(clause.everywhere),
      i_boundary_ghostzones(clause.everywhere or clause.boundary_ghostzones)
    {}
    
    // Accessors
    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,
                     int vi, int it, int rl, int m, int tl) const;
    void report_error(cFunctionData const* function_data,
                      int vi, int it, int rl, int m, int tl,
                      char const* what, char const* where) const;
    void report_warning(cFunctionData const* function_data,
                        int vi, int it, int rl, int m, int tl,
                        char const* what, char const* where) const;
    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(const gridpoint_t& oldgp, const location_t& l) const;

    static bool there_was_an_error;
    static bool there_was_a_warning;
  };


  inline ostream& operator<< (ostream& os, const gridpoint_t& a) {
    a.output(os);
    return os;
  }
}

#endif