SheafSystem  0.0.0.0
property_disc_iterator.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 
22 #include "SheafSystem/property_disc_iterator.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/base_space_member.h"
26 #include "SheafSystem/binary_section_space_schema_member.h"
27 #include "SheafSystem/error_message.h"
28 #include "SheafSystem/eval_family.h"
29 #include "SheafSystem/property_disc_iterator_1_1.h"
30 #include "SheafSystem/property_disc_iterator_1_2.h"
31 #include "SheafSystem/property_disc_iterator_1_3.h"
32 #include "SheafSystem/property_disc_iterator_4_2.h"
33 #include "SheafSystem/property_disc_iterator_4_3.h"
34 #include "SheafSystem/sec_rep_descriptor.h"
35 #include "SheafSystem/section_evaluator.h"
36 #include "SheafSystem/section_space_schema_member.h"
37 #include "SheafSystem/sec_ed_invertible.h"
38 #include "SheafSystem/sec_vd.h"
39 #include "SheafSystem/std_limits.h"
40 #include "SheafSystem/structured_block_1d.h"
41 #include "SheafSystem/structured_block_2d.h"
42 #include "SheafSystem/structured_block_3d.h"
43 #include "SheafSystem/subposet_member_iterator.h"
44 #include "SheafSystem/uniform_eval_family.h"
45 #include "SheafSystem/field_vd.h"
46 
47 using namespace std;
48 using namespace fields; // Workaround for MS C++ bug.
49 
50 //#define DIAGNOSTIC_OUTPUT 1
51 
52 // ===========================================================
53 // PROPERTY_DISC_ITERATOR FACET
54 // ===========================================================
55 
56 // PUBLIC MEMBER FUNCTIONS
57 
61  const section_space_schema_member& xprop_schema)
62 {
63  property_disc_iterator* result;
64 
65  // Preconditions:
66 
67  require(xcoords_schema.state_is_read_accessible());
68  require(xprop_schema.state_is_read_accessible());
69 
70  // Body:
71 
72  if(xcoords_schema.evaluator_family_name() == "uniform")
73  {
74  // Uniform coordinates.
75 
76  if(xprop_schema.rep().eval_is_above_disc())
77  {
78  result = new property_disc_iterator_4_2(xcoords_schema, xprop_schema);
79  }
80  else
81  {
82  result = new property_disc_iterator_4_3(xcoords_schema, xprop_schema);
83  }
84  }
85  else if(xcoords_schema.evaluator_family_name() == "dlinear")
86  {
87  // Vertex element dlinear coordinates
88 
89  if(xprop_schema.evaluator_family_name() == "dlinear")
90  {
91  // Vertex element dlinear property.
92 
93  result = new property_disc_iterator_1_1(xcoords_schema, xprop_schema);
94  }
95  else if(xprop_schema.evaluation().name() == "__elements")
96  {
97  // Property eval same as coordinates eval.
98 
99  if(xprop_schema.rep().eval_is_above_disc())
100  {
101  // Property disc is below elements, but not just vertices.
102 
103  result = new property_disc_iterator_1_2(xcoords_schema, xprop_schema);
104  }
105  else
106  {
107  // Property disc is at or above elements
108  // (typically element element constant).
109 
110  result = new property_disc_iterator_1_3(xcoords_schema, xprop_schema);
111  }
112  }
113  else
114  {
115  // Property eval is not same as coordinates;
116  // we don't support this yet.
117 
118  post_fatal_error_message("Property rep not supported with this coordinates rep.");
119  }
120  }
121  else if(xcoords_schema.rep().name() == "vertex_vertex_constant")
122  {
123  // Vertex_vertex_constant coordinates
124 
125  if(xprop_schema.rep().name() == "vertex_vertex_constant")
126  {
127  // Vertex_vertex_constant property.
128 
129  result = new property_disc_iterator_1_1(xcoords_schema, xprop_schema);
130  }
131  else
132  {
133  // Property rep is not same as coordinates;
134  // we don't support this yet.
135 
136  post_fatal_error_message("Property rep not supported with this coordinates rep.");
137  }
138  }
139  else
140  {
141  // Unsupported coordinates rep.
142 
143  post_fatal_error_message("Coordinates rep not supported.");
144  }
145 
146  // Postconditions:
147 
148  ensure(result != 0);
149  ensure(result->coordinates_schema().is_same_state(&xcoords_schema));
150  ensure(result->property_schema().is_same_state(&xprop_schema));
151 
152  // Exit:
153 
154  return result;
155 }
156 
159 {
160  // Preconditions:
161 
162  // Body:
163 
164  // Postconditions:
165 
166 }
167 
171 {
172  // Preconditions:
173 
174  require(is_initialized());
175 
176  // Body:
177 
178  // Invariant ensures cast is appropriate.
179 
180  const section_space_schema_member& result = *_coord_state.schema;
181 
182  // Postconditions:
183 
184  // Exit
185 
186  return result;
187 }
188 
192 {
193  // Preconditions:
194 
195  require(is_initialized());
196 
197  // Body:
198 
199  // Invariant ensures cast is appropriate.
200 
201  const section_space_schema_member& result = *_prop_state.schema;
202 
203  // Postconditions:
204 
205  // Exit
206 
207  return result;
208 }
209 
212 base_space() const
213 {
214 
215  // Preconditions:
216 
217 
218  // Body:
219 
220  const base_space_poset& result = *_coord_state.base_space_host;
221 
222  // Postconditions:
223 
224  ensure(result.is_same_state(coordinates_schema().base_space().host()));
225  ensure(result.is_same_state(property_schema().base_space().host()));
226 
227  // Exit:
228 
229  return result;
230 }
231 
232 const sheaf::subposet&
235 {
236  // Preconditions:
237 
238  // Body:
239 
240  const subposet& result = _coord_state.eval_sp;
241 
242  // Postconditions:
243 
244  ensure(result.is_same_state(&coordinates_schema().evaluation()));
245 
246  // Exit:
247 
248  return result;
249 }
250 
251 const sheaf::subposet&
254 {
255  // Preconditions:
256 
257  // Body:
258 
259  const subposet& result = _prop_state.eval_sp;
260 
261  // Postconditions:
262 
263  ensure(result.is_same_state(&property_schema().evaluation()));
264 
265  // Exit:
266 
267  return result;
268 }
269 
270 int
272 db() const
273 {
274  int result;
275 
276  // Preconditions:
277 
278  require(!is_done());
279 
280  // Body:
281 
282  result = base_space().db(index());
283 
284  // Postconditions:
285 
286  ensure(result >= 0);
287 
288  // Exit:
289 
290  return result;
291 }
292 
295 type_id() const
296 {
297  pod_index_type result;
298 
299  // Preconditions:
300 
301  require(!is_done());
302 
303  // Body:
304 
305  result = base_space().type_id(index());
306 
307  // Postconditions:
308 
309 
310  // Exit:
311 
312  return result;
313 }
314 
315 std::string
317 type_name() const
318 {
319  // Preconditions:
320 
321  require(!is_done());
322 
323  // Body:
324 
327 
328  string result(base_space().type_name(index()));
329 
330  // Postconditions:
331 
332 
333  // Exit:
334 
335  return result;
336 }
337 
341 {
342  // Preconditions:
343 
344  require(is_initialized());
345  require(!is_done());
346 
347  // Body:
348 
349  // The section space schema invariant ensures that the evaluator family
350  // is compatible with the base space and hence the following call to
351  // eval_family::member returns a non-void evaluator.
352 
353  section_evaluator& result = *_coord_state.evaluators->member(type_id());
354 
355  // Postconditions:
356 
357  // Exit
358 
359  return result;
360 }
361 
365 {
366  // Preconditions:
367 
368  require(is_initialized());
369  require(!is_done());
370 
371  // Body:
372 
373  // The section space schema invariant ensures that the evaluator family
374  // is compatible with the base space and hence the following call to
375  // eval_family::member returns a non-void evaluator.
376 
377  section_evaluator& result = *_prop_state.evaluators->member(type_id());
378 
379  // Postconditions:
380 
381  // Exit
382 
383  return result;
384 }
385 
389 {
390  // Preconditions:
391 
392  require(!is_done());
393 
394  // Body:
395 
396  const block<discretization_context>& result =
397  _coord_state.discretization_members;
398 
399  // Postconditions:
400 
401  // Exit
402 
403  return result;
404 }
405 
409 {
410  // Preconditions:
411 
412  require(!is_done());
413 
414  // Body:
415 
416  const block<discretization_context>& result =
417  _prop_state.discretization_members;
418 
419  // Postconditions:
420 
421  // Exit
422 
423  return result;
424 }
425 
426 
427 void
430 {
431  // Preconditions:
432 
433  require(xsec.state_is_read_accessible());
434  require(xsec.schema().is_same_state(&coordinates_schema()));
435 
437 
438  require(xsec.schema().df() <= 3);
439 
440  // Body:
441 
442  is_abstract();
443 
444  // Postconditions:
445 
446 
447  // Exit:
448 
449  return;
450 }
451 
452 
453 // PROTECTED MEMBER FUNCTIONS
454 
455 void
458 {
459 
460  // Preconditions:
461 
462  require(xfield.state_is_read_accessible());
463  require(xfield.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
464  require(xfield.property().schema().base_space().le(&xfield.coordinates().schema().base_space()));
465 
466  // Body:
467 
468  disable_invariant_check();
469 
470  // Initialize the iteration descriptors.
471 
472  _coord_state.initialize(xfield.coordinates().schema());
473  _prop_state.initialize(xfield.property().schema());
474 
475  // Initialize the inherited iterator features.
476  // By definition, this iterates over the property schema.
477 
478  initialize_order(xorder);
479  initialize_traversal(xfield.property().schema().base_space());
480 
481  reset();
482 
483  enable_invariant_check();
484 
485  // Postconditions:
486 
487  ensure(invariant());
488  ensure(is_initialized());
489  ensure(coordinates_schema().is_same_state(&xfield.coordinates().schema()));
490  ensure(coordinates_schema().is_same_type(&xfield.coordinates().schema()));
491  ensure(coordinates_schema().version() == xfield.coordinates().schema().version());
492  ensure(property_schema().is_same_state(&xfield.property().schema()));
493  ensure(property_schema().is_same_type(&xfield.property().schema()));
494  ensure(property_schema().version() == xfield.property().schema().version());
495  ensure(descending());
496  ensure(!strict());
497  ensure(unexecutable(!is_done() implies this is first member));
498 
499  return;
500 }
501 
502 
503 void
506  const section_space_schema_member& xproperty_schema,
507  order_type xorder)
508 {
509 
510  // Preconditions:
511 
512  require(xcoordinates_schema.state_is_read_accessible());
513  require(xcoordinates_schema.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
514  require(xproperty_schema.state_is_read_accessible());
515  require(xproperty_schema.base_space().le(&xcoordinates_schema.base_space()));
516 
517  // Body:
518 
519  disable_invariant_check();
520 
521  // Initialize the iteration descriptors.
522 
523  _coord_state.initialize(xcoordinates_schema);
524  _prop_state.initialize(xproperty_schema);
525 
526  // Initialize the inherited iterator features
527 
528  initialize_order(xorder);
529  initialize_traversal(xproperty_schema.base_space());
530 
531  reset();
532 
533  enable_invariant_check();
534 
535  // Postconditions:
536 
537  ensure(invariant());
538  ensure(is_initialized());
539  ensure(coordinates_schema().is_same_state(&xcoordinates_schema));
540  ensure(coordinates_schema().is_same_type(&xcoordinates_schema));
541  ensure(coordinates_schema().version() == xcoordinates_schema.version());
542  ensure(property_schema().is_same_state(&xproperty_schema));
543  ensure(property_schema().is_same_type(&xproperty_schema));
544  ensure(property_schema().version() == xproperty_schema.version());
545  ensure(descending());
546  ensure(!strict());
547  ensure(unexecutable(!is_done() implies this is first member));
548 
549  return;
550 }
551 
552 
553 // ===========================================================
554 // ANY FACET
555 // ===========================================================
556 
557 // PUBLIC MEMBER FUNCTIONS
558 
559 bool
561 is_ancestor_of(const any* xother) const
562 {
563  // Preconditions:
564 
565  // Body:
566 
567  bool result = dynamic_cast<const property_disc_iterator*>(xother) != 0;
568 
569  // Postconditions:
570 
571  // Exit
572 
573  return result;
574 }
575 
578 clone() const
579 {
580  // Preconditions:
581 
582  // Body:
583 
584  property_disc_iterator* result = 0; // Just to silence compiler.
585 
586  is_abstract();
587 
588  // Postconditions:
589 
590  // ensure(invariant());
591  ensure(result != 0);
592 
593  // Exit
594 
595  return result;
596 }
597 
598 bool
600 invariant() const
601 {
602  bool result = true;
603 
604  // Preconditions:
605 
606  // Body:
607 
608 
609  if(invariant_check())
610  {
611  invariance(depth_first_iterator::invariant());
612 
613  disable_invariant_check();
614 
615  invariance(anchor().is_same_state(&(property_schema().base_space())));
616  invariance(property_schema().base_space().le(&coordinates_schema().base_space()));
617 
618  // Finished, turn invariant checking back on.
619 
620  enable_invariant_check();
621  }
622 
623  // Postconditions:
624 
625  // Exit
626 
627  return result;
628 }
629 
630 
631 // ===========================================================
632 // DEPTH_FIRST_ITERATOR FACET
633 // ===========================================================
634 
635 // PUBLIC MEMBER FUNCTIONS
636 
637 void
640 {
641  // Preconditions:
642 
643  // Body:
644 
645  _prop_state.down_set.set_ct(0);
646  _prop_state.discretization_members.set_ct(0);
647 
648  _coord_state.down_set.set_ct(0);
649  _coord_state.discretization_members.set_ct(0);
650 
651  _above = true;
652  _at = false;
653 
654  depth_first_iterator::force_is_done();
655 
656  // Postconditions:
657 
658  ensure(invariant());
659  ensure(is_done());
660 
661  // Exit
662 
663  return;
664 }
665 
std::string name() const
Definition: subposet.h:796
A client handle for a subposet.
Definition: subposet.h:86
const block< discretization_context > & coordinate_discretization_members() const
The coordinate discretization members in the downset of the current evaluation member.
A property discretization iterator for a proerty section with the same evaluation subposet as the coo...
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
virtual void get_prop_disc_values(const sec_vd &xsec)=0
The gets the values of xsec at the property discretization points.
A property discretization iterator for a field with uniform coordinates section and a property sectio...
Namespace for fields component of sheaf system.
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...
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
subposet & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
const section_space_schema_member & property_schema() const
The property field schema member which is being iterated over.
section_evaluator & coordinate_evaluator() const
The coordinate field evaluator associated with the current evaluation member.
STL namespace.
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
order_type
The types of order in which the iterator will visit the members of the poset. Determines which action...
std::string name() const
A name for this.
section_evaluator & property_evaluator() const
The property field evaluator associated with the current evaluation member.
void initialize_iteration(const field_vd &xfield, order_type xorder)
Initializes this for iteration of type xorder over the schema of xfield.
pod_index_type type_id() const
The type id of the current member.
virtual property_disc_iterator * clone() const =0
Make a new instance of the same type as this.
Abstract base class with useful features for all objects.
Definition: any.h:39
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
std::string type_name() const
The type name of the current member.
bool eval_is_above_disc() const
True is the evaluation subposet is strictly above the discretization subposet.
const base_space_poset & base_space() const
The base space shared by both schema.
const subposet & coordinates_evaluation() const
The evaluation subposet for the coordinates.
A vd-valued property as a function of global coordinates.
Definition: field_vd.h:69
sec_vd & property() const
The dependent variable of this field.
Definition: field_vd.cc:357
bool le(pod_index_type xother_index) const
True if this is less than or equal to the member with index xother_index.
std::string evaluator_family_name() const
The name of the evaluator family for section spaces on schemae hosted by this.
virtual void force_is_done()
Force the iterator to be done.
base_space_member & base_space() const
The base space of this field.
Definition: field_vd.cc:373
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
const block< discretization_context > & property_discretization_members() const
The property discretization members in the downset of the current evaluation member.
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
const subposet & property_evaluation() const
The evaluation subposet for the property.
total_poset_member & base_space()
The base space component of this (mutable version).
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
static property_disc_iterator * new_property_disc_iterator(const section_space_schema_member &xcoords_schema, const section_space_schema_member &xprop_schema)
Creates an iterator appropriate for xcoords and xprop.
A client handle for a poset member which has been prepared for use as a schema for a section space...
sec_ed_invertible & coordinates() const
The independent variable of this field.
Definition: field_vd.cc:339
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
int db() const
The dimension of the current evaluation member.
A property discretization iterator for a property section with the same evaluation subposet as the co...
const section_space_schema_member & coordinates_schema() const
The coordinates field schema member which is being iterated over.
int df() const
The dimension of the fiber space component.
bool is_same_state(const poset_state_handle *xother) const
True if this is attached to the same state as xother.
A property discretization iterator for a property section with the same discretization as the coordin...
bool invariant() const
The class invariant.
sec_rep_descriptor & rep()
The representation for section spaces on this schema (mutable version).
virtual schema_poset_member & schema()
The schema for this member (mutable version).
A property discretization iterator for a field with uniform coordinates section and a property sectio...
Abstract iterator over the discretization of the property section of a field_vd. Concurrently travers...