SheafSystem  0.0.0.0
quad_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 quad_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/quad_connectivity.h"
22 
23 using namespace fiber_bundle; // Workaround for MS C++ bug.
24 
25 
26 // ===========================================================
27 // QUAD_CONNECTIVITY FACET
28 // ===========================================================
29 
33 {
34 
35  // Preconditions:
36 
37  // Body:
38 
39  _nodes_per_element = NODES_PER_ELEMENT;
40 
41  // Postconditions:
42 
43  ensure(element_ct() == 0);
44  ensure(node_ct() == 0);
45  ensure(node_id_ct() == 0);
46  ensure(node_ids() == 0);
47  ensure(!delete_node_ids());
48  ensure(nodes_per_element() == NODES_PER_ELEMENT);
49  ensure(start_id() == 0);
50 }
51 
54 {
55 
56  // Preconditions:
57 
58  // Body:
59 
60  // Postconditions:
61 
62  ensure(postcondition_of(block_connectivity(xother)));
63 }
64 
67  size_type xnode_id_ct,
68  size_type xnode_ct)
69  : block_connectivity(xnode_ids, xnode_id_ct, NODES_PER_ELEMENT, xnode_ct)
70 {
71 
72  // Preconditions:
73 
74  require(xnode_id_ct > 0);
75  require((xnode_id_ct % NODES_PER_ELEMENT) == 0);
76 
77  // Body:
78 
79 
80  // Postconditions:
81 
82  ensure(element_ct() == xnode_id_ct/NODES_PER_ELEMENT);
83  ensure(xnode_ct > 0 ? node_ct() == xnode_ct : node_ct() > 0);
84  ensure(node_id_ct() == xnode_id_ct);
85  ensure(node_ids() == xnode_ids);
86  ensure(!delete_node_ids());
87  ensure(nodes_per_element() == NODES_PER_ELEMENT);
88 
89  // Exit:
90 }
91 
94  : block_connectivity(xstart_id)
95 {
96 
97  // Preconditions:
98 
99  // Body:
100 
101  create_connectivity(xi_size, xj_size, xstart_id);
102 
103  // Postconditions:
104 
105  ensure(element_ct() == xi_size*xj_size);
106  ensure(node_ct() == (xi_size+1)*(xj_size+1));
107  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
108  ensure(node_ids() != 0);
109  ensure(delete_node_ids());
110  ensure(nodes_per_element() == NODES_PER_ELEMENT);
111  ensure(start_id() == xstart_id);
112  ensure(node_ids()[0] == xstart_id);
113 }
114 
117 {
118  // Preconditions:
119 
120  // Body:
121 
122  // Postconditions:
123 }
124 
125 void
128  size_type xj_size,
129  pod_index_type xstart_id)
130 {
131 
132  // Preconditions:
133 
134  require(xi_size > 0);
135  require(xj_size > 0);
136 
137  // Body:
138 
139  _element_ct = xi_size*xj_size;
140  _node_ct = (xi_size+1)*(xj_size+1);
141  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
143  _delete_node_ids = true;
144  _nodes_per_element = NODES_PER_ELEMENT;
145  _start_id = xstart_id;
146 
147 
148  size_type vertex_ct_j = xj_size+1;
149 
150  size_type index = 0;
151 
152  for(size_type i=0; i<xi_size; ++i)
153  {
154  size_type ladd = i*vertex_ct_j + _start_id;
155 
156  for(size_type j=0; j<xj_size; ++j)
157  {
158  pod_index_type n0 = j + ladd;
159  pod_index_type n1 = n0 + vertex_ct_j;
160  pod_index_type n2 = n1 + 1;
161  pod_index_type n3 = n0 + 1;
162 
163  _node_ids[index++] = n0;
164  _node_ids[index++] = n1;
165  _node_ids[index++] = n2;
166  _node_ids[index++] = n3;
167  }
168  }
169 
170  // Postconditions:
171 
172  ensure(element_ct() == xi_size*xj_size);
173  ensure(node_ct() == (xi_size+1)*(xj_size+1));
174  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
175  ensure(node_ids() != 0);
176  ensure(delete_node_ids());
177  ensure(nodes_per_element() == NODES_PER_ELEMENT);
178  ensure(start_id() == xstart_id);
179  ensure(node_ids()[0] == xstart_id);
180 
181 }
182 
183 // ===========================================================
184 // BLOCK_RELATION FACET
185 // ===========================================================
186 
190 {
191  return QUAD;
192 }
193 
194 // ===========================================================
195 // ANY FACET
196 // ===========================================================
197 
199 fiber_bundle::quad_connectivity::
200 clone() const
201 {
202  quad_connectivity* result;
203 
204  // Preconditions:
205 
206  // Body:
207 
208  result = new quad_connectivity();
209 
210  // Postconditions:
211 
212  ensure(result->is_same_type(this));
213 
214  // Exit:
215 
216  return result;
217 }
218 
219 bool
220 fiber_bundle::quad_connectivity::
221 invariant() const
222 {
223  bool result = true;
224 
225  // Preconditions:
226 
227  // Body:
228 
229  if(invariant_check())
230  {
231  // Prevent recursive calls to invariant
232 
234 
235  invariance(block_connectivity::invariant());
236 
237  // Finished, turn invariant checking back on.
238 
240  }
241 
242  // Postconditions:
243 
244  // Exit
245 
246  return result;
247 }
248 
249 bool
250 fiber_bundle::quad_connectivity::
251 is_ancestor_of(const any* other) const
252 {
253 
254  // Preconditions:
255 
256  require(other != 0);
257 
258  // Body:
259 
260  // True if other conforms to this.
261 
262  bool result = dynamic_cast<const quad_connectivity*>(other) != 0;
263 
264  // Postconditions:
265 
266  return result;
267 }
268 
269 
270 
pod_index_type * _node_ids
The nodal 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
size_type nodes_per_element() const
The number of nodes per element.
void create_connectivity(size_type xi_size, size_type xj_size, pod_index_type xstart_id)
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.
virtual ~quad_connectivity()
Destructor.
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.
Nodal connectivity for a block containing zones of type quad.
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.
virtual cell_type element_type() const
The element type.
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
quad_connectivity()
Default constructor. Equivalent to quad_connectivity(1, 1)
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.