SheafSystem  0.0.0.0
field_eval_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/field_eval_iterator.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/base_space_member.h"
26 #include "SheafSystem/base_space_poset.h"
27 #include "SheafSystem/binary_section_space_schema_member.h"
28 #include "SheafSystem/eval_family.h"
29 #include "SheafSystem/sec_rep_descriptor.h"
30 #include "SheafSystem/section_evaluator.h"
31 #include "SheafSystem/section_space_schema_member.h"
32 #include "SheafSystem/section_space_schema_poset.h"
33 #include "SheafSystem/sec_ed_invertible.h"
34 #include "SheafSystem/sec_vd.h"
35 #include "SheafSystem/std_limits.h"
36 #include "SheafSystem/subposet_member_iterator.h"
37 #include "SheafSystem/field_vd.h"
38 
39 using namespace std;
40 using namespace fields; // Workaround for MS C++ bug.
41 
42 //#define DIAGNOSTIC_OUTPUT 1
43 
44 //const
45 //int
46 //fields::field_eval_iterator::BUFFER_UB;
47 
48 // ===========================================================
49 // FIELD_EVAL_ITERATOR FACET
50 // ===========================================================
51 
52 // PUBLIC MEMBER FUNCTIONS
53 
54 fields::field_eval_iterator::
55 field_eval_iterator(const field_vd& xfield)
57  _coordinate_discretization_members(BUFFER_UB),
58  _property_discretization_members(BUFFER_UB),
59  _non_discretization_members(BUFFER_UB)
60 {
61 
62  // Preconditions:
63 
64  require(xfield.state_is_read_accessible());
66  require(xfield.property().schema().base_space().is_same_state(&xfield.coordinates().schema().base_space()));
67  require(xfield.same_evaluation());
68 
69  // Body:
70 
72 
73  // Initialize the coordinate field features.
74 
76 
77  // Initialize the property field features.
78 
80 
81  // Initialize the connectivity correction trick.
82 
84 
85  // Initialize the inherited iterator features
86 
87  initialize_order(BIORDER);
88  initialize_traversal(_coordinate_schema_anchor->base_space());
89  reset();
90 
92 
93  // Postconditions:
94 
95  ensure(invariant());
96  ensure(is_initialized());
97  ensure(coordinate_schema_anchor().is_same_state(&xfield.coordinates().schema()));
99  ensure(coordinate_schema_anchor().version() == xfield.coordinates().schema().version());
100  ensure(property_schema_anchor().is_same_state(&xfield.property().schema()));
101  ensure(property_schema_anchor().is_same_type(&xfield.property().schema()));
102  ensure(property_schema_anchor().version() == xfield.property().schema().version());
103  ensure(descending());
104  ensure(!strict());
105  ensure(unexecutable(!is_done() implies this is first member));
106 
107  return;
108 }
109 
110 
111 fields::field_eval_iterator::
112 field_eval_iterator(
113  const section_space_schema_member& xcoordinate_schema_anchor,
114  const section_space_schema_member& xproperty_schema_anchor)
116  _coordinate_discretization_members(BUFFER_UB),
117  _property_discretization_members(BUFFER_UB),
118  _non_discretization_members(BUFFER_UB)
119 {
120 
121  // Preconditions:
122 
123  require(xcoordinate_schema_anchor.state_is_read_accessible());
124  require(xcoordinate_schema_anchor.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
125  require(xproperty_schema_anchor.state_is_read_accessible());
126  require(xproperty_schema_anchor.base_space().is_same_state(&xcoordinate_schema_anchor.base_space()));
127  require(xproperty_schema_anchor.evaluation().is_same_state(&xcoordinate_schema_anchor.evaluation()));
128 
129  // Body:
130 
132 
133  // Initialize the coordinate field features.
134 
135  initialize_coordinate_schema(xcoordinate_schema_anchor);
136 
137  // Initialize the property field features.
138 
139  initialize_property_schema(xproperty_schema_anchor);
140 
141  // Initialize the connectivity correction trick.
142 
144 
145  // Initialize the inherited iterator features
146 
147  initialize_order(BIORDER);
148  initialize_traversal(_coordinate_schema_anchor->base_space());
149  reset();
150 
152 
153  // Postconditions:
154 
155  ensure(invariant());
156  ensure(is_initialized());
157  ensure(coordinate_schema_anchor().is_same_state(&xcoordinate_schema_anchor));
158  ensure(coordinate_schema_anchor().is_same_type(&xcoordinate_schema_anchor));
159  ensure(coordinate_schema_anchor().version() == xcoordinate_schema_anchor.version());
160  ensure(property_schema_anchor().is_same_state(&xproperty_schema_anchor));
161  ensure(property_schema_anchor().is_same_type(&xproperty_schema_anchor));
162  ensure(property_schema_anchor().version() == xproperty_schema_anchor.version());
163  ensure(descending());
164  ensure(!strict());
165  ensure(unexecutable(!is_done() implies this is first member));
166 
167  return;
168 }
169 
170 
173 {
174  // Preconditions:
175 
176  // Body:
177 
178  _coordinate_schema_anchor->detach_from_state();
179  delete _coordinate_schema_anchor;
180 
181  _property_schema_anchor->detach_from_state();
182  delete _property_schema_anchor;
183 
184  _evaluation.detach_from_state();
185 
186  delete _property_has_been_visited;
187 
188  // Postconditions:
189 
190 }
191 
195 {
196  // Preconditions:
197 
198  require(is_initialized());
199 
200  // Body:
201 
202  // Invariant ensures cast is appropriate.
203 
204  section_space_schema_member& result = *_coordinate_schema_anchor;
205 
206  // Postconditions:
207 
208  // Exit
209 
210  return result;
211 }
212 
216 {
217  // Preconditions:
218 
219  require(is_initialized());
220 
221  // Body:
222 
223  // Invariant ensures cast is appropriate.
224 
225  section_space_schema_member& result = *_property_schema_anchor;
226 
227  // Postconditions:
228 
229  // Exit
230 
231  return result;
232 }
233 
236 base_space() const
237 {
238 
239  // Preconditions:
240 
241 
242  // Body:
243 
244  const base_space_poset& result = *_base_space;
245 
246  // Postconditions:
247 
248  ensure(result.is_same_state(coordinate_schema_anchor().base_space().host()));
249  ensure(result.is_same_state(property_schema_anchor().base_space().host()));
250 
251  // Exit:
252 
253  return result;
254 }
255 
256 const sheaf::subposet&
258 evaluation() const
259 {
260 
261  // Preconditions:
262 
263 
264  // Body:
265 
266  const subposet& result = _evaluation;
267 
268  // Postconditions:
269 
271  ensure(result.is_same_state(&property_schema_anchor().evaluation()));
272 
273  // Exit:
274 
275  return result;
276 }
277 
278 int
280 db() const
281 {
282  int result;
283 
284  // Preconditions:
285 
286  require(!is_done());
287 
288  // Body:
289 
290  result = _base_space->db(index());
291 
292  // Postconditions:
293 
294  ensure(result >= 0);
295 
296  // Exit:
297 
298  return result;
299 }
300 
303 type_id() const
304 {
305  pod_index_type result;
306 
307  // Preconditions:
308 
309  require(!is_done());
310 
311  // Body:
312 
313  result = _base_space->type_id(index());
314 
315  // Postconditions:
316 
317 
318  // Exit:
319 
320  return result;
321 }
322 
323 std::string
325 type_name() const
326 {
327  // Preconditions:
328 
329  require(!is_done());
330 
331  // Body:
332 
335 
336  string result(_base_space->type_name(index()));
337 
338  // Postconditions:
339 
340 
341  // Exit:
342 
343  return result;
344 }
345 
349 {
350  // Preconditions:
351 
352  require(is_initialized());
353  require(!is_done());
354 
355  // Body:
356 
357  // The section space schema invariant ensures that the evaluator family
358  // is compatible with the base space and hence the following call to
359  // eval_family::member returns a non-void evaluator.
360 
361  section_evaluator& result =
362  *_coordinate_evaluators->member(type_id());
363 
364  // Postconditions:
365 
366  // Exit
367 
368  return result;
369 }
370 
374 {
375  // Preconditions:
376 
377  require(is_initialized());
378  require(!is_done());
379 
380  // Body:
381 
382  // The section space schema invariant ensures that the evaluator family
383  // is compatible with the base space and hence the following call to
384  // eval_family::member returns a non-void evaluator.
385 
386  section_evaluator& result =
387  *_property_evaluators->member(type_id());
388 
389  // Postconditions:
390 
391  // Exit
392 
393  return result;
394 }
395 
399 {
400  // Preconditions:
401 
402  require(!is_done());
403 
404  // Body:
405 
406  const block<scoped_index>& result = _coordinate_discretization_members;
407 
408  // Postconditions:
409 
410  // Exit
411 
412  return result;
413 }
414 
418 {
419  // Preconditions:
420 
421  require(!is_done());
422 
423  // Body:
424 
425  const block<scoped_index>& result = _property_discretization_members;
426 
427  // Postconditions:
428 
429  // Exit
430 
431  return result;
432 }
433 
434 bool
437 {
438  // Preconditions:
439 
440  // Body:
441 
442  bool result = (*_property_has_been_visited)[xhub_id];
443 
444  // Postconditions:
445 
446  // Exit
447 
448  return result;
449 }
450 
451 bool
454 {
455  // Preconditions:
456 
457  // Body:
458 
459  return property_has_been_visited(xid.hub_pod());
460 }
461 
462 void
466 {
467  // Preconditions:
468 
469  require(xcoord.state_is_read_accessible());
470  require(xcoord.schema().is_same_state(&coordinate_schema_anchor()));
471  require(xdofs.ub() >= coordinate_discretization_members().ct()*xcoord.schema().df());
472 
473  // Preceeding precondition and indexing below only correct for binary schema.
475 
476  require(dynamic_cast<const binary_section_space_schema_member*>(&xcoord.schema()) != 0);
477 
478  // Body:
479 
480  size_type ldf = xcoord.schema().df();
481  size_type ldofs_ct = 0;
482  size_type ldofs_ub = xdofs.ub();
483  sec_vd::dof_type* ldofs = xdofs.base();
484 
485  for(size_type i=0; i<_coordinate_discretization_members.ct(); ++i)
486  {
487  xcoord.get_fiber(_coordinate_discretization_members[i], ldofs,
488  ldofs_ub*sizeof(sec_vd::dof_type), false);
489 
490  ldofs += ldf;
491  ldofs_ct += ldf;
492  ldofs_ub -= ldf;
493  }
494 
495  xdofs.set_ct(ldofs_ct);
496 
497  // Postconditions:
498 
499  ensure(xdofs.ct() == coordinate_discretization_members().ct()*xcoord.schema().df());
500 
501  // Exit:
502 
503  return;
504 }
505 
509 {
510  int lresult = depth() - _top_zone_depth;
511 
512  return lresult >= 0 ? lresult : 0;
513 }
514 
515 void
518 {
519  // Preconditions:
520 
521  require(!is_done());
522 
523  // Body:
524 
525  // Client may have added members to the base space.
526  // Make sure has_visited still has enough capacity.
527 
528  size_type lmember_index_ub = _base_space->member_index_ub().pod();
529 
530  has_visited()->extend_to(lmember_index_ub);
531  _property_has_been_visited->extend_to(lmember_index_ub);
532 
533  // Postconditions:
534 
535  ensure(enough_capacity());
536 
537  // Exit:
538 
539  return;
540 }
541 
542 bool
545 {
546  bool result;
547 
548  // Preconditions:
549 
550  require(!is_done());
551 
552  // Body:
553 
554  size_type lmember_index_ub = _base_space->member_index_ub().pod();
555 
556  result =
557  (has_visited()->ub() >= lmember_index_ub) &&
558  (_property_has_been_visited->ub() >= lmember_index_ub);
559 
560  // Postconditions:
561 
562 
563  // Exit:
564 
565  return result;
566 }
567 
568 
569 // PROTECTED MEMBER FUNCTIONS
570 
571 void
574  const section_space_schema_member& xcoordinate_schema_anchor)
575 {
576  // Preconditions:
577 
578  require(xcoordinate_schema_anchor.state_is_read_accessible());
579  require(is_done());
580 
581  // Body:
582 
583  // Allocate the schema anchor if needed.
584 
585  // Set the coordinate schema anchor.
586 
587  _coordinate_schema_anchor = xcoordinate_schema_anchor.clone();
588  _coordinate_schema_anchor->attach_to_state(&xcoordinate_schema_anchor);
589 
590  // Get the proper evaluator family for the coordinate schema.
591 
592  _coordinate_evaluators =
593  eval_family::new_family(xcoordinate_schema_anchor.evaluator_family_name(),
594  *xcoordinate_schema_anchor.name_space());
595 
596  // Initialize features shared by coordinate and property schema.
597 
598  _base_space = &_coordinate_schema_anchor->host()->base_space();
599  _evaluation.attach_to_state(&_coordinate_schema_anchor->evaluation());
600 
601  // Postconditions:
602 
603  // Can not ensure invariant until inherited iterator features initialized..
604 
605  ensure(_coordinate_schema_anchor->is_same_state(&xcoordinate_schema_anchor));
606  ensure(_coordinate_schema_anchor->version() == xcoordinate_schema_anchor.version());
607  ensure(_coordinate_schema_anchor->is_same_type(&xcoordinate_schema_anchor));
608  ensure(_coordinate_evaluators != 0);
609 
610  // Exit
611 
612  return;
613 }
614 
615 void
618  const section_space_schema_member& xproperty_schema_anchor)
619 {
620  // Preconditions:
621 
622  require(xproperty_schema_anchor.state_is_read_accessible());
623  require(is_done());
624 
625  // Body:
626 
627  // Allocate the schema anchor if needed.
628 
629  // Set the property schema anchor.
630 
631  _property_schema_anchor = xproperty_schema_anchor.clone();
632  _property_schema_anchor->attach_to_state(&xproperty_schema_anchor);
633 
634  // Get the proper evaluator family for the property schema.
635 
636  _property_evaluators =
637  eval_family::new_family(xproperty_schema_anchor.evaluator_family_name(),
638  *xproperty_schema_anchor.name_space());
639 
640  // Create the previously visited markers.
641 
642  _property_has_been_visited = new zn_to_bool(_base_space->member_index_ub().pod());
643 
644  // Postconditions:
645 
646  // Can not ensure invariant until inherited iterator features initialized..
647 
648  ensure(_property_schema_anchor->is_same_state(&xproperty_schema_anchor));
649  ensure(_property_schema_anchor->version() == xproperty_schema_anchor.version());
650  ensure(_property_schema_anchor->is_same_type(&xproperty_schema_anchor));
651  ensure(_property_evaluators != 0);
652  ensure(_property_has_been_visited != 0);
653 
654  // Exit
655 
656  return;
657 }
658 
659 void
662 {
663  // Preconditions:
664 
665  // Body:
666 
667  // The connectivity reversal trick should be applied to evaluation
668  // members which are 2D and have edges in their down set. This
669  // includes prototypes "triangle", "quad", "tri_shell", and "quad_shell".
670  // Currently only "quad" is supported in the base_space_member_prototypes
671  // poset.
672 
673  _correction_set.insert(_base_space->prototype_type_id("quad"));
674 
675  _coordinate_correction_enabled = false;
676  _property_correction_enabled = false;
677  _coordinate_vertex_discretization =
678  (_coordinate_schema_anchor->discretization().name() == "__vertices");
679  _property_vertex_discretization =
680  (_property_schema_anchor->discretization().name() == "__vertices");
681 
682  // Postconditions:
683 
684 
685  // Exit:
686 
687  return;
688 }
689 
690 
691 void
694 {
695  // Preconditions:
696 
697  require(xdisc_mbrs.ct() == 2);
698 
699  // Body:
700 
701  // We assume that the current evaluator is 2-D, that its
702  // downset contains edges and vertices, and that the
703  // current discretization point is a vertex.
704  //
705  // The first evaluator to contain the edge which contains the
706  // current discretization point is the evaluator which constructed
707  // that edge, and it constructed that edge in a "positive"
708  // orientation wrt that evaluator. An edge in a 2-d space
709  // separates that space into 2 parts. So at most 1 other
710  // evaluator can share that edge and, if it exists, that evaluator
711  // views the edge as "negatively" oriented. In addition,
712  // that evaluator will be the second evaluator in the upper
713  // cover of that edge.
714 
715  // greater_index() refers to the edge containing this discretization
716  // point in the path from the current evaluator. If the current
717  // evaluator is the first evaluator in that edge's upper cover, then
718  // it constructed the edge, and the edge is in the positive orientation.
719  // Otherwise, the current evaluator did not construct the edge,
720  // the edge is negatively oriented, and the discretization member
721  // order should be reversed.
722 
723  poset_state_handle* lanchor_host =_anchor->host();
724 
725  pod_index_type first_eval = lanchor_host->first_cover_member(UPPER, greater_index().hub_pod());
726 
727  bool is_reversed = (_evaluator_id.hub_pod() != first_eval);
728 
729  if(is_reversed)
730  {
731  const scoped_index& save = xdisc_mbrs[0];
732  xdisc_mbrs[0] = xdisc_mbrs[1];
733  xdisc_mbrs[1] = save;
734  }
735 
736  // Postconditions:
737 
738 
739  // Exit:
740 
741  return;
742 }
743 
744 
745 // ===========================================================
746 // DEPTH_FIRST_ITERATOR FACET
747 // ===========================================================
748 
749 // PUBLIC MEMBER FUNCTIONS
750 
751 void
754 {
755  // Preconditions:
756 
757  // Body:
758 
759  // Clear the down set collection buffers.
760 
761  _down_set_collection_enabled = false;
762  _coordinate_discretization_members.set_ct(0);
763  _property_discretization_members.set_ct(0);
764  _non_discretization_members.set_ct(0);
765 
767 
768  // Postconditions:
769 
770  ensure(invariant());
771  ensure(is_done());
772 
773  // Exit
774 
775  return;
776 }
777 
778 void
780 next(bool xtruncate)
781 {
782  // Preconditions:
783 
784  require(!is_done());
785 
786  // Body:
787 
788  bool ltruncate = xtruncate;
789 
790  // Continue traversing the graph until the traversal is done
791  // or we are in the postvisit action of an evaluation member
792  // and return to the client.
793 
794  depth_first_iterator::next(ltruncate);
795 
796  while(!is_done())
797  {
798  if(action() == PREVISIT_ACTION)
799  {
800 
801 #ifdef DIAGNOSTIC_OUTPUT
802  cout << "previsit: "
803  << " id: " << setw(4) << index()
804  << " type" << setw(20) << (_base_space->is_jim(index(), false) ? type_name() : "")
805  << " depth(): " << setw(4) << depth()
806  << " top_zone_depth: " << setw(14) << _top_zone_depth
807  << " refinement_depth: " << setw(4) << refinement_depth()
808  << endl;
809 #endif
810 
811  // The evaluation, coordinate discretization, and property discretization
812  // are not necessarily distinct. In particular, the property discretization
813  // can be the same as the evaluation or the coordinate discretization.
814  // So we have to test each independently of the others.
815 
816  bool lnone_of_the_above = true;
817 
818  if(_evaluation.contains_member(index()))
819  {
820  // This member is an evaluation member.
821 
822  if(_top_zone_depth == numeric_limits<int>::max())
823  {
824  // This is the top level zone on this path; mark its depth.
825 
826  _top_zone_depth = depth();
827  }
828 
829  if(_base_space->jims().contains_member(index()))
830  {
831  // This member is also a jim, so it is an active evaluation member,
832  // i.e. there are no finer evaluation members in its down set.
833 
834  _evaluator_id = index();
835  _evaluator_refinement_depth = _base_space->refinement_depth(_evaluator_id);
836 
837  // Enable discretization order correction if possible.
838 
839  bool lis_correctable =
840  (_correction_set.find(type_id()) != _correction_set.end());
841  _coordinate_correction_enabled =
842  lis_correctable && _coordinate_vertex_discretization;
843  _property_correction_enabled =
844  lis_correctable && _property_vertex_discretization;
845 
846  // Reset the down set collection buffers.
847 
848  _coordinate_discretization_members.set_ct(0);
849 
850  for(int i=0; i<_property_discretization_members.ct(); ++i)
851  {
852  _property_has_been_visited->put(_property_discretization_members[i].pod(), true);
853  }
854  _property_discretization_members.set_ct(0);
855 
856  _non_discretization_members.set_ct(0);
857 
858  _down_set_collection_enabled = true;
859 
860  // Do not truncate, continue descending.
861 
862  ltruncate = false;
863 
864  lnone_of_the_above = false;
865  }
866  }
867 
868  // We assume the coordinate discretization is the lowest level we need
869  // to visit and in particular that coord disc <= prop disc.
870  // Hence we can truncate the traversal once we've processed the coord disc.
871  // Assume we won't truncate here, chnage it in the coord disc branch below.
872 
873  ltruncate = false;
874 
875  if(property_schema_anchor().discretization().contains_member(index()) &&
876  (_base_space->refinement_depth(index()) <= _evaluator_refinement_depth))
877  {
878  // This is a property discretization member.
879  // Invariant ensures discretization is not above evaluation,
880  // so down set collection must be enabled.
881  // Enter this member in the discretization collection.
882 
883  _property_discretization_members.push_back(index());
884 
885  if(_property_correction_enabled &&
886  (_property_discretization_members.ct() == 2))
887  {
888  ensure_discretization_order(_property_discretization_members);
889  }
890 
891  lnone_of_the_above = false;
892  }
893 
894  if(coordinate_schema_anchor().discretization().contains_member(index()) &&
895  (_base_space->refinement_depth(index()) <= _evaluator_refinement_depth))
896  {
897  // This is a coordinate discretization member.
898  // Invariant ensures discretization is not above evaluation,
899  // so down set collection must be enabled.
900  // Enter this member in the discretization collection.
901 
902  _coordinate_discretization_members.push_back(index());
903 
904  if(_coordinate_correction_enabled &&
905  (_coordinate_discretization_members.ct() == 2))
906  {
907  ensure_discretization_order(_coordinate_discretization_members);
908  }
909 
910  // Assume the coordinate discretization is the lowest level we need to visit,
911  // so we never need to go below this member; truncate.
912 
913  ltruncate = true;
914 
915  lnone_of_the_above = false;
916  }
917 
918  if(lnone_of_the_above)
919  {
920  // This member is neither an eval member nor a disc member.
921 
922  if(_down_set_collection_enabled)
923  {
924  // Enter this member in the non-discretization collection.
925 
926  _non_discretization_members.push_back(index());
927  }
928  }
929  }
930  else if(action() == POSTVISIT_ACTION)
931  {
932  if(depth() == _top_zone_depth)
933  {
934  // We're back to the top level zone on this path; unmark the depth;
935 
936  _top_zone_depth = numeric_limits<int>::max();
937  }
938 
939 
940 #ifdef DIAGNOSTIC_OUTPUT
941  cout << "postvisit: "
942  << " id: " << setw(4) << index()
943  << " type" << setw(20) << (_base_space->is_jim(index(), false) ? type_name() : "")
944  << " depth(): " << setw(4) << depth()
945  << " top_zone_depth: " << setw(14) << _top_zone_depth
946  << " refinement_depth: " << setw(4) << refinement_depth()
947  << endl;
948 #endif
949 
950  if(_evaluation.contains_member(index()))
951  {
952  // This member is an evaluation member.
953 
954  if(_base_space->jims().contains_member(index()))
955  {
956  // This member is also a jim, so it is an active evaluation member,
957  // i.e. there are no finer evaluation members in its down set.
958 
959  // Postvisit of eval member;
960  // we are done iterating over discretization members
961  // associated with this evaluation member;
962  // return to the client with the discretization collection.
963 
964  // Clear the has visited markers for the down set.
965 
966  for(int i=0; i<_coordinate_discretization_members.ct(); ++i)
967  {
968  put_has_visited(_coordinate_discretization_members[i], false);
969  }
970  for(int i=0; i<_property_discretization_members.ct(); ++i)
971  {
972  put_has_visited(_property_discretization_members[i], false);
973  }
974 
975  for(int i=0; i<_non_discretization_members.ct(); ++i)
976  {
977  put_has_visited(_non_discretization_members[i], false);
978  }
979  _non_discretization_members.set_ct(0);
980 
981  // Turn off down set collection.
982 
983  _down_set_collection_enabled = false;
984 
985  // Reinitialize discretization order correction.
986 
987  _coordinate_correction_enabled = false;
988  _property_correction_enabled = false;
989 
990  // Return to the client.
991 
992  break;
993  }
994  }
995  else
996  {
997  // Not an evaluation member; nothing to do.
998  // Continue traversal.
999  }
1000 
1001  // If we invoke depth_first_iterator::next() from the postvisit action,
1002  // the truncation flag will be ignored, since you can only truncate
1003  // in the previsit action. But just to be specific, we'll set it false no
1004  // matter what we've done here.
1005 
1006  ltruncate = false;
1007  }
1008  else
1009  {
1010  post_fatal_error_message("unrecognized action");
1011  }
1012 
1013  depth_first_iterator::next(ltruncate);
1014  } // end while(!is_done())
1015 
1016  // Postconditions:
1017 
1018  ensure(invariant());
1019  ensure(!is_done() ? action() == POSTVISIT_ACTION : true);
1020  ensure(!is_done() ? coordinate_schema_anchor().evaluation().contains_member(index()) : true);
1021 
1022  // Exit
1023 
1024  return;
1025 }
1026 
1027 void
1029 repeat(bool xwas_eval_member)
1030 {
1031  // Preconditions:
1032 
1033 
1034  // Body:
1035 
1036  if(xwas_eval_member)
1037  {
1038  // We've just refined the current member and
1039  // removed it from the evaluation subposet.
1040 
1041  // Make sure the bit vectors have enough capacity
1042  // for the now larger base space.
1043 
1044  update_capacity();
1045 
1046  if(_top_zone_depth == numeric_limits<int>::max())
1047  {
1048  // This is the top level zone on this path; mark the depth.
1049 
1050  _top_zone_depth = depth();
1051  }
1052  }
1053 
1054  // Just reset the iterator state back to the previsit action and continue.
1055  // Traversal will repeat down set of the current member.
1056 
1059 
1060  _state = EXECUTE_PREVISIT_ACTION;
1061 
1062  next(false);
1063 
1064 
1065  // Postconditions:
1066 
1067 
1068  // Exit:
1069 
1070  return;
1071 }
1072 
1073 void
1075 reset(bool xreset_markers)
1076 {
1077  // Preconditions:
1078 
1079 
1080  // Body:
1081 
1082  if(xreset_markers)
1083  {
1084  _property_has_been_visited->make_false();
1085  }
1086  else
1087  {
1088  for(int i=0; i<_property_discretization_members.ct(); ++i)
1089  {
1090  _property_has_been_visited->put(_property_discretization_members[i].pod(), true);
1091  }
1092  }
1093 
1094  _coordinate_discretization_members.set_ct(0);
1095  _property_discretization_members.set_ct(0);
1096  _non_discretization_members.set_ct(0);
1097  _top_zone_depth = numeric_limits<int>::max();
1098 
1099  depth_first_iterator::reset(xreset_markers);
1100 
1101  // Postconditions:
1102 
1103 
1104  // Exit:
1105 
1106  return;
1107 }
1108 
1109 
1110 // ===========================================================
1111 // ANY FACET
1112 // ===========================================================
1113 
1114 // PUBLIC MEMBER FUNCTIONS
1115 
1116 bool
1118 is_ancestor_of(const any* xother) const
1119 {
1120  // Preconditions:
1121 
1122  // Body:
1123 
1124  bool result = dynamic_cast<const field_eval_iterator*>(xother) != 0;
1125 
1126  // Postconditions:
1127 
1128  // Exit
1129 
1130  return result;
1131 }
1132 
1135 clone() const
1136 {
1137  // Preconditions:
1138 
1139  // Body:
1140 
1141  field_eval_iterator* result =
1143 
1144  // Postconditions:
1145 
1146  // ensure(invariant());
1147  ensure(result != 0);
1148 
1149  // Exit
1150 
1151  return result;
1152 }
1153 
1154 bool
1156 invariant() const
1157 {
1158  bool result = true;
1159 
1160  // Preconditions:
1161 
1162  // Body:
1163 
1164 
1165  if(invariant_check())
1166  {
1167  invariance(depth_first_iterator::invariant());
1168 
1170 
1171  invariance(order() == BIORDER);
1172  invariance(anchor().is_same_state(&(coordinate_schema_anchor().base_space())));
1173  invariance(property_schema_anchor().base_space().is_same_state(&coordinate_schema_anchor().base_space()));
1174  invariance(property_schema_anchor().evaluation().is_same_state(&coordinate_schema_anchor().evaluation()));
1175 
1176  // The entire notion of gathering the discretization members
1177  // for each evaluation member only makes sense if the discretization
1178  // subposet is not coarser than the evaluation subposet. But we
1179  // currently have no executable way to state this invariant.
1180 
1181  invariance(unexecutable("coordinate discretization is not coarser than evaluation"));
1182  invariance(unexecutable("property discretization is not coarser than evaluation"));
1183 
1184  // Finished, turn invariant checking back on.
1185 
1187  }
1188 
1189  // Postconditions:
1190 
1191  // Exit
1192 
1193  return result;
1194 }
poset_state_handle * host() const
The poset which this is a handle to a component of.
std::string name() const
Definition: subposet.h:796
virtual void force_is_done()
Force the iterator to be done.
A client handle for a subposet.
Definition: subposet.h:86
void repeat(bool xwas_eval_member)
Repeats the iteration over the down set of index(). If index() refers to a zone that has just been re...
void next()
Makes this the next member of the subset.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
virtual field_eval_iterator * clone() const
Make a new instance of the same type as this.
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
section_evaluator & property_evaluator() const
The property field evaluator associated with the current evaluation member.
size_type ct() const
The number of items currently in use.
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
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 is_ancestor_of(const any *xother) const
True if other conforms to this.
void initialize_order(order_type xorder)
Initializes _order and _transition_fcn.
std::string type_name(pod_index_type xmbr_hub_id) const
The type id of the member with hub id xmbr_hub_id.
action_type action() const
The type of action the client should take when the iterator returns control to the client...
abstract_poset_member * _anchor
The top member of the down set being iterated over.
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...
int refinement_depth(pod_index_type xmbr_hub_id) const
The refinement depth of the member with hub id xmbr_hub_id.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void get_fiber(pod_index_type xdisc_id, vd_lite &xfiber) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
Definition: sec_vd.cc:1087
pod_index_type type_id() const
The type id of the current member.
virtual void force_is_done()
Force the iterator to be done.
An iterator which concurrently traverses the schema of both the coordinates and property sections of ...
subposet & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
section_space_schema_member & coordinate_schema_anchor() const
The coordinates field schema member which is being iterated over.
A client handle for a general, abstract partially order set.
virtual bool contains_member(pod_index_type xmbr_hub_id) const
True if this poset contains poset member with hub id xmbr_hub_id.
Definition: subposet.cc:955
STL namespace.
bool property_has_been_visited(pod_index_type xhub_id) const
True if xhub_id is the hub id of a property discretization member that has been visited previously...
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.
void put(int i, bool value)
Sets i-th member to value.
Definition: zn_to_bool.cc:537
int ub() const
The upper bound for the domain index.
Definition: zn_to_bool.cc:214
void update_capacity()
Updates capacity of internal data structures to match any changes in the size of the base space...
virtual namespace_poset * name_space() const
The namespace of host()
size_t depth() const
The length of the path from anchor() to the current member.
size_type refinement_depth() const
The refinement depth; the number of evaluation members the current evaluation member is contained in...
pod_index_type prototype_type_id(const std::string &xname, bool xauto_access=true) const
The type id of the base space member prototype with name xname.
section_space_schema_member & property_schema_anchor() const
The property field schema member which is being iterated over.
void attach_to_state(const poset_state_handle *xhost, pod_index_type xhub_id)
Attach this handle to the state with hub id xhub_id in the current version of host xhost...
void gather_coordinate_dofs(const sec_vd &xcoord, block< sec_vd::dof_type > &xdofs)
Gather the coordinate dofs for the current evaluation member from xcoord into xdofs.
const block< scoped_index > & property_discretization_members() const
The property discretization members in the downset of the current evaluation member.
void ensure_discretization_order(block< scoped_index > &xdisc_mbrs)
Ensures correct order of the discretization members.
Abstract base class with useful features for all objects.
Definition: any.h:39
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
Definition: zn_to_bool.h:52
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
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
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
virtual abstract_poset_member & anchor()
The poset member whose downset is being iterated over; the top member of the domain of iteration (mut...
order_type order() const
The order of the iteration. Determines which actions are exported to the client.
pointer_type base() const
The underlying storage array.
const subposet & evaluation() const
The evaluation subposet shared by both schema.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual poset_type type_id() const
Identifier for the type of this poset.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
bool descending() const
True if iterating over down set of anchor.
section_evaluator & coordinate_evaluator() const
The coordinate field evaluator associated with the current evaluation member.
zn_to_bool * make_false()
Constant function false, auto-allocated. Note on terminology: "false" is a keyword, so this function can not be just "false"
Definition: zn_to_bool.cc:930
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
const block< scoped_index > & coordinate_discretization_members() const
The coordinate discretization members in the downset of the current evaluation member.
const bool UPPER
Selector for upper cover.
Definition: sheaf.h:72
int db(pod_index_type xmbr_hub_id) const
The base space dimension of the member with hub id xmbr_hub_id.
void initialize_property_schema(const section_space_schema_member &xanchor)
Initializes the property schema anchor.
void next()
Makes this the next member of the subset.
std::string evaluator_family_name() const
The name of the evaluator family for section spaces on schemae hosted by this.
subposet & discretization()
The discretization subposet for section spaces on this schema (mutable version).
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
SHEAF_DLL_SPEC void max(const vd &x0, vd_value_type &xresult, bool xauto_access)
Maximum component of x0, pre-allocated version.
Definition: vd.cc:2097
base_space_member & base_space() const
The base space of this field.
Definition: field_vd.cc:373
const scoped_index & greater_index() const
The index of the greater member of the current link.
std::string type_name() const
The type name of the current 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
bool is_done() const
True if iteration finished.
bool same_evaluation() const
True if the coordinates and property sections both use the same evaluation subposet.
Definition: field_vd.cc:822
static const poset_path & standard_schema_path()
The path of the schema required by this class.
virtual void detach_from_state()
Detach this handle from its state, if any.
void first()
Moves this to the first member of the iteration.
void initialize_coordinate_schema(const section_space_schema_member &xanchor)
Initializes the coordinate schema anchor.
iterator_state _state
The current state of iteration.
const base_space_poset & base_space() const
The base space shared by both schema.
virtual void reset(bool xreset_markers=true)
Restarts the iteration over the down set of anchor().
void put_has_visited(pod_index_type xhub_id, bool xvalue)
Set the visited marker for hub id xhub_id to xvalue. Intended for use reseting iterator without havin...
virtual void detach_from_state()
Detach this handle from its state, if any.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
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).
bool invariant() const
The class invariant.
void initialize_traversal(const abstract_poset_member &xanchor)
Initializes the anchor, has_visited markers and filter.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
zn_to_bool * has_visited() const
The marker bit vector. /.
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
bool invariant() const
The class invariant.
sec_vd_dof_type dof_type
The type of degree of freedom.
Definition: sec_vd.h:91
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
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...
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
virtual subposet & jims()
The subset of all jims (mutable version)
virtual void reset(bool xreset_markers=true)
Restarts the iteration.
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.
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
pod_index_type first_cover_member(bool xlower, pod_index_type xmbr_hub_id) const
Hub id of the first member of the lower (xlower true) or upper (xlower false) cover of the member wit...
void extend_to(int xub)
Make the upper bound at least xub.
Definition: zn_to_bool.cc:362
virtual schema_poset_member & schema()
The schema for this member (mutable version).
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
virtual void attach_to_state(pod_index_type xbase_space_id, pod_index_type xfiber_schema_id)=0
Attach to the state in host() with component ids xbase_id and xfiber_schema_id.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
bool strict() const
True if iterating over xstrict up/down set of anchor.
int db() const
The dimension of the current evaluation member.
section_space_schema_member * clone(bool xnew_state, bool xauto_access=true) const
Make a new handle instance of current. Attach the new instance to a new state if xnew_state is true...
base_space_poset & base_space()
The base space for section spaces on this schema.
bool enough_capacity() const
True if the internal data structures have enough capacity for the current size of base_space()...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
const scoped_index & index() const
The index of the current member of the iteration.
void initialize_discretization_order_correction()
Initializes the set of evaluation member prototypes for which the discretization member order correct...