SheafSystem  0.0.0.0
block_adjacency.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 block_adjacency
19 
20 #include "SheafSystem/block_adjacency.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/block_connectivity.h"
24 #include "SheafSystem/std_iomanip.h"
25 
26 using namespace std;
27 using namespace fiber_bundle;
28 
29 // ===========================================================
30 // BLOCK_ADJACENCY FACET
31 // ===========================================================
32 
36 {
37 
38  // Preconditions:
39 
40 
41  // Body:
42 
43  _node_ct = 0;
44  _zone_ct = 0;
45 
46  _element_type = CELL_TYPE_END;
47 
48  // Postconditions:
49 
50  ensure(invariant());
51 
52  // Exit:
53 
54  return;
55 }
56 
57 
61 {
62 
63  // Preconditions:
64 
65 
66  // Body:
67 
68  _adj = xother._adj;
69  _node_ct = xother._node_ct;
70  _zone_ct = xother._zone_ct;
71  _element_type = xother._element_type;
72 
73  // Postconditions:
74 
75  ensure(invariant());
76 
77  // Exit:
78 
79  return;
80 }
81 
85 {
86  // Preconditions:
87 
88 
89  // Body:
90 
91  put_connectivity(xconn);
92 
93  // Postconditions:
94 
95 
96  // Exit:
97 
98  return;
99 }
100 
101 #ifndef DOXYGEN_SKIP_TYPEDEF_MAPPING
105  size_type xnodes_per_zone,
106  size_type xnode_ids_ct,
107  const pod_index_type* xnode_ids,
108  cell_type xelement_type)
109 {
110  // Preconditions:
111 
112  require(xnode_ids_ct == xzone_ct*xnodes_per_zone);
113 
114  // Body:
115 
116  _element_type = xelement_type;
117  put_connectivity(xzone_ct, xnodes_per_zone, xnode_ids_ct, xnode_ids);
118 
119  // Postconditions:
120 
121  ensure(element_type() == xelement_type);
122  ensure(zone_ct() == xzone_ct);
123 
124  // Exit:
125 
126  return;
127 }
128 #endif // ifndef DOXYGEN_SKIP_TYPEDEF_MAPPING
129 
133 {
134  // Preconditions:
135 
136 
137  // Body:
138 
139  // Nothing to do.
140 
141  // Postconditions:
142 
143  // Exit:
144 
145  return;
146 }
147 
149 void
152 {
153  // Preconditions:
154 
155 
156  // Body:
157 
158  _element_type = xconn.element_type();
159 
160  size_type lzone_ct = xconn.element_ct();
161  size_type lnodes_per_zone = xconn.nodes_per_element();
162  size_type lnode_ids_ct = xconn.node_id_ct();
163  const pod_index_type* lnode_ids = xconn.node_ids();
164 
165  put_connectivity(lzone_ct, lnodes_per_zone, lnode_ids_ct, lnode_ids);
166 
167  // Postconditions:
168 
169  ensure(element_type() == xconn.element_type());
170  ensure(zone_ct() == xconn.element_ct());
171 
172  // Exit:
173 
174  return;
175 }
176 
178 void
181  size_type xnodes_per_zone,
182  size_type xnode_ids_ct,
183  const pod_index_type* xnode_ids)
184 {
185  // Preconditions:
186 
187  require(xnode_ids_ct == xzone_ct*xnodes_per_zone);
188 
189  // Body:
190 
191  _zone_ct = xzone_ct;
192 
193  // Transpose the connectivity to form the adjacency.
194 
195  _adj.clear();
196  size_type k = 0;
197 
198  for(size_type i=0; i<xzone_ct; ++i)
199  {
200  for(size_type j=0; j<xnodes_per_zone; ++j)
201  {
202  assertion(k < xnode_ids_ct);
203  pod_index_type lvertex = xnode_ids[k++];
204 
205  _adj[lvertex].push_front(i);
206  }
207  }
208 
209  // Store node ct directly because
210  // STL only ensures size() performance O(n).
211 
212  _node_ct = _adj.size();
213 
214 
215 #ifdef DIAGNOSTIC_OUTPUT
216 
217  cout << *this << endl;
218 #endif
219 
220 
221  // Postconditions:
222 
223  ensure(zone_ct() == xzone_ct);
224 
225  // Exit:
226 
227  return;
228 }
229 
234 {
235  // Preconditions:
236 
237 
238  // Body:
239 
240  put_connectivity(xconn);
241 
242  // Postconditions:
243 
244 
245  // Exit:
246 
247  return *this;
248 }
249 
254 {
255  return _adj.begin();
256 }
257 
261 begin() const
262 {
263  return _adj.begin();
264 }
265 
270 {
271  return _adj.end();
272 }
273 
277 end() const
278 {
279  return _adj.end();
280 }
281 
285 node_ct() const
286 {
287  return _node_ct;
288 }
289 
293 zone_ct() const
294 {
295  return _zone_ct;
296 }
297 
298 
299 // ===========================================================
300 // BLOCK_RELATION FACET
301 // ===========================================================
302 
307 {
308  return _element_type;
309 }
310 
311 // ===========================================================
312 // ANY FACET
313 // ===========================================================
314 
315 
317 bool
319 is_ancestor_of(const any* other) const
320 {
321 
322  // Preconditions:
323 
324  require(other != 0);
325 
326  // Body:
327 
328  // True if other conforms to this
329 
330  bool result = dynamic_cast<const block_adjacency*>(other) != 0;
331 
332  // Postconditions:
333 
334  return result;
335 }
336 
340 clone() const
341 {
342  block_adjacency* result;
343 
344  // Preconditions:
345 
346  // Body:
347 
348  result = new block_adjacency();
349 
350  // Postconditions:
351 
352  ensure(result != 0);
353  ensure(is_same_type(result));
354 
355  // Exit:
356 
357  return result;
358 }
359 
360 
365 {
366 
367  // Preconditions:
368 
369 
370  // Body:
371 
372  not_implemented();
373 
374  // Postconditions:
375 
376  ensure(invariant());
377 
378  // Exit
379 
380  return *this;
381 }
382 
384 bool
386 invariant() const
387 {
388  bool result = true;
389 
390  if(invariant_check())
391  {
392  // Prevent recursive calls to invariant
393 
394  disable_invariant_check();
395 
396  // Must satisfy base class invariant
397 
398  invariance(block_relation::invariant());
399 
400  // Invariances for this class:
401 
402  // Finished, turn invariant checking back on.
403 
404  enable_invariant_check();
405  }
406 
407  // Exit
408 
409  return result;
410 }
411 
412 
413 // ===========================================================
414 // NON-MEMBER FUNCTIONS
415 // ===========================================================
416 
418 std::ostream&
420 operator<<(std::ostream& xos, const fiber_bundle::block_adjacency& xadj)
421 {
422  // Preconditions:
423 
424 
425  // Body:
426 
429 
430  for(node_itr_type v = xadj.begin(); v != xadj.end(); ++v)
431  {
432  cout << " node: " << setw(4) << v->first << " zones: ";
433  for(zone_itr_type z = v->second.begin(); z != v->second.end(); ++z)
434  {
435  cout << setw(4) << *z;
436  }
437  }
438  cout << endl;
439 
440  // Postconditions:
441 
442 
443  // Exit:
444 
445  return xos;
446 }
adj_type::iterator node_iterator_type
Type of iterator for nodes.
size_type _zone_ct
The number of distinct zones.
node_iterator_type begin()
Beginning of adjacency relation.
cell_type _element_type
The element type.
size_type node_id_ct() const
The number of entries in node_ids().
size_type _node_ct
The number of distinct nodes.
size_type zone_ct() const
The number of distinct zones.
virtual bool invariant() const
Class invariant.
STL namespace.
Zone to node connectivity relation for a block of zones of a given type.
size_type node_ct() const
The number of distinct nodes.
pod_index_type * node_ids()
The nodal connectivity array.
adj_type::const_iterator const_node_iterator_type
Type of const iterator for nodes.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual block_adjacency * clone() const
Virtual constructor, makes a new instance of the same type as this.
size_type nodes_per_element() const
The number of nodes per element.
virtual cell_type element_type() const =0
The element (zone) type.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual cell_type element_type() const
The element type.
block_adjacency & operator=(const block_connectivity &xconn)
Makes this the transpose of connectivity xconn; synonym for put_connectivity(xconn).
Node to zone adjacency relation for a block of zones of a given type.
virtual ~block_adjacency()
Destructor.
void put_connectivity(const block_connectivity &xconn)
Makes this the transpose of connectivity xconn.
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
adj_type::mapped_type::const_iterator const_zone_iterator_type
Type of const iterator for zones.
adj_type _adj
Storage for the adjcency relation.
node_iterator_type end()
End of adjacency relation.
Namespace for the fiber_bundles component of the sheaf system.
block_adjacency()
Default constructor.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const binary_index &xbi)
Insert binary_index& xbi into ostream& os.
Definition: binary_index.cc:35