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