SheafSystem  0.0.0.0
field_refinement_policy.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #include "SheafSystem/field_refinement_policy.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/factory.impl.h"
25 #include "SheafSystem/field_refinement_buffer.h"
26 #include "SheafSystem/field_vd.h"
27 
28 using namespace std;
29 using namespace fields; // Workaround for MS C++ bug.
30 
31 // ===========================================================
32 // FIELD_REFINEMENT_POLICY FACET
33 // ===========================================================
34 
35 // PUBLIC MEMBER FUNCTIONS
36 
38 field_refinement_policy(size_type xrefinement_depth_ub)
39  : _refinement_depth_ub(xrefinement_depth_ub)
40 {
41  // Preconditions:
42 
43  // Body:
44 
45  // Postconditions:
46 
47  ensure(invariant());
48  ensure(refinement_depth_ub() == xrefinement_depth_ub);
49 
50  // Exit:
51 
52  return;
53 }
54 
58 {
59 
60  // Preconditions:
61 
62 
63  // Body:
64 
65 
66  // Postconditions:
67 
68  ensure(invariant());
69 
70  // Exit:
71 
72  return;
73 }
74 
77 {
78  // Preconditions:
79 
80  // Body:
81 
82  // Nothing to do.
83 
84  // Postconditions:
85 
86  // Exit:
87 
88  return;
89 }
90 
91 bool
93 should_refine(field_refinement_buffer& xbuffer, size_type xrefinement_depth) const
94 {
95  bool result = false;
96 
97  // Preconditions:
98 
99  require(xbuffer.target.state_is_read_accessible());
100  require(xbuffer.source.state_is_read_accessible());
101 
102  // Body:
103 
104  is_abstract();
105 
106  // Postconditions:
107 
108  ensure( result ? xrefinement_depth < refinement_depth_ub() : true);
109 
110  // Exit:
111 
112  return result;
113 }
114 
118 {
119  return _refinement_depth_ub;
120 }
121 
122 void
125 {
126  // Preconditions:
127 
128  // Body:
129 
130  _refinement_depth_ub = xub;
131 
132  // Postconditions:
133 
134  ensure(refinement_depth_ub() == xub);
135 
136  // Exit:
137 
138  return;
139 }
140 
141 const std::string&
143 class_name() const
144 {
145  // Preconditions:
146 
147  // Body:
148 
149  const string& result = static_class_name();
150 
151  // Postconditions:
152 
153 
154  // Exit:
155 
156  return result;
157 }
158 
159 const std::string&
162 {
163 
164  // Preconditions:
165 
166 
167  // Body:
168 
169  static const string result("field_refinement_policy");
170 
171  // Postconditions:
172 
173 
174  // Exit:
175 
176  return result;
177 }
178 
181 new_policy(const std::string& xname)
182 {
183  field_refinement_policy* result;
184 
185  // Preconditions:
186 
187  require(policy_factory().contains_prototype(xname));
188 
189  // Body:
190 
191  result = policy_factory().new_instance(xname);
192 
193  // Postconditions:
194 
195  ensure(result != 0);
196  ensure(unexecutable("result is default constructed"));
197 
198  // Exit:
199 
200  return result;
201 }
202 
206 {
207 
208  // Preconditions:
209 
210 
211  // Body:
212 
213  static factory<field_refinement_policy> result;
214 
215  // Postconditions:
216 
217 
218  // Exit:
219 
220  return result;
221 }
222 
223 
224 // ===========================================================
225 // ANY FACET
226 // ===========================================================
227 
228 // PUBLIC MEMBER FUNCTIONS
229 
230 bool
232 is_ancestor_of(const any* other) const
233 {
234 
235  // Preconditions:
236 
237  require(other != 0);
238 
239  // Body:
240 
241  // True if other conforms to this
242 
243  bool result = dynamic_cast<const field_refinement_policy*>(other) != 0;
244 
245  // Postconditions:
246 
247  return result;
248 }
249 
253 {
254 
255  // Preconditions:
256 
257 
258  // Body:
259 
261 
262  // Postconditions:
263 
264  ensure(invariant());
265 
266  // Exit
267 
268  return *this;
269 }
270 
271 bool
273 invariant() const
274 {
275  bool result = true;
276 
277  if(invariant_check())
278  {
279  // Prevent recursive calls to invariant
280 
282 
283  // Must satisfy base class invariant
284 
285  invariance(any::invariant());
286 
287  // Invariances for this class:
288 
289  // Finished, turn invariant checking back on.
290 
292  }
293 
294  // Exit
295 
296  return result;
297 }
298 
299 
300 // ===========================================================
301 // NON-MEMBER FUNCTIONS
302 // ===========================================================
303 
304 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
static factory< field_refinement_policy > & policy_factory()
A factory for making policy objects.
virtual ~field_refinement_policy()
Destructor.
size_type _refinement_depth_ub
The upper bound and the refinement level of a cell.
static field_refinement_policy * new_policy(const std::string &xname)
Creates an instance of the policy with class name xname.
field_refinement_policy(size_type xrefinement_depth_ub)
Creates an instance with reinement upper bound xrefinement_ub.
A buffer for data which is used by both a local_field_refiner object and its associated field_refinem...
Namespace for fields component of sheaf system.
size_type refinement_depth_ub() const
The upper bound on the refinement depth of a cell. A cell will not be refined if its refinement depth...
STL namespace.
Abstract base class with useful features for all objects.
Definition: any.h:39
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
virtual bool should_refine(field_refinement_buffer &xbuffer, size_type xrefinement_depth) const =0
True if the zone specified by xzone_id should be refined.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
An abstract policy that determines the conditions under which a zone should be refined.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
static const std::string & static_class_name()
The class name of this class.
field_vd & target
The field being refined.
virtual field_refinement_policy & operator=(const field_refinement_policy &xother)
Assignment operator.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool invariant() const
Class invariant.
const field_vd & source
The reference field.
virtual const std::string & class_name() const
The class name of this.
bool state_is_read_accessible() const
True if this is attached and if the coordinates and property are accessible for read or access contro...
Definition: field_vd.cc:1380
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
void put_refinement_depth_ub(size_type xub)
Set the refinement depth upper bound to xub.