SheafSystem  0.0.0.0
depth_bound_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/depth_bound_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 // DEPTH_BOUND_REFINEMENT_POLICY FACET
33 // ===========================================================
34 
35 // PUBLIC MEMBER FUNCTIONS
36 
39  : field_refinement_policy(xrefinement_depth_ub)
40 {
41 
42  // Preconditions:
43 
44 
45  // Body:
46 
47  // Postconditions:
48 
49  ensure(invariant());
50  ensure(refinement_depth_ub() == xrefinement_depth_ub);
51 
52 
53  // Exit:
54 
55  return;
56 }
57 
58 
61  : field_refinement_policy(xother)
62 {
63 
64  // Preconditions:
65 
66 
67  // Body:
68 
69  // Postconditions:
70 
71  ensure(invariant());
72 
73  // Exit:
74 
75  return;
76 }
77 
78 
81 {
82  // Preconditions:
83 
84 
85  // Body:
86 
87  // Nothing to do.
88 
89  // Postconditions:
90 
91  // Exit:
92 
93  return;
94 }
95 
96 
97 // PRIVATE MEMBER FUNCTIONS
98 
99 bool
100 fields::depth_bound_refinement_policy::
101 _has_prototype = make_prototype();
102 
103 bool
104 fields::depth_bound_refinement_policy::
105 make_prototype()
106 {
107  bool result = true;
108 
109  // Preconditions:
110 
111 
112  // Body:
113 
116 
117  policy_factory().insert_prototype(lproto);
118 
119  // Postconditions:
120 
121  ensure(policy_factory().contains_prototype(static_class_name()));
122 
123  // Exit:
124 
125  return result;
126 }
127 
128 
129 // ===========================================================
130 // FIELD_REFINEMENT_POLICY FACET
131 // ===========================================================
132 
133 // PUBLIC MEMBER FUNCTIONS
134 
135 bool
137 should_refine(field_refinement_buffer& xbuffer, size_type xrefinement_depth) const
138 {
139  bool result;
140 
141  // Preconditions:
142 
143  require(xbuffer.source.state_is_read_accessible());
144  require(xbuffer.target.state_is_read_accessible());
145  require(xbuffer.target.same_evaluation());
146 
147  // Body:
148 
149  result = (xrefinement_depth < _refinement_depth_ub);
150 
151  // Postconditions:
152 
153  ensure( result ? xrefinement_depth < refinement_depth_ub() : true);
154 
155  // Exit:
156 
157  return result;
158 }
159 
160 const std::string&
162 class_name() const
163 {
164 
165  // Preconditions:
166 
167 
168  // Body:
169 
170  const string& result = static_class_name();
171 
172  // Postconditions:
173 
174 
175  // Exit:
176 
177  return result;
178 }
179 
180 const std::string&
183 {
184 
185  // Preconditions:
186 
187 
188  // Body:
189 
190  static const string result("depth_bound_refinement_policy");
191 
192  // Postconditions:
193 
194 
195  // Exit:
196 
197  return result;
198 }
199 
200 
201 // ===========================================================
202 // ANY FACET
203 // ===========================================================
204 
205 // PUBLIC MEMBER FUNCTIONS
206 
207 bool
209 is_ancestor_of(const any* other) const
210 {
211 
212  // Preconditions:
213 
214  require(other != 0);
215 
216  // Body:
217 
218  // True if other conforms to this
219 
220  bool result = dynamic_cast<const depth_bound_refinement_policy*>(other) != 0;
221 
222  // Postconditions:
223 
224  return result;
225 }
226 
229 clone() const
230 {
232 
233  // Preconditions:
234 
235  // Body:
236 
237  result = new depth_bound_refinement_policy(*this);
238 
239  // Postconditions:
240 
241  ensure(result != 0);
242  ensure(is_same_type(result));
243 
244  // Exit:
245 
246  return result;
247 }
248 
253 {
254 
255  // Preconditions:
256 
257  require(is_ancestor_of(&xother));
258 
259  // Body:
260 
261  not_implemented();
262 
263  // Postconditions:
264 
265  ensure(invariant());
266 
267  // Exit:
268 
269  return *this;
270 }
271 
275 {
276 
277  // Preconditions:
278 
279 
280  // Body:
281 
283 
284  // Postconditions:
285 
286  ensure(invariant());
287 
288  // Exit
289 
290  return *this;
291 }
292 
293 bool
295 invariant() const
296 {
297  bool result = true;
298 
299  if(invariant_check())
300  {
301  // Prevent recursive calls to invariant
302 
304 
305  // Must satisfy base class invariant
306 
307  invariance(any::invariant());
308 
309  // Invariances for this class:
310 
311  // Finished, turn invariant checking back on.
312 
314  }
315 
316  // Exit
317 
318  return result;
319 }
320 
321 
322 // ===========================================================
323 // NON-MEMBER FUNCTIONS
324 // ===========================================================
325 
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.
size_type _refinement_depth_ub
The upper bound and the refinement level of a cell.
virtual bool invariant() const
Class invariant.
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.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
virtual depth_bound_refinement_policy & operator=(const field_refinement_policy &xother)
Assignment operator.
Abstract base class with useful features for all objects.
Definition: any.h:39
A policy that determines a zone should be refined if the refinement depth is less than a given upper ...
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.
virtual const std::string & class_name() const
The class name of this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual depth_bound_refinement_policy * clone() const
Virtual constructor, makes a new instance of the same type as this.
field_vd & target
The field being refined.
bool same_evaluation() const
True if the coordinates and property sections both use the same evaluation subposet.
Definition: field_vd.cc:822
static const std::string & static_class_name()
The class name of this class.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
const field_vd & source
The reference field.
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
depth_bound_refinement_policy(size_type xrefinement_level_ub=2)
Creates an instance with refinement upper bound xrefinement_ub.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual bool should_refine(field_refinement_buffer &xbuffer, size_type xrefinement_depth) const
True if the zone specified by xzone_id should be refined.