SheafSystem  0.0.0.0
line_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 line_connectivity
19 
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/line_connectivity.h"
22 
23 using namespace fiber_bundle; // Workaround for MS C++ bug.
24 
25 // ===========================================================
26 // LINE_CONNECTIVITY FACET
27 // ===========================================================
28 
32 {
33  // Preconditions:
34 
35  // Body:
36 
37  _nodes_per_element = NODES_PER_ELEMENT;
38 
39  // Postconditions:
40 
41  ensure(element_ct() == 0);
42  ensure(node_ct() == 0);
43  ensure(node_id_ct() == 0);
44  ensure(node_ids() == 0);
45  ensure(!delete_node_ids());
46  ensure(nodes_per_element() == NODES_PER_ELEMENT);
47  ensure(start_id() == 0);
48 }
49 
52 {
53 
54  // Preconditions:
55 
56  // Body:
57 
58  // Postconditions:
59 
60  ensure(postcondition_of(block_connectivity(xother)));
61 }
62 
64 line_connectivity(const pod_index_type* xnode_ids, size_type xnode_id_ct, size_type xnode_ct)
65  : block_connectivity(xnode_ids, xnode_id_ct, NODES_PER_ELEMENT, xnode_ct)
66 {
67  // Preconditions:
68 
69  require(xnode_id_ct > 0);
70  require((xnode_id_ct % NODES_PER_ELEMENT) == 0);
71 
72  // Body:
73 
74  // Postconditions:
75 
76  ensure(element_ct() == xnode_id_ct/NODES_PER_ELEMENT);
77  ensure(xnode_ct > 0 ? node_ct() == xnode_ct : node_ct() > 0);
78  ensure(node_id_ct() == xnode_id_ct);
79  ensure(node_ids() == xnode_ids);
80  ensure(!delete_node_ids());
81  ensure(nodes_per_element() == NODES_PER_ELEMENT);
82 
83  // Exit:
84 }
85 
88  : block_connectivity(xstart_id)
89 {
90  // Preconditions:
91 
92  // Body:
93 
94  create_connectivity(xi_size, xstart_id);
95 
96  // Postconditions:
97 
98  ensure(element_ct() == xi_size);
99  ensure(node_ct() == (xi_size+1));
100  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
101  ensure(node_ids() != 0);
102  ensure(delete_node_ids());
103  ensure(nodes_per_element() == NODES_PER_ELEMENT);
104  ensure(start_id() == xstart_id);
105  ensure(node_ids()[0] == xstart_id);
106 }
107 
110 {
111  // Preconditions:
112 
113  // Body:
114 
115  // Postconditions:
116 }
117 
118 void
121 {
122  // Preconditions:
123 
124  require(xi_size > 0);
125 
126  // Body:
127 
128  _element_ct = xi_size;
129  _node_ct = xi_size+1;
130  _node_id_ct = _element_ct * NODES_PER_ELEMENT;
132  _delete_node_ids = true;
133  _nodes_per_element = NODES_PER_ELEMENT;
134  _start_id = xstart_id;
135 
136  size_type index = 0;
137 
138  for(size_type i=0; i<xi_size; ++i)
139  {
140  pod_index_type n0 = i + _start_id;
141  pod_index_type n1 = n0 + 1;
142 
143  _node_ids[index++] = n0;
144  _node_ids[index++] = n1;
145  }
146 
147  // Postconditions:
148 
149  ensure(element_ct() == xi_size);
150  ensure(node_ct() == (xi_size+1));
151  ensure(node_id_ct() == element_ct() * NODES_PER_ELEMENT);
152  ensure(node_ids() != 0);
153  ensure(delete_node_ids());
154  ensure(nodes_per_element() == NODES_PER_ELEMENT);
155  ensure(start_id() == xstart_id);
156  ensure(node_ids()[0] == xstart_id);
157 }
158 
159 // ===========================================================
160 // BLOCK_RELATION FACET
161 // ===========================================================
162 
167 {
168  return LINE;
169 }
170 
171 // ===========================================================
172 // ANY FACET
173 // ===========================================================
174 
177 clone() const
178 {
179  line_connectivity* result;
180 
181  // Preconditions:
182 
183 
184  // Body:
185 
186  result = new line_connectivity();
187 
188  // Postconditions:
189 
190  ensure(result->is_same_type(this));
191 
192  // Exit:
193 
194  return result;
195 }
196 
197 bool
199 invariant() const
200 {
201  bool result = true;
202 
203  // Preconditions:
204 
205  // Body:
206 
207  if(invariant_check())
208  {
209  // Prevent recursive calls to invariant
210 
212 
213  invariance(block_connectivity::invariant());
214 
215  // Finished, turn invariant checking back on.
216 
218  }
219 
220  // Postconditions:
221 
222  // Exit
223 
224  return result;
225 }
226 
227 bool
229 is_ancestor_of(const any* other) const
230 {
231 
232  // Preconditions:
233 
234  require(other != 0);
235 
236  // Body:
237 
238  // True if other conforms to this.
239 
240  bool result = dynamic_cast<const line_connectivity*>(other) != 0;
241 
242  // Postconditions:
243 
244  return result;
245 }
virtual bool invariant() const
Class invariant.
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().
virtual ~line_connectivity()
Destructor.
virtual line_connectivity * clone() const
Virtual constructor, makes a new instance of the same type as this.
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.
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
line_connectivity()
Default constructor. Equivalent to quad_connectivity(1, 1)
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.
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.
Nodal connectivity for a block containing zones of type segment.
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_ct
The number of distinct nodes.
void create_connectivity(size_type xi_size, pod_index_type xstart_id)
Allocates and initializes the connectivity array.
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.