SheafSystem  0.0.0.0
tetra_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 tetra_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/tetra_connectivity.h"
22 
23 using namespace std;
24 using namespace fiber_bundle; // Workaround for MS C++ bug.
25 
26 // ===========================================================
27 // TETRA_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 
55  // Preconditions:
56 
57  // Body:
58 
59  // Postconditions:
60 
61  ensure(postcondition_of(block_connectivity(xother)));
62 }
63 
65 tetra_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  cout << "sizes are: " << xi_size << " " << xj_size << " " << xk_size << " " << xstart_id << endl;
106 
107  create_connectivity(xi_size, xj_size, xk_size, xstart_id);
108 
109  // Postconditions:
110 
111 
112  ensure(element_ct() == 6*xi_size*xj_size*xk_size);
113  ensure(node_ct() == (xi_size+1)*(xj_size+1)*(xk_size+1));
114  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
115  ensure(node_ids() != 0);
116  ensure(delete_node_ids());
117  ensure(nodes_per_element() == NODES_PER_ELEMENT);
118  ensure(start_id() == xstart_id);
119  ensure(node_ids()[0] == xstart_id);
120 }
121 
124 {
125  // Preconditions:
126 
127  // Body:
128 
129  // Postconditions:
130 }
131 
132 void
135  size_type xj_size,
136  size_type xk_size,
137  pod_index_type xstart_id)
138 {
139  // Preconditions:
140 
141  require(xi_size > 0);
142  require(xj_size > 0);
143  require(xk_size > 0);
144 
145  // Body:
146 
147  _element_ct = 6*xi_size*xj_size*xk_size;
148  _node_ct = (xi_size+1)*(xj_size+1)*(xk_size+1);
149  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
151  _delete_node_ids = true;
152  _nodes_per_element = NODES_PER_ELEMENT;
153  _start_id = xstart_id;
154 
155  size_type index = 0;
156 
157  for(size_type i=0; i<xi_size; ++i)
158  {
159  for(size_type j=0; j<xj_size; ++j)
160  {
161  for(size_type k=0; k<xk_size; ++k)
162  {
163 
164  pod_index_type n0 = node_id(i, j, k);
165  pod_index_type n1 = node_id(i+1, j, k);
166  pod_index_type n2 = node_id(i+1, j+1, k);
167  pod_index_type n3 = node_id(i, j+1, k);
168 
169  pod_index_type n4 = node_id(i, j, k+1);
170  pod_index_type n5 = node_id(i+1, j, k+1);
171  pod_index_type n6 = node_id(i+1, j+1, k+1);
172  pod_index_type n7 = node_id(i, j+1, k+1);
173 
174  _node_ids[index++] = n0;
175  _node_ids[index++] = n1;
176  _node_ids[index++] = n2;
177  _node_ids[index++] = n6;
178 
179  _node_ids[index++] = n0;
180  _node_ids[index++] = n2;
181  _node_ids[index++] = n3;
182  _node_ids[index++] = n6;
183 
184  _node_ids[index++] = n0;
185  _node_ids[index++] = n3;
186  _node_ids[index++] = n7;
187  _node_ids[index++] = n6;
188 
189  _node_ids[index++] = n0;
190  _node_ids[index++] = n7;
191  _node_ids[index++] = n4;
192  _node_ids[index++] = n6;
193 
194  _node_ids[index++] = n0;
195  _node_ids[index++] = n4;
196  _node_ids[index++] = n5;
197  _node_ids[index++] = n6;
198 
199  _node_ids[index++] = n0;
200  _node_ids[index++] = n5;
201  _node_ids[index++] = n1;
202  _node_ids[index++] = n6;
203  }
204  }
205  }
206 
207  // Postconditions:
208 
209  ensure(element_ct() == 6*xi_size*xj_size*xk_size);
210  ensure(node_ct() == (xi_size+1)*(xj_size+1)*(xk_size+1));
211  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
212  ensure(node_ids() != 0);
213  ensure(delete_node_ids());
214  ensure(nodes_per_element() == NODES_PER_ELEMENT);
215  ensure(start_id() == xstart_id);
216  ensure(node_ids()[0] == xstart_id);
217 }
218 
219 size_type
222 {
223  return (xi*_j_vertex_size + xj)*_k_vertex_size + xk + _start_id;
224 }
225 
226 // ===========================================================
227 // BLOCK_RELATION FACET
228 // ===========================================================
229 
233 {
234  return TETRA;
235 }
236 
237 // ===========================================================
238 // ANY FACET
239 // ===========================================================
240 
243 clone() const
244 {
245  tetra_connectivity* result;
246 
247  // Preconditions:
248 
249 
250  // Body:
251 
252  result = new tetra_connectivity();
253 
254  // Postconditions:
255 
256  ensure(result->is_same_type(this));
257 
258  // Exit:
259 
260  return result;
261 }
262 
263 bool
265 invariant() const
266 {
267  bool result = true;
268 
269  // Preconditions:
270 
271  // Body:
272 
273  if(invariant_check())
274  {
275  // Prevent recursive calls to invariant
276 
278 
279  invariance(block_connectivity::invariant());
280 
281  // Finished, turn invariant checking back on.
282 
284  }
285 
286  // Postconditions:
287 
288  // Exit
289 
290  return result;
291 }
292 
293 bool
295 is_ancestor_of(const any* other) const
296 {
297 
298  // Preconditions:
299 
300  require(other != 0);
301 
302  // Body:
303 
304  // True if other conforms to this.
305 
306  bool result = dynamic_cast<const tetra_connectivity*>(other) != 0;
307 
308  // Postconditions:
309 
310  return result;
311 }
virtual tetra_connectivity * clone() const
Virtual constructor, makes a new instance of the same type as this.
pod_index_type * _node_ids
The nodal connectivity array.
virtual cell_type element_type() const
The element type.
size_type _nodes_per_element
The number of nodes per element.
size_type node_id_ct() const
The number of entries in node_ids().
tetra_connectivity()
Default constructor. Equivalent to tetra_connectivity(1, 1, 1)
STL namespace.
Zone to node connectivity relation for a block of zones of a given type.
Nodal connectivity for a block containing zones of type tetra.
pod_index_type * node_ids()
The nodal connectivity array.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual ~tetra_connectivity()
Destructor.
size_type nodes_per_element() const
The number of nodes per element.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
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.
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
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.
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 _k_vertex_size
The number of vertices in the k-direction.
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.
size_type node_id(size_type xi, size_type xj, size_type xk) const
The node id associated with (xi,xj,xk).
size_type _j_vertex_size
The number of vertices in the j-direction.
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
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.
size_type _i_vertex_size
The number of vertices in the i-direction.
virtual bool invariant() const
Class invariant.