SheafSystem  0.0.0.0
constant_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 constant_eval_family
19 
20 
21 #include "SheafSystem/constant_eval_family.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_member.h"
25 #include "SheafSystem/constant_hex.h"
26 #include "SheafSystem/constant_point.h"
27 #include "SheafSystem/constant_quad.h"
28 #include "SheafSystem/constant_segment.h"
29 #include "SheafSystem/constant_tet.h"
30 #include "SheafSystem/constant_triangle.h"
31 #include "SheafSystem/factory.h"
32 #include "SheafSystem/fiber_bundles_namespace.h"
33 #include "SheafSystem/int_set.h"
34 #include "SheafSystem/namespace_poset.h"
35 #include "SheafSystem/sheaf.h"
36 
37 using namespace std;
38 using namespace fiber_bundle; // Workaround for MS C++ bug.
39 
40 // PUBLIC MEMBER FUNCTIONS
41 
42 // CANONICAL MEMBERS
43 
45 fiber_bundle::constant_eval_family::
46 constant_eval_family(const constant_eval_family& xother)
47  : eval_family(xother)
48 {
49 
50  // Preconditions:
51 
52  // Body:
53 
54  // Postconditions:
55 
56  ensure(invariant());
57 
58  // Exit:
59 }
60 
61 
62 
66 clone() const
67 {
68  constant_eval_family* result;
69 
70  // Preconditions:
71 
72  // Body:
73 
74  result = new constant_eval_family(*this);
75 
76  // Postconditions:
77 
78  ensure(result != 0);
79  ensure(is_same_type(result));
80 
81  // Exit:
82 
83  return result;
84 }
85 
86 
90 {
91 
92  // Preconditions:
93 
94  // Body:
95 
96  // Postconditions:
97 
98  // Exit:
99 
100  return;
101 }
102 
103 
105 bool
107 invariant() const
108 {
109  bool result = true;
110 
111  // Preconditions:
112 
113  // Body:
114 
115  // Must satisfy base class invariant
116 
117  result = result && eval_family::invariant();
118 
119  if(invariant_check())
120  {
121  // Prevent recursive calls to invariant
122 
124 
125  // Finished, turn invariant checking back on.
126 
128  }
129 
130  // Postconditions:
131 
132  // Exit
133 
134  return result;
135 }
136 
138 bool
140 is_ancestor_of(const any* xother) const
141 {
142 
143  // Preconditions:
144 
145  require(xother != 0);
146 
147  // Body:
148 
149  // True if other conforms to this
150 
151  bool result = dynamic_cast<const constant_eval_family*>(xother) != 0;
152 
153  // Postconditions:
154 
155  return result;
156 
157 }
158 
159 
160 
161 // DLINEAR_FAMILY FACET
162 
163 
165 fiber_bundle::constant_eval_family::
166 constant_eval_family(const namespace_poset& xname_space)
167 {
168 
169  // Preconditions:
170 
171  require(xname_space.state_is_read_accessible());
173 
174  // Body:
175 
176  initialize(xname_space);
177 
178  // Postconditions:
179 
180  ensure(invariant());
181 }
182 
184 const std::string&
186 class_name() const
187 {
188  // Preconditions:
189 
190  // Body:
191 
192  const string& result = static_class_name();
193 
194  // Postconditions:
195 
196  ensure(!result.empty());
197 
198  // Exit:
199 
200  return result;
201 }
202 
204 const std::string&
207 {
208  // Preconditions:
209 
210  // Body:
211 
212  static const string result("constant");
213 
214  // Postconditions:
215 
216  ensure(!result.empty());
217 
218  // Exit:
219 
220  return result;
221 }
222 
223 
225 void
227 initialize(const namespace_poset& xname_space)
228 {
229 
230  // Preconditions:
231 
232  require(!is_initialized());
233  require(xname_space.state_is_read_accessible());
235 
236 
237  // Body:
238 
239  eval_family::initialize(xname_space);
240 
241  // The type codes used here must be the same as those used
242  // in fiber_bundles_namespace::make_base_space_member_prototypes().
243 
245  lhost->get_read_access();
246 
247  // Allocate enough storage for the members.
248 
250 
251  // Get the type id of each member of the family and
252  // and create the appropriate entry in _members.
253 
261 
262  base_space_member lmbr;
263  lmbr.attach_to_state(lhost, "point");
264  _members.force_item(lmbr.type_id(), new constant_point);
265 
266  lmbr.attach_to_state(lhost, "segment");
267  _members.force_item(lmbr.type_id(), new constant_segment);
268 
269  lmbr.attach_to_state(lhost, "segment_complex");
270  _members.force_item(lmbr.type_id(), new constant_segment);
271 
272  lmbr.attach_to_state(lhost, "triangle");
273  _members.force_item(lmbr.type_id(), new constant_triangle);
274 
275  lmbr.attach_to_state(lhost, "triangle_nodes");
276  _members.force_item(lmbr.type_id(), new constant_triangle);
277 
278  lmbr.attach_to_state(lhost, "triangle_complex");
279  _members.force_item(lmbr.type_id(), new constant_triangle);
280 
281  lmbr.attach_to_state(lhost, "quad");
282  _members.force_item(lmbr.type_id(), new constant_quad);
283 
284  lmbr.attach_to_state(lhost, "quad_nodes");
285  _members.force_item(lmbr.type_id(), new constant_quad);
286 
287  lmbr.attach_to_state(lhost, "quad_complex");
288  _members.force_item(lmbr.type_id(), new constant_quad);
289 
290  lmbr.attach_to_state(lhost, "hex");
291  _members.force_item(lmbr.type_id(), new constant_hex);
292 
293  lmbr.attach_to_state(lhost, "hex_nodes");
294  _members.force_item(lmbr.type_id(), new constant_hex);
295 
296  lmbr.attach_to_state(lhost, "hex_complex");
297  _members.force_item(lmbr.type_id(), new constant_hex);
298 
299  lmbr.attach_to_state(lhost, "structured_block_1d");
300  _members.force_item(lmbr.type_id(), new constant_segment);
301 
302  lmbr.attach_to_state(lhost, "structured_block_2d");
303  _members.force_item(lmbr.type_id(), new constant_quad);
304 
305  lmbr.attach_to_state(lhost, "structured_block_3d");
306  _members.force_item(lmbr.type_id(), new constant_hex);
307 
308  lmbr.attach_to_state(lhost, "tetra");
309  _members.force_item(lmbr.type_id(), new constant_tet);
310 
311  lmbr.attach_to_state(lhost, "tetra_nodes");
312  _members.force_item(lmbr.type_id(), new constant_tet);
313 
314  lmbr.attach_to_state(lhost, "tetra_complex");
315  _members.force_item(lmbr.type_id(), new constant_tet);
316 
317  lmbr.detach_from_state();
318  lhost->release_access();
319 
320  // Postconditions:
321 
322  ensure(invariant());
323  ensure(is_initialized());
324 
325  // Exit:
326 
327  return;
328 }
329 
331 bool
334 {
335  return true;
336 }
337 
339 bool
342 {
343  return true;
344 }
345 
346 
347 // ===========================================================
348 // PRIVATE MEMBERS
349 // ===========================================================
350 
352 fiber_bundle::constant_eval_family::
353 constant_eval_family()
354  : eval_family()
355 {
356 
357  // Preconditions:
358 
359  // Body:
360 
361  // Nothing to do; base class does it all.
362 
363  // Postconditions:
364 
365  ensure(invariant());
366 
367  // Exit:
368 
369  return;
370 }
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
virtual bool invariant() const
Class invariant.
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 section evaluator with a constant value over a square 2D domain.
Definition: constant_quad.h:38
A section evaluator with a constant value over a 1D domain.
void force_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, resizing if necessary; any other new storage allocated is uninit...
A section evaluator with a constant value over a 1D domain.
STL namespace.
A section evaluator with a constant value over a triangular 2D domain.
eval_family()
Default constructor.
Definition: eval_family.cc:429
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.
bool is_initialized() const
True if this has been populated with members.
Definition: eval_family.cc:418
static const std::string & prototypes_poset_name()
The name of the prototypes poset.
virtual void initialize(const namespace_poset &xname_space)
Initializes this to contain members for name space xname_space.
virtual bool extrema_are_dofs() const
True if the extrema (minima or maxima) of the members of this family occur at the discretization poin...
A client handle for a member of a base space poset.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Abstract base class with useful features for all objects.
Definition: any.h:39
static const std::string & static_class_name()
The name of this class of families.
A client handle for a mutable partially ordered set.
Definition: poset.h:40
A family of compatible section evaluators, one for each member of some family of cell types; a map fr...
Definition: eval_family.h:67
virtual bool dofs_are_values() const
True if the dofs used by the members of this family are section values, that is, the evaluators are i...
virtual constant_eval_family * clone() const
Virtual constructor; makes a new instance of the same type as 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 void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
void initialize_members(size_type xmembers_ub)
Initialize storage for the members.
Definition: eval_family.cc:451
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
A family of section evaluators containing members for constant functions on primitive cells...
virtual const std::string & class_name() const
The name of this family.
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
A section evaluator with a constant value over a tetrahedral 3D domain.
Definition: constant_tet.h:38
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
virtual void get_read_access() const
Get read access to the state associated with this.
A section evaluator using trilinear interpolation over a cubic 3D domain.
Definition: constant_hex.h:38
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
virtual bool invariant() const
Class invariant.
Definition: eval_family.cc:122
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual void initialize(const namespace_poset &xname_space)=0
Initializes this to contain members for name space xname_space.
Definition: eval_family.cc:394