SheafSystem  0.0.0.0
implicit_crg_interval.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/implicit_crg_interval.h"
22 
23 #include "SheafSystem/arg_list.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/index_space_family.h"
26 #include "SheafSystem/index_space_iterator.h"
27 #include "SheafSystem/list_index_space_handle.h"
28 #include "SheafSystem/list_index_space_state.h"
29 #include "SheafSystem/poset_state_handle.h"
30 
31 using namespace std;
32 
33 // ===========================================================
34 // IMPLICIT_CRG_INTERVAL FACET
35 // ===========================================================
36 
37 // PUBLIC DATA MEMBERS
38 
41  : _private_data_initialized(false),
42  _dof_tuple_ids_initialized(false),
43  _is_finalized(false)
44 {
45  // Preconditions:
46 
47  // Body:
48 
49  // Postconditions:
50 
51  ensure(invariant());
52  ensure(!is_initialized());
53 
54  // Exit:
55 
56  return;
57 }
58 
61 {
62  // Preconditions:
63 
64  // Body:
65 
66  // Nothing to do.
67 
68  // Postconditions:
69 
70  // Exit:
71 
72  return;
73 }
74 
75 // PROTECTED DATA MEMBERS
76 
77 // PRIVATE DATA MEMBERS
78 
79 
80 // ===========================================================
81 // IMPLICIT INTERVAL FACET
82 // ===========================================================
83 
84 // PUBLIC DATA MEMBERS
85 
89 {
90  // Preconditions:
91 
92  require(local_id_space_initialized());
93 
94  // Body:
95 
96  return _local_id_space.offset()+1;
97 }
98 
99 void
102 {
103  // Preconditions:
104 
105  require(local_id_space_initialized());
106 
107  // Body:
108 
109  result.put(hub_id_space(), implicit_begin());
110 
111  // Postconditions:
112 
113  ensure(result.is_hub_scope());
114 
115  // Exit:
116 
117  return;
118 }
119 
123 {
124  // Preconditions:
125 
126  require(local_id_space_initialized());
127 
128  // Body:
129 
130  return begin();
131 }
132 
133 void
136 {
137  // Preconditions:
138 
139  require(local_id_space_initialized());
140 
141  // Body:
142 
143  begin(result);
144 
145  // Postconditions:
146 
147  ensure(result.is_hub_scope());
148 
149  // Exit:
150 
151  return;
152 }
153 
154 bool
157 {
158  // Preconditions:
159 
160  require(local_id_space_initialized());
161 
162  // Body:
163 
164  return (_local_id_space.offset() == xindex);
165 }
166 
167 bool
169 is_interval_member(const scoped_index& xindex) const
170 {
171  // Preconditions:
172 
173  require(local_id_space_initialized());
174 
175  // Body:
176 
177  return is_interval_member(xindex.hub_pod());
178 }
179 
180 // PROTECTED DATA MEMBERS
181 
182 // PRIVATE DATA MEMBERS
183 
184 
185 // ===========================================================
186 // COVER SET FACET
187 // ===========================================================
188 
189 // PUBLIC MEMBER FUNCTIONS
190 
191 // PROTECTED MEMBER FUNCTIONS
192 
193 std::string
195 implicit_cover_name(bool xlower, pod_index_type xmbr_index)
196 {
197  // Preconditions:
198 
199  // Body:
200 
201  string suffix = xlower ? "_lower_cover" : "_upper_cover";
202 
203  string result = poset_path::make_reserved_name("implicit_", xmbr_index, suffix);
204 
205  // Postconditions:
206 
207  ensure(!result.empty());
208 
209  // Exit:
210 
211  return result;
212 }
213 
214 std::string
216 implicit_cover_name(bool xlower, const scoped_index& xmbr_index)
217 {
218  // Preconditions:
219 
220  // Body:
221 
222  return implicit_cover_name(xlower, xmbr_index.hub_pod());
223 }
224 
225 // PRIVATE MEMBER FUNCTIONS
226 
227 
228 // ===========================================================
229 // DOF_TUPLE_ID FACET
230 // ===========================================================
231 
232 // PUBLIC DATA MEMBERS
233 
234 bool
236 is_jim(pod_index_type xmbr_index) const
237 {
238  bool result = false; // Just to silence the compiler warnings.
239 
240  // Preconditions:
241 
242  require(contains_member(xmbr_index));
243 
244  // Body:
245 
246  is_abstract();
247 
248  // Postconditions:
249 
250  // Exit:
251 
252  return result;
253 }
254 
255 bool
257 is_jim(const scoped_index& xmbr_index) const
258 {
259  // Preconditions:
260 
261  require(contains_member(xmbr_index));
262 
263  // Body:
264 
265  return is_jim(xmbr_index.hub_pod());
266 }
267 
270 dof_tuple_id(const scoped_index& xmbr_index) const
271 {
272  // Preconditions:
273 
274  require(contains_member(xmbr_index));
275 
276  // Body:
277 
278  return dof_tuple_id(xmbr_index.hub_pod());
279 }
280 
284 {
285  return _dof_tuple_ids;
286 }
287 
291 {
292  return _dof_tuple_ids;
293 }
294 
295 void
298 {
299  // Preconditions:
300 
301 
302  // Body:
303 
304  _dof_tuple_ids.reserve(xdof_tuple_ids.ct());
305  _dof_tuple_ids.set_ct(xdof_tuple_ids.ct());
306 
307  for(int i=0; i<xdof_tuple_ids.ct(); ++i)
308  {
309  _dof_tuple_ids[i] = xdof_tuple_ids[i];
310  }
311 
313 
314  // Postconditions:
315 
316  ensure(dof_tuple_ids_initialized());
317  ensure(dof_tuple_ids().ct() == xdof_tuple_ids.ct());
318  ensure_for_all(i, 0, xdof_tuple_ids.ct(), dof_tuple_ids()[i] == xdof_tuple_ids[i]);
319 
320  // Exit:
321 
322  return;
323 }
324 
325 bool
328 {
330 }
331 
332 // PROTECTED DATA MEMBERS
333 
334 // PRIVATE DATA MEMBERS
335 
336 
337 // ===========================================================
338 // I/O SUPPORT FACET
339 // ===========================================================
340 
341 // PUBLIC DATA MEMBERS
342 
343 void
345 clean_cover(bool xlower, pod_index_type xmbr_index)
346 {
347  // Preconditions:
348 
349  require(contains_member(xmbr_index));
350 
351  // Body:
352 
354 
355  // Posconditions:
356 
357  // Exit:
358 
359  return;
360 }
361 
362 // PROTECTED DATA MEMBERS
363 
364 // PRIVATE DATA MEMBERS
365 
366 
367 // ===========================================================
368 // PRIVATE_DATA FACET
369 // ===========================================================
370 
371 // PUBLIC DATA MEMBERS
372 
376 {
377  // Preconditions:
378 
379  // Body:
380 
381  // Initialize to the implicit private data size.
382 
384 
385  // Add explicit member upper and lower cover sizes.
386 
387  result += 2;
388 
389  explicit_cover_map_type::const_iterator litr;
390 
391  // Count explicit upper covers.
392 
393  for(litr = _explicit_upper_cover_map.begin(); litr != _explicit_upper_cover_map.end(); ++litr)
394  {
395  // Add the member id, size of cover and cover members.
396 
397  result += (2+ _id_spaces->ct(litr->second));
398  }
399 
400  // Count explicit lower covers.
401 
402  for(litr = _explicit_lower_cover_map.begin(); litr != _explicit_lower_cover_map.end(); ++litr)
403  {
404  // Add the member id, size of cover and cover members.
405 
406  result += (2+ _id_spaces->ct(litr->second));
407  }
408 
409  // Postconditions:
410 
411  // Exit:
412 
413  return result;
414 }
415 
416 void
419 {
420  // Preconditions:
421 
422  // Body:
423 
424  xdata.reserve(private_data_size());
425 
426  // Insert implicit private data.
427 
429 
430  // Insert explicit private data.
431 
432  explicit_cover_map_type::const_iterator litr;
433 
434  // Insert explicit upper covers.
435 
436  xdata.push_back(_explicit_upper_cover_map.size());
437 
438  for(litr = _explicit_upper_cover_map.begin(); litr != _explicit_upper_cover_map.end(); ++litr)
439  {
440  // The private data has the member id, size of cover and cover members.
441 
442  xdata.push_back(litr->first);
443  xdata.push_back(_id_spaces->ct(litr->second));
444 
445  index_space_iterator& lcover_itr = _id_spaces->get_id_space_iterator(litr->second);
446  while(!lcover_itr.is_done())
447  {
448  xdata.push_back(lcover_itr.hub_pod());
449 
450  lcover_itr.next();
451  }
453  }
454 
455  // Insert explicit lower covers.
456 
457  xdata.push_back(_explicit_lower_cover_map.size());
458 
459  for(litr = _explicit_lower_cover_map.begin(); litr != _explicit_lower_cover_map.end(); ++litr)
460  {
461  // The private data has the member id, size of cover and cover members.
462 
463  xdata.push_back(litr->first);
464  xdata.push_back(_id_spaces->ct(litr->second));
465 
466  index_space_iterator& lcover_itr = _id_spaces->get_id_space_iterator(litr->second);
467  while(!lcover_itr.is_done())
468  {
469  xdata.push_back(lcover_itr.hub_pod());
470 
471  lcover_itr.next();
472  }
474  }
475 
476  // Postconditions:
477 
478  ensure(xdata.ct() == private_data_size());
479 
480  // Exit:
481 
482  return;
483 }
484 
485 void
488 {
489  // Preconditions:
490 
491  // Body:
492 
493  // Read the implicit private data.
494 
496 
497  // Read the explicit private data.
498 
500  size_type lmember_ct;
501  pod_index_type lmember_id;
502  size_type lcover_ct;
504 
505  // Read upper cover.
506 
507  lmember_ct = xdata[idx];
508  for(pod_index_type i = 0; i < lmember_ct; ++i)
509  {
510  // Read member id.
511 
512  lmember_id = xdata[++idx];
513 
514  // Read cover.
515 
516  lcover_ct = xdata[++idx];
517 
518  list_index_space_handle lcover =
520 
521  for(pod_index_type j = 0; j < lcover_ct; ++j)
522  {
523  lcover.push_back(xdata[++idx]);
524  }
525 
526  // Insert cover into the map.
527 
528  _explicit_upper_cover_map[lmember_id] = lcover.index();
529  }
530 
531  // Read lower cover.
532 
533  lmember_ct = xdata[++idx];
534  for(pod_index_type i = 0; i < lmember_ct; ++i)
535  {
536  // Read member id.
537 
538  lmember_id = xdata[++idx];
539 
540  // Read cover.
541 
542  lcover_ct = xdata[++idx];
543 
544  list_index_space_handle lcover =
546 
547  for(pod_index_type j = 0; j < lcover_ct; ++j)
548  {
549  lcover.push_back(xdata[++idx]);
550  }
551 
552  // Insert cover into the map.
553 
554  _explicit_lower_cover_map[lmember_id] = lcover.index();
555  }
556 
557  // Mark private data as initialized.
558 
560 
561  // Postconditions:
562 
563  ensure(private_data_initialized());
564 
565  // Exit:
566 
567  return;
568 }
569 
570 bool
573 {
575 }
576 
577 // PROTECTED DATA MEMBERS
578 
582 {
583  size_type result = 0;
584 
585  // Preconditions:
586 
587  // Body:
588 
589  is_abstract();
590 
591  // Postconditions:
592 
593  // Exit:
594 
595  return result;
596 }
597 
598 void
601 {
602  // Preconditions:
603 
604  // Body:
605 
606  is_abstract();
607 
608  // Postconditions:
609 
610  ensure(xdata.ct() == implicit_private_data_size());
611 
612  // Exit:
613 
614  return;
615 }
616 
617 void
620 {
621  // Preconditions:
622 
623  // Body:
624 
625  is_abstract();
626 
627  // Postconditions:
628 
629  ensure(invariant());
630 
631  // Exit:
632 
633  return;
634 }
635 
636 // PRIVATE DATA MEMBERS
637 
638 
639 // ===========================================================
640 // FINIALIZE FACET
641 // ===========================================================
642 
643 // PUBLIC DATA MEMBERS
644 
645 void
648 {
649  // Preconditions:
650 
651  require(xhost.state_is_read_accessible());
652 
653  // Body:
654 
655  // Have enough information to determine jims() membership.
656 
657  for(pod_index_type i=begin(); i<end(); ++i)
658  {
659  if(is_jim(i))
660  {
661  xhost.jims().insert_member(i);
662  }
663  }
664 
665  _is_finalized = true;
666 
667  // Postconditions:
668 
669  ensure(is_initialized());
670 
671  // Exit:
672 
673  return;
674 }
675 
676 // PROTECTED DATA MEMBERS
677 
678 // PRIVATE DATA MEMBERS
679 
680 
681 // ===========================================================
682 // FACTORY FACET
683 // ===========================================================
684 
685 // PUBLIC DATA MEMBERS
686 
687 void
689 initialize(const namespace_poset& xnamespace)
690 {
691  // Preconditions:
692 
693  // Body:
694 
695  crg_interval::initialize(xnamespace);
696 
699  _is_finalized = true;
700 
701  // Postconditions:
702 
703  ensure(is_initialized());
704 
705  // Exit:
706 
707  return;
708 }
709 
710 bool
713 {
714  bool result =
718 
719  return result;
720 }
721 
722 const std::string&
724 class_name() const
725 {
726  static const string result("implicit_crg_interval");
727  return result;
728 }
729 
730 // PROTECTED DATA MEMBERS
731 
732 // PRIVATE DATA MEMBERS
733 
734 
735 // ===========================================================
736 // ANY FACET
737 // ===========================================================
738 
739 // PUBLIC DATA MEMBERS
740 
741 bool
743 is_ancestor_of(const any* other) const
744 {
745 
746  // Preconditions:
747 
748  require(other != 0);
749 
750  // Body:
751 
752  // True if other conforms to this
753 
754  bool result = dynamic_cast<const implicit_crg_interval*>(other) != 0;
755 
756  // Postconditions:
757 
758  return result;
759 }
760 
763 clone() const
764 {
765  implicit_crg_interval* result = 0;
766 
767  // Preconditions:
768 
769  // Body:
770 
771  is_abstract();
772 
773  // Postconditions:
774 
775  ensure(result != 0);
776  ensure(is_same_type(result));
777 
778  // Exit:
779 
780  return result;
781 }
782 
783 bool
785 invariant() const
786 {
787  bool result = true;
788 
789  if(invariant_check())
790  {
791  // Prevent recursive calls to invariant
792 
794 
795  // Must satisfy base class invariant
796 
797  invariance(crg_interval::invariant());
798 
799  // Invariances for this class:
800 
801  invariance(local_id_space_initialized() ? implicit_begin() == local_id_space().offset()+1 : true);
802  invariance(local_id_space_initialized() ? interval_member() == begin() : true);
803 
804  // Finished, turn invariant checking back on.
805 
807  }
808 
809  // Exit
810 
811  return result;
812 }
813 
814 // PROTECTED DATA MEMBERS
815 
816 // PRIVATE DATA MEMBERS
817 
818 
819 // ===========================================================
820 // NON-MEMBER FUNCTIONS
821 // ===========================================================
822 
823 size_t
824 sheaf::deep_size(const implicit_crg_interval& xp, bool xinclude_shallow)
825 {
826  size_t result;
827 
828  // Preconditions:
829 
830  // Body:
831 
832  result = xinclude_shallow ? sizeof(xp) : 0;
833 
834  // Add the deep size of the data members.
835 
837  result += deep_size(xp._dof_tuple_ids, false);
838 
840  result += xp.private_data_size();
841 
842  // Postconditions:
843 
844  ensure(result >= 0);
845 
846  // Exit
847 
848  return result;
849 }
850 
An implementation of class scattered_insertion_index_space_handle that has a interval id space state...
virtual pod_index_type dof_tuple_id(pod_index_type xmbr_index) const =0
The dof tuple id of the member with index xmbr_index.
void initialize(const namespace_poset &xnamespace)
Sets is_initialized() == true; dummy routine provided to satisfy factory template.
index_space_family * _id_spaces
The id space family of this interval.
Definition: crg_interval.h:186
virtual pod_type index() const
Index of this space.
void get_private_data(block< pod_index_type > &xdata) const
Initializes this using private data xdata.
size_type ct() const
The number of items currently in use.
explicit_cover_map_type _explicit_lower_cover_map
The map from ids to explicit lower cover id spaces.
Definition: crg_interval.h:354
An abstract iterator over the ids of an id space.
block< pod_index_type > _dof_tuple_ids
The ids of the dof tuples associated with this interval.
const hub_index_space_handle & hub_id_space() const
The hub id space of this interval.
virtual bool is_initialized() const
True if fully initialized.
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...
A client handle for a general, abstract partially order set.
static list_index_space_handle new_space(index_space_family &xid_spaces, const std::string &xname, bool xis_persistent)
Create a new list id space in the id space family xid_space at the next available id space index with...
An map implementation of class scattered_insertion_index_space_handle. This representation is intende...
bool is_interval_member(pod_index_type xindex) const
True if xindex is the interval member.
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
block< pod_index_type > & dof_tuple_ids()
The ids of the dof tuples associated with this interval.
primary_index_space_handle _local_id_space
The id space of this interval.
Definition: crg_interval.h:232
virtual implicit_crg_interval * clone() const =0
Virtual constructor, makes a new instance of the same type as this.
pod_index_type begin() const
The beginning of the member interval; this emulates members in the interval [begin(), end()), includes interval member.
explicit_cover_map_type _explicit_upper_cover_map
The map from ids to explicit upper cover id spaces.
Definition: crg_interval.h:349
virtual void next()=0
Makes id() the next id in the iteration.
pod_index_type implicit_begin() const
The beginning of the implicit member interval (begin(), end()), excludes interval member; synonym for...
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual ~implicit_crg_interval()
Destructor.
static std::string explicit_cover_name(bool xlower, const scoped_index &xmbr_index)
Creates a name for the explicit cover id space for member with index, xmbr_index. ...
index_space_iterator & get_id_space_iterator(const std::string &xname) const
Allocates an id space iterator from the iterator pool attached to state with name xname...
virtual const std::string & class_name() const
The name of this class; provided to satisfy factory template.
void initialize_dof_tuple_ids(const block< pod_index_type > &xdof_tuple_ids)
Allocates and initializes dof_tuple_ids() with xdof_tuple_ids.
virtual void get_implicit_private_data(block< pod_index_type > &xdata) const =0
Initializes this using private data xdata.
Abstract implementation of crg_interval for an interval of implicit cover relation graph members...
bool is_hub_scope() const
True if and only if the id space of this is the hub id space.
Definition: scoped_index.h:575
bool local_id_space_initialized() const
True if local id space has been initialized.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual void put_implicit_private_data(const block< pod_index_type > &xdata)=0
Initializes this using private data xdata.
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
bool is_done() const
True if iteration is finished.
pod_index_type end() const
The end of the member interval.
bool _private_data_initialized
True if private data has been initialized.
void release_id_space_iterator(index_space_iterator &xitr) const
Returns the id space iterator xitr to the iterator pool.
void set_ct(size_type xct)
Sets ct() == xct.
pod_index_type interval_member() const
The index of the interval member itself; synonym for begin().
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual size_type implicit_private_data_size() const =0
The size of the private data.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
implicit_crg_interval()
Default Constructor; constructs an uninitialized interval.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
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
size_type private_data_size() const
The size of the private data.
const bool UPPER
Selector for upper cover.
Definition: sheaf.h:72
virtual void finalize(poset_state_handle &xhost)
Finialize the initialization of this crg interval in the host xhost.
bool private_data_initialized() const
True if private data has been initialized.
void put(const index_space_handle &xid_space, pod_type xpod)
Set the scope to id space, xid_space and pod() to xpod.
Definition: scoped_index.h:332
static std::string implicit_cover_name(bool xlower, const scoped_index &xmbr_index)
Creates a name for the implicit cover id space for member with index, xmbr_index. ...
bool contains_member(pod_index_type xindex) const
True if and only if the index xindex is contained in this interval.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual bool is_jim(pod_index_type xmbr_index) const =0
True if and only if the member with index xmbr_index is join-irreducible.
bool _is_finalized
True if the initialization of this crg interval has been finalized.
friend SHEAF_DLL_SPEC size_t deep_size(const implicit_crg_interval &xp, bool xinclude_shallow)
The deep size of the referenced object of type implicit_crg_interval; if xinclude_shallow, add the sizeof xp to the result.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
void initialize(const namespace_poset &xnamespace)
Sets is_initialized() == true; dummy routine provided to satisfy factory template.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool invariant() const
Class invariant.
virtual subposet & jims()
The subset of all jims (mutable version)
void push_back(const scoped_index &xhub_id)
Make the next id in this space equivalent to xhub_id in the hub id space. synonym for push_back(xhub_...
void clean_cover(bool xlower, pod_index_type xmbr_index)
Removes members of the cover that are no longer members of the crg.
const primary_index_space_handle & local_id_space() const
The local id space of this interval.
bool _dof_tuple_ids_initialized
True if dof tuple ids have been initialized.
pod_type offset() const
The offset into the hub id space.
size_type ct(const std::string &xname) const
The number of members for the id space with name xname.
bool dof_tuple_ids_initialized() const
True if dof tuple ids have been initialized.
An auto_block with a no-initialization initialization policy.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void put_private_data(const block< pod_index_type > &xdata)
Initializes this using private data xdata.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
pod_type hub_pod() const
The current unglued hub id in the iteration. synonym for unglued_hub_pod().
static std::string make_reserved_name(const std::string &xprefix, const size_t &xindex, const std::string &xsuffix)
Creates a string reserved_prefix()_xprefix_xindex_xsuffix.
Definition: poset_path.cc:733
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710