SheafSystem  0.0.0.0
triangle_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 triangle_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/triangle_connectivity.h"
22 
23 using namespace fiber_bundle; // Workaround for MS C++ bug.
24 
25 
26 // ===========================================================
27 // TRIANGLE_CONNECTIVITY FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
34 {
35 
36  // Preconditions:
37 
38  // Body:
39 
40  _nodes_per_element = NODES_PER_ELEMENT;
41 
42  // Postconditions:
43 
44  ensure(element_ct() == 0);
45  ensure(node_ct() == 0);
46  ensure(node_id_ct() == 0);
47  ensure(node_ids() == 0);
48  ensure(!delete_node_ids());
49  ensure(nodes_per_element() == NODES_PER_ELEMENT);
50  ensure(start_id() == 0);
51 }
52 
55  : block_connectivity(xother)
56 {
57 
58  // Preconditions:
59 
60  // Body:
61 
62  // Postconditions:
63 
64  ensure(postcondition_of(block_connectivity(xother)));
65 }
66 
68 triangle_connectivity(const pod_index_type* xnode_ids, size_type xnode_id_ct, size_type xnode_ct)
69  : block_connectivity(xnode_ids, xnode_id_ct, NODES_PER_ELEMENT, xnode_ct)
70 {
71  // Preconditions:
72 
73  require(xnode_id_ct > 0);
74  require((xnode_id_ct % NODES_PER_ELEMENT) == 0);
75 
76  // Body:
77 
78  // Postconditions:
79 
80  ensure(element_ct() == xnode_id_ct/NODES_PER_ELEMENT);
81  ensure(xnode_ct > 0 ? node_ct() == xnode_ct : node_ct() > 0);
82  ensure(node_id_ct() == xnode_id_ct);
83  ensure(node_ids() == xnode_ids);
84  ensure(!delete_node_ids());
85  ensure(nodes_per_element() == NODES_PER_ELEMENT);
86 
87  // Exit:
88 }
89 
92  size_type xj_size,
93  pod_index_type xstart_id,
94  bool xlower_left_to_upper_right_diagonals)
95 {
96 
97  // Preconditions:
98 
99  // Body:
100 
101  create_connectivity(xi_size, xj_size, xstart_id, xlower_left_to_upper_right_diagonals);
102 
103  // Postconditions:
104 
105 
106  ensure(element_ct() == 2*xi_size*xj_size);
107  ensure(node_ct() == (xi_size+1)*(xj_size+1));
108  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
109  ensure(node_ids() != 0);
110  ensure(delete_node_ids());
111  ensure(nodes_per_element() == NODES_PER_ELEMENT);
112  ensure(start_id() == xstart_id);
113  ensure(node_ids()[0] == xstart_id);
114 }
115 
118 {
119  // Preconditions:
120 
121  // Body:
122 
123  // Postconditions:
124 }
125 
126 // PROTECTED MEMBER FUNCTIONS
127 
128 void
131  size_type xj_size,
132  pod_index_type xstart_id,
133  bool xlower_left_to_upper_right_diagonals)
134 {
135  // Preconditions:
136 
137  require(xi_size > 0);
138  require(xj_size > 0);
139 
140  // Body:
141 
142  _element_ct = 2*xi_size*xj_size;
143  _node_ct = (xi_size+1)*(xj_size+1);
144  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
146  _delete_node_ids = true;
147  _nodes_per_element = NODES_PER_ELEMENT;
148  _start_id = xstart_id;
149 
150  size_type vertex_ct_j = xj_size+1;
151 
152  size_type index = 0;
153 
154  for(size_type i=0; i<xi_size; ++i)
155  {
156  size_type ladd = i*vertex_ct_j + _start_id;
157 
158  for(size_type j=0; j<xj_size; ++j)
159  {
160  pod_index_type n0 = j + ladd;
161  pod_index_type n1 = n0 + vertex_ct_j;
162  pod_index_type n2 = n1 + 1;
163  pod_index_type n3 = n0 + 1;
164 
165  if(xlower_left_to_upper_right_diagonals)
166  {
167  _node_ids[index++] = n0;
168  _node_ids[index++] = n2;
169  _node_ids[index++] = n3;
170 
171  _node_ids[index++] = n0;
172  _node_ids[index++] = n1;
173  _node_ids[index++] = n2;
174  }
175  else // upper left to lower right diagonals
176  {
177  _node_ids[index++] = n3;
178  _node_ids[index++] = n0;
179  _node_ids[index++] = n1;
180 
181  _node_ids[index++] = n3;
182  _node_ids[index++] = n1;
183  _node_ids[index++] = n2;
184  }
185  }
186  }
187 
188 
189  // Postconditions:
190 
191  ensure(element_ct() == 2*xi_size*xj_size);
192  ensure(node_ct() == (xi_size+1)*(xj_size+1));
193  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
194  ensure(node_ids() != 0);
195  ensure(delete_node_ids());
196  ensure(nodes_per_element() == NODES_PER_ELEMENT);
197  ensure(start_id() == xstart_id);
198  ensure(node_ids()[0] == xstart_id);
199 
200 }
201 
202 // ===========================================================
203 // BLOCK_RELATION FACET
204 // ===========================================================
205 
206 // PUBLIC MEMBER FUNCTIONS
207 
212 {
213  return TRIANGLE;
214 }
215 
216 // PROTECTED MEMBER FUNCTIONS
217 
218 // PRIVATE MEMBER FUNCTIONS
219 
220 // ===========================================================
221 // ANY FACET
222 // ===========================================================
223 
226 clone() const
227 {
228  triangle_connectivity* result;
229 
230  // Preconditions:
231 
232 
233  // Body:
234 
235  result = new triangle_connectivity();
236 
237  // Postconditions:
238 
239  ensure(result->is_same_type(this));
240 
241  // Exit:
242 
243  return result;
244 }
245 
246 bool
248 invariant() const
249 {
250  bool result = true;
251 
252  // Preconditions:
253 
254  // Body:
255 
256  if(invariant_check())
257  {
258  // Prevent recursive calls to invariant
259 
261 
262  invariance(block_connectivity::invariant());
263 
264  // Finished, turn invariant checking back on.
265 
267  }
268 
269  // Postconditions:
270 
271  // Exit
272 
273  return result;
274 }
275 
276 bool
278 is_ancestor_of(const any* other) const
279 {
280 
281  // Preconditions:
282 
283  require(other != 0);
284 
285  // Body:
286 
287  // True if other conforms to this.
288 
289  bool result = dynamic_cast<const triangle_connectivity*>(other) != 0;
290 
291  // Postconditions:
292 
293  return result;
294 }
pod_index_type * _node_ids
The nodal connectivity array.
triangle_connectivity()
Creates an empty instance.
size_type _nodes_per_element
The number of nodes per element.
virtual cell_type element_type() const
The element type.
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.
Nodal connectivity for a block containing zones of type triangle.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual bool invariant() const
Class invariant.
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
void create_connectivity(size_type xi_size, size_type xj_size, pod_index_type xstart_id, bool xlower_left_to_upper_right_diagonals)
Allocates and initializes the connectivity array.
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.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual triangle_connectivity * clone() const
Virtual constructor, makes a new instance of the same type as this.
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.
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.