aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Requirements/src/gridpoint.cc
blob: 3b5354d0055967e9634574402d7baeb9a04830fe (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <cctk.h>
#include <cctk_Parameters.h>

#include <Requirements.hh>

#include <gridpoint.hh>
#include <util.hh>

namespace Requirements {

  using namespace std;
  
  bool gridpoint_t::there_was_an_error = false;
  bool gridpoint_t::there_was_a_warning = false;

  // Accessors
  void gridpoint_t::set_interior(bool b, const location_t &l)
  {
    const gridpoint_t oldgp = *this;
    i_interior = b;
    output_location(oldgp, l);
  }
  void gridpoint_t::set_boundary(bool b, const location_t &l)
  {
    const gridpoint_t oldgp = *this;
    i_boundary = b;
    output_location(oldgp, l);
  }
  void gridpoint_t::set_ghostzones(bool b, const location_t &l)
  {
    const gridpoint_t oldgp = *this;
    i_ghostzones = b;
    output_location(oldgp, l);
  }
  void gridpoint_t::set_boundary_ghostzones(bool b, const location_t &l)
  {
    const gridpoint_t oldgp = *this;
    i_boundary_ghostzones = b;
    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,
                                cFunctionData const* const function_data,
                                int const vi,
                                int const rl, int const m, int const tl)
    const
  {
    if (not i_interior) {
      if (clause.everywhere or clause.interior) {
        report_error(function_data, vi, rl, m, tl,
                     "calling function", "interior");
      }
    }
    if (not i_boundary) {
      if (clause.everywhere or clause.boundary) {
        report_error(function_data, vi, rl, m, tl,
                     "calling function", "boundary");
      }
    }
    if (not i_ghostzones) {
      if (clause.everywhere) {
        report_error(function_data, vi, rl, m, tl,
                     "calling function", "ghostzones");
      }
    }
    if (not i_boundary_ghostzones) {
      if (clause.everywhere or clause.boundary_ghostzones) {
        report_error(function_data, vi, rl, m, tl,
                     "calling", "boundary-ghostzones");
      }
    }
  }
  
  void gridpoint_t::report_error(cFunctionData const* const function_data,
                                 int const vi,
                                 int const rl, int const m, int const tl,
                                 char const* const what,
                                 char const* const where) const
  {
    char* const fullname = CCTK_FullName(vi);
    ostringstream state;
    state << "current state: " << *this << std::endl;
    if (function_data) {
      // The error is related to a scheduled function
      CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,
                 "Schedule READS clause not satisfied: "
                 "Function %s::%s in %s: "
                 "Variable %s reflevel=%d map=%d timelevel=%d: "
                 "%s not valid for %s. %s",
                 function_data->thorn, function_data->routine,
                 function_data->where,
                 fullname, rl, m, tl,
                 where, what, state.str().c_str());
    } else {
      // The error is not related to a scheduled function
      CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,
                 "Schedule READS clause not satisfied: "
                 "Variable %s reflevel=%d map=%d timelevel=%d: "
                 "%s not valid for %s. %s",
                 fullname, rl, m, tl,
                 where, what, state.str().c_str());
    }
    free(fullname);
    there_was_an_error = true;
  }
  
  void gridpoint_t::report_warning(cFunctionData const* const function_data,
                                   int const vi,
                                   int const rl, int const m, int const tl,
                                   char const* const what,
                                   char const* const where) const
  {
    char* const fullname = CCTK_FullName(vi);
    ostringstream state;
    state << "current state: " << *this << std::endl;
    if (function_data) {
      // The error is related to a scheduled function
      CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,
                 "Schedule WRITES clause is superfluous: "
                 "Function %s::%s in %s: "
                 "Variable %s reflevel=%d map=%d timelevel=%d: "
                 "%s already valid for %s. %s",
                 function_data->thorn, function_data->routine,
                 function_data->where,
                 fullname, rl, m, tl,
                 where, what, state.str().c_str());
    } else {
      // The error is not related to a scheduled function
      CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,
                 "Schedule WRITES clause already satisfied: "
                 "Variable %s reflevel=%d map=%d timelevel=%d: "
                 "%s already valid for %s. %s",
                 fullname, rl, m, tl,
                 where, what, state.str().c_str());
    }
    free(fullname);
    there_was_a_warning = true;
  }
  
  // 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, const location_t &loc)
  {
    const gridpoint_t oldgp = *this;
    if (clause.everywhere or clause.interior) {
      i_interior = true;
    }
    if (clause.everywhere or clause.boundary) {
      i_boundary = true;
    }
    if (clause.everywhere) {
      i_ghostzones = true;
    }
    if (clause.everywhere or clause.boundary_ghostzones) {
      i_boundary_ghostzones = true;
    }
    output_location(oldgp, loc);
  }
  
  void gridpoint_t::output(ostream& os) const
  {
    os << "(";
    if (i_interior) os << "interior;";
    if (i_boundary) os << "boundary;";
    if (i_ghostzones) os << "ghostzones;";
    if (i_boundary_ghostzones) os << "boundary_ghostzones;";
    os << ")";
  }
  
  // Some readable and parsable debug output
  void gridpoint_t::output_location(const gridpoint_t& oldgp,
                                    const location_t& l) const
  {
    DECLARE_CCTK_PARAMETERS;
    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";
  }

}