SheafSystem  0.0.0.0
structured_block.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/assert_contract.h"
22 #include "SheafSystem/block.impl.h"
23 #include "SheafSystem/chart_point_3d.h"
24 #include "SheafSystem/fiber_bundles_namespace.h"
25 #include "SheafSystem/poset_path.h"
26 #include "SheafSystem/preorder_iterator.h"
27 #include "SheafSystem/quad_connectivity.h"
28 #include "SheafSystem/schema_descriptor.h"
29 #include "SheafSystem/schema_poset_member.h"
30 #include "SheafSystem/structured_block.h"
31 #include "SheafSystem/wsv_block.h"
32 
33 using namespace std;
34 using namespace fiber_bundle; // Workaround for MS C++ bug.
35 
36 // ===========================================================
37 // HOST FACTORY FACET
38 // ===========================================================
39 
40 // PUBLIC MEMBER FUNCTIONS
41 
44 new_host(namespace_type& xns, const poset_path& xhost_path, const poset_path& xschema_path, int xmax_db, bool xauto_access)
45 {
46  // cout << endl << "Entering structured_block::new_host." << endl;
47 
48  // Preconditions:
49 
50  require(xns.state_is_auto_read_write_accessible(xauto_access));
51 
52  require(!xhost_path.empty());
53  require(!xns.contains_path(xhost_path, xauto_access));
54 
55  require(xschema_path.full());
56  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
57  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
58 
59  require(xmax_db >= 0);
60 
61  // Body:
62 
63  host_type& result =
64  host_type::new_table(xns, xhost_path, xschema_path, xmax_db, xauto_access);
65 
66  // Postconditions:
67 
68  ensure(xns.owns(result, xauto_access));
69  ensure(result.path(true) == xhost_path);
70  ensure(result.state_is_not_read_accessible());
71  ensure(result.schema(true).path(xauto_access) == xschema_path);
72 
73  ensure(result.max_db() == xmax_db);
74 
75  // Exit:
76 
77  // cout << "Leaving structured_block::new_host." << endl;
78  return result;
79 }
80 
83 new_host(namespace_type& xns, const poset_path& xhost_path, int xmax_db, bool xauto_access)
84 {
85  // cout << endl << "Entering structured_block::new_host." << endl;
86 
87  // Preconditions:
88 
89  require(xns.state_is_auto_read_write_accessible(xauto_access));
90  require(!xhost_path.empty());
91  require(!xns.contains_path(xhost_path, xauto_access));
92  require(xns.path_is_auto_read_accessible(standard_schema_path(), xauto_access));
93 
94  require(xmax_db >= 0);
95 
96  // Body:
97 
98  host_type& result =
99  new_host(xns, xhost_path, standard_schema_path(), xmax_db, xauto_access);
100 
101  // Postconditions:
102 
103  ensure(xns.owns(result, xauto_access));
104  ensure(result.path(true) == xhost_path);
105  ensure(result.state_is_not_read_accessible());
106  ensure(result.schema(true).path(xauto_access) == standard_schema_path());
107 
108  ensure(result.max_db() == xmax_db);
109 
110  // Exit:
111 
112  // cout << "Leaving structured_block::new_host." << endl;
113  return result;
114 }
115 
116 // PROTECTED MEMBER FUNCTIONS
117 
118 // PRIVATE MEMBER FUNCTIONS
119 
120 
121 // ===========================================================
122 // STRUCTURED_BLOCK FACET
123 // ===========================================================
124 
125 // PUBLIC DATA MEMBERS
126 
129 {
130 
131  // Preconditions:
132 
133  // Body:
134 
135  // Postconditions:
136 
137  ensure(invariant());
138  ensure(! is_attached() );
139 }
140 
143 {
144 
145  // Preconditions:
146 
147  // Body:
148 
149  // Exit
150 
151  return;
152 }
153 
154 // PROTECTED DATA MEMBERS
155 
156 void
159 {
160  // Preconditions:
161 
162  require(state_is_read_accessible());
163 
164  // Body:
165 
166  // Have just attached to a new or different host.
167  // Initialize the handle data members for the different host.
168 
169  // Get the elements client id map.
170  // d_cells_name(xdb, xdb) returns "_elements" no matter what xdb is.
171 
173 
174  subposet lsp(host(), base_space_poset::d_cells_name(2, 2));
175  _elements_id_space = &lsp.id_space();
176  lsp.detach_from_state();
177 
178  // Postconditions:
179 
180  ensure(unexecutable(data members created but not attached));
181 
182  // Exit
183 
184  return;
185 }
186 
187 void
190  scoped_index::pod_type& xchart_id,
191  size_type xchart_id_ub) const
192 {
193  // Preconditions:
194 
195  static const chart_point_coord_type ONE =
196  1.0 + 1000.0*numeric_limits<chart_point_coord_type>::epsilon();
197 
198  require((-ONE <= xcoord) && (xcoord <= ONE));
199 
200  // Body:
201 
203 
204  chart_point_coord_type lcoord = (xcoord + 1.0)*0.5*xchart_id_ub;
205 
206  // Integer part is sequence id of refined chart id component,
207  // fractional part is refined local coord component.
208 
209  chart_point_coord_type lref_chart;
210  xcoord = (modf(lcoord, &lref_chart)*2.0) - 1.0;
211 
212  xchart_id = static_cast<scoped_index::pod_type>(lref_chart);
213 
214  // If lcoord in on boundary between two charts,
215  // modf returns lower bound of greater chart.
216  // This is acceptable unless lcoord in on the
217  // upper bound of the domain, in which case
218  // there is no greater chart and we want the
219  // upper bound of the lesser chart.
220 
221  if(xchart_id == xchart_id_ub)
222  {
223  xchart_id--;
224  xcoord = 1.0;
225  }
226 
227  // Postconditions:
228 
229  ensure((xchart_id >= 0) && (xchart_id < xchart_id_ub));
230  ensure((-ONE <= xcoord) && (xcoord <= ONE));
231 
232  // Exit:
233 
234  return;
235 }
236 
237 // PRIVATE DATA MEMBERS
238 
239 
240 // ===========================================================
241 // LOCAL_BASE_SPACE_MEMBER FACET
242 // ===========================================================
243 
244 // PUBLIC DATA MEMBERS
245 
248 refine_point(const chart_point& xpt) const
249 {
250  chart_point* result;
251 
252  // Preconditions:
253 
254  require(precondition_of(refine_point_pa(xpt, *result)));
255 
256  // Body:
257 
258  result = const_cast<chart_point&>(xpt).clone();
259  refine_point_pa(xpt, *result);
260 
261  // Postconditions:
262 
263  ensure(postcondition_of(refine_point_pa(xpt, *result)));
264 
265  // Exit:
266 
267  return result;
268 }
269 
270 void
272 refine_point_pa(const chart_point& xpt, chart_point& result) const
273 {
274  // Preconditions:
275 
276  require(state_is_read_accessible());
277 
278  require(xpt.chart_id() == index().pod());
279 
280  // One is tempted to require xpt.db() == db(), but the implementations
281  // of this routine don't actually need it and in practice allowing xpt.db() > db()
282  // enables preallocating chart points before one knows the exact dimension.
283 
284  require(xpt.db() >= db());
285  require(result.db() >= db());
286 
287  // Body:
288 
289  is_abstract();
290 
291  // Postconditions:
292 
293  ensure(covers(result.chart_id()));
294 
295  // Exit:
296 
297  return;
298 }
299 
300 void
303 {
304  // Preconditions:
305 
306  require(state_is_read_accessible());
307 
308  require(xpt.chart_id() == index().pod());
309 
310  // One is tempted to require xpt.db() == db(), but the implementations
311  // of this routine don't actually need it and in practice allowing xpt.db() > db()
312  // enables preallocating chart points before one knows the exact dimension.
313 
314  require(xpt.db() >= db());
315  require(db() <= 3);
316 
317  // Body:
318 
319  is_abstract();
320 
321  // Postconditions:
322 
323  // Exit:
324 
325  return;
326 }
327 
330 unrefine_point(const chart_point& xpt) const
331 {
332  chart_point* result;
333 
334  // Preconditions:
335 
336  require(precondition_of(unrefine_point_pa(xpt, *result)));
337 
338  // Body:
339 
340  result = const_cast<chart_point&>(xpt).clone();
341  unrefine_point_pa(xpt, *result);
342 
343  // Postconditions:
344 
345  ensure(postcondition_of(unrefine_point_pa(xpt, *result)));
346 
347  // Exit:
348 
349  return result;
350 }
351 
352 void
354 unrefine_point_pa(const chart_point& xpt, chart_point& result) const
355 {
356  // Preconditions:
357 
358  require(state_is_read_accessible());
359 
364 
365  // require(covers(xpt.chart_id()));
366 
367  // One is tempted to require xpt.db() == db(), but the implementations
368  // of this routine don't actually need it and in practice allowing xpt.db() > db()
369  // enables preallocating chart points before one knows the exact dimension.
370 
371  require(xpt.db() >= db());
372  require(result.db() >= db());
373 
374  // Body:
375 
376  is_abstract();
377 
378  // Postcondition:
379 
380  ensure(result.chart_id() == index().pod());
381 
382  // Exit:
383 
384  return;
385 }
386 
387 void
390 {
391  // Preconditions:
392 
393  require(state_is_read_write_accessible());
394  require(is_jim());
395 
396  // Body:
397 
398  is_abstract();
399 
400  // Postconditions:
401 
402  ensure(!is_jim());
403 
404  // Exit:
405 
406  return;
407 }
408 
409 
410 void
413 {
414  // Preconditions:
415 
416  require(state_is_read_write_accessible());
417  require(!is_jim());
418 
419  // Body:
420 
421  is_abstract();
422 
423  // Postconditions:
424 
425  ensure(is_jim());
426 
427  // Exit:
428 
429  return;
430 }
431 
432 void
435 {
436  // Preconditions:
437 
438  require(state_is_read_write_accessible());
439  require(is_jim());
440 
441  // Body:
442 
443  is_abstract();
444 
445  // Postconditions:
446 
447  ensure(!is_jim());
448 
449  // Exit:
450 
451  return;
452 }
453 
454 
455 void
458 {
459  // Preconditions:
460 
461  require(state_is_read_write_accessible());
462  require(!is_jim());
463 
464  // Body:
465 
466  is_abstract();
467 
468  // Postconditions:
469 
470  ensure(is_jim());
471 
472  // Exit:
473 
474  return;
475 }
476 
477 // PROTECTED DATA MEMBERS
478 
479 // PRIVATE DATA MEMBERS
480 
481 
482 // ===========================================================
483 // HOMOGENEOUS_BLOCK FACET
484 // ===========================================================
485 
486 // PUBLIC DATA MEMBERS
487 
488 // PROTECTED DATA MEMBERS
489 
490 // PRIVATE DATA MEMBERS
491 
492 
493 // ===========================================================
494 // BASE_SPACE_MEMBER FACET
495 // ===========================================================
496 
497 // PUBLIC DATA MEMBERS
498 
499 // PROTECTED DATA MEMBERS
500 
501 // PRIVATE DATA MEMBERS
502 
503 
504 // ===========================================================
505 // TOTAL_POSET_MEMBER FACET
506 // ===========================================================
507 
508 // PUBLIC DATA MEMBERS
509 
510 // PROTECTED DATA MEMBERS
511 
512 // PRIVATE DATA MEMBERS
513 
514 
515 // ===========================================================
516 // ABSTRACT_POSET_MEMBER FACET
517 // ===========================================================
518 
519 // PUBLIC DATA MEMBERS
520 
523 clone() const
524 {
525  structured_block* result = 0;
526 
527  // Preconditions:
528 
529  // Body:
530 
531  is_abstract();
532 
533  // Postconditions:
534 
535  ensure(result != 0);
536 
537  // Exit
538 
539  return result;
540 }
541 
542 // PROTECTED DATA MEMBERS
543 
544 // PRIVATE DATA MEMBERS
545 
546 
547 // ===========================================================
548 // ANY FACET
549 // ===========================================================
550 
551 // PUBLIC DATA MEMBERS
552 
553 bool
555 invariant() const
556 {
557  // Preconditions:
558 
559  // Body:
560 
561  // Must satisfy base class invariant
562 
563  invariance(homogeneous_block::invariant());
564 
565  if(invariant_check())
566  {
567  // Prevent recursive calls to invariant
568 
569  disable_invariant_check();
570 
571  // Invariants for this class:
572 
573  invariance(state_is_read_accessible() ? is_jim(false) : true);
574 
575  // Finished, turn invariant checking back on.
576 
577  enable_invariant_check();
578  }
579 
580  // Postconditions:
581 
582  // Exit
583 
584  return true;
585 }
586 
587 bool
589 is_ancestor_of(const any* xother) const
590 {
591  bool result;
592 
593  // Preconditions:
594 
595  // Body:
596 
597  result = dynamic_cast<const structured_block*>(xother) != 0;
598 
599  // Postconditions:
600 
601  // Exit
602 
603  return result;
604 }
605 
609 {
610  // Preconditions:
611 
612  // Body:
613 
614  attach_to_state(&xother);
615 
616  // Postconditions:
617 
618  ensure(is_same_state(&xother));
619 
620  // Exit
621 
622  return *this;
623 }
624 
628 {
629 
630  // Preconditions:
631 
632  require(is_ancestor_of(&xother));
633 
634  // Body
635 
636  not_implemented();
637 
638  // Postconditions
639 
640  ensure(invariant());
641 
642  // Exit
643 
644  return *this;
645 
646 }
647 
648 // PROTECTED DATA MEMBERS
649 
650 // PRIVATE DATA MEMBERS
651 
652 
653 //==============================================================================
654 // NON-MEMBER FUNCTIONS
655 //==============================================================================
656 
657 size_t
658 fiber_bundle::
659 deep_size(const structured_block& x0, bool xinclude_shallow)
660 {
661  size_t result;
662 
663  // Preconditions:
664 
665  // Body:
666 
669 
670  result = 0;
671 
672  // Postconditions:
673 
674  ensure(result == 0);
675  //ensure(result >= 0);
676 
677  // Exit
678 
679  return result;
680 }
681 
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, int xmax_db, bool xauto_access)
Creates a new host poset for members of this type. The poset is created in namespace xns with path xh...
double chart_point_coord_type
The type of local coordinate in the base space; the scalar type for the local coordinate vector space...
Definition: fiber_bundle.h:57
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
bool state_is_auto_read_write_accessible(bool xauto_access) const
True if state is auto accessible for read and write, that is, if the state is already accessible for ...
A client handle for a subposet.
Definition: subposet.h:86
chart_point * refine_point(const chart_point &xpt) const
A chart point in the direct refinement of this which is the same as xpt in this; auto-allocated versi...
virtual void unsimplify()=0
Removes the standard simplex refinement of this from its lower cover and changes this from a jrm to a...
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
poset_path path(bool xauto_access=true) const
A path to this component.
bool path_is_auto_read_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read accessible.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
virtual int db() const =0
The dimension of this chart.
Definition: chart_point.cc:141
virtual bool is_ancestor_of(const any *other) const
True if other conforms to this.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
STL namespace.
virtual void simplify()=0
Inserts the standard simplex refinement of this into its lower cover and changes this from a jim to a...
A point in chart space.
Definition: chart_point.h:52
virtual bool invariant() const
Class invariant.
virtual ~structured_block()
Destructor; deletes a poset member and its attached state, if any.
pod_index_type chart_id() const
The id of the chart this point is in.
Definition: chart_point.cc:96
A client handle for a base space member which represents a homgeneous collection of local cells...
Abstract base class with useful features for all objects.
Definition: any.h:39
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
virtual structured_block & operator=(const abstract_poset_member &xother)
Assignment operator; attaches this to the same state as xother.
void refine_coordinate(chart_point_coord_type &xcoord, scoped_index::pod_type &xchart_id, size_type xchart_id_ub) const
Transforms local coordinate xcoord from block local to zone local.
structured_block()
Default constructor; creates a new, unattached structured_block handle.
bool owns(const poset_state_handle &xposet, bool xauto_access) const
True if and only if this contains the poset xposet. synonym for contains_poset(xposet.poset_path(true), xauto_access)
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
SHEAF_DLL_SPEC void modf(const sec_at0 &x0, sec_at0 &xintpart, sec_at0 &xfractpart, bool xauto_access)
Compute modf of x0 (modf(x0)) (pre-allocated version).
Definition: sec_at0.cc:1474
virtual void refine_point_pa(const chart_point &xpt, chart_point &result) const =0
A chart point in the direct refinement of this which is the same as xpt in this; pre-allocated versio...
const scattered_insertion_index_space_handle & id_space() const
The id space for the members of with this (const version).
Definition: subposet.cc:508
virtual void detach_from_state()
Detach this handle from its state, if any.
chart_point * unrefine_point(const chart_point &xpt) const
The point in this which is the same as xpt in the direct refinement of this; auto-allocated version...
pod_index_type pod_type
The "plain old data" storage type for this.
Definition: scoped_index.h:128
virtual void unrefine_point_pa(const chart_point &xpt, chart_point &result) const =0
The point in this which is the same as xpt in the direct refinement of this; pre-allocated version...
virtual void init_handle_data_members()
Initializes handle data members when attaching to a different member in a different host...
virtual structured_block * clone() const =0
Make a new handle, no state instance of current.
int max_db() const
The maximum dimension of the members of this base space.
An abstract client handle for a member of a poset.
An auto_block with a no-initialization initialization policy.
Namespace for the fiber_bundles component of the sheaf system.
bool state_is_not_read_accessible() const
True if this is attached and if the state is accessible for read or if access control is disabled...
virtual void refine()=0
Inserts the standard refinement of this into its lower cover and changes this from a jim to a jrm...
virtual void unrefine()=0
Removes the standard refinement of this from its lower cover and changes this from a jrm to a jim...