SheafSystem  0.0.0.0
ijk_product_structure.cc
Go to the documentation of this file.
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 
20 
21 #include "SheafSystem/ijk_product_structure.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 
25 // ===========================================================
26 // IJK_PRODUCT_STRUCTURE FACET
27 // ===========================================================
28 
29 // PUBLIC MEMBER FUNCTIONS
30 
33  : _i_ub(xi_ub),
34  _j_ub(xj_ub),
35  _k_ub(xk_ub)
36 {
37  // Preconditions:
38 
39  require(xi_ub > 0);
40  require(xj_ub > 0);
41  require(xk_ub > 0);
42 
43  // Body:
44 
45  // Postconditions:
46 
47  ensure(invariant());
48  ensure(ub(0) == xi_ub);
49  ensure(ub(1) == xj_ub);
50  ensure(ub(2) == xk_ub);
51  ensure(ordinal_ub() == xi_ub*xj_ub*xk_ub);
52 
53  // Exit:
54 
55  return;
56 }
57 
60 {
61  // Preconditions:
62 
63  // Body:
64 
65  *this = xother;
66 
67  // Postconditions:
68 
69  ensure(invariant());
70  ensure((*this) == xother);
71 
72  // Exit:
73 
74  return;
75 }
76 
80 {
81  // Preconditions:
82 
83  // Body:
84 
85  _i_ub = xother._i_ub;
86  _j_ub = xother._j_ub;
87  _k_ub = xother._k_ub;
88 
89  // Postconditions:
90 
91  ensure(invariant());
92  ensure((*this) == xother);
93 
94  // Exit
95 
96  return *this;
97 }
98 
101 {
102  // Preconditions:
103 
104  // Body:
105 
106  // nothing to do.
107 
108  // Postconditions:
109 
110  // Exit:
111 
112  return;
113 }
114 
115 // PROTECTED MEMBER FUNCTIONS
116 
117 // PRIVATE MEMBER FUNCTIONS
118 
119 
120 // ===========================================================
121 // IJK_PRODUCT_STRUCTURE FACET
122 // ===========================================================
123 
124 // PUBLIC MEMBER FUNCTIONS
125 
128 clone() const
129 {
130  ijk_product_structure* result;
131 
132  // Preconditions:
133 
134  // Body:
135 
136  result = new ijk_product_structure(_i_ub, _j_ub, _k_ub);
137 
138  // Postconditions:
139 
140  ensure(result != 0);
141  ensure(is_same_type(result));
142 
143  // Exit:
144 
145  return result;
146 }
147 
151 {
152  // Preconditions:
153 
154  require(is_ancestor_of(&xother));
155 
156  // Body:
157 
158  const ijk_product_structure lother =
159  dynamic_cast<const ijk_product_structure&>(xother);
160 
161  _i_ub = lother._i_ub;
162  _j_ub = lother._j_ub;
163  _k_ub = lother._k_ub;
164 
165  // Postconditions:
166 
167  ensure(invariant());
168  ensure((*this) == xother);
169 
170  // Exit
171 
172  return *this;
173 }
174 
175 bool
178 {
179  // Preconditions:
180 
181  require(is_ancestor_of(&xother));
182 
183  // Body:
184 
185  const ijk_product_structure& lother =
186  dynamic_cast<const ijk_product_structure&>(xother);
187 
188  bool result = (_i_ub == lother._i_ub);
189  result = result && (_j_ub == lother._j_ub);
190  result = result && (_k_ub == lother._k_ub);
191 
192  // Postconditions:
193 
194  ensure(is_basic_query);
195 
196  // Exit
197 
198  return result;
199 }
200 
201 // PROTECTED MEMBER FUNCTIONS
202 
203 // PRIVATE MEMBER FUNCTIONS
204 
205 
206 // ===========================================================
207 // PRODUCT FACET
208 // ===========================================================
209 
210 // PUBLIC MEMBER FUNCTIONS
211 
214 d() const
215 {
216  // Preconditions:
217 
218  // Body:
219 
220  size_type result = 3;
221 
222  // Postconditions:
223 
224  ensure(result > 1);
225 
226  // Exit:
227 
228  return result;
229 }
230 
233 ub(pod_type xi) const
234 {
235  // Preconditions:
236 
237  require((0 <= xi) && (xi < d()));
238 
239  // Body:
240 
241  size_type result;
242 
243  switch(xi)
244  {
245  case 0:
246  result = _i_ub;
247  break;
248 
249  case 1:
250  result = _j_ub;
251  break;
252 
253  case 2:
254  result = _k_ub;
255  break;
256  }
257 
258  // Postconditions:
259 
260  ensure(result > 0);
261 
262  // Exit:
263 
264  return result;
265 }
266 
269 i_ub() const
270 {
271  // Preconditions:
272 
273  // Body:
274 
275  // Postconditions:
276 
277  ensure(is_basic_query);
278 
279  // Exit:
280 
281  return _i_ub;
282 }
283 
286 j_ub() const
287 {
288  // Preconditions:
289 
290  // Body:
291 
292  // Postconditions:
293 
294  ensure(is_basic_query);
295 
296  // Exit:
297 
298  return _j_ub;
299 }
300 
303 k_ub() const
304 {
305  // Preconditions:
306 
307  // Body:
308 
309  // Postconditions:
310 
311  ensure(is_basic_query);
312 
313  // Exit:
314 
315  return _k_ub;
316 }
317 
318 void
320 ordinal(pod_type xi, pod_type xj, pod_type xk, pod_type& xordinal) const
321 {
322  // Preconditions:
323 
324  require((0 <= xi) && (xi < ub(0)));
325  require((0 <= xj) && (xj < ub(1)));
326  require((0 <= xk) && (xk < ub(2)));
327 
328  // Body:
329 
330  xordinal = sheaf::ordinal(xi, xj, xk, _j_ub, _k_ub);
331 
332  // Postconditions:
333 
334  ensure((0 <= xordinal) && (xordinal < ordinal_ub()));
335 
336  // Exit:
337 
338  return;
339 }
340 
341 void
343 ordinal(pod_type* xtuple, pod_type& xordinal) const
344 {
345  // Preconditions:
346 
347  require(unexecutable("length of xtuple equals d()"));
348  require_for_range(pod_type i=0, i<d(), ++i,
349  (0 <= xtuple[i]) && (xtuple[i] < ub(i)));
350 
351  // Body:
352 
353  xordinal = sheaf::ordinal(xtuple[0], xtuple[1], xtuple[2], _j_ub, _k_ub);
354 
355  // Postconditions:
356 
357  ensure((0 <= xordinal) && (xordinal < ordinal_ub()));
358 
359  // Exit:
360 
361  return;
362 }
363 
364 void
366 tuple(pod_type xordinal, pod_type& xi, pod_type& xj, pod_type& xk) const
367 {
368  // Preconditions:
369 
370  require((0 <= xordinal) && (xordinal < ordinal_ub()));
371 
372  // Body:
373 
374  sheaf::tuple(xordinal, _j_ub, _k_ub, xi, xj, xk);
375 
376  // Postconditions:
377 
378  ensure((0 <= xi) && (xi < ub(0)));
379  ensure((0 <= xj) && (xj < ub(1)));
380  ensure((0 <= xk) && (xk < ub(2)));
381 
382  // Exit:
383 
384  return;
385 }
386 
387 void
389 tuple(pod_type xordinal, pod_type* xtuple) const
390 {
391  // Preconditions:
392 
393  require((0 <= xordinal) && (xordinal < ordinal_ub()));
394  require(unexecutable("length of xtuple equals d()"));
395 
396  // Body:
397 
398  sheaf::tuple(xordinal, _j_ub, _k_ub, xtuple[0], xtuple[1], xtuple[2]);
399 
400  // Postconditions:
401 
402  ensure_for_range(pod_type i=0, i<d(), ++i,
403  (0 <= xtuple[i]) && (xtuple[i] < ub(i)));
404 
405  // Exit:
406 
407  return;
408 }
409 
410 void
412 put_ubs(size_type xi_ub, size_type xj_ub, size_type xk_ub)
413 {
414  // Preconditions:
415 
416  require(xi_ub > 0);
417  require(xj_ub > 0);
418  require(xk_ub > 0);
419 
420  // Body:
421 
422  _i_ub = xi_ub;
423  _j_ub = xj_ub;
424  _k_ub = xk_ub;
425 
426  // Postconditions:
427 
428  ensure(ub(0) == xi_ub);
429  ensure(ub(1) == xj_ub);
430  ensure(ub(2) == xk_ub);
431 
432  // Exit:
433 
434  return;
435 }
436 
437 void
440 {
441  // Preconditions:
442 
443  require(unexecutable("xubs.length >= d()"));
444  require_for_range(pod_type i=0, i<d(), ++i, xubs[i] > 0);
445 
446  // Body:
447 
448  _i_ub = xubs[0];
449  _j_ub = xubs[1];
450  _k_ub = xubs[2];
451 
452  // Postconditions:
453 
454  ensure_for_range(pod_type i=0, i<d(), ++i, ub(i) == xubs[i]);
455 
456  // Exit:
457 
458  return;
459 }
460 
461 // PROTECTED MEMBER FUNCTIONS
462 
463 // PRIVATE MEMBER FUNCTIONS
464 
465 
466 // ===========================================================
467 // ANY FACET
468 // ===========================================================
469 
470 // PUBLIC MEMBER FUNCTIONS
471 
472 bool
474 is_ancestor_of(const any *other) const
475 {
476  // Preconditions:
477 
478  require(other != 0);
479 
480  // Body:
481 
482  // True if other conforms to this
483 
484  bool result = dynamic_cast<const ijk_product_structure*>(other) != 0;
485 
486  // Postconditions:
487 
488  // Exit:
489 
490  return result;
491 }
492 
493 bool
495 invariant() const
496 {
497  bool result = true;
498 
499  if(invariant_check())
500  {
501  // Prevent recursive calls to invariant
502 
504 
505  // Must satisfy base class invariant
506 
508 
509  // Invariances for this class:
510 
511  invariance(d() == 3);
512 
513  // Finished, turn invariant checking back on.
514 
516  }
517 
518  // Exit
519 
520  return result;
521 }
522 
523 // PROTECTED MEMBER FUNCTIONS
524 
525 // PRIVATE MEMBER FUNCTIONS
526 
527 
528 // ===========================================================
529 // NON-MEMBER FUNCTIONS
530 // ===========================================================
531 
532 size_t
533 sheaf::
534 deep_size(const ijk_product_structure& xn, bool xinclude_shallow)
535 {
536  // Preconditions:
537 
538  // Body:
539 
540  size_t result = xinclude_shallow ? sizeof(xn) : 0;
541 
542  // Postconditions:
543 
544  ensure(result >= 0);
545 
546  // Exit
547 
548  return result;
549 }
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void put_ubs(size_type xi_ub, size_type xj_ub, size_type xk_ub)
Set the upper-bounds for this product structure.
void tuple(pod_type xordinal, pod_type &xi, pod_type &xj, pod_type &xk) const
Ordinal to 3-tuple conversion.
A 3D implementation of abstract_product_structure.
An abstract class that defines the product structure for an id space.
virtual bool operator==(const abstract_product_structure &xother) const
True if this is equivalent to xother.
void ordinal(pod_type xi, pod_type xj, pod_type xk, pod_type &xordinal) const
3-tuple to ordinal conversion.
pod_index_type ordinal(pod_index_type xi, pod_index_type xj, size_type xj_ub)
2-tuple to ordinal conversion.
size_type k_ub() const
The upper bound in the k-direction.
virtual bool invariant() const
Class invariant.
size_type ordinal_ub() const
The upper-bound of the ordinal.
Abstract base class with useful features for all objects.
Definition: any.h:39
size_type j_ub() const
The upper bound in the j-direction.
ijk_product_structure & operator=(const ijk_product_structure &xother)
Assignment operator.
virtual bool invariant() const
Class invariant.
size_type _k_ub
The upper bound in the k-direction.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual size_type ub(pod_type xi) const
The upper-bound for the dimension xi.
pod_index_type pod_type
The "plain old data" index type for this.
virtual ijk_product_structure * clone() const
Virtual constructor, makes a new instance of the same type as this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
ijk_product_structure()
Default constructor; disabled.
virtual ~ijk_product_structure()
Destructor.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual size_type d() const
The product dimension.
size_type _i_ub
The upper bound in the i-direction.
size_type _j_ub
The upper bound in the j-direction.
void tuple(pod_index_type x, size_type xj_ub, pod_index_type &xi, pod_index_type &xj)
Ordinal to 2-tuple conversion.
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
size_type i_ub() const
The upper bound in the i-direction.