SheafSystem  0.0.0.0
sec_st2.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/sec_st2.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/binary_section_space_schema_member.impl.h"
25 #include "SheafSystem/binary_section_space_schema_poset.h"
26 #include "SheafSystem/fiber_bundles_namespace.h"
27 #include "SheafSystem/sec_at0.h"
28 #include "SheafSystem/sec_at0_space.h"
29 #include "SheafSystem/sec_stp_space.h"
30 #include "SheafSystem/sec_tuple_space.impl.h"
31 #include "SheafSystem/section_space_schema_member.impl.h"
32 #include "SheafSystem/section_space_schema_poset.h"
33 #include "SheafSystem/stp.h"
34 #include "SheafSystem/stp_space.h"
35 
36 using namespace std;
37 using namespace fiber_bundle; // Workaround for MS C++ bug.
38 
39 //==============================================================================
40 // CLASS SEC_ST2
41 //==============================================================================
42 
43 // ===========================================================
44 // HOST FACTORY FACET OF CLASS SEC_ST2
45 // ===========================================================
46 
47 // PUBLIC MEMBER FUNCTIONS
48 
52  const poset_path& xhost_path,
53  const poset_path& xschema_path,
54  const poset_path& xscalar_space_path,
55  bool xauto_access)
56 {
57  // cout << endl << "Entering sec_st2::new_host." << endl;
58 
59  // Preconditions:
60 
61  require(xns.state_is_auto_read_write_accessible(xauto_access));
62 
63  require(!xhost_path.empty());
64  require(!xns.contains_path(xhost_path, xauto_access));
65 
66  require(xschema_path.full());
67  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
68  require(host_type::fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
69 
70  require(xns.path_is_auto_read_accessible<scalar_type::host_type>(xscalar_space_path, xauto_access));
71 
72  require(host_type::same_scalar_fiber_space(xns, xschema_path, xscalar_space_path, xauto_access));
73 
74  // Body:
75 
76  host_type& result = host_type::new_table(xns, xhost_path, xschema_path, xscalar_space_path, xauto_access);
77 
78  // Postconditions:
79 
80  ensure(xns.owns(result, xauto_access));
81  ensure(result.path(true) == xhost_path);
82  ensure(result.state_is_not_read_accessible());
83  ensure(result.schema(true).path(xauto_access) == xschema_path);
84 
85  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
86  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
87  ensure(result.d(true) == result.dd(true));
88  ensure(result.scalar_space_path(true) == xscalar_space_path);
89  ensure(result.p(true) == result.schema(true).fiber_space<fiber_type::host_type>().p(xauto_access));
90  ensure(result.p(true) == 2);
91  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
92  ensure(result.vector_space_path(true) == xhost_path);
93 
94  // Exit:
95 
96  // cout << "Leaving sec_st2::new_host." << endl;
97  return result;
98 }
99 
100 // PROTECTED MEMBER FUNCTIONS
101 
102 // PRIVATE MEMBER FUNCTIONS
103 
104 
105 //==============================================================================
106 // ST2 FACET OF CLASS SEC_ST2
107 //==============================================================================
108 
109 // PUBLIC MEMBER FUNCTIONS
110 
113 {
114  // Preconditions:
115 
116  // Body:
117 
118  // Postconditions:
119 
120  ensure(invariant());
121 }
122 
124 sec_st2(const sec_rep_space* xhost, pod_index_type xhub_id)
125 {
126  // Preconditions:
127 
128  require(xhost != 0);
129  require(xhost->state_is_read_accessible());
130  require(xhost->contains_member(xhub_id));
131 
132  // Body:
133 
134  attach_to_state(xhost, xhub_id);
135 
136  // Postconditions:
137 
138  ensure(invariant());
139  //ensure(host() == xhost);
140  ensure(index() == xhub_id);
141  ensure(is_attached());
142  ensure(!is_restricted());
143 }
144 
146 sec_st2(const sec_rep_space* xhost, const scoped_index& xid)
147 {
148  // Preconditions:
149 
150  require(xhost != 0);
151  require(xhost->state_is_read_accessible());
152  require(xhost->contains_member(xid));
153 
154  // Body:
155 
156  attach_to_state(xhost, xid.hub_pod());
157 
158  // Postconditions:
159 
160  ensure(invariant());
161  //ensure(host() == xhost);
162  ensure(index() ==~ xid);
163  ensure(is_attached());
164  ensure(!is_restricted());
165 }
166 
168 sec_st2(const sec_rep_space* xhost, const std::string& xname)
169 {
170 
171  // Preconditions:
172 
173  require(xhost != 0);
174  require(xhost->state_is_read_accessible());
175  require(!xname.empty());
176  require(xhost->contains_member(xname));
177 
178  // Body:
179 
180  attach_to_state(xhost, xname);
181 
182  // Postconditions:
183 
184  ensure(invariant());
185  //ensure(host() == xhost);
186  ensure(name() == xname);
187  ensure(is_attached());
188  ensure(!is_restricted());
189 
190 }
191 
192 
194 sec_st2(const namespace_poset* xnamespace,
195  const poset_path& xpath,
196  bool xauto_access)
197 {
198 
199  // Preconditions:
200 
201  require(precondition_of(attach_to_state(same args)));
202 
203  // Body:
204 
205  attach_to_state(xnamespace, xpath, xauto_access);
206 
207  // Postconditions:
208 
209  ensure(postcondition_of(attach_to_state(same args)));
210 
211  // Exit:
212 
213  return;
214 }
215 
216 
219 {
220 
221  // Preconditions:
222 
223  require(xother != 0);
224 
225  // Body:
226 
227  attach_to_state(xother);
228 
229  // Postconditions:
230 
231  ensure(invariant());
232  ensure(is_attached());
233  ensure(is_same_state(xother));
234  ensure(is_same_restriction(xother));
235 
236 }
237 
239 sec_st2(sec_rep_space* xhost, section_dof_map* xdof_map, bool xauto_access)
240 {
241 
242  // Preconditions:
243 
244  require(precondition_of(new_jim_state(xhost, xdof_map, false, xauto_access)));
245 
246  // Body:
247 
248  new_jim_state(xhost, xdof_map, false, xauto_access);
249 
250  // Postconditions:
251 
252  ensure(postcondition_of(new_jim_state(xhost, xdof_map, false, xauto_access)));
253 
254  // Exit:
255 
256  return;
257 }
258 
261  abstract_poset_member& xbase_mbr,
262  int xbase_version, bool xauto_access)
263 {
264 
265  // Preconditions:
266 
267  require(precondition_of(new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access)));
268 
269  // Body:
270 
271  new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access);
272 
273  // Postconditions:
274 
275  ensure(postcondition_of(new_jim_state(xhost, xbase_mbr, xbase_version, xauto_access)));
276 
277  // Exit:
278 
279  return;
280 }
281 
285 {
286  // Preconditions:
287 
288  require(is_ancestor_of(&xother));
289  require(precondition_of(attach_to_state(&xother)));
290 
291  // Body:
292 
293  attach_to_state(&xother);
294 
295  // Postconditions:
296 
297  ensure(postcondition_of(attach_to_state(&xother)));
298 
299  // Exit:
300 
301  return *this;
302 }
303 
306 operator=(const sec_st2& xother)
307 {
308  // Preconditions:
309 
310  require(precondition_of(attach_to_state(&xother)));
311 
312  // Body:
313 
314  attach_to_state(&xother);
315 
316  // Postconditions:
317 
318  ensure(postcondition_of(attach_to_state(&xother)));
319 
320  // Exit:
321 
322  return *this;
323 }
324 
327 operator=(const st2& xfiber)
328 {
329  // Preconditions:
330 
331  require(precondition_of(sec_vd::operator=(xfiber)));
332 
333  // Body:
334 
335  sec_vd::operator=(xfiber);
336 
337  // Postconditions:
338 
339  ensure(postcondition_of(sec_vd::operator=(xfiber)));
340 
341  // Exit:
342 
343  return *this;
344 }
345 
348 operator=(const st2_lite& xfiber)
349 {
350  // Preconditions:
351 
352  require(precondition_of(sec_vd::operator=(xfiber)));
353 
354  // Body:
355 
356  sec_vd::operator=(xfiber);
357 
358  // Postconditions:
359 
360  ensure(postcondition_of(sec_vd::operator=(xfiber)));
361 
362  // Exit:
363 
364  return *this;
365 }
366 
369 {
370 
371  // Preconditions:
372 
373  // Body:
374 
375  // Postconditions:
376 
377 }
378 
382 {
383  // Preconditions:
384 
385  // Body:
386 
387  static const fiber_type result;
388 
389  // Postconditions:
390 
391  // Exit:
392 
393  return result;
394 }
395 
396 // PROTECTED MEMBER FUNCTIONS
397 
398 // PRIVATE MEMBER FUNCTIONS
399 
400 
401 //==============================================================================
402 // STP FACET OF CLASS SEC_ST2
403 //==============================================================================
404 
405 // PUBLIC MEMBER FUNCTIONS
406 
407 // PROTECTED MEMBER FUNCTIONS
408 
409 // PRIVATE MEMBER FUNCTIONS
410 
411 
412 //==============================================================================
413 // TP FACET OF CLASS SEC_ST2
414 //==============================================================================
415 
416 // PUBLIC MEMBER FUNCTIONS
417 
418 // PROTECTED MEMBER FUNCTIONS
419 
420 // PRIVATE MEMBER FUNCTIONS
421 
422 
423 //==============================================================================
424 // VD FACET OF CLASS SEC_ST2
425 //==============================================================================
426 
427 // PUBLIC MEMBER FUNCTIONS
428 
429 // PROTECTED MEMBER FUNCTIONS
430 
431 // PRIVATE MEMBER FUNCTIONS
432 
433 
434 //==============================================================================
435 // TUPLE FACET OF CLASS SEC_ST2
436 //==============================================================================
437 
438 // PUBLIC MEMBER FUNCTIONS
439 
440 // PROTECTED MEMBER FUNCTIONS
441 
442 // PRIVATE MEMBER FUNCTIONS
443 
444 
445 //==============================================================================
446 // ABSTRACT POSET MEMBER FACET OF CLASS SEC_ST2
447 //==============================================================================
448 
449 // PUBLIC MEMBER FUNCTIONS
450 
451 const std::string&
453 class_name() const
454 {
455  // Preconditions:
456 
457  // Body:
458 
459  const string& result = static_class_name();
460 
461  // Postconditions:
462 
463  ensure(!result.empty());
464 
465  // Exit:
466 
467  return result;
468 }
469 
470 const std::string&
473 {
474  // Preconditions:
475 
476  // Body:
477 
478  static const string result("sec_st2");
479 
480  // Postconditions:
481 
482  ensure(!result.empty());
483 
484  // Exit:
485 
486  return result;
487 }
488 
491 clone() const
492 {
493 
494  // Preconditions:
495 
496  // Body:
497 
498  // create new handle of the current class.
499 
500  sec_st2 *result = new sec_st2();
501 
502  // Postconditions:
503 
504  ensure(result != 0);
505  ensure(result->invariant());
506 
507  // Exit:
508 
509  return result;
510 
511 }
512 
513 // PROTECTED MEMBER FUNCTIONS
514 
515 // PRIVATE MEMBER FUNCTIONS
516 
517 
518 //==============================================================================
519 // ANY FACET OF CLASS SEC_ST2
520 //==============================================================================
521 
522 // PUBLIC MEMBER FUNCTIONS
523 
524 bool
526 fiber_is_ancestor_of(const any* xother) const
527 {
528 
529  // Preconditions:
530 
531  require(xother != 0);
532 
533  // Body:
534 
535  // If xother may be dynamically cast to the type of this fiber then this
536  // fiber is an ancestor of xother.
537 
538  bool result = dynamic_cast<const st2*>(xother) != 0;
539 
540  // Postconditions:
541 
542  ensure(invariant());
543  ensure(xother->invariant());
544 
545  // Exit:
546 
547  return result;
548 
549 }
550 
551 bool
553 is_ancestor_of(const any* xother) const
554 {
555  // Preconditions:
556 
557  require(xother != 0);
558 
559  // Body:
560 
561  // If other may be dynamically cast to the type of this then this is an
562  // ancestor of other.
563 
564  bool result = dynamic_cast<const sec_st2*>(xother) != 0;
565 
566  // Postconditions:
567 
568  //ensure(invariant());
569 
570  // Exit:
571 
572  return result;
573 
574 }
575 
576 bool
578 invariant() const
579 {
580  bool result = true;
581 
582  // Preconditions:
583 
584  // Body:
585 
586  // Must satisfy base class invariant
587 
588  invariance(sec_stp::invariant());
589 
590  if (invariant_check())
591  {
592  // Prevent recursive calls to invariant
593 
594  disable_invariant_check();
595 
596  invariance(is_attached() ? p() == 2 : true);
597 
598  // Finished, turn invariant checking back on.
599 
600  enable_invariant_check();
601  }
602 
603  // Postconditions:
604 
605  ensure(is_derived_query);
606 
607  // Exit:
608 
609  return result;
610 }
611 
612 // PROTECTED MEMBER FUNCTIONS
613 
614 // PRIVATE MEMBER FUNCTIONS
615 
616 //==============================================================================
617 // NON-MEMBER FUNCTIONS
618 //==============================================================================
619 
620 namespace
621 {
622  using namespace fiber_bundle::st2_algebra;
623 
624  class trace_functor
625  {
626  public:
627  void operator()(const st2_lite& xl0, at0_lite& xlresult) const
628  {
629  xlresult = trace(xl0);
630  }
631  };
632 
633 } //end unnamed namespace
634 
635 //==============================================================================
636 //==============================================================================
637 
638 #include "SheafSystem/sec_at0.h"
639 #include "SheafSystem/sec_st2_e2.h"
640 #include "SheafSystem/sec_st2_e3.h"
641 #include "SheafSystem/sec_vd.impl.h"
642 
643 using namespace fiber_bundle::sec_vd_algebra;
644 
645 void
647 trace(const sec_st2& x0, sec_at0& xresult, bool xauto_access)
648 {
649  // Preconditions:
650 
651  require(x0.state_is_auto_read_accessible(xauto_access));
652  require(xresult.state_is_auto_read_write_accessible(xauto_access));
653 
654  // Body:
655 
656  unary_op(x0, xresult, trace_functor(), xauto_access);
657 
658  // Postconditions:
659 
660  // Exit:
661 
662  return;
663 }
664 
665 void
667 determinant(const sec_st2& x0, sec_at0& xresult, bool xauto_access)
668 {
669  // Preconditions:
670 
671  require(x0.state_is_auto_read_accessible(xauto_access));
672  require(xresult.state_is_auto_read_write_accessible(xauto_access));
673 
674  // Body:
675 
676  //unary_op(x0, xresult, determinant_functor(), xauto_access);
677 
678  const sec_st2_e2* st2_e2_x0 = dynamic_cast<const sec_st2_e2*>(&x0);
679  const sec_st2_e3* st2_e3_x0 = dynamic_cast<const sec_st2_e3*>(&x0);
680 
681  if(st2_e2_x0)
682  {
683  determinant(*st2_e2_x0, xresult, xauto_access);
684  }
685  else if(st2_e3_x0)
686  {
687  determinant(*st2_e3_x0, xresult, xauto_access);
688  }
689  else
690  {
691  post_fatal_error_message(\
692  "Unsupported argument types in call to determinant(...)");
693  }
694 
695  // Postconditions:
696 
697  // Exit:
698 
699  return;
700 }
701 
702 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
static int factor_ct(int xd)
Factor_ct() as a function of dimension xd.
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 ...
An abstract symmetric tensor section space of degree p.
Definition: sec_stp_space.h:47
SHEAF_DLL_SPEC void trace(const sec_st2 &x0, sec_at0 &xresult, bool xauto_access)
The trace of x0.
Definition: sec_st2.cc:647
SHEAF_DLL_SPEC void determinant(const sec_st2 &x0, sec_at0 &xresult, bool xauto_access)
The determinant of x0.
Definition: sec_st2.cc:667
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual sec_st2 * clone() const
Make a new handle, no state instance of current.
Definition: sec_st2.cc:491
A Cartesian product section space.
The abstract map from section dof ids to section dof values of heterogeneous type.
poset_path path(bool xauto_access=true) const
A path to this component.
The default name space; a poset which contains other posets as members.
virtual sec_st2 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: sec_st2.cc:284
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void unary_op(const S0 &x0, SR &xresult, F xfunctor, bool xauto_access)
Unary operator.
Definition: sec_vd.impl.h:224
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...
~sec_st2()
Destructor.
Definition: sec_st2.cc:368
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
bool invariant() const
Class invariant.
Definition: sec_st2.cc:578
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
A member of a sec_rep_space; a section.
A section of a bundle with fiber type st2_e2.
Definition: sec_st2_e2.h:48
poset_path vector_space_path() const
The path of the underlying vector space.
STL namespace.
A schema poset for a section space. A binary Cartesian product subspace of the binary tensor product ...
virtual const fiber_type & fiber_prototype() const
Virtual constructor for the associated fiber type.
Definition: sec_st2.cc:381
static const std::string & static_class_name()
The name of this class.
Definition: sec_st2.cc:472
virtual const std::string & class_name() const
The name of this class.
Definition: sec_st2.cc:453
SHEAF_DLL_SPEC void determinant(const st2 &x0, vd_value_type &xresult, bool xauto_access)
The determinant of a symmetric tensor (pre-allocated version for persistent types).
Definition: st2.cc:1228
SHEAF_DLL_SPEC void trace(const st2 &x0, vd_value_type &xresult, bool xauto_access)
The trace of a symmetric tensor (pre-allocated version for persistent types).
Definition: st2.cc:1116
sec_st2()
Default constructor.
Definition: sec_st2.cc:112
Abstract base class with useful features for all objects.
Definition: any.h:39
int p() const
The tensor degree of this space.
A general symmetric tensor of degree 2 over an abstract vector space (volatile version).
Definition: st2.h:43
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
virtual int d(int xp, int xdd) const
Dimension d() as a function of degree xp and domain dimension xdd.
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)
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
A section of a bundle with fiber type st2.
Definition: sec_st2.h:46
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
Antisymetric tensor of degree 0 (volatile version).
Definition: at0.h:127
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
int dd() const
The dimension of the underlying ("domain") vector space.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
bool is_ancestor_of(const any *xother) const
True if xother conforms to current.
Definition: sec_st2.cc:553
bool fiber_is_ancestor_of(const any *xother) const
True if xother conforms to an instance of the fiber of current.
Definition: sec_st2.cc:526
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
poset_path scalar_space_path() const
The path of the underlying space of scalars.
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
Namespace containing the algrebra functions for a a section of a fiber bundle with a d-dimensional ve...
Definition: sec_vd.h:691
An abstract client handle for a member of a poset.
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, const poset_path &xscalar_space_path, bool xauto_access)
Creates a new host table for members of this type. The poset is created in namespace xns with path xh...
Definition: sec_st2.cc:51
An abstract symmetric tensor space of degree p.
Definition: stp_space.h:42
Namespace for the fiber_bundles component of the sheaf system.
A general symmetric tensor of degree 2 over an abstract vector space (persistent version).
Definition: st2.h:234
Antisymetric tensor of degree 0. As the degree is 0 there is nothing to be symmetric or antisymmetric...
Definition: sec_at0.h:51
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...
Namespace containing the 2d symmetric tensor algrebra functions for the fiber_bundles component of th...
Definition: st2.h:512
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
A section of a bundle with fiber type st2_e3.
Definition: sec_st2_e3.h:48
A handle for a poset whose members are numerical representations of sections of a fiber bundle...
Definition: sec_rep_space.h:61