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