SheafSystem  0.0.0.0
eval_family.cc
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 
18 // Implementation for class eval_family
19 
20 #include "SheafSystem/eval_family.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/constant_eval_family.h"
24 #include "SheafSystem/dlinear_eval_family.h"
25 #include "SheafSystem/factory.impl.h"
26 #include "SheafSystem/section_evaluator.h"
27 #include "SheafSystem/uniform_eval_family.h"
28 
29 using namespace std;
30 using namespace fiber_bundle; // Workaround for MS C++ bug.
31 
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
35 // CANONICAL MEMBERS
36 
39 eval_family(const eval_family& xother)
40 {
41 
42  // Preconditions:
43 
44  // Body:
45 
46  eval_family& lfam = const_cast<eval_family&>(xother);
47 
48  _members.reserve(lfam._members.ct());
49 
50  for(int i=0; i<lfam._members.ct(); ++i)
51  {
52  section_evaluator* lsec = lfam._members[i];
53 
54  if (lsec != 0)
55  _members[i] = lsec->clone();
56  else
57  _members[i] = 0;
58  }
59  _members.set_ct(lfam._members.ct());
60  _is_initialized = xother._is_initialized;
61 
62  // Postconditions:
63 
64  ensure(invariant());
65 }
66 
67 
68 
72 clone() const
73 {
74  eval_family* result = 0; // Initialize to avoid compiler warnings.
75 
76  // Preconditions:
77 
78  // Body:
79 
80  is_abstract();
81 
82  // Postconditions:
83 
84  ensure(result != 0);
85  ensure(is_same_type(result));
86 
87  // Exit:
88 
89  return result;
90 }
91 
92 
96 {
97 
98  // Preconditions:
99 
100  // Body:
101 
102  for(int i=0; i<_members.ct(); i++)
103  {
104  section_evaluator* lmbr = _members[i];
105  if(lmbr != 0)
106  {
107  delete lmbr;
108  }
109  }
110 
111  // Postconditions:
112 
113  // Exit:
114 
115  return;
116 }
117 
118 
120 bool
122 invariant() const
123 {
124  bool result = true;
125 
126  // Preconditions:
127 
128  // Body:
129 
130  // Must satisfy base class invariant
131 
132  result = result && any::invariant();
133 
134  if(invariant_check())
135  {
136  // Prevent recursive calls to invariant
137 
138  disable_invariant_check();
139 
140  // Finished, turn invariant checking back on.
141 
142  enable_invariant_check();
143  }
144 
145  // Postconditions:
146 
147  // Exit
148 
149  return result;
150 }
151 
153 bool
155 is_ancestor_of(const any* xother) const
156 {
157 
158  // Preconditions:
159 
160  require(xother != 0);
161 
162  // Body:
163 
164  // True if other conforms to this
165 
166  bool result = dynamic_cast<const eval_family*>(xother) != 0;
167 
168  // Postconditions:
169 
170  return result;
171 
172 }
173 
174 
175 
176 // EVALUATOR_FAMILY FACET
177 
181 new_family(const std::string& xname)
182 {
183  eval_family* result;
184 
185  // Preconditions:
186 
187  require(family_factory().contains_prototype(xname));
188 
189  // Body:
190 
191  result = family_factory().new_instance(xname);
192 
193  // Postconditions:
194 
195  ensure(result != 0);
196  ensure(result->class_name() == xname);
197  ensure(!result->is_initialized());
198 
199  // Exit
200 
201  return result;
202 }
203 
207 new_family(const std::string& xname, const namespace_poset& xname_space)
208 {
209  eval_family* result;
210 
211  // Preconditions:
212 
213  require(family_factory().contains_prototype(xname));
214  require(xname_space.state_is_read_accessible());
215 
216  // Body:
217 
218  result = family_factory().new_instance(xname, const_cast<namespace_poset&>(xname_space));
219 
220  // Postconditions:
221 
222  ensure(result != 0);
223  ensure(result->class_name() == xname);
224  ensure(result->is_initialized());
225 
226  // Exit
227 
228  return result;
229 }
230 
231 void
234 {
235  // Preconditions:
236 
237  require(xprototype != 0);
238 
239  // Body:
240 
241  family_factory().insert_prototype(xprototype);
242 
243  // Postconditions:
244 
245  ensure(family_factory().contains_prototype(xprototype->class_name()));
246 
247  // Exit:
248 
249  return;
250 }
251 
252 
257 {
258 
259  // Preconditions:
260 
261 
262  // Body:
263 
264  static factory<fiber_bundle::eval_family>& result = initialize_family_factory();
265 
266  // Postconditions:
267 
268 
269  // Exit:
270 
271  return result;
272 }
273 
275 const std::string&
277 class_name() const
278 {
279 
280  // Preconditions:
281 
282  // Body:
283 
284  is_abstract();
285 
286  static const string result;
287 
288  // Postconditions:
289 
290  ensure(!result.empty());
291 
292  // Exit
293 
294  return result;
295 }
296 
297 
301 member(pod_index_type xtype_id) const
302 {
303  section_evaluator* result;
304 
305  // Preconditions:
306 
307  require((0 <= xtype_id) && (xtype_id < size()));
308 
309  // Body:
310 
311  // Get the family member associated with base space member.
312 
313  result = _members[xtype_id];
314 
315  // Postconditions:
316 
317  // Exit
318 
319  return result;
320 }
321 
325 {
326  section_evaluator* result;
327 
328  // Preconditions:
329 
330  require(xhost.state_is_read_accessible());
331  require(xhost.schema().conforms_to(base_space_member::standard_schema_path()));
332  require(xhost.contains_member(xhub_id));
333  require(xhost.is_jim(xhub_id));
334 
335  // Body:
336 
337  // Get the family member associated with base space member.
338 
339  void* ldof_tuple = const_cast<poset_state_handle&>(xhost).member_dof_map(xhub_id).dof_tuple();
340  pod_index_type ltype_id =
341  reinterpret_cast<base_space_member::row_dof_tuple_type*>(ldof_tuple)->type_id;
342 
343  result = member(ltype_id);
344 
345  // Postconditions:
346 
347  // Exit
348 
349  return result;
350 }
351 
354 member(const poset_state_handle& xhost, const scoped_index& xid)
355 {
356  section_evaluator* result;
357 
358  // Preconditions:
359 
360  require(xhost.state_is_read_accessible());
361  require(xhost.schema().conforms_to(base_space_member::standard_schema_path()));
362  require(xhost.contains_member(xid));
363  require(xhost.is_jim(xid));
364 
365  // Body:
366 
367  return member(xhost, xid.hub_pod());
368 }
369 
373 size() const
374 {
375  size_type result;
376 
377  // Preconditions:
378 
379  // Body:
380 
381  result = _members.ct();
382 
383  // Postconditions:
384 
385 
386  // Exit:
387 
388  return result;
389 }
390 
392 void
394 initialize(const namespace_poset& xname_space)
395 {
396  // Preconditions:
397 
398  require(!is_initialized());
399  require(xname_space.state_is_read_accessible());
400 
401  // Body:
402 
403  _is_initialized = true;
404 
405  // Postconditions:
406 
407  ensure(invariant());
408  ensure(is_initialized());
409 
410  // Exit:
411 
412  return;
413 }
414 
416 bool
419 {
420  return _is_initialized;
421 }
422 
423 // ===========================================================
424 // PROTECTED MEMBER FUNCTIONS
425 // ===========================================================
426 
430  : _is_initialized(false)
431 {
432 
433  // Preconditions:
434 
435  // Body:
436 
437  // Nothing to do.
438 
439  // Initialize_members() must be called from descendants
440  // in order to avoid repeatedly getting a handle and access
441  // to the prototypes poset.
442 
443  // Postconditions:
444 
445  ensure(invariant());
446 }
447 
449 void
452 {
453  // Preconditions:
454 
455  // Body:
456 
457  _members.reserve(xmembers_ub);
459  // _members.assign(0); auto_block zero initialization policy make this unnecessary.
460 
461  // Postconditions:
462 
463  ensure(_members.ct() == _members.ub());
464  ensure_for_all(i, 0, _members.ct(), _members[i] == 0);
465 
466  // Exit:
467 
468  return;
469 }
470 
473 fiber_bundle::eval_family::
474 initialize_family_factory()
475 {
476 
477  // Preconditions:
478 
479  // Body:
480 
482 
486 
487  // Postconditions:
488 
489 
490  // Exit:
491 
492  return result;
493 }
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
static void insert_family_prototype(eval_family *xprototype)
Inserts xprototype in family_factory().
Definition: eval_family.cc:233
bool conforms_to(const schema_poset_member &xother) const
True if the dofs defined by this agree in type and in order with the dofs defined by xother...
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
members_type _members
The members of the family.
Definition: eval_family.h:221
A client handle for a general, abstract partially order set.
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
A family of section evaluators containing uni-, bi-, and tri-linear evaluators.
eval_family()
Default constructor.
Definition: eval_family.cc:429
bool _is_initialized
True if this has been populated with members.
Definition: eval_family.h:226
bool is_initialized() const
True if this has been populated with members.
Definition: eval_family.cc:418
virtual const std::string & class_name() const =0
The name of this family.
Definition: eval_family.cc:277
Abstract base class with useful features for all objects.
Definition: any.h:39
size_type size() const
The number of members of this family.
Definition: eval_family.cc:373
static eval_family * new_family(const std::string &xname)
Creates an instance of the evaluator family associated with name xname.
Definition: eval_family.cc:181
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
Definition: eval_family.h:49
void set_ct(size_type xct)
Sets ct() == xct.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
A family of compatible section evaluators, one for each member of some family of cell types; a map fr...
Definition: eval_family.h:67
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
A family of evaluators for uniform meshes.
static factory< eval_family > & family_factory()
A factory for making eval_family objects.
Definition: eval_family.cc:256
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Definition: eval_family.cc:155
virtual section_evaluator * clone() const =0
Virtual constructor, makes a new instance of the same type as this.
void initialize_members(size_type xmembers_ub)
Initialize storage for the members.
Definition: eval_family.cc:451
A family of section evaluators containing members for constant functions on primitive cells...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool is_jim(pod_index_type xmbr_hub_id, bool xin_current_version=true) const
True if the member with hub id xmbr_hub_id is a jim in the current version (xin_current_version == tr...
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
Definition: factory.impl.h:144
section_evaluator * member(pod_index_type xtype_id) const
The evaluator associated with cell type xtype_id. Note that the result may be void.
Definition: eval_family.cc:301
The type of row dof tuple for base_space_member.
Namespace for the fiber_bundles component of the sheaf system.
virtual bool invariant() const
Class invariant.
Definition: eval_family.cc:122
virtual eval_family * clone() const
Virtual constructor; makes a new instance of the same type as this.
Definition: eval_family.cc:72
virtual void initialize(const namespace_poset &xname_space)=0
Initializes this to contain members for name space xname_space.
Definition: eval_family.cc:394
virtual ~eval_family()
Destructor.
Definition: eval_family.cc:95
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710