SheafSystem  0.0.0.0
base_space_member.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/base_space_member.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/arg_list.h"
25 #include "SheafSystem/base_space_poset.h"
26 #include "SheafSystem/fiber_bundles_namespace.h"
27 #include "SheafSystem/poset_path.h"
28 #include "SheafSystem/preorder_iterator.h"
29 #include "SheafSystem/tern.h"
30 #include "SheafSystem/wsv_block.h"
31 
32 using namespace std;
33 using namespace fiber_bundle;
34 
35 // ===========================================================
36 // HOST FACTORY FACET
37 // ===========================================================
38 
39 // PUBLIC MEMBER FUNCTIONS
40 
41 
42 const sheaf::poset_path&
45 {
46 
47  // Preconditions:
48 
49  // Body:
50 
51  static const poset_path result("base_space_schema", "base_space_member_schema");
52 
53  // Postconditions:
54 
55  // Exit
56 
57  return result;
58 }
59 
60 
61 const sheaf::poset_path&
63 schema_path() const
64 {
65  // Preconditions:
66 
67  // Body:
68 
69  const poset_path& result = standard_schema_path();
70 
71  // Postconditions:
72 
73  // Exit
74 
75  return result;
76 }
77 
78 void
81 {
82  // Preconditions:
83 
84  require(xns.state_is_read_write_accessible());
85  require(xns.contains_poset(standard_schema_path(), false));
86  require(!xns.contains_poset_member(standard_schema_path(), false));
87 
88  // Body:
89 
90  string ldof_specs = "max_db INT true";
91  ldof_specs += " db INT false";
92  ldof_specs += " type_id INT false";
93  ldof_specs += " type_name C_STRING false";
94  ldof_specs += " refinement_depth INT false";
95  ldof_specs += " local_cell_type_id INT false";
96  ldof_specs += " local_cell_type_name C_STRING false";
97  ldof_specs += " size SIZE_TYPE false";
98  ldof_specs += " i_size SIZE_TYPE false";
99  ldof_specs += " j_size SIZE_TYPE false";
100  ldof_specs += " k_size SIZE_TYPE false";
101 
102 
103  schema_poset_member lschema(xns,
104  standard_schema_path().member_name(),
105  poset_path(standard_schema_path().poset_name(), "bottom"),
106  ldof_specs,
107  false);
108 
109  lschema.detach_from_state();
110 
111  // Postconditions:
112 
113  ensure(xns.contains_poset_member(standard_schema_path(), false));
114 
115  // Exit:
116 
117  return;
118 }
119 
120 const std::string&
123 {
124 
125  // Preconditions:
126 
127  // Body:
128 
129  // static const string result = base_space_member_prototype::standard_host_path().poset_name();
130  static const string result = "base_space_member_prototypes";
131 
132  // Postconditions:
133 
134  ensure(!result.empty());
135 
136  // Exit
137 
138  return result;
139 }
140 
143 new_host(namespace_type& xns, const poset_path& xhost_path, const poset_path& xschema_path, int xmax_db, bool xauto_access)
144 {
145  // cout << endl << "Entering base_space_member::new_host." << endl;
146 
147  // Preconditions:
148 
149  require(xns.state_is_auto_read_write_accessible(xauto_access));
150 
151  require(!xhost_path.empty());
152  require(!xns.contains_path(xhost_path, xauto_access));
153 
154  require(xschema_path.full());
155  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
156  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
157 
158  require(xmax_db >= 0);
159 
160  // Body:
161 
162  host_type& result =
163  host_type::new_table(xns, xhost_path, xschema_path, xmax_db, xauto_access);
164 
165  // Postconditions:
166 
167  ensure(xns.owns(result, xauto_access));
168  ensure(result.path(true) == xhost_path);
169  ensure(result.state_is_not_read_accessible());
170  ensure(result.schema(true).path(xauto_access) == xschema_path);
171 
172  ensure(result.max_db() == xmax_db);
173 
174  // Exit:
175 
176  // cout << "Leaving base_space_member::new_host." << endl;
177  return result;
178 }
179 
182 standard_host(namespace_type& xns, const poset_path& xhost_path, int xmax_db, bool xauto_access)
183 {
184  // cout << endl << "Entering base_space_member::standard_host." << endl;
185 
186  // Preconditions:
187 
188  require(xns.state_is_auto_read_write_accessible(xauto_access));
189 
190  require(poset_path::is_valid_name(xhost_path.poset_name()));
191  require(xns.path_is_auto_read_write_available<host_type>(xhost_path.poset_name(), xauto_access));
192 
193  require(xns.path_is_auto_read_accessible(standard_schema_path(), xauto_access));
194 
195  require(xmax_db >= 0);
196 
197  // Body:
198 
199  host_type* result_ptr;
200  if(xns.contains_path(xhost_path.poset_name(), xauto_access))
201  {
202  result_ptr = &xns.member_poset<host_type>(xhost_path, xauto_access);
203  }
204  else
205  {
206  result_ptr = &new_host(xns, xhost_path, standard_schema_path(), xmax_db, xauto_access);
207  }
208 
209  host_type& result = *result_ptr;
210 
211  // Postconditions:
212 
213  ensure(xns.owns(result, xauto_access));
214  ensure(result.path(true) == xhost_path);
215  ensure(result.state_is_not_read_accessible());
216  ensure(result.schema(true).path(xauto_access) == standard_schema_path());
217 
218  ensure(result.max_db() == xmax_db);
219 
220  // Exit:
221 
222  // cout << "Leaving base_space_member::standard_host." << endl;
223  return result;
224 }
225 
226 // PROTECTED MEMBER FUNCTIONS
227 
228 // PRIVATE MEMBER FUNCTIONS
229 
230 
231 // ===========================================================
232 // BASE_SPACE_MEMBER FACET
233 // ===========================================================
234 
235 // PUBLIC MEMBER FUNCTIONS
236 
239 {
240 
241  // Preconditions:
242 
243  // Body:
244 
245  // Postconditions:
246 
247  ensure(invariant());
248  ensure(! is_attached() );
249 }
250 
251 
254  bool xnew_jem,
255  bool xauto_access)
256 {
257 
258  // Preconditions:
259 
260  require(xnew_jem ? xother.is_attached() : true);
261 
262  // Body:
263 
264  if(xnew_jem)
265  {
266  new_jem_state(const_cast<abstract_poset_member*>(&xother), true, xauto_access);
267  }
268  else
269  {
270  attach_to_state(&xother);
271  }
272 
273  // postconditions:
274 
275  ensure(invariant());
276  ensure(is_attached() == xother.is_attached() );
277 }
278 
281 {
282 
283  // Preconditions:
284 
285  // Body:
286 
287  // Exit
288 
289  return;
290 }
291 
292 // NEW HANDLE, NEW STATE CONSTRUCTORS
293 
296  array_poset_dof_map* xdof_map,
297  bool xcopy_dof_map,
298  bool xauto_access)
299 {
300 
301  // Preconditions:
302 
303  require(precondition_of(new_jim_state(same args)));
304 
305  // Body:
306 
307  new_jim_state(xhost, xdof_map, xcopy_dof_map, xauto_access);
308 
309  // Postconditions:
310 
311  ensure(postcondition_of(new_jim_state(same args)));
312 
313  // Exit:
314 
315  return;
316 }
317 
318 
321  const std::string& xprototype_name,
322  bool xcopy_dof_map,
323  bool xauto_access)
324 {
325 
326  // Preconditions:
327 
328  require(xauto_access ? xhost->is_attached() : xhost->in_jim_edit_mode());
329  require(xauto_access || xhost->name_space()->member_poset(prototypes_poset_name(), true).state_is_read_accessible());
330  require(!xprototype_name.empty());
331  require(xhost->name_space()->contains_poset_member(poset_path(prototypes_poset_name(), xprototype_name), true));
332 
333 
334  // Body:
335 
336  if(xauto_access)
337  {
338  xhost->begin_jim_edit_mode(true);
339  xhost->name_space()->member_poset(prototypes_poset_name(), true).get_read_access();
340  }
341 
342  pod_index_type lid = xhost->new_member(xprototype_name, xcopy_dof_map);
343  attach_to_state(xhost, lid);
344 
345  if(xauto_access)
346  {
347  xhost->name_space()->member_poset(prototypes_poset_name(), true).release_access();
348  xhost->end_jim_edit_mode(true, true);
349  }
350 
351  // Postconditions:
352 
353 
354  // Exit:
355 
356  return;
357 }
358 
361  const std::string& xtype_name,
362  int xdb,
363  const std::string& xlocal_cell_name,
364  bool xauto_access)
365 {
366  // Preconditions:
367 
368  require(xauto_access || xhost->in_jim_edit_mode());
369  require(!xtype_name.empty());
370  require(!xhost->contains_member(xtype_name, true));
371  require(xlocal_cell_name.empty() || xhost->contains_member(xlocal_cell_name));
372 
373  // Body:
374 
375  // Can't check invariant until construction done.
376 
377  disable_invariant_check();
378 
379  if(xauto_access)
380  {
381  xhost->begin_jim_edit_mode(true);
382  }
383 
384 // // Create the member and set its name.
385 
386 // new_jim_state(xhost, 0, false, false);
387 
388 // // Initialize the dofs.
389 
390 // init_member_prototype(xtype_name, xdb, xlocal_cell_name);
391 
392  pod_index_type lid = xhost->new_member(xtype_name, xdb, xlocal_cell_name);
393  attach_to_state(xhost, lid);
394 
395 
396  // Now we can check the invaraint.
397 
398  enable_invariant_check();
399 
400  // Postconditions:
401 
402  ensure(invariant());
403  ensure(host() == xhost);
404  ensure(name() == xtype_name);
405  ensure(db() == xdb);
406  ensure(type_name() == xtype_name);
407  ensure(refinement_depth() == 0);
408  ensure(local_cell_type_name() == xlocal_cell_name);
409 
410 
411  if(xauto_access)
412  {
413  xhost->end_jim_edit_mode(true, true);
414  }
415 
416  // Exit:
417 
418  return;
419 }
420 
423  scoped_index* xexpansion,
424  int xexpansion_ct,
425  const tern& xnew_jem,
426  bool xauto_access)
427 {
428 
429  // Preconditions:
430 
431  require(precondition_of(new_jrm_state(same args)));
432 
433  // Body:
434 
435  new_jrm_state(xhost, xexpansion, xexpansion_ct, xnew_jem, xauto_access);
436 
437  // Postconditions:
438 
439  ensure(postcondition_of(new_jrm_state(same args)));
440 
441  // Exit:
442 
443  return;
444 }
445 
446 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
447 
449 base_space_member(const poset* xhost, pod_index_type xhub_id)
450 {
451 
452  // Preconditions:
453 
454  require(precondition_of(attach_to_state(xhost, xhub_id)));
455 
456  // Body:
457 
458  attach_to_state(xhost, xhub_id);
459 
460  // Postconditions:
461 
462  ensure(postcondition_of(attach_to_state(xhost, xhub_id)));
463 }
464 
466 base_space_member(const poset* xhost, const scoped_index& xid)
467 {
468 
469  // Preconditions:
470 
471  require(precondition_of(attach_to_state(xhost, xid)));
472 
473  // Body:
474 
475  attach_to_state(xhost, xid.hub_pod());
476 
477  // Postconditions:
478 
479  ensure(postcondition_of(attach_to_state(xhost, xid)));
480 }
481 
483 base_space_member(const poset* xhost, const std::string& xname)
484 {
485 
486  // Preconditions:
487 
488  require(precondition_of(attach_to_state(same args)));
489 
490  // Body:
491 
492  attach_to_state(xhost, xname);
493 
494  // Postconditions:
495 
496  ensure(postcondition_of(attach_to_state(same args)));
497 }
498 
500 base_space_member(const namespace_poset* xnamespace, const poset_path& xpath, bool xauto_access)
501 {
502 
503  // Preconditions:
504 
506 
507  require(precondition_of(attach_to_state(same args)));
508 
509  // Body:
510 
511  attach_to_state(xnamespace, xpath, xauto_access);
512 
513  // Postconditions:
514 
515  ensure(postcondition_of(attach_to_state(same args)));
516 
517  // Exit:
518 
519  return;
520 }
521 
524  pod_index_type xposet_id,
525  pod_index_type xmember_id)
526 {
527 
528  // Preconditions:
529 
531 
532  require(precondition_of(attach_to_state(same args)));
533 
534  // Body:
535 
536  attach_to_state(xnamespace, xposet_id, xmember_id);
537 
538  // Postconditions:
539 
540  ensure(postcondition_of(attach_to_state(same args)));
541 
542  // Exit:
543 
544  return;
545 }
546 
549  const scoped_index& xposet_id,
550  const scoped_index& xmember_id)
551 {
552 
553  // Preconditions:
554 
556 
557  require(precondition_of(attach_to_state(same args)));
558 
559  // Body:
560 
561  attach_to_state(xnamespace,
562  xposet_id.hub_pod(),
563  xmember_id.hub_pod());
564 
565  // Postconditions:
566 
567  ensure(postcondition_of(attach_to_state(same args)));
568 
569  // Exit:
570 
571  return;
572 }
573 
574 // EXISTING HANDLE, NEW STATE "CONSTRUCTORS"
575 
576 // FEATURES
577 
581 {
582  // Preconditions:
583 
584  require(state_is_read_accessible());
585 
587 
588  // Body:
589 
590  poset_path result(prototypes_poset_name(), type_name());
591 
592  // Postconditions:
593 
594  // Exit:
595 
596  return result;
597 }
598 
601 prototype_path(const namespace_poset* xnamespace,
603 {
604  // Preconditions:
605 
606  require(xnamespace->state_is_read_accessible());
607  require(xnamespace->contains_poset_member(xid.poset_id, xid.member_id));
608 
609  // Body:
610 
613 
614  base_space_member lproto(xnamespace, xid.poset_id, xid.member_id);
615  lproto.get_read_access();
616 
617  poset_path result(lproto.path());
618 
619  lproto.release_access();
620  lproto.detach_from_state();
621 
622  // Postconditions:
623 
624  // Exit:
625 
626  return result;
627 }
628 
629 bool
631 prototype_exists(const std::string& xname, bool xauto_access)
632 {
633  bool result;
634 
635  // Preconditions:
636 
637 
638  // Body:
639 
640  poset_path lproto_path(prototypes_poset_name(), xname);
641 
642  result = lproto_path.member_exists(xauto_access);
643 
644  // Postconditions:
645 
646 
647  // Exit:
648 
649  return result;
650 }
651 
652 
655 row_dof_tuple(bool xrequire_write_access)
656 {
657  row_dof_tuple_type* result;
658 
659  // Preconditions:
660 
661  require(xrequire_write_access ?
662  state_is_read_write_accessible() : state_is_read_accessible());
663  require(is_jim(false));
664 
665  // Body:
666 
667  result =
668  reinterpret_cast<row_dof_tuple_type*>(dof_map().dof_tuple());
669 
670  // Postconditions:
671 
672  ensure(result != 0);
673 
674  // Exit:
675 
676  return result;
677 }
678 
681 new_row_dof_map(const poset* xhost, const std::string& xprototype_name)
682 {
683  // Preconditions:
684 
685  require(xhost->state_is_read_accessible());
686  require(xhost->name_space()->member_poset(prototypes_poset_name(), true).state_is_read_accessible());
687  require(!xprototype_name.empty());
688  require(xhost->name_space()->member_poset(prototypes_poset_name(), true).contains_member(xprototype_name));
689 
690 
691  // Body:
692 
695 
696  // Create the dof map.
697 
698  array_poset_dof_map* result = new array_poset_dof_map(xhost, false);
699  result->put_defaults();
700 
701  // Get a handle for the prototype.
702 
703  poset_path lproto_path(prototypes_poset_name(), xprototype_name);
704  base_space_member lproto(xhost->name_space(), lproto_path, false);
705 
706  // Initialize the dofs.
707 
708  row_dof_tuple_type& ltuple =
709  *reinterpret_cast<row_dof_tuple_type*>(result->dof_tuple());
710 
711  ltuple.db = lproto.db();
712  ltuple.type_id = lproto.type_id();
713  ltuple.type_name = strdup(lproto.type_name());
714  ltuple.refinement_depth = lproto.refinement_depth();
715 
716  lproto.detach_from_state();
717 
718  // Postconditions:
719 
720  ensure(result != 0);
721 
722  // Exit:
723 
724  return result;
725 }
726 
727 const sheaf::scoped_index&
729 new_row_dof_map(poset_state_handle& xhost, const std::string& xprototype_name, bool xauto_access)
730 {
731  // Preconditions:
732 
733  require(xhost.state_is_auto_read_write_accessible(xauto_access));
734  require(xhost.name_space()->member_poset(prototypes_poset_name(), true).state_is_auto_read_accessible(xauto_access));
735  require(!xprototype_name.empty());
736  require(xhost.name_space()->member_poset(prototypes_poset_name(), true).contains_member(xprototype_name));
737 
738 
739  // Body:
740 
741  if(xauto_access)
742  {
743  xhost.get_read_write_access();
744  xhost.name_space()->get_read_access();
745  xhost.name_space()->member_poset(prototypes_poset_name(), false).get_read_access();
746  }
747 
748  define_old_variable(int old_xhost_row_dof_tuple_ct = xhost.row_dof_tuple_ct());
749 
750  // Create the dof map and set dofs to defaults.
751 
752  const scoped_index& result = xhost.new_row_dof_map();
753  row_dof_tuple_type* ltuple =
754  reinterpret_cast<row_dof_tuple_type*>(xhost.row_dof_map(result, true).dof_tuple());
755 
756  // Get the prototype.
757 
758  poset_path lproto_path(prototypes_poset_name(), xprototype_name);
759  base_space_member lproto(xhost.name_space(), lproto_path, false);
760 
761  // Copy its dofs.
762 
763  ltuple->db = lproto.db();
764  ltuple->type_id = lproto.type_id();
765  ltuple->type_name = strdup(lproto.type_name());
766  ltuple->refinement_depth = lproto.refinement_depth();
767 
768  // Release the prototype.
769 
770  lproto.detach_from_state();
771 
772  if(xauto_access)
773  {
774  xhost.name_space()->member_poset(prototypes_poset_name(), false).release_access();
775  xhost.name_space()->release_access();
776  xhost.release_access();
777  }
778 
779  // Postconditions
780 
781  // Exit:
782 
783  return result;
784 }
785 
786 // PROTECTED MEMBER FUNCTIONS
787 
788 
789 // PRIVATE MEMBER FUNCTIONS
790 
791 
792 // ===========================================================
793 // ROW DOFS FACET
794 // ===========================================================
795 
796 // PUBLIC MEMBER FUNCTIONS
797 
798 int
800 db() const
801 {
802  int result = -1;
803 
804  // Preconditions:
805 
806  require(state_is_read_accessible());
807 
808  // Body:
809 
810  if(is_jim(false))
811  {
812  // Dimension is a dof.
813 
814  base_space_member* cthis = const_cast<base_space_member*>(this);
815  result = cthis->row_dof_tuple()->db;
816  }
817  else
818  {
819  // Dimension is max dimension of maximal jims in downset.
820 
821  preorder_iterator itr(*this, "jims", DOWN, NOT_STRICT);
822  while(!itr.is_done())
823  {
824  pod_index_type ldof_tuple_id =
825  host()->member_dof_tuple_id(itr.index().hub_pod(), false);
826 
827  array_poset_dof_map& lmap =
828  reinterpret_cast<array_poset_dof_map&>(host()->row_dof_map(ldof_tuple_id));
829 
830  int lmbr_dim =
831  reinterpret_cast<row_dof_tuple_type*>(lmap.dof_tuple())->db;
832 
833  result = lmbr_dim > result ? lmbr_dim : result;
834 
835  // Only need to look at the maximal jims.
836 
837  itr.truncate();
838  }
839  }
840 
841  // Postconditions:
842 
843  ensure(result >= -1);
844  ensure( (result == -1) == is_jem(&(host()->bottom())) );
845 
846  // Exit
847 
848  return result;
849 }
850 
853 type_id() const
854 {
855  // Preconditions:
856 
857  require(state_is_read_accessible());
858  require(is_jim(false));
859 
860  // Body:
861 
862  base_space_member* cthis = const_cast<base_space_member*>(this);
863  const pod_index_type& result = cthis->row_dof_tuple()->type_id;
864 
865  // Postconditions:
866 
867  // Exit
868 
869  return result;
870 }
871 
872 const char*
874 type_name() const
875 {
876 
877  // Preconditions:
878 
879  require(state_is_read_accessible());
880  require(is_jim(false));
881 
882  // Body:
883 
884  base_space_member* cthis = const_cast<base_space_member*>(this);
885  const char* result = cthis->row_dof_tuple(false)->type_name;
886 
887  // Postconditions:
888 
889 
890  // Exit:
891 
892  return result;
893 }
894 
895 int
898 {
899  // Preconditions:
900 
901  require(state_is_read_accessible());
902  require(is_jim(false));
903 
904  // Body:
905 
906  base_space_member* cthis = const_cast<base_space_member*>(this);
907  int result = cthis->row_dof_tuple()->refinement_depth;
908 
909  // Postconditions:
910 
911  // Exit
912 
913  return result;
914 }
915 
916 void
919 {
920  // Preconditions:
921 
922  require(state_is_read_write_accessible());
923  require(is_jim(false));
924 
925  // Body:
926 
927  row_dof_tuple()->refinement_depth = xdepth;
928 
929  // Postconditions:
930 
931  ensure(refinement_depth() == xdepth);
932 
933  // Exit:
934 
935  return;
936 }
937 
941 {
942  pod_index_type result;
943 
944  // Preconditions:
945 
946  require(state_is_read_accessible());
947 
948  // Body:
949 
950  base_space_member* cthis = const_cast<base_space_member*>(this);
951  result = cthis->row_dof_tuple(false)->local_cell_type_id;
952 
953  // Postconditions:
954 
955 
956  // Exit:
957 
958  return result;
959 }
960 
961 
962 const char*
965 {
966  const char* result;
967 
968  // Preconditions:
969 
970  require(state_is_read_accessible());
971 
972  // Body:
973 
974  base_space_member* cthis = const_cast<base_space_member*>(this);
975  result = cthis->row_dof_tuple(false)->local_cell_type_name;
976 
977  // Postconditions:
978 
979  ensure(result != 0);
980 
981  // Exit:
982 
983  return result;
984 }
985 
986 // PROTECTED MEMBER FUNCTIONS
987 
988 // PRIVATE MEMBER FUNCTIONS
989 
990 
991 // ===========================================================
992 // CELLULAR SPACE FACET
993 // ===========================================================
994 
995 // PUBLIC MEMBER FUNCTIONS
996 
997 void
999 d_cells_ct(block<size_type>& xresult, bool xauto_access) const
1000 {
1001  // Preconditions:
1002 
1003  require(xauto_access || state_is_read_accessible());
1004 
1005  // Body:
1006 
1007  if(xauto_access)
1008  {
1009  get_read_access();
1010  }
1011 
1014 
1015  base_space_poset* lhost = reinterpret_cast<base_space_poset*>(host());
1016 
1017  int lmax_db = lhost->max_db();
1018  xresult.reserve(lmax_db);
1019  xresult.set_ct(lmax_db);
1020  xresult.assign(0);
1021 
1022  preorder_iterator litr(*this, lhost->jims(), DOWN, NOT_STRICT);
1023  while(!litr.is_done())
1024  {
1025  int lmbr_db = lhost->db(litr.index());
1026  xresult[lmbr_db]++;
1027  litr.next(lmbr_db == 0);
1028  }
1029 
1030  // Postconditions:
1031 
1033 
1034  ensure(unexecutable(xresult.ct() == host()->max_db()));
1035 
1036  // Exit:
1037 
1038  return;
1039 }
1040 
1043 c_not(bool xauto_access)
1044 {
1045  base_space_member* result;
1046 
1047  // Preconditions:
1048 
1049  require(is_attached());
1050  require(xauto_access || state_is_read_write_accessible());
1051 
1052  // Body:
1053 
1054  if(xauto_access)
1055  {
1056  get_read_write_access();
1057  }
1058 
1059  result = clone();
1060  c_not_pa(*result, false);
1061 
1062  if(xauto_access)
1063  {
1064  release_access();
1065  }
1066 
1067  // Postconditions:
1068 
1069  ensure(result != 0);
1070  ensure(postcondition_of(c_not_pa(result, false)));
1071 
1072  // Exit:
1073 
1074  return result;
1075 }
1076 
1077 void
1079 c_not_pa(base_space_member& result, bool xauto_access)
1080 {
1081  // Preconditions:
1082 
1083  require(is_attached());
1084  require(xauto_access || state_is_read_write_accessible());
1085 
1086  if(xauto_access)
1087  {
1088  get_read_write_access();
1089  }
1090 
1091  require(host()->includes_subposet("__elements"));
1092 
1093  // Body:
1094 
1095  // Find all the zones that are not contained in this:
1096  // make a copy of all zones and removes those contained in this.
1097 
1098  subposet lall_zones(host(), "__elements");
1099  subposet lother_zones(lall_zones, true);
1100 
1101  preorder_iterator litr(*this, host()->jims(), DOWN, NOT_STRICT);
1102  while(!litr.is_done())
1103  {
1104  lother_zones.remove_member(litr.index());
1105 
1106  // Zones are maximal jimes, so if we've
1107  // already found one, no need to go deeper.
1108 
1109  litr.truncate();
1110  }
1111 
1112  if(!lother_zones.is_empty())
1113  {
1114  // Join them to form the result.
1115 
1116  lother_zones.l_join_pa(&result, false);
1117  }
1118  else
1119  {
1120  // Complement is empty; result is bottom.
1121 
1122  result.attach_to_state(&host()->bottom());
1123  }
1124 
1125  // Clean up.
1126 
1127  lother_zones.delete_state();
1128  lall_zones.detach_from_state();
1129 
1130  if(xauto_access)
1131  {
1132  release_access();
1133  }
1134 
1135  // Postconditions:
1136 
1137  ensure(unexecutable(this->join(&result)->is_same_state(&host()->top())));
1138 
1139  // Exit:
1140 
1141  return;
1142 }
1143 
1146 c_minus(base_space_member& xother, bool xnew_jem, bool xauto_access)
1147 {
1148  base_space_member* result;
1149 
1150  // Preconditions:
1151 
1152  require(state_is_auto_read_write_accessible(xauto_access));
1153  require(in_same_space(&xother));
1154 
1155  // Body:
1156 
1157  if(xauto_access)
1158  {
1159  get_read_write_access();
1160  }
1161 
1162  result = clone();
1163  c_minus(xother, *result, xnew_jem, false);
1164 
1165  if(xauto_access)
1166  {
1167  release_access();
1168  }
1169 
1170  // Postconditions:
1171 
1172  ensure(result != 0);
1173  ensure(postcondition_of(c_not_pa(xother, result, false)));
1174 
1175  // Exit:
1176 
1177  return result;
1178 }
1179 
1180 void
1183  base_space_member& result,
1184  bool xnew_jem,
1185  bool xauto_access)
1186 {
1187  // Preconditions:
1188 
1189  require(state_is_auto_read_write_accessible(xauto_access));
1190  require(in_same_space(&xother));
1191 
1192  if(xauto_access)
1193  {
1194  get_read_write_access();
1195  }
1196 
1197  require(host()->includes_subposet("__elements", xauto_access));
1198 
1199  // Body:
1200 
1201  // Find all the zones in this.
1202 
1203  subposet lzones(host());
1204 
1205  preorder_iterator litr(*this, "__elements", DOWN, NOT_STRICT);
1206  while(!litr.is_done())
1207  {
1208  lzones.insert_member(litr.index());
1209  litr.truncate();
1210  }
1211 
1212  // Reset the iterator to iterate over xother.
1213  // Turn off visit_once so we don't have to
1214  // pay the cost of resetting the visited bit vector.
1215 
1216  litr.put_anchor(xother.index());
1217  litr.put_visit_once(false);
1218  litr.reset(false);
1219 
1220  while(!litr.is_done())
1221  {
1222  lzones.remove_member(litr.index());
1223  litr.truncate();
1224  }
1225 
1226  lzones.l_join_pa(&result, xnew_jem);
1227 
1228  // Clean up.
1229 
1230  lzones.delete_state();
1231 
1232  if(xauto_access)
1233  {
1234  release_access();
1235  }
1236 
1237  // Postconditions:
1238 
1239  ensure(unexecutable(this->join(&result)->is_same_state(&host()->top())));
1240 
1241  // Exit:
1242 
1243  return;
1244 }
1245 
1246 // PROTECTED MEMBER FUNCTIONS
1247 
1248 // PRIVATE MEMBER FUNCTIONS
1249 
1250 
1251 // ===========================================================
1252 // TOTAL_POSET_MEMBER FACET
1253 // ===========================================================
1254 
1255 // PUBLIC MEMBER FUNCTIONS
1256 
1257 // PROTECTED MEMBER FUNCTIONS
1258 
1259 // PRIVATE MEMBER FUNCTIONS
1260 
1261 
1262 // ===========================================================
1263 // ABSTRACT_POSET_MEMBER FACET
1264 // ===========================================================
1265 
1266 // PUBLIC MEMBER FUNCTIONS
1267 
1268 // PROTECTED MEMBER FUNCTIONS
1269 
1270 // PRIVATE MEMBER FUNCTIONS
1271 
1272 
1273 // ===========================================================
1274 // DEGREE OF FREEDOM (DOF) TUPLE FACET
1275 // ===========================================================
1276 
1277 // PUBLIC MEMBER FUNCTIONS
1278 
1281 dof_map(bool xrequire_write_access)
1282 {
1283  // Preconditions:
1284 
1285  require(xrequire_write_access ?
1286  state_is_read_write_accessible() :
1287  state_is_read_accessible());
1288  require(is_jim(false));
1289 
1290  // Body:
1291 
1292  array_poset_dof_map& result =
1293  reinterpret_cast<array_poset_dof_map&>(total_poset_member::dof_map());
1294 
1295  // Postconditions:
1296 
1297  ensure(is_basic_query);
1298 
1299  // Exit:
1300 
1301  return result;
1302 }
1303 
1306 dof_map(bool xrequire_write_access) const
1307 {
1308  // Preconditions:
1309 
1310  require(xrequire_write_access ?
1311  state_is_read_write_accessible() :
1312  state_is_read_accessible());
1313  require(is_jim(false));
1314 
1315  // Body:
1316 
1317  const array_poset_dof_map& result =
1318  reinterpret_cast<const array_poset_dof_map&>(total_poset_member::dof_map());
1319 
1320  // Postconditions:
1321 
1322  ensure(is_basic_query);
1323 
1324  // Exit:
1325 
1326  return result;
1327 }
1328 
1329 bool
1332 {
1333  bool result;
1334 
1335  // Preconditions:
1336 
1337  require(xdof_map != 0);
1338 
1339  // Body:
1340 
1341  // This handle requires xdof_map to be of type array_poset_dof_map.
1342 
1343  result = dynamic_cast<const array_poset_dof_map*>(xdof_map) != 0;
1344 
1345  // Postconditions:
1346 
1347  // Exit
1348 
1349  return result;
1350 }
1351 
1352 // PROTECTED MEMBER FUNCTIONS
1353 
1354 // PRIVATE MEMBER FUNCTIONS
1355 
1356 
1357 // ===========================================================
1358 // POSET_COMPONENT FACET
1359 // ===========================================================
1360 
1361 // PUBLIC MEMBER FUNCTIONS
1362 
1365 host() const
1366 {
1367  poset* result;
1368 
1369  // Preconditions:
1370 
1371  // Body:
1372 
1373  result = reinterpret_cast<poset*>(total_poset_member::host());
1374 
1375  // Postconditions:
1376 
1377  // Exit:
1378 
1379  return result;
1380 }
1381 
1382 bool
1385 {
1386  bool result;
1387 
1388  // Preconditions:
1389 
1390  require(xother != 0);
1391 
1392  // Body:
1393 
1394  result = dynamic_cast<const poset*>(xother) != 0;
1395 
1396  // Postconditions:
1397 
1398  // Exit
1399 
1400  return result;
1401 }
1402 
1403 // PROTECTED MEMBER FUNCTIONS
1404 
1405 // PRIVATE MEMBER FUNCTIONS
1406 
1407 
1408 // ===========================================================
1409 // ANY FACET
1410 // ===========================================================
1411 
1412 // PUBLIC MEMBER FUNCTIONS
1413 
1414 bool
1416 invariant() const
1417 {
1418  // Preconditions:
1419 
1420  // Body:
1421 
1422  // Must satisfy base class invariant
1423 
1424  invariance(total_poset_member::invariant());
1425 
1426  if(invariant_check())
1427  {
1428  // Prevent recursive calls to invariant
1429 
1430  disable_invariant_check();
1431 
1432  // Invariants for this class:
1433 
1436 
1438 
1439  // Finished, turn invariant checking back on.
1440 
1441  enable_invariant_check();
1442  }
1443 
1444  // Postconditions:
1445 
1446  // Exit
1447 
1448  return true;
1449 }
1450 
1451 bool
1453 is_ancestor_of(const any* xother) const
1454 {
1455  bool result;
1456 
1457  // Preconditions:
1458 
1459  // Body:
1460 
1461  result = dynamic_cast<const base_space_member*>(xother) != 0;
1462 
1463  // Postconditions:
1464 
1465  // Exit
1466 
1467  return result;
1468 }
1469 
1472 clone() const
1473 {
1474 
1475  // Preconditions:
1476 
1477  // Body:
1478 
1479  // Create new handle of the current class.
1480 
1481  base_space_member *result = new base_space_member();
1482 
1483  // Postconditions:
1484 
1485  ensure(result != 0);
1486  ensure(result->invariant());
1487 
1488  // Exit:
1489 
1490  return result;
1491 
1492 }
1493 
1497 {
1498  // Preconditions:
1499 
1500  // Body:
1501 
1502  attach_to_state(&xother);
1503 
1504  // Postconditions:
1505 
1506  ensure(is_same_state(&xother));
1507 
1508  // Exit
1509 
1510  return *this;
1511 }
1512 
1516 {
1517  // Preconditions:
1518 
1519  // Body:
1520 
1521  attach_to_state(&xother);
1522 
1523  // Postconditions:
1524 
1525  ensure(is_same_state(&xother));
1526 
1527  // Exit
1528 
1529  return *this;
1530 }
1531 
1532 // PROTECTED MEMBER FUNCTIONS
1533 
1534 // PRIVATE MEMBER FUNCTIONS
1535 
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
Index for identifying a poset member relative to a given name space.
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
bool state_is_auto_read_write_accessible(bool xauto_access) const
True if state is auto accessible for read and write, that is, if the state is already accessible for ...
A client handle for a subposet.
Definition: subposet.h:86
virtual base_space_member & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
void truncate()
Makes this the next member of the subset which is not less than old this, i.e. the depth-first descen...
bool path_is_auto_read_write_available(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath does not exist or exists and is auto read-write accessible...
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
size_type ct() const
The number of items currently in use.
int db() const
The base space dimension.
poset_path path(bool xauto_access=true) const
A path to this component.
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...
bool path_is_auto_read_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read accessible.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
void d_cells_ct(block< size_type > &xresult, bool xauto_access) const
The number of cells (jims) of each dimension in the down set of this.
void l_join_pa(abstract_poset_member *result, bool xnew_jem=true)
Lattice join of the members of this, pre-allocated The lattice join is the least upper bound in the...
Definition: subposet.cc:2351
const char * local_cell_type_name
The local cell type name.
void put_visit_once(bool xvisit_once)
Set visit_once() to xvisit_once.
virtual ~base_space_member()
Destructor; deletes a poset member and its attached state, if any.
void c_not_pa(base_space_member &result, bool xauto_access)
The cellular space psuedo-complement of this, pre-allocated.
bool contains_poset_member(pod_index_type xposet_hub_id, pod_index_type xmember_hub_id, bool xauto_access=true) const
True if this contains a poset with hub id xposet_hub_id which contains a member with hub id xmember_h...
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
A client handle for a general, abstract partially order set.
A three state "bool". Does not provide the operations of ternary logic and is intended for use mostly...
Definition: tern.h:45
scoped_index poset_id
The index of the poset relative to the namespace.
base_space_member * c_not(bool xauto_access)
The cellular space psuedo-complement of this, auto-allocated. The cellular space psuedo-complement is...
virtual void * dof_tuple()=0
The dof tuple (mutable version).
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
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.
const scoped_index & index() const
The index of the component state this handle is attached to.
const pod_index_type & type_id() const
The cell type id of this. The id of the prototype of this in the "cell_types" id space of the prototy...
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
static const std::string & prototypes_poset_name()
The name of the prototypes poset.
base_space_member * c_minus(base_space_member &xother, bool xnew_jem, bool xauto_access)
The cellular space difference of this and xother, auto-allocated. The cellular space difference is de...
A client handle for a member of a base space poset.
pod_index_type local_cell_type_id() const
The local cell type id.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual array_poset_dof_map & dof_map(bool xrequire_write_access=false)
The map from client_ids to dof values for this poset member (mutable version)
scoped_index member_id
The index of the member relative to the poset.
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
virtual const poset_path & schema_path() const
The path of the schema required by this.
const bool NOT_STRICT
Iteration strictness control.
Definition: sheaf.h:102
const bool DOWN
Iteration directions.
Definition: sheaf.h:77
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
A client handle for a mutable partially ordered set.
Definition: poset.h:40
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
virtual const scoped_index & new_row_dof_map()
Creates a new row dof map.
virtual bool dof_map_is_ancestor_of(const poset_dof_map *xdof_map) const
True if xdof_map conforms to (is derived from) the type of dof map required by this handle...
poset * host() const
The poset which this is a handle to a member of.
bool owns(const poset_state_handle &xposet, bool xauto_access) const
True if and only if this contains the poset xposet. synonym for contains_poset(xposet.poset_path(true), xauto_access)
static bool prototype_exists(const std::string &xname, bool xauto_access)
True if base space member prototypes poset in the current name space contains a member with name xnam...
virtual void detach_from_state()
Detach this handle from its state, if any.
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
virtual bool is_attached() const
True if this handle is attached to a non-void state.
virtual void get_read_access() const
Get read access to the state associated with this.
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
virtual void insert_member(pod_index_type xmbr_hub_id)
Inserts the member of host() with hub id xmbr_hub_id.
Definition: subposet.cc:1091
static array_poset_dof_map * new_row_dof_map(const poset *xhost, const std::string &xprototype_name)
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
size_type row_dof_tuple_ct() const
The number of row_dof_tuples of this poset.
bool is_empty() const
True if this poset is empty.
Definition: subposet.cc:1340
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. ...
int db(pod_index_type xmbr_hub_id) const
The base space dimension of the member with hub id xmbr_hub_id.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
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...
pod_index_type new_member(const std::string &xprototype_name, bool xcopy_dof_map)
Creates a disconnected jim using the prototype with name xprototype_name. If xcopy_dof_map or if xhos...
const char * type_name() const
The cell type name.
const char * local_cell_type_name() const
The local cell type name.
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
bool is_done() const
True if iteration finished.
void put_refinement_depth(int xdepth)
Sets the refinement depth to xdepth.
static host_type & standard_host(namespace_type &xns, const poset_path &xhost_path, int xmax_db, bool xauto_access)
The host with path xhost_path. Returns the host if it already exists, otherwise, creates it in namesp...
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.
virtual poset_dof_map & row_dof_map(pod_index_type xtuple_hub_id, bool xrequire_write_access=false) const
The map from row dof client_ids to row dof values for dof tuple hub id xtuple_hub_id.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
bool member_exists(bool xauto_access) const
Definition: poset_path.cc:1079
base_space_member()
Default constructor; creates a new, unattached base_space_member handle.
virtual void * dof_tuple()
The dof tuple (mutable version).
virtual void reset(bool xreset_markers=true)
Restarts the iteration over the down set of anchor().
poset_path prototype_path() const
The path of the prototype for this.
virtual bool invariant() const
Class invariant.
virtual void remove_member(pod_index_type xmbr_hub_id)
Removes the member of host() with hub id xmbr_hub_id.
Definition: subposet.cc:1209
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
virtual subposet & jims()
The subset of all jims (mutable version)
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
Definition: poset.cc:253
virtual void put_anchor(const abstract_poset_member *xanchor)
Set anchor() to xanchor.
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.
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, int xmax_db, bool xauto_access)
Creates a new host poset for members of this type. The poset is created in namespace xns with path xh...
virtual void get_read_access() const
Get read access to the state associated with this.
int max_db() const
The maximum dimension of the members of this base space.
An abstract client handle for a member of a poset.
The type of row dof tuple for base_space_member.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
An array representation of abstract class poset_dof_map.
Namespace for the fiber_bundles component of the sheaf system.
virtual void delete_state(bool xauto_access=false)
Detach this from its state and delete the state.
Definition: subposet.cc:2876
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
bool state_is_not_read_accessible() const
True if this is attached and if the state is accessible for read or if access control is disabled...
int refinement_depth() const
The refinement depth.
A client handle for a poset member which has been prepared for use as a schema.
virtual bool host_is_ancestor_of(const poset_state_handle *other) const
True if other conforms to host.
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...
row_dof_tuple_type * row_dof_tuple(bool xrequire_write_access=false)
The row dof tuple for this.
virtual base_space_member * clone() const
Make a new handle, no state instance of current.
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.
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
Definition: poset.cc:230