SheafSystem  0.0.0.0
structured_block_1d_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/structured_block_1d_crg_interval.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_poset.h"
25 #include "SheafSystem/constant_index_space_interval.h"
26 #include "SheafSystem/error_message.h"
27 #include "SheafSystem/explicit_index_space_interval.h"
28 #include "SheafSystem/factory.h"
29 #include "SheafSystem/offset_index_space_handle.h"
30 #include "SheafSystem/offset_index_space_state.h"
31 #include "SheafSystem/list_index_space_handle.h"
32 #include "SheafSystem/list_index_space_state.h"
33 #include "SheafSystem/i_adjacency_index_space_interval.h"
34 #include "SheafSystem/i_connectivity_index_space_interval.h"
35 #include "SheafSystem/index_space_iterator.h"
36 #include "SheafSystem/section_space_schema_member.h"
37 #include "SheafSystem/std_iomanip.h"
38 #include "SheafSystem/std_string.h"
39 #include "SheafSystem/std_sstream.h"
40 #include "SheafSystem/structured_block_1d.h"
41 
42 using namespace std;
43 using namespace fiber_bundle; // Workaround for MS C++ bug.
44 
45 // ===========================================================
46 // STRUCTURED_BLOCK_1D_CRG_INTERVAL FACET
47 // ===========================================================
48 
49 // PUBLIC DATA MEMBERS
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  _i_size = 0;
59 
60  _i_vertex_size = 0;
61 
62  _zone_begin = 0;
63 
64  _vertex_begin = 0;
65 
66  // Postconditions:
67 
68  ensure(invariant());
69  ensure(!is_initialized());
70 
71  return;
72 }
73 
76 {
77  // Preconditions:
78 
79  // Body:
80 
81  if(is_valid(_lower_covers_begin))
82  {
83  // Delete the block interval.
84 
85  _id_spaces->delete_space(_lower_covers_begin);
86 
87  // Delete the zones interval.
88 
89  _id_spaces->delete_space(_lower_covers_begin + 1);
90 
91  // Delete the vertices interval.
92 
93  _id_spaces->delete_space(_lower_covers_begin + 1 + _i_size);
94  }
95 
96  if(is_valid(_upper_covers_begin))
97  {
98  // Delete the block interval.
99 
100  _id_spaces->delete_space(_upper_covers_begin);
101 
102  // Delete the zones interval.
103 
104  _id_spaces->delete_space(_upper_covers_begin + 1);
105 
106  // Delete the vertices interval.
107 
108  _id_spaces->delete_space(_upper_covers_begin + 1 + _i_size);
109  }
110 
111  // Postconditions:
112 
113  // Exit:
114 
115  return;
116 }
117 
120 i_size() const
121 {
122  return _i_size;
123 }
124 
125 // PROTECTED DATA MEMBERS
126 
127 // PRIVATE DATA MEMBERS
128 
129 
130 // ===========================================================
131 // HOMOGENEOUS_BLOCK_CRG_INTERVAL FACET
132 // ===========================================================
133 
134 // PUBLIC DATA MEMBERS
135 
136 // PROTECTED DATA MEMBERS
137 
138 // PRIVATE DATA MEMBERS
139 
140 
141 // ===========================================================
142 // ZONES FACET
143 // ===========================================================
144 
145 // PUBLIC DATA MEMBERS
146 
147 // PROTECTED DATA MEMBERS
148 
149 void
152 {
153  // Preconditions:
154 
155  require(id_spaces_initialized());
156  require(local_id_space_initialized());
157  require(!zones_initialized());
158 
159  // Body:
160 
161  // Construct the zone id space.
162 
163  const string& lzone_id_space_name =
164  section_space_schema_member::intersection_id_space_name(xhost.d_cells(1),
165  interval_member());
166 
167  _zones_space_id =
168  offset_index_space_state::new_space(*_id_spaces,
169  lzone_id_space_name,
170  _zone_begin,
171  _i_size).index();
172 
173  _zones_initialized = true;
174 
175  // Postconditions:
176 
177  ensure(zones_initialized());
178 
179  // Exit:
180 
181  return;
182 }
183 
184 // PRIVATE DATA MEMBERS
185 
186 
187 // ===========================================================
188 // VERTICES FACET
189 // ===========================================================
190 
191 // PUBLIC DATA MEMBERS
192 
193 // PROTECTED DATA MEMBERS
194 
195 void
198 {
199  // Preconditions:
200 
201  require(id_spaces_initialized());
202  require(local_id_space_initialized());
203  require(!vertices_initialized());
204 
205  // Body:
206 
207  // Construct the vertex id space.
208 
209  const string& lvertex_id_space_name =
210  section_space_schema_member::intersection_id_space_name(xhost.d_cells(0),
211  interval_member());
212 
213  _vertices_space_id =
214  offset_index_space_state::new_space(*_id_spaces,
215  lvertex_id_space_name,
216  _vertex_begin,
217  _i_vertex_size).index();
218 
219  _vertices_initialized = true;
220 
221  // Postconditions:
222 
223  ensure(vertices_initialized());
224 
225  // Exit:
226 
227  return;
228 }
229 
230 // PRIVATE DATA MEMBERS
231 
232 
233 // ===========================================================
234 // BASE_SPACE_CRG_INTERVAL FACET
235 // ===========================================================
236 
237 // PUBLIC DATA MEMBERS
238 
239 int
241 db(pod_index_type xmbr_id) const
242 {
243  // Preconditions:
244 
245  require(contains_member(xmbr_id));
246 
247  // Body:
248 
249  static const int ldb[MEMBER_CLASS_END] =
250  {
251  1, 1, 0
252  };
253 
254  int result = ldb[member_class(xmbr_id)];
255 
256  // Postconditions:
257 
258 
259  // Exit:
260 
261  return result;
262 }
263 
266 d_cells_space_id(int xd) const
267 {
268  // Preconditions:
269 
270  // Body:
271 
272  pod_index_type result;
273 
274  switch(xd)
275  {
276  case 0:
277  result = _vertices_space_id;
278  break;
279 
280  case 1:
281  result = _zones_space_id;
282  break;
283 
284  default:
285  result = invalid_pod_index();
286  break;
287  }
288 
289  // Postconditions:
290 
291  // Exit:
292 
293  return result;
294 }
295 
296 // PROTECTED DATA MEMBERS
297 
298 // PRIVATE DATA MEMBERS
299 
300 
301 // ===========================================================
302 // BLOCK VERTICES FACET
303 // ===========================================================
304 
305 // PUBLIC DATA MEMBERS
306 
307 // PROTECTED DATA MEMBERS
308 
309 void
312 {
313  // Preconditions:
314 
315  require(!block_vertices_initialized());
316  require(vertices_initialized());
317 
318  // Body:
319 
320  // Construct the block vertices id space.
321 
322  list_index_space_handle lblock_vertices_id_space =
323  list_index_space_state::new_space(*_id_spaces,
324  block_vertices_name(),
325  false);
326 
327  _block_vertices_space_id = lblock_vertices_id_space.index();
328 
329  // Insert the private data into the id space.
330 
331  lblock_vertices_id_space.push_back(_vertex_begin);
332  lblock_vertices_id_space.push_back(_vertex_begin + _i_size); // Same as _vertex_begin + _i_vertex_size - 1
333 
334  // The block vertices is initialized.
335 
336  _block_vertices_initialized = true;
337 
338  // Postconditions:
339 
340  ensure(block_vertices_initialized());
341 
342  // Exit:
343 
344  return;
345 }
346 
347 // PRIVATE DATA MEMBERS
348 
349 
350 // ===========================================================
351 // IMPLICIT_CRG_INTERVAL FACET
352 // ===========================================================
353 
354 // PUBLIC DATA MEMBERS
355 
356 // PROTECTED DATA MEMBERS
357 
358 // PRIVATE DATA MEMBERS
359 
360 
361 // ===========================================================
362 // CRG_INTERVAL FACET
363 // ===========================================================
364 
365 // PUBLIC DATA MEMBERS
366 
367 // PROTECTED DATA MEMBERS
368 
369 // PRIVATE DATA MEMBERS
370 
371 
372 // ===========================================================
373 // INTERVAL FACET
374 // ===========================================================
375 
376 // PUBLIC DATA MEMBERS
377 
378 void
380 get_size(size_type xi_size, size_type& result)
381 {
382  // Preconditions:
383 
384 
385  // Body:
386 
387  size_type lzone_size = xi_size;
388  size_type lvertex_size = xi_size + 1;
389 
390  result = 1 + lzone_size + lvertex_size;
391 
392  // Postconditions:
393 
394 
395  // Exit:
396 
397  return;
398 }
399 
400 // PROTECTED DATA MEMBERS
401 
402 // PRIVATE DATA MEMBERS
403 
404 
405 // ===========================================================
406 // COVER SET FACET
407 // ===========================================================
408 
409 // PUBLIC DATA MEMBERS
410 
411 // PROTECTED DATA MEMBERS
412 
413 void
416 {
417  // Preconditions:
418 
419  require(id_spaces_initialized());
420  require(local_id_space_initialized());
421  require(!covers_initialized(LOWER));
422 
423  // Body:
424 
425  // Construct the lower cover of the block.
426  //
427  // The lower cover of the block is initialized to an id space that contains
428  // all the zones.
429 
430  _lower_covers_begin =
431  explicit_index_space_interval::new_space(*_id_spaces, 1).begin();
432 
433  offset_index_space_state::new_space(*_id_spaces,
434  _lower_covers_begin,
435  implicit_cover_name(LOWER, interval_member()),
436  _zone_begin,
437  _i_size);
438 
439  // Construct the lower cover of the zones.
440  //
441  // The lower cover of the zones is initialized to the nodal connectivity.
442  // The user may change the lower cover of the zones by using the explicit
443  // overrides in crg_range. However, the underlineing connectivity id space
444  // interval will remain in the id space family. For that reason, we can
445  // set the connectivity begin to beginning of the connectivity id space
446  // interval created below.
447 
448  _connectivity_begin =
449  i_connectivity_index_space_interval::new_space(*_id_spaces, _i_size, _vertex_begin).begin();
450 
451  // Construct the lower cover of the vertices.
452  //
453  // The lower cover of the vertices is initialized to bottom.
454 
455  constant_index_space_interval::new_space(*_id_spaces, _i_vertex_size, BOTTOM_INDEX);
456 
457  // The lower cover is initialized.
458 
459  _lower_covers_initialized = true;
460 
461  // Posconditions:
462 
463  ensure(covers_initialized(LOWER));
464 
465  // Exit:
466 
467  return;
468 }
469 
470 void
473 {
474  // Preconditions:
475 
476  require(id_spaces_initialized());
477  require(local_id_space_initialized());
478  require(!covers_initialized(UPPER));
479 
480  // Body:
481 
482  // Construct the upper cover of the block
483  //
484  // The upper cover of block is initialized to an empty explicit id space.
485 
486  _upper_covers_begin =
487  explicit_index_space_interval::new_space(*_id_spaces, 1).begin();
488 
489  list_index_space_state::new_space(*_id_spaces,
490  _upper_covers_begin,
491  explicit_cover_name(UPPER, interval_member()),
492  false);
493 
494  // Construct the upper cover of the zones.
495  //
496  // The upper cover of the zones is initialized to the block.
497 
498  constant_index_space_interval::new_space(*_id_spaces, _i_size, interval_member());
499 
500  // Construct the upper cover of the vertices.
501  //
502  // The upper cover of the vertices is initialized to the zonal adjacency.
503  // The user may change the upper cover of the vertices by using the explicit
504  // overrides in crg_range. However, the underlineing adjacency id space
505  // interval will remain in the id space family. For that reason, we can
506  // set the adjacency begin to the beginning of the adjacency id space
507  // interval created below.
508 
509  _adjacency_begin =
510  i_adjacency_index_space_interval::new_space(*_id_spaces, _i_vertex_size, _zone_begin, _i_size).begin();
511 
512  // The upper cover is initialized.
513 
514  _upper_covers_initialized = true;
515 
516  // Posconditions:
517 
518  ensure(covers_initialized(UPPER));
519 
520  // Exit:
521 
522  return;
523 }
524 
525 // PRIVATE DATA MEMBERS
526 
527 
528 // ===========================================================
529 // DOF_TUPLE_ID FACET
530 // ===========================================================
531 
532 // PUBLIC DATA MEMBERS
533 
534 void
537  size_type xi_size,
538  block<pod_index_type>& result)
539 {
540  // Preconditions:
541 
542 
543  // Body:
544 
545  result.reserve(MEMBER_CLASS_END);
546  result.set_ct(MEMBER_CLASS_END);
547 
548 
549  result[BLOCK] = structured_block_1d::new_row_dof_map(xhost, xi_size, true).hub_pod();
550  result[ZONE] = base_space_member::new_row_dof_map(xhost, "segment_complex", true).hub_pod();
551  result[VERTEX] = base_space_member::new_row_dof_map(xhost, "point", true).hub_pod();
552 
553  // Postconditions:
554 
555 
556  // Exit:
557 
558  return;
559 }
560 
561 // PROTECTED DATA MEMBERS
562 
563 // PRIVATE DATA MEMBERS
564 
565 
566 // ===========================================================
567 // PRIVATE_DATA FACET
568 // ===========================================================
569 
570 // PUBLIC DATA MEMBERS
571 
572 void
575 {
576  // Preconditions:
577 
578  // Body:
579 
580  result.reserve(3);
581  result.set_ct(3);
582 
583  result[0] = xi_size;
584  result[1] = 0;
585  result[2] = 0;
586 
587  // Postconditions:
588 
589  // Exit:
590 
591  return;
592 }
593 
594 // PROTECTED DATA MEMBERS
595 
599 {
600  return 1;
601 }
602 
603 void
606 {
607  // Preconditions:
608 
609  // Body:
610 
611  xdata.push_back(_i_size);
612 
613  // Postconditions:
614 
615  ensure(xdata.ct() == implicit_private_data_size());
616 
617  // Exit:
618 
619  return;
620 }
621 
622 void
625 {
626  // Preconditions:
627 
628  // Body:
629 
630  _i_size = xdata[0];
631  _i_vertex_size = _i_size + 1;
632  _zone_begin = implicit_begin();
633  _vertex_begin = _zone_begin + _i_size;
634 
635  // Postconditions:
636 
637  ensure(invariant());
638 
639  // Exit:
640 
641  return;
642 }
643 
644 // PRIVATE DATA MEMBERS
645 
646 
647 // ===========================================================
648 // FINIALIZE FACET
649 // ===========================================================
650 
651 // PUBLIC DATA MEMBERS
652 
653 void
656 {
657  // Preconditions:
658 
659  require(dynamic_cast<base_space_poset*>(&xhost) != 0);
660  require(xhost.state_is_read_accessible());
661 
662  // Body:
663 
664  base_space_poset& lhost = dynamic_cast<base_space_poset&>(xhost);
665 
666  // Initialize the zone id space.
667 
668  initialize_zones(lhost);
669 
670  // Initialize the vertex id space.
671 
672  initialize_vertices(lhost);
673 
674  // Initialize the block vertices id space.
675 
676  initialize_block_vertices();
677 
678  // Initialize the cover id spaces.
679 
680  initialize_covers();
681 
682  // Now this can be inserted in the standard subposets (d-cells, etc).
683 
684  lhost.insert_interval_in_standard_subposets(*this);
685 
686  // Insert the vertices into the upper cover of bottom.
687 
688  xhost.append_upper_cover_of_bottom(_vertex_begin,
689  _vertex_begin + _i_vertex_size);
690 
691  homogeneous_block_crg_interval::finalize(xhost);
692 
693  // Postconditions:
694 
695  ensure(invariant());
696  ensure(is_initialized());
697 
698  // Exit:
699 
700  return;
701 }
702 
703 // PROTECTED DATA MEMBERS
704 
705 // PRIVATE DATA MEMBERS
706 
707 
708 // ===========================================================
709 // FACTORY FACET
710 // ===========================================================
711 
712 // PUBLIC DATA MEMBERS
713 
714 const std::string&
716 class_name() const
717 {
718  static const string result("structured_block_1d_crg_interval");
719  return result;
720 }
721 
722 // PROTECTED DATA MEMBERS
723 
724 // PRIVATE DATA MEMBERS
725 
726 bool
727 fiber_bundle::structured_block_1d_crg_interval::
728 make_prototype()
729 {
730  // Preconditions:
731 
732 
733  // Body:
734 
736 
737  interval_factory().insert_prototype(lproto);
738 
739  // Postconditions:
740 
741 
742  // Exit:
743 
744  return true;
745 }
746 
747 
748 // ===========================================================
749 // ANY FACET
750 // ===========================================================
751 
752 // PUBLIC DATA MEMBERS
753 
754 bool
756 is_ancestor_of(const any* other) const
757 {
758 
759  // Preconditions:
760 
761  require(other != 0);
762 
763  // Body:
764 
765  // True if other conforms to this
766 
767  bool result = dynamic_cast<const structured_block_1d_crg_interval*>(other) != 0;
768 
769  // Postconditions:
770 
771  return result;
772 }
773 
776 clone() const
777 {
778  // Preconditions:
779 
780  // Body:
781 
783 
784  // Postconditions:
785 
786  ensure(result != 0);
787  ensure(is_same_type(result));
788 
789  // Exit:
790 
791  return result;
792 }
793 
794 bool
796 invariant() const
797 {
798  bool result = true;
799 
800  if(invariant_check())
801  {
802  // Prevent recursive calls to invariant
803 
804  disable_invariant_check();
805 
806  // Must satisfy base class invariant
807 
808  invariance(homogeneous_block_crg_interval::invariant());
809 
810  // Invariances for this class:
811 
812  invariance(dof_tuple_ids_initialized() ? is_valid(block_dof_tuple_id()) : true);
813  invariance(dof_tuple_ids_initialized() ? is_valid(zone_dof_tuple_id()) : true);
814  invariance(dof_tuple_ids_initialized() ? is_valid(vertex_dof_tuple_id()) : true);
815 
816  // Finished, turn invariant checking back on.
817 
818  enable_invariant_check();
819  }
820 
821  // Exit
822 
823  return result;
824 }
825 
826 // PROTECTED DATA MEMBERS
827 
828 // PRIVATE DATA MEMBERS
829 
830 
831 // ===========================================================
832 // NON-MEMBER FUNCTIONS
833 // ===========================================================
834 
virtual void put_implicit_private_data(const block< pod_index_type > &xdata)
Initializes this using private data xdata.
virtual pod_type index() const
Index of this space.
size_type ct() const
The number of items currently in use.
virtual const std::string & class_name() const
The name of this class; provided to satisfy factory template.
virtual int db(pod_index_type xmbr_id) const
The dimension of the member with id xmbr_id. Does not require access to dof tuple.
void initialize_zones(base_space_poset &xhost)
Initialize the zones id space.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
subposet & d_cells(int xd)
The subposet containing the cells of dimension xd (mutable version).
virtual void get_implicit_private_data(block< pod_index_type > &xdata) const
The private data for this instance.
A client handle for a general, abstract partially order set.
An map implementation of class scattered_insertion_index_space_handle. This representation is intende...
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
void append_upper_cover_of_bottom(pod_index_type xmbr_hub_begin, pod_index_type xmbr_hub_end)
Appends the interval of hub ids [xmbr_hub_begin, xmbr_hub_end) to the upper cover of bottom...
Abstract base class with useful features for all objects.
Definition: any.h:39
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
virtual structured_block_1d_crg_interval * clone() const
Virtual constructor, makes a new instance of the same type as this.
static void get_size(size_type xi_size, size_type &result)
The size for an instance created with parameter xi_size.
size_type i_size() const
The number of zones in the i direction in this block.
Emulator for a interval of implicit base space members representing a 1 dimensional structured block...
void set_ct(size_type xct)
Sets ct() == xct.
void initialize_vertices(base_space_poset &xhost)
Initialize the vertex id space.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
static void get_private_data(size_type xi_size, block< pod_index_type > &result)
The private data for an instance with parameter xi_size.
virtual void initialize_lower_covers()
Initialize the lower covers for this interval.
virtual void finalize(poset_state_handle &xhost)
Finialize the initialization of this crg interval in the host xhost.
const bool UPPER
Selector for upper cover.
Definition: sheaf.h:72
void initialize_block_vertices()
Initialize the block vertices id space.
const bool LOWER
Selector for lower cover.
Definition: sheaf.h:67
virtual pod_index_type d_cells_space_id(int xd) const
The id space index for the cells of dimension xd. Returns invalid_pod_index() if there is no id space...
virtual size_type implicit_private_data_size() const
The size of the private data.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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_...
static void get_dof_tuple_ids(poset_state_handle &xhost, size_type xi_size, block< pod_index_type > &result)
The dof tuple ids for an instance created with parameter xi_size.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
virtual void initialize_upper_covers()
Initialize the upper cover for this interval.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.