SheafSystem  0.0.0.0
hex_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 hex_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/hex_connectivity.h"
22 
23 using namespace fiber_bundle; // Workaround for bug in MS C++.
24 
25 // ===========================================================
26 // HEX_CONNECTIVITY FACET
27 // ===========================================================
28 
32 {
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 
55  // Preconditions:
56 
57  // Body:
58 
59  // Postconditions:
60 
61  ensure(postcondition_of(block_connectivity(xother)));
62 }
63 
65 hex_connectivity(const pod_index_type* xnode_ids, size_type xnode_id_ct, size_type xnode_ct)
66  : block_connectivity(xnode_ids, xnode_id_ct, NODES_PER_ELEMENT, xnode_ct)
67 {
68 
69  // Preconditions:
70 
71  require(xnode_id_ct > 0);
72  require((xnode_id_ct % NODES_PER_ELEMENT) == 0);
73 
74  // Body:
75 
76 
77  // Postconditions:
78 
79  ensure(element_ct() == xnode_id_ct/NODES_PER_ELEMENT);
80  ensure(xnode_ct > 0 ? node_ct() == xnode_ct : node_ct() > 0);
81  ensure(node_id_ct() == xnode_id_ct);
82  ensure(node_ids() == xnode_ids);
83  ensure(!delete_node_ids());
84  ensure(nodes_per_element() == NODES_PER_ELEMENT);
85 
86  // Exit:
87 }
88 
91  size_type xj_size,
92  size_type xk_size,
93  pod_index_type xstart_id)
94  : block_connectivity(xstart_id)
95 {
96 
97  // Preconditions:
98 
99  // Body:
100 
101  _i_vertex_size = xi_size + 1;
102  _j_vertex_size = xj_size + 1;
103  _k_vertex_size = xk_size + 1;
104 
105  create_connectivity(xi_size, xj_size, xk_size, xstart_id);
106 
107  // Postconditions:
108 
109 
110  ensure(element_ct() == xi_size*xj_size*xk_size);
111  ensure(node_ct() == (xi_size+1)*(xj_size+1)*(xk_size+1));
112  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
113  ensure(node_ids() != 0);
114  ensure(delete_node_ids());
115  ensure(nodes_per_element() == NODES_PER_ELEMENT);
116  ensure(start_id() == xstart_id);
117  ensure(node_ids()[0] == xstart_id);
118 }
119 
122 {
123  // Preconditions:
124 
125  // Body:
126 
127  // Postconditions:
128 }
129 
130 void
133  size_type xj_size,
134  size_type xk_size,
135  pod_index_type xstart_id)
136 {
137  // Preconditions:
138 
139  require(xi_size > 0);
140  require(xj_size > 0);
141  require(xk_size > 0);
142 
143  // Body:
144 
145  _element_ct = xi_size*xj_size*xk_size;
146  _node_ct = (xi_size+1)*(xj_size+1)*(xk_size+1);
147  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
149  _delete_node_ids = true;
150  _nodes_per_element = NODES_PER_ELEMENT;
151  _start_id = xstart_id;
152 
153  size_type index = 0;
154 
155  for(size_type i=0; i<xi_size; ++i)
156  {
157  for(size_type j=0; j<xj_size; ++j)
158  {
159  for(size_type k=0; k<xk_size; ++k)
160  {
161  _node_ids[index++] = node_id(i, j, k);
162  _node_ids[index++] = node_id(i+1, j, k);
163  _node_ids[index++] = node_id(i+1, j+1, k);
164  _node_ids[index++] = node_id(i, j+1, k);
165 
166  _node_ids[index++] = node_id(i, j, k+1);
167  _node_ids[index++] = node_id(i+1, j, k+1);
168  _node_ids[index++] = node_id(i+1, j+1, k+1);
169  _node_ids[index++] = node_id(i, j+1, k+1);
170  }
171  }
172  }
173 
174  // Postconditions:
175 
176  ensure(element_ct() == xi_size*xj_size*xk_size);
177  ensure(node_ct() == (xi_size+1)*(xj_size+1)*(xk_size+1));
178  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
179  ensure(node_ids() != 0);
180  ensure(delete_node_ids());
181  ensure(nodes_per_element() == NODES_PER_ELEMENT);
182  ensure(start_id() == xstart_id);
183  ensure(node_ids()[0] == xstart_id);
184 }
185 
186 size_type
189 {
190  return (xi*_j_vertex_size + xj)*_k_vertex_size + xk + _start_id;
191 }
192 
193 // ===========================================================
194 // BLOCK_CONNECTIVITY FACET
195 // ===========================================================
196 
200 {
201  return HEX;
202 }
203 
204 // ===========================================================
205 // ANY FACET
206 // ===========================================================
207 
210 clone() const
211 {
212  hex_connectivity* result;
213 
214  // Preconditions:
215 
216 
217  // Body:
218 
219  result = new hex_connectivity();
220 
221  // Postconditions:
222 
223  ensure(result->is_same_type(this));
224 
225  // Exit:
226 
227  return result;
228 }
229 
230 bool
232 invariant() const
233 {
234  bool result = true;
235 
236  // Preconditions:
237 
238  // Body:
239 
240  if(invariant_check())
241  {
242  // Prevent recursive calls to invariant
243 
245 
246  invariance(block_connectivity::invariant());
247 
248  // Finished, turn invariant checking back on.
249 
251  }
252 
253  // Postconditions:
254 
255  // Exit
256 
257  return result;
258 }
259 
260 bool
262 is_ancestor_of(const any* other) const
263 {
264 
265  // Preconditions:
266 
267  require(other != 0);
268 
269  // Body:
270 
271  // True if other conforms to this.
272 
273  bool result = dynamic_cast<const hex_connectivity*>(other) != 0;
274 
275  // Postconditions:
276 
277  return result;
278 }
hex_connectivity()
Default constructor. Equivalent to hex_connectivity(1, 1, 1)
pod_index_type * _node_ids
The nodal connectivity array.
virtual hex_connectivity * clone() const
Virtual constructor, makes a new instance of the same type as this.
size_type _k_vertex_size
The number of vertices in the k-direction.
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.
size_type _j_vertex_size
The number of vertices in the j-direction.
pod_index_type * node_ids()
The nodal connectivity array.
virtual ~hex_connectivity()
Destructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
size_type nodes_per_element() const
The number of nodes per element.
size_type _i_vertex_size
The number of vertices in the i-direction.
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
Nodal connectivity for a block containing zones of type hex.
virtual cell_type element_type() const
The element type.
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.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
size_type node_ct() const
The number of distinct nodes.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
size_type element_ct() const
The number of elements.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
size_type node_id(size_type xi, size_type xj, size_type xk) const
The node id associated with (xi,xj,xk).
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.
void create_connectivity(size_type xi_size, size_type xj_size, size_type xk_size, pod_index_type xstart_id=0)
Allocates and initializes the connectivity array.
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.