SheafSystem  0.0.0.0
field_refiner_family.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_refiner_family.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_member.h"
25 #include "SheafSystem/base_space_poset.h"
26 #include "SheafSystem/factory.impl.h"
27 #include "SheafSystem/field_refinement_policy.h"
28 #include "SheafSystem/local_field_refiner.h"
29 #include "SheafSystem/namespace_poset.h"
30 
31 using namespace std;
32 using namespace fields; // Workaround for MS C++ bug.
33 
34 // ===========================================================
35 // FIELD_REFINER_FAMILY FACET
36 // ===========================================================
37 
40 new_family(const std::string& xname)
41 {
42  field_refiner_family* result;
43 
44  // Preconditions:
45 
46  require(family_factory().contains_prototype(xname));
47 
48  // Body:
49 
50  result = family_factory().new_instance(xname);
51 
52  // Postconditions:
53 
54  ensure(result != 0);
55  ensure(result->class_name() == xname);
56  ensure(!result->is_initialized());
57 
58  // Exit
59 
60  return result;
61 }
62 
65 {
66 
67  // Preconditions:
68 
69  // Body:
70 
71  _members.reserve(xother._members.ct());
72 
73  for(int i=0; i<xother._members.ct(); ++i)
74  {
75  local_field_refiner* lmbr = xother._members[i];
76  _members[i] = (lmbr != 0) ? lmbr->clone() : 0;
77  }
78  _members.set_ct(xother._members.ct());
79 
80  _policy = 0;
81  if(xother.is_initialized())
82  {
83  _policy = xother._policy->clone();
84  }
85 
86  if(xother._cell_type_id_space != 0)
87  {
88  _cell_type_id_space = &xother._cell_type_id_space->get_id_space();
89  }
90  else
91  {
92  _cell_type_id_space = 0;
93  }
94 
95  _is_initialized = xother._is_initialized;
96 
97  // Postconditions:
98 
99  ensure(invariant());
100 }
101 
104 {
105  // Preconditions:
106 
107  // Body:
108 
109  for(size_type i=0; i<_members.ct(); ++i)
110  {
111  local_field_refiner* lref = _members[i];
112  if(lref !=0)
113  {
114  delete lref;
115  }
116  }
117 
118  if(_is_initialized)
119  {
120  delete _policy;
121  }
122 
123  if(_cell_type_id_space != 0)
124  {
125  _cell_type_id_space->release_id_space();
126  }
127 
128  // Postconditions:
129 
130  // Exit:
131 
132  return;
133 }
134 
135 const std::string&
137 class_name() const
138 {
139  // Preconditions:
140 
141  // Body:
142 
143  is_abstract();
144 
145  static const string result;
146 
147  // Postconditions:
148 
149  ensure(!result.empty());
150 
151  // Exit
152 
153  return result;
154 }
155 
158 member(pod_index_type xtype_id) const
159 {
160  local_field_refiner* result;
161 
162  // Preconditions:
163 
164  require((0 <= xtype_id) && (xtype_id < size()));
165 
166  // Body:
167 
168  // Get the family member associated with base space member.
169 
170  result = _members[xtype_id];
171 
172  // Postconditions:
173 
174  // Exit
175 
176  return result;
177 }
178 
181 size() const
182 {
183  size_type result;
184 
185  // Preconditions:
186 
187  // Body:
188 
189  result = _members.ct();
190 
191  // Postconditions:
192 
193 
194  // Exit:
195 
196  return result;
197 }
198 
201 policy() const
202 {
203  // Preconditions:
204 
205  require(is_initialized());
206 
207  // Body:
208 
209  field_refinement_policy& result = *_policy;
210 
211  // Postconditions:
212 
213 
214  // Exit:
215 
216  return result;
217 }
218 
222 {
223 
224  // Preconditions:
225 
226 
227  // Body:
228 
229  static factory<field_refiner_family> result;
230 
231  // Postconditions:
232 
233 
234  // Exit:
235 
236  return result;
237 }
238 
239 
240 void
242 initialize(const base_space_poset& xbase_space, const field_refinement_policy& xpolicy)
243 {
244  // Preconditions:
245 
246  require(!is_initialized());
247  require(xbase_space.state_is_read_accessible());
248 
249  // Body:
250 
251  poset& lprototypes_poset =
252  xbase_space.name_space()->member_poset<poset>(base_space_member::prototypes_poset_name(), false);
253 
254  lprototypes_poset.get_read_access();
255 
256  // Initialize the members.
257 
258  _members.reserve(lprototypes_poset.member_index_ub().pod());
259 
260  _members.set_ct(_members.ub());
261  _members.assign(0);
262 
263  // Initialize refinement policy.
264 
265  _policy = xpolicy.clone();
266 
267  // Initialize the cell type id space.
268 
269  _cell_type_id_space =
270  &lprototypes_poset.member_id_spaces(false).get_id_space("cell_types");
271 
272  // Mark as initialized.
273 
274  _is_initialized = true;
275 
276  // Clean up.
277 
278  lprototypes_poset.release_access();
279 
280  // Postconditions:
281 
282  ensure(invariant());
283  ensure(is_initialized());
284  ensure_for_all(i, 0, size(), (member(i) != 0) ? (&member(i)->policy() == &xpolicy) : true);
285 
286  // Exit:
287 
288  return;
289 }
290 
291 bool
294 {
295  return _is_initialized;
296 }
297 
298 
299 // PROTECTED MEMBER FUNCTIONS
300 
303  : _policy(0),
304  _cell_type_id_space(0),
305  _is_initialized(false)
306 {
307  // Preconditions:
308 
309  // Body:
310 
311  // Postconditions:
312 
313  ensure(invariant());
314 }
315 
316 
317 // ===========================================================
318 // ANY FACET
319 // ===========================================================
320 
321 // PUBLIC MEMBER FUNCTIONS
322 
325 clone() const
326 {
327  field_refiner_family* result = 0; // Initialize to avoid compiler warnings.
328 
329  // Preconditions:
330 
331  // Body:
332 
333  is_abstract();
334 
335  // Postconditions:
336 
337  ensure(result != 0);
338  ensure(is_same_type(result));
339 
340  // Exit:
341 
342  return result;
343 }
344 
345 bool
347 invariant() const
348 {
349  bool result = true;
350 
351  // Preconditions:
352 
353  // Body:
354 
355  // Must satisfy base class invariant
356 
357  result = result && any::invariant();
358 
359  if(invariant_check())
360  {
361  // Prevent recursive calls to invariant
362 
364 
365  // Finished, turn invariant checking back on.
366 
368  }
369 
370  // Postconditions:
371 
372  // Exit
373 
374  return result;
375 }
376 
377 bool
379 is_ancestor_of(const any* xother) const
380 {
381 
382  // Preconditions:
383 
384  require(xother != 0);
385 
386  // Body:
387 
388  // True if other conforms to this
389 
390  bool result = dynamic_cast<const field_refiner_family*>(xother) != 0;
391 
392  // Postconditions:
393 
394  return result;
395 
396 }
397 
398 
399 
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 field_refiner_family * new_family(const std::string &xname)
Creates an instance of the refiner family associated with name xname.
static factory< field_refiner_family > & family_factory()
A factory for making field_refiner_family objects.
A family of compatible local_field_refiners, one for each member of some family of cell types; a map ...
Namespace for fields component of sheaf system.
field_refinement_policy & policy() const
The refinement policy for this family.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
size_type size() const
The number of members of this family.
virtual field_refiner_family * clone() const
Virtual constructor; makes a new instance of the same type as this.
virtual ~field_refiner_family()
Destructor.
STL namespace.
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
virtual index_space_handle & get_id_space() const =0
Allocates an id space handle from the handle pool attached to the same id space.
bool is_initialized() const
True if this has been populated with members.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual const std::string & class_name() const =0
The name of this family.
index_space_handle * _cell_type_id_space
The id space for base space cell type ids.
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
field_refiner_family()
Default constructor.
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
A client handle for a mutable partially ordered set.
Definition: poset.h:40
local_field_refiner * member(pod_index_type xtype_id) const
The evaluator associated with cell type xtype_id. Note that the result may be void.
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 void initialize(const base_space_poset &xbase_space, const field_refinement_policy &xpolicy)=0
Initializes this to contain members for base space xbase_space and using policy xpolicy.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
block< local_field_refiner * > _members
The members of the family.
namespace_poset * name_space() const
The namespace this poset resides in.
bool _is_initialized
True if this has been populated with members.
An abstract refiner for a field over a local region (primitive cell) in the base space.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool invariant() const
Class invariant.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual void get_read_access() const
Get read access to the state associated with this.
virtual field_refinement_policy * clone() const =0
Virtual constructor, makes a new instance of the same type as this.
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
field_refinement_policy * _policy
The refinement policy for this family.
virtual local_field_refiner * clone() const =0
Virtual constructor, makes a new instance of the same type as this.