SheafSystem  0.0.0.0
section_dof_map.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 
19 
20 // Implementation for class section_dof_map
21 
22 #include "SheafSystem/section_dof_map.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/binary_section_space_schema_member.h"
26 #include "SheafSystem/poset_type.h"
27 
28 using namespace std;
29 using namespace fiber_bundle; // Workaround for MS C++ bug.
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
34 const std::string&
36 class_name() const
37 {
38  // Preconditions:
39 
40  // Body:
41 
42  const string& result = static_class_name();
43 
44  // Postconditions:
45 
46  ensure(!result.empty());
47 
48  // Exit:
49 
50  return result;
51 }
52 
54 const std::string&
57 {
58  // Preconditions:
59 
60  // Body:
61 
62  static const string result("section_dof_map");
63 
64  // Postconditions:
65 
66  ensure(!result.empty());
67  ensure(result == "section_dof_map");
68 
69  // Exit:
70 
71  return result;
72 }
73 
74 // CANONICAL MEMBERS
75 
76 
80 operator=(const section_dof_map& xother)
81 {
82 
83  // Preconditions:
84 
85  require(xother.is_initialized());
86 
87  // Body:
88 
89  poset_dof_map::operator=(xother);
90 
91  // Postconditions:
92 
93  // Exit
94 
95  return *this;
96 }
97 
98 
102 {
103 
104  // Preconditions:
105 
106 
107  // Body:
108 
109  // Postconditions:
110 
111  // Exit
112 
113  return;
114 }
115 
116 
118 bool
120 invariant() const
121 {
122  bool result = true;
123 
124  // Preconditions:
125 
126  // Body:
127 
128  result = result && poset_dof_map::invariant();
129 
130  if(invariant_check())
131  {
132  // Prevent recursive calls to invariant
133 
134  disable_invariant_check();
135 
136  // Invariants for this class:
137 
138  result = result &&
139  (_host != 0 ? dynamic_cast<sec_rep_space*>(_host) != 0 : true);
140 
141  result = result &&
142  (_schema != 0
143  ? dynamic_cast<section_space_schema_member*>(_schema) != 0 : true);
144 
145  // Finished, turn invariant checking back on.
146 
147  enable_invariant_check();
148  }
149 
150  // Postconditions:
151 
152  // Exit
153 
154  return result;
155 }
156 
157 
158 // MAP INTERFACE
159 
160 
161 
165 host() const
166 {
167  sec_rep_space* result;
168 
169  // Preconditions:
170 
171  // Body:
172 
173  result = dynamic_cast<sec_rep_space*>(_host);
174 
175  // Postconditions:
176 
177  ensure((result == 0) == (poset_dof_map::host() == 0));
178 
179  // Exit
180 
181  return result;
182 }
183 
188 {
189  // Preconditions:
190 
191  require(is_initialized());
192 
193  // Body:
194 
196  *(dynamic_cast<section_space_schema_member*>(_schema));
197 
198  // Postconditions:
199 
200  // Exit
201 
202  return result;
203 }
204 
208 schema() const
209 {
210  // Preconditions:
211 
212  require(is_initialized());
213 
214  // Body:
215 
217  *(dynamic_cast<section_space_schema_member*>(_schema));
218 
219  // Postconditions:
220 
221  // Exit
222 
223  return result;
224 }
225 
226 
227 // ===========================================================
228 // NEW DOF ACCESS FACET
229 // ===========================================================
230 
231 bool
233 dof_in_bounds(pod_index_type xdof_id, bool xis_table_dofs) const
234 {
235  // Preconditions:
236 
237 
238  // Body:
239 
240  // Essentially abstract; always true in this class.
241  // Intended to be redefined in descendants.
242 
243  bool result = true;
244 
245  // Postconditions:
246 
247 
248  // Exit:
249 
250  return result;
251 }
252 
253 bool
255 dof_in_bounds(pod_index_type xdisc_id, pod_index_type xfiber_id, bool xis_table_dofs) const
256 {
257  // Preconditions:
258 
259 
260  // Body:
261 
262  // Essentially abstract; always true in this class.
263  // Intended to be redefined in descendants.
264 
265  bool result = true;
266 
267  // Postconditions:
268 
269 
270  // Exit:
271 
272  return result;
273 }
274 
275 void
277 get_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, void* xdof, size_type xdof_size) const
278 {
279  // Preconditions:
280 
281  require(schema().state_is_read_accessible());
282  require(schema().discretization_id_space().contains(xdisc_id));
283  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
284  require(unexecutable("xdof points to buffer of size xdof_size"));
285  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false));
286 
287 
288  // Body:
289 
290  is_abstract();
291 
292  // Postconditions:
293 
294 
295  // Exit:
296 
297  return;
298 }
299 
300 
301 void
303 get_dof(const scoped_index& xdisc_id,
304  const scoped_index& xfiber_dof_id,
305  void* xdof,
306  size_type xdof_size) const
307 {
308  // Preconditions:
309 
310  require(schema().state_is_read_accessible());
311  require(schema().discretization_id_space().contains(xdisc_id));
312  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
313  require(unexecutable("dof_in_bounds(xdisc_id, xfiber_dof_id, false)"));
314  require(unexecutable("xdof points to buffer of size xdof_size"));
315  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false, false));
316 
317 
318  // Body:
319 
320  pod_index_type ldisc_id =
321  schema().discretization_id_space().pod(xdisc_id);
322  pod_index_type lfiber_dof_id =
323  schema().fiber_schema_id_space(false).pod(xfiber_dof_id);
324 
325  get_dof(ldisc_id, lfiber_dof_id, xdof, xdof_size);
326 
327  // Postconditions:
328 
329 
330  // Exit:
331 
332  return;
333 }
334 
335 void
337 put_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, const void* xdof, size_type xdof_size)
338 {
339  // Preconditions:
340 
341  require(schema().state_is_read_accessible());
342  require(schema().discretization_id_space().contains(xdisc_id));
343  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
344  require(dof_in_bounds(xdisc_id, xfiber_dof_id, false));
345  require(unexecutable("xdof points to buffer of size xdof_size"));
346  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false));
347 
348  // Body:
349 
350  is_abstract();
351 
352  // Postconditions:
353 
354 
355  // Exit:
356 
357  return;
358 }
359 
360 
361 void
363 put_dof(const scoped_index& xdisc_id,
364  const scoped_index& xfiber_dof_id,
365  const void* xdof,
366  size_type xdof_size)
367 {
368  // Preconditions:
369 
370  require(schema().state_is_read_accessible());
371  require(schema().discretization_id_space().contains(xdisc_id));
372  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
373  require(unexecutable("dof_in_bounds(xdisc_id, xfiber_dof_id, false)"));
374  require(unexecutable("xdof points to buffer of size xdof_size"));
375  require(xdof_size >= schema().size(xdisc_id, xfiber_dof_id, false, false));
376 
377 
378  // Body:
379 
380  pod_index_type ldisc_id =
381  schema().discretization_id_space().pod(xdisc_id);
382  pod_index_type lfiber_dof_id =
383  schema().fiber_schema_id_space(false).pod(xfiber_dof_id);
384 
385  put_dof(ldisc_id, lfiber_dof_id, xdof, xdof_size);
386 
387  // Postconditions:
388 
389 
390  // Exit:
391 
392  return;
393 }
394 
395 
396 bool
398 fiber_in_bounds(pod_index_type xdisc_id, bool xis_table_dofs) const
399 {
400  // Preconditions:
401 
402 
403  // Body:
404 
405  // Essentially abstract; always true in this class.
406  // Intended to be redefined in descendants.
407 
408  bool result = true;
409 
410  // Postconditions:
411 
412 
413  // Exit:
414 
415  return result;
416 }
417 
418 void
420 get_fiber(pod_index_type xdisc_id, void* xfiber, size_type xfiber_size) const
421 {
422  // Preconditions:
423 
424  require(schema().state_is_read_accessible());
425  require(schema().discretization_id_space().contains(xdisc_id));
426  require(fiber_in_bounds(xdisc_id, false));
427  require(unexecutable("xfiber points to buffer of size xfiber_size"));
428  require(xfiber_size >= schema().fiber_size());
429 
430 
431  // Body:
432 
433  is_abstract();
434 
435  // Postconditions:
436 
437 
438  // Exit:
439 
440  return;
441 }
442 
443 void
445 get_fiber(const scoped_index& xdisc_id, void* xfiber, size_type xfiber_size) const
446 {
447  // Preconditions:
448 
449  require(schema().state_is_read_accessible());
450  require(schema().discretization_id_space().contains(xdisc_id));
451  require(unexecutable("fiber_in_bounds(xdisc_id, false)"));
452  require(unexecutable("xfiber points to buffer of size xfiber_size"));
453  require(xfiber_size >= schema().fiber_size());
454 
455  // Body:
456 
457  pod_index_type ldisc_id = schema().discretization_id_space().pod(xdisc_id);
458 
459  get_fiber(ldisc_id, xfiber, xfiber_size);
460 
461  // Postconditions:
462 
463 
464  // Exit:
465 
466  return;
467 }
468 
469 void
471 put_fiber(pod_index_type xdisc_id, const void* xfiber, size_type xfiber_size)
472 {
473  // Preconditions:
474 
475  require(schema().state_is_read_accessible());
476  require(schema().discretization_id_space().contains(xdisc_id));
477  require(fiber_in_bounds(xdisc_id, false));
478  require(unexecutable("xfiber points to buffer of size xfiber_size"));
479  require(xfiber_size >= schema().fiber_size());
480 
481 
482  // Body:
483 
484  is_abstract();
485 
486  // Postconditions:
487 
488 
489  // Exit:
490 
491  return;
492 }
493 
494 void
496 put_fiber(const scoped_index& xdisc_id, const void* xfiber, size_type xfiber_size)
497 {
498  // Preconditions:
499 
500  require(schema().state_is_read_accessible());
501  require(schema().discretization_id_space().contains(xdisc_id));
502  require(unexecutable("fiber_in_bounds(xdisc_id, false)"));
503  require(unexecutable("xfiber points to buffer of size xfiber_size"));
504  require(xfiber_size >= schema().fiber_size());
505 
506  // Body:
507 
508  pod_index_type ldisc_id = schema().discretization_id_space().pod(xdisc_id);
509 
510  put_fiber(ldisc_id, xfiber, xfiber_size);
511 
512  // Postconditions:
513 
514 
515  // Exit:
516 
517  return;
518 }
519 
520 void
522 force_fiber(pod_index_type xdisc_id, const void* xfiber, size_type xfiber_size)
523 {
524  // Preconditions:
525 
526  require(schema().state_is_read_accessible());
527  require(schema().discretization_id_space().contains(xdisc_id));
528  require(unexecutable("xfiber points to buffer of size xfiber_size"));
529  require(xfiber_size >= schema().fiber_size());
530 
531 
532  // Body:
533 
534  // Equivalent to put_fiber in this class;
535  // intended to be redefined in descendants.
536 
537  put_fiber(xdisc_id, xfiber, xfiber_size);
538 
539  // Postconditions:
540 
541 
542  // Exit:
543 
544  return;
545 }
546 
547 void
549 force_fiber(const scoped_index& xdisc_id, const void* xfiber, size_type xfiber_size)
550 {
551  // Preconditions:
552 
553  require(schema().state_is_read_accessible());
554  require(schema().discretization_id_space().contains(xdisc_id));
555  require(unexecutable("xfiber points to buffer of size xfiber_size"));
556  require(xfiber_size >= schema().fiber_size());
557 
558  // Body:
559 
560  pod_index_type ldisc_id = schema().discretization_id_space().pod(xdisc_id);
561 
562  force_fiber(ldisc_id, xfiber, xfiber_size);
563 
564  // Postconditions:
565 
566 
567  // Exit:
568 
569  return;
570 }
571 
572 void
574 get_component(pod_index_type xfiber_dof_id, void* xcomponent, size_type xcomponent_size) const
575 {
576  // Preconditions:
577 
578  require(schema().state_is_read_accessible());
579  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
580  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
581  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
582 
583 
584  // Body:
585 
586  is_abstract();
587 
588  // Postconditions:
589 
590 
591  // Exit:
592 
593  return;
594 }
595 
596 void
598 get_component(const scoped_index& xfiber_dof_id, void* xcomponent, size_type xcomponent_size) const
599 {
600  // Preconditions:
601 
602  require(schema().state_is_read_accessible());
603  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
604  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
605  require(xcomponent_size >= schema().component_size(xfiber_dof_id, false));
606 
607  // Body:
608 
609  pod_index_type lfiber_id =
610  schema().fiber_schema_id_space(false).pod(xfiber_dof_id);
611 
612  get_component(lfiber_id, xcomponent, xcomponent_size);
613 
614  // Postconditions:
615 
616 
617  // Exit:
618 
619  return;
620 }
621 
622 void
624 put_component(pod_index_type xfiber_dof_id, const void* xcomponent, size_type xcomponent_size)
625 {
626  // Preconditions:
627 
628  require(schema().state_is_read_accessible());
629  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
630  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
631  require(xcomponent_size >= schema().component_size(xfiber_dof_id));
632 
633 
634  // Body:
635 
636  is_abstract();
637 
638  // Postconditions:
639 
640 
641  // Exit:
642 
643  return;
644 }
645 
646 void
648 put_component(const scoped_index& xfiber_dof_id, const void* xcomponent, size_type xcomponent_size)
649 {
650  // Preconditions:
651 
652  require(schema().state_is_read_accessible());
653  require(schema().fiber_schema_id_space(false).contains(xfiber_dof_id));
654  require(unexecutable("xcomponent points to buffer of size xcomponent_size"));
655  require(xcomponent_size >= schema().component_size(xfiber_dof_id, false));
656 
657  // Body:
658 
659  pod_index_type lfiber_id =
660  schema().fiber_schema_id_space(false).pod(xfiber_dof_id);
661 
662  put_component(lfiber_id, xcomponent, xcomponent_size);
663 
664  // Postconditions:
665 
666 
667  // Exit:
668 
669  return;
670 }
671 
672 // ===========================================================
673 // END NEW DOF ACCESS FACET
674 // ===========================================================
675 
677 bool
680 {
682 
683  return true;
684 }
685 
686 // PROTECTED MEMBER FUNCTIONS
687 
688 // CANONICAL MEMBERS
689 
692 {
693 
694  // Preconditions:
695 
696 
697  // Body:
698 
699  // No action required
700 
701  // Postconditions:
702 
703  // Exit
704 
705  return;
706 }
707 
708 
711  : poset_dof_map(xother)
712 {
713 
714  // Preconditions:
715 
716  // Body:
717 
718  // Postconditions:
719 
720  // Exit
721 
722  return;
723 }
724 
725 
726 // OTHER CONSTRUCTORS
727 
730 section_dof_map(sec_rep_space* xhost, pod_index_type xbase_id, int xversion)
731 {
732 
733  // Preconditions:
734 
735  require(xhost != 0);
736  require(xhost->state_is_read_accessible());
737  require(xhost->base().geqv(xbase_id));
738  require(xhost->has_version(xversion));
739 
740  // Body:
741 
742  _host = xhost;
743 
744  _index.invalidate();
745 
746  // Create a handle of the same actual type as the host schema and
747  // attach it to the schema of the partial section.
748 
749  section_space_schema_member* lschema = xhost->schema().clone();
750  lschema->attach_to_state(xhost->schema().host(),
751  xbase_id,
752  xhost->schema().fiber_schema_id());
753 
754  // Give the schema member a name if it does not already have one.
755 
756  if(lschema->name(true).empty())
757  {
758  lschema->put_standard_name(true, true);
759  }
760 
761  // Make sure the version is unalised, so it can't magically change
762  // after the dof storage has been allocated.
763 
764  lschema->put_version(xversion, true);
765 
766  // Save a reference to the schema.
767 
768  _schema = lschema;
769 
770  // This is a row dof map.
771 
772  _is_table_dof_map = false;
773 
776 
777  _ref_ct = 0;
778 
779  // Postconditions:
780 
781  ensure(is_initialized());
782  ensure(host() == xhost);
783  ensure(!index().is_valid());
784  ensure(schema().base_space_id() == xbase_id);
785  ensure(schema().fiber_schema_id() == xhost->schema().fiber_schema_id());
786  ensure(dof_ct() == schema().row_dof_ct());
787  ensure(dof_tuple_ub() == schema().row_dof_tuple_ub());
788  ensure(ref_ct() == 0);
789  ensure(version() == xhost->schema().unaliased_version(xversion));
790 
791  // Exit
792 
793  return;
794 }
795 
virtual void put_fiber(pod_index_type xdisc_id, const void *xfiber, size_type xfiber_size)=0
Sets the fiber referred to by discretization id xdisc_id to xfiber.
void put_standard_name(bool xunique, bool xauto_access)
Sets the name of this member to a standard name; if xunique, make xname the only name.
bool geqv(pod_index_type xother_index) const
True if this is greater than or equivalent to the member with index xother_index. ...
int unaliased_version(int xversion) const
The actual version associated with (possibly aliased) version xversion in this.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
The abstract map from section dof ids to section dof values of heterogeneous type.
virtual void get_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, void *xdof, size_type xdof_size) const =0
Copies the dof referred to by xdisc_id, xfiber_dof_id into xdof.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
int version() const
The version of the host of the schema this is defined on.
unsigned int _ref_ct
The number of references to this map /.
virtual section_space_schema_member & schema()
The schema on which this is allocated (mutable version).
static int dof_ct(const namespace_poset &xns, const poset_path &xpath, bool xis_table_dof, bool xauto_access=true)
The number of table dofs (xis_table_dof true) or row dofs defined by the schema specified by xns and ...
bool _is_table_dof_map
True if this is a table dof map.
bool is_initialized() const
True if this has been initialized, that is, if the schema has been set and the dof map storage alloca...
STL namespace.
void invalidate()
Make this id invalid.
Definition: scoped_index.h:852
The general, abstract map from dof ids to dof values.
Definition: poset_dof_map.h:59
virtual bool fiber_in_bounds(pod_index_type xdisc_id, bool xis_table_dofs) const
True if and only if the fiber asociated with discretization id xdisc_id is within the current capacit...
abstract_poset_member & base()
The base space for this section space (mutable version)
bool has_version(int xversion) const
True if xversion is a valid version.
section_dof_map()
Default constructor.
virtual const std::string & class_name() const
The name of the actual (possibly derived) class of this instance.
size_t _dof_tuple_ub
The size of the dof tuple.
virtual bool supports_xfr_opt() const
True if this dof map type supports dof tuple transfer optimization. /.
virtual ~section_dof_map()
Destructor.
pod_index_type fiber_schema_id() const
The member id of the fiber schema component of this.
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
static const std::string & static_class_name()
The name of this class.
virtual bool invariant() const
The class invariant.
size_t dof_tuple_ub() const
The size of the dof tuple in bytes.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
std::string name(pod_index_type xdof_id, bool xis_table_dof) const
The name of the table dof (xis_table_dof true) or row dof referred to by xdof_id in the schema define...
scoped_index _index
The poset member for which this stores the dofs.
int _dof_ct
The number of dofs in this map.
section_dof_map & operator=(const section_dof_map &xother)
Assignment operator.
virtual void put_version(int xversion, bool xunalias=false)
Sets version to (possibly aliased) xversion. If unalias == true, set version to the actual version al...
int dof_ct() const
The number of dofs in this map.
size_t dof_tuple_ub(bool xis_table_dof) const
The size in bytes of the table dof tuple (xis_table_dof true) or the row dof tuple defined by this sc...
schema_poset_member * _schema
The schema on which this is instantiated.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool dof_in_bounds(pod_index_type xdof_id, bool xis_table_dofs) const
True if and only if the dof asociated with id xdof_id is within the current capacity of the dofs stor...
virtual void put_component(pod_index_type xfiber_dof_id, const void *xcomponent, size_type xcomponent_size)=0
Sets the component referred to by fiber id xfiber_dof_id to xcomponent.
virtual void put_dof(pod_index_type xdisc_id, pod_index_type xfiber_dof_id, const void *xdof, size_type xdof_size)=0
Sets the dof referred to by xdof_id to the value at xdof.
A client handle for a poset member which has been prepared for use as a schema for a section space...
virtual void force_fiber(pod_index_type xdisc_id, const void *xfiber, size_type xfiber_size)
Sets the fiber referred to by discretization id xdisc_id to xfiber; allocates additional memory if ne...
poset_state_handle * _host
The host of the poset member for which this stores the dofs.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
Namespace for the fiber_bundles component of the sheaf system.
virtual void attach_to_state(pod_index_type xbase_space_id, pod_index_type xfiber_schema_id)=0
Attach to the state in host() with component ids xbase_id and xfiber_schema_id.
virtual void get_fiber(pod_index_type xdisc_id, void *xfiber, size_type xfiber_size) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
unsigned int ref_ct() const
The number of references to this map.
virtual sec_rep_space * host() const
The poset which hosts member()
const scoped_index & index() const
The index of this in host() dof tuple table.
section_space_schema_member * clone(bool xnew_state, bool xauto_access=true) const
Make a new handle instance of current. Attach the new instance to a new state if xnew_state is true...
virtual void get_component(pod_index_type xfiber_dof_id, void *xcomponent, size_type xcomponent_size) const =0
Sets xcomponent to the component referred to by fiber id xfiber_dof_id.
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61