SheafSystem  0.0.0.0
point_connectivity.cc
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 
18 // Implementation for class point_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/point_connectivity.h"
22 
23 using namespace fiber_bundle; // Workaround for MS C++ bug.
24 
25 
26 // ===========================================================
27 // POINT_CONNECTIVITY FACET
28 // ===========================================================
29 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  _nodes_per_element = NODES_PER_ELEMENT;
39 
40  // Postconditions:
41 
42  ensure(element_ct() == 0);
43  ensure(node_ct() == 0);
44  ensure(node_id_ct() == 0);
45  ensure(node_ids() == 0);
46  ensure(!delete_node_ids());
47  ensure(nodes_per_element() == NODES_PER_ELEMENT);
48  ensure(start_id() == 0);
49 }
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  // Postconditions:
59 
60  ensure(postcondition_of(block_connectivity(xother)));
61 }
62 
65  : block_connectivity(xstart_id)
66 {
67 
68  // Preconditions:
69 
70  // Body:
71 
72  create_connectivity(xi_size, xstart_id);
73 
74  // Postconditions:
75 
76  ensure(element_ct() == xi_size);
77  ensure(node_ct() == xi_size);
78  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
79  ensure(node_ids() != 0);
80  ensure(delete_node_ids());
81  ensure(nodes_per_element() == NODES_PER_ELEMENT);
82  ensure(start_id() == xstart_id);
83  ensure(node_ids()[0] == xstart_id);
84 }
85 
88 {
89  // Preconditions:
90 
91  // Body:
92 
93  // Postconditions:
94 }
95 
96 void
99 {
100  // Preconditions:
101 
102  require(xi_size > 0);
103 
104  // Body:
105 
106  _element_ct = xi_size;
107  _node_ct = xi_size;
108  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
110  _delete_node_ids = true;
111  _nodes_per_element = NODES_PER_ELEMENT;
112  _start_id = xstart_id;
113 
114  size_type index = 0;
115 
116  for(size_type i=0; i<xi_size; ++i)
117  {
118  _node_ids[i] = i + _start_id;
119  }
120 
121  // Postconditions:
122  ensure(element_ct() == xi_size);
123  ensure(node_ct() == xi_size);
124  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
125  ensure(node_ids() != 0);
126  ensure(delete_node_ids());
127  ensure(nodes_per_element() == NODES_PER_ELEMENT);
128  ensure(start_id() == xstart_id);
129  ensure(node_ids()[0] == xstart_id);
130 }
131 
132 // ===========================================================
133 // BLOCK_RELATION FACET
134 // ===========================================================
135 
139 {
140  return POINT;
141 }
142 
143 
144 // ===========================================================
145 // ANY FACET
146 // ===========================================================
147 
150 clone() const
151 {
152  point_connectivity* result;
153 
154  // Preconditions:
155 
156 
157  // Body:
158 
159  result = new point_connectivity();
160 
161  // Postconditions:
162 
163  ensure(result->is_same_type(this));
164 
165  // Exit:
166 
167  return result;
168 }
169 
170 bool
172 invariant() const
173 {
174  bool result = true;
175 
176  // Preconditions:
177 
178  // Body:
179 
180  if(invariant_check())
181  {
182  // Prevent recursive calls to invariant
183 
185 
186  invariance(block_connectivity::invariant());
187 
188  // Finished, turn invariant checking back on.
189 
191  }
192 
193  // Postconditions:
194 
195  // Exit
196 
197  return result;
198 }
199 
200 bool
202 is_ancestor_of(const any* other) const
203 {
204 
205  // Preconditions:
206 
207  require(other != 0);
208 
209  // Body:
210 
211  // True if other conforms to this.
212 
213  bool result = dynamic_cast<const point_connectivity*>(other) != 0;
214 
215  // Postconditions:
216 
217  return result;
218 }
pod_index_type * _node_ids
The nodal connectivity array.
void create_connectivity(size_type xi_size, pod_index_type xstart_id)
Allocates and initializes the connectivity array.
size_type _nodes_per_element
The number of nodes per element.
size_type node_id_ct() const
The number of entries in node_ids().
Zone to node connectivity relation for a block of zones of a given type.
pod_index_type * node_ids()
The nodal connectivity array.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual cell_type element_type() const
The element type.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
size_type nodes_per_element() const
The number of nodes per element.
size_type _node_id_ct
the number of entyries in _node_ids.
virtual bool invariant() const
Class invariant.
block_connectivity()
Default constructor.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual point_connectivity * clone() const
Virtual constructor, makes a new instance of the same type as this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
size_type _element_ct
The number of elements.
size_type node_ct() const
The number of distinct nodes.
point_connectivity()
Default constructor. Equivalent to point_connectivity(1)
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
size_type element_ct() const
The number of elements.
virtual ~point_connectivity()
Destructor.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
size_type _node_ct
The number of distinct nodes.
pod_index_type _start_id
The id given to the first node id generated. Mostly only useful for creating 1 (vs 0) based node numb...
pod_index_type start_id() const
The id given to the first node id generated.
Nodal connectivity for a block containing zones of type point. Since a point block is just a collecti...
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual bool invariant() const
Class invariant.
bool _delete_node_ids
True if destructor of this should delete _node_ids.
bool delete_node_ids() const
True if destructor of this should delete _node_ids.