SheafSystem  0.0.0.0
sec_jcb_space.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_jcb_space.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/binary_section_space_schema_member.impl.h"
26 #include "SheafSystem/binary_section_space_schema_poset.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/namespace_poset_member.h"
29 #include "SheafSystem/poset_handle_factory.h"
30 #include "SheafSystem/sec_at1.h"
31 #include "SheafSystem/sec_at1_space.h"
32 #include "SheafSystem/sec_jcb.h"
33 #include "SheafSystem/sec_tuple_space.impl.h"
34 #include "SheafSystem/section_space_schema_member.impl.h"
35 #include "SheafSystem/section_space_schema_poset.h"
36 #include "SheafSystem/jcb.h"
37 #include "SheafSystem/jcb_space.h"
38 
39 using namespace std;
40 using namespace fiber_bundle; // Workaround for MS C++ bug.
41 
42 //#define DIAGNOSTIC_OUTPUT
43 
44 //==============================================================================
45 // SEC_JCB_SPACE FACET
46 //==============================================================================
47 
48 // PUBLIC MEMBER FUNCTIONS
49 
50 bool
53  const poset_path& xschema_path,
54  const poset_path& xdomain_path,
55  const poset_path& xrange_path,
56  bool xauto_access)
57 {
58  // cout << endl << "Entering sec_jcb_space::same_vector_fiber_space." << endl;
59 
60  // Preconditions:
61 
62  require(xns.state_is_auto_read_accessible(xauto_access));
63  require(xns.path_is_auto_read_accessible<section_space_schema_poset>(xschema_path, xauto_access));
64  require(xns.path_is_auto_read_accessible<domain_space_type::host_type>(xdomain_path, xauto_access));
65  require(xns.path_is_auto_read_accessible<range_space_type::host_type>(xrange_path, xauto_access));
66 
67  // Body:
68 
69  section_space_schema_poset& lschema_host = xns.member_poset<section_space_schema_poset>(xschema_path, xauto_access);
70  domain_space_type::host_type& ldomain_host = xns.member_poset<domain_space_type::host_type>(xdomain_path, xauto_access);
71  range_space_type::host_type& lrange_host = xns.member_poset<range_space_type::host_type>(xrange_path, xauto_access);
72 
73  fiber_type::host_type* lfiber_space = dynamic_cast<fiber_type::host_type*>(&lschema_host.fiber_space());
74  bool result = false;
75  if(lfiber_space != 0)
76  {
77  result =
78  (lfiber_space->domain_path(xauto_access) == ldomain_host.schema().fiber_space().path(xauto_access)) &&
79  (lfiber_space->range_path(xauto_access) == lrange_host.schema().fiber_space().path(xauto_access));
80  }
81 
82  // Postconditions:
83 
84 
85  // Exit:
86 
87  // cout << "Leaving sec_jcb_space::same_vector_fiber_space." << endl;
88  return result;
89 }
90 
91 
95  const poset_path& xpath,
96  const poset_path& xschema_path,
97  const poset_path& xdomain_path,
98  const poset_path& xrange_path,
99  bool xauto_access)
100 {
101  // cout << endl << "Entering sec_jcb_space::new_table." << endl;
102 
103  // Preconditions:
104 
105 
106  require(!xpath.empty());
107  require(!xns.contains_path(xpath, xauto_access));
108 
109  require(xschema_path.full());
110  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
111  require(fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
112 
113  require(xns.path_is_auto_read_accessible<domain_space_type::host_type>(xdomain_path, xauto_access));
114  require(xns.path_is_auto_read_accessible<range_space_type::host_type>(xrange_path, xauto_access));
115 
116  require(same_vector_fiber_space(xns, xschema_path, xdomain_path, xrange_path, xauto_access));
117 
118  // Body:
119 
120  // Create the table; have to new it because namespace keeps a pointer.
121 
122  typedef sec_jcb_space table_type;
123 
124  table_type& result = *(new table_type());
125 
126  // Create a handle of the right type for the schema member.
127 
128  schema_type lschema(xns, xschema_path, xauto_access);
129 
130  if(xauto_access)
131  {
132  lschema.get_read_access();
133  }
134 
135  // Get the section scalar space path from the section vector space.
136 
137  poset_path lscalar_space_path =
138  xns.member_poset<domain_space_type::host_type>(xdomain_path, xauto_access).scalar_space_path(xauto_access);
139 
140  // Create the table dof map.
141 
142  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
143 
144  // The table dofs are mostly the same as the fiber schema,
145  // so just copy them from the fiber schema.
146  // Can't use copy constructor because schema objects are different.
147 
148  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
149  lmap.copy_dof_tuple(lfiber_map);
150 
151  // Replace the fiber scalar space path with the section scalar space path.
152 
153  lmap.put_dof("scalar_space_path", lscalar_space_path);
154 
155  // Replace the fiber domain space path with the section domain space path.
156 
157  lmap.put_dof("domain_path", xdomain_path);
158 
159  // Replace the fiber range space path with the section range space path.
160 
161  lmap.put_dof("range_path", xrange_path);
162 
163  // Create the state.
164 
165  result.new_state(xns, xpath, lschema, lmap);
166 
167  if(xauto_access)
168  {
169  lschema.release_access();
170  }
171 
172  // Postconditions:
173 
174  ensure(xns.owns(result, xauto_access));
175  ensure(result.path(true) == xpath);
176  ensure(result.state_is_not_read_accessible());
177  ensure(result.schema(true).path(xauto_access) == xschema_path);
178 
179  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
180  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
181  ensure(result.scalar_space_path(true) ==
182  xns.member_poset<domain_space_type::host_type>(xdomain_path, xauto_access).scalar_space_path(xauto_access));
183  ensure(result.scalar_space_path(true) ==
184  xns.member_poset<range_space_type::host_type>(xrange_path, xauto_access).scalar_space_path(xauto_access));
185  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
186  ensure(result.dr(true) == result.schema(true).fiber_space<fiber_type::host_type>().dr(xauto_access));
187  ensure(result.domain_path(true) == xdomain_path);
188  ensure(result.range_path(true) == xrange_path);
189 
190  // Exit:
191 
192  // cout << "Leaving sec_jcb_space::new_table." << endl;
193  return result;
194 }
195 
196 //==============================================================================
197 // TABLE DOFS
198 //==============================================================================
199 
200 int
202 d(int xdd, int xdr)
203 {
204  return xdd*xdr;
205 }
206 
207 int
209 dd() const
210 {
211  // Preconditions:
212 
213  require(state_is_read_accessible());
214 
215  // Body:
216 
217  int result = sheaf::table_dofs(*this).dd;
218 
219  // Postconditions:
220 
221  // Exit:
222 
223  return result;
224 }
225 
226 int
228 dd(bool xauto_access) const
229 {
230  // Preconditions:
231 
232  require(state_is_auto_read_accessible(xauto_access));
233 
234  // Body:
235 
236  if(xauto_access)
237  {
238  get_read_access();
239  }
240 
241  int result = sheaf::table_dofs(*this).dd;
242 
243  if(xauto_access)
244  {
245  release_access();
246  }
247 
248  // Postconditions:
249 
250  // Exit:
251 
252  return result;
253 }
254 
257 domain_path() const
258 {
259  // Preconditions:
260 
261  require(state_is_read_accessible());
262 
263  // Body:
264 
265  poset_path result(sheaf::table_dofs(*this).domain_path);
266 
267  // Postconditions:
268 
269  ensure(!result.empty());
270 
271  // Exit:
272 
273  return result;
274 }
275 
278 domain_path(bool xauto_access) const
279 {
280  // Preconditions:
281 
282  require(state_is_auto_read_accessible(xauto_access));
283 
284  // Body:
285 
286  if(xauto_access)
287  {
288  get_read_access();
289  }
290 
291  poset_path result(sheaf::table_dofs(*this).domain_path);
292 
293  if(xauto_access)
294  {
295  release_access();
296  }
297 
298  // Postconditions:
299 
300  ensure(!result.empty());
301 
302  // Exit:
303 
304  return result;
305 }
306 
307 int
309 dr() const
310 {
311  // Preconditions:
312 
313  require(state_is_read_accessible());
314 
315  // Body:
316 
317  int result = sheaf::table_dofs(*this).dr;
318 
319  // Postconditions:
320 
321  // Exit:
322 
323  return result;
324 }
325 
326 int
328 dr(bool xauto_access) const
329 {
330  // Preconditions:
331 
332  require(state_is_auto_read_accessible(xauto_access));
333 
334  // Body:
335 
336  if(xauto_access)
337  {
338  get_read_access();
339  }
340 
341  int result = sheaf::table_dofs(*this).dr;
342 
343  if(xauto_access)
344  {
345  release_access();
346  }
347 
348  // Postconditions:
349 
350  // Exit:
351 
352  return result;
353 }
354 
357 range_path() const
358 {
359  // Preconditions:
360 
361  require(state_is_read_accessible());
362 
363  // Body:
364 
365  poset_path result(sheaf::table_dofs(*this).range_path);
366 
367  // Postconditions:
368 
369  ensure(!result.empty());
370 
371  // Exit:
372 
373  return result;
374 }
375 
378 range_path(bool xauto_access) const
379 {
380  // Preconditions:
381 
382  require(state_is_auto_read_accessible(xauto_access));
383 
384  // Body:
385 
386  if(xauto_access)
387  {
388  get_read_access();
389  }
390 
391  poset_path result(sheaf::table_dofs(*this).range_path);
392 
393  if(xauto_access)
394  {
395  release_access();
396  }
397 
398  // Postconditions:
399 
400  ensure(!result.empty());
401 
402  // Exit:
403 
404  return result;
405 }
406 
407 // PROTECTED MEMBER FUNCTIONS
408 
411  : sec_vd_space(new sec_jcb, new sec_jcb)
412 {
413  // Preconditions:
414 
415  // Body:
416 
417  // Nothing to do, handled by base class
418 
419  // Postconditions:
420 
421  ensure(postcondition_of(sec_vd_space::sec_vd_space()));
422 }
423 
426 {
427  // Preconditions:
428 
429  // Body:
430 
431  // Postconditions:
432 
433  // Exit
434 
435  return;
436 }
437 
439 sec_jcb_space(sec_jcb* xtop, sec_jcb* xbottom)
440  : sec_vd_space(xtop, xbottom)
441 {
442  // Preconditions:
443 
444  require(xtop != 0);
445  require(xbottom != 0);
446 
447  // Body:
448 
449  // Nothing to do.
450 
451  // Postconditions:
452 
453  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
454 
455  // Exit:
456 
457  return;
458 }
459 
460 // PRIVATE MEMBER FUNCTIONS
461 
462 
463 // ===========================================================
464 // SEC_VD_SPACE FACET
465 // ===========================================================
466 
467 // PUBLIC MEMBER FUNCTIONS
468 
469 // PROTECTED MEMBER FUNCTIONS
470 
471 // PRIVATE MEMBER FUNCTIONS
472 
473 
474 // ===========================================================
475 // SEC_TUPLE_SPACE FACET
476 // ===========================================================
477 
478 // PUBLIC MEMBER FUNCTIONS
479 
480 // PROTECTED MEMBER FUNCTIONS
481 
482 // PRIVATE MEMBER FUNCTIONS
483 
484 
485 // ===========================================================
486 // SEC_REP_SPACE FACET
487 // ===========================================================
488 
489 // PUBLIC MEMBER FUNCTIONS
490 
491 // PROTECTED MEMBER FUNCTIONS
492 
493 // PRIVATE MEMBER FUNCTIONS
494 
495 bool
496 fiber_bundle::sec_jcb_space::
497 make_prototype()
498 {
499  bool result = false;
500 
501  // Preconditions:
502 
503  // Body:
504 
505  sec_jcb_space* lproto = new sec_jcb_space;
506  poset_type ltype = lproto->type_id();
507 
508  factory().insert_prototype(lproto);
509  factory().insert_prototype(ltype, lproto);
510 
511  // Postconditions:
512 
513  // Exit:
514 
515  return result;
516 }
517 
518 
519 //==============================================================================
520 // POSET_STATE_HANDLE FACET
521 //==============================================================================
522 
523 // PUBLIC MEMBER FUNCTIONS
524 
527 type_id() const
528 {
529  return SEC_JCB_SPACE_ID;
530 }
531 
534 
535 const char*
537 class_name() const
538 {
539  // Preconditions:
540 
541  // Body:
542 
543  static const char* result = "sec_jcb_space";
544 
545  // Postconditions:
546 
547  // Exit:
548 
549  return result;
550 }
551 
554 prereq_id(int xi) const
555 {
556  // Preconditions:
557 
558  require(state_is_read_accessible());
559  require(name_space()->state_is_read_accessible());
560 
561  // Body:
562 
563  pod_index_type result;
564 
565  switch(xi)
566  {
567  case 0:
568 
569  // The first prerequisite is always the schema.
570 
571  result = schema().host()->index().pod();
572  break;
573 
574  case 1:
575 
576  // The domain vector space.
577 
578  result = name_space()->member_id(domain_path().poset_name(), false);
579  break;
580 
581  case 2:
582 
583  // The range vector space.
584 
585  result = name_space()->member_id(range_path().poset_name(), false);
586  break;
587 
588  default:
589 
590  // No other prerequisites.
591 
592  result = invalid_pod_index();
593  break;
594  }
595 
596  // Postconditions:
597 
598  // Exit:
599 
600  return result;
601 }
602 
603 // PROTECTED MEMBER FUNCTIONS
604 
605 // PRIVATE MEMBER FUNCTIONS
606 
607 
608 //==============================================================================
609 // READ_WRITE_MONITOR_HANDLE FACET
610 //==============================================================================
611 
612 // PUBLIC MEMBER FUNCTIONS
613 
614 // PROTECTED MEMBER FUNCTIONS
615 
616 // PRIVATE MEMBER FUNCTIONS
617 
618 
619 //==============================================================================
620 // ANY FACET
621 //==============================================================================
622 
623 // PUBLIC MEMBER FUNCTIONS
624 
625 bool
627 is_ancestor_of(const any* xother) const
628 {
629  bool result;
630 
631  // Preconditions:
632 
633  // Body:
634 
635  result = dynamic_cast<const sec_jcb_space*>(xother) != 0;
636 
637  // Postconditions:
638 
639  // Exit
640 
641  return result;
642 }
643 
646 clone() const
647 {
648  sec_jcb_space* result;
649 
650  // Preconditions:
651 
652  // Body:
653 
654  result = new sec_jcb_space;
655 
656  // Postconditions:
657 
658  ensure(result != 0);
659  ensure(is_same_type(result));
660  ensure(!result->is_attached());
661 
662  // Exit
663 
664  return result;
665 }
666 
667 bool
669 invariant() const
670 {
671  bool result = true;
672 
673 
674  if(invariant_check())
675  {
677 
678  invariance(sec_vd_space::invariant());
679 
680  invariance(state_is_read_accessible() ? factor_ct() == d() : true);
681 
683  }
684 
685  return result;
686 }
687 
688 // PROTECTED MEMBER FUNCTIONS
689 
690 // PRIVATE MEMBER FUNCTIONS
691 
692 
693 
virtual sec_jcb_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
virtual poset_path path(bool xauto_access=true) const
The path of this poset.
virtual poset_type type_id() const
Identifier for the type of this poset.
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
A client handle for a poset member which has been prepared for use as a schema for a section space...
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
poset_path range_path() const
The path of the range vector space.
static bool same_vector_fiber_space(const namespace_poset &xns, const poset_path &xschema_path, const poset_path &xdomain_path, const poset_path &xrange_path, bool xauto_access)
True if and only if domain space of fiber space == fiber space of domain space and the range space of...
const scoped_index & index() const
The member index of this poset within the namespace host()
A space of scalars viewed as an antisymmetric tensor section space of degree 1.
Definition: sec_at1_space.h:48
poset_path domain_path() const
The path of the domain vector space.
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
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...
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
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...
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
virtual bool invariant() const
Class invariant.
STL namespace.
A schema poset for a section space. A binary Cartesian product subspace of the binary tensor product ...
An abstract vector section space of dimension d.
Definition: sec_vd_space.h:52
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
virtual bool invariant() const
Class invariant.
virtual void get_read_access() const
Get read access to the state associated with this.
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
void copy_dof_tuple(const poset_dof_map &xother)
Copies the dof tuple of xother into this.
virtual const char * class_name() const
The name of this class.
sec_jcb_space()
Default constructor; creates a new sec_jcb_space handle not attached to any state.
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
Abstract base class with useful features for all objects.
Definition: any.h:39
poset & fiber_space()
The fiber space for section spaces on this schema.
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
virtual ~sec_jcb_space()
Destructor.
virtual int dr() const
Dimension of the range.
int dd() const
The dimension of the underlying ("domain") vector space.
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)
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
poset_state_handle()
Default constructor.
sec_vd_space()
Default constructor; creates a new sec_vd_space handle not attached to any state. ...
static poset_handle_factory & factory()
The poset handle factory.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
int factor_ct() const
The number of factors in this product.
A section of a bundle with fiber type jcb.
Definition: sec_jcb.h:49
An abstract schema poset for a section space. A Cartesian product subspace of the tensor product of a...
virtual void put_dof(pod_index_type xdof_id, const void *xdof, size_type xdof_size)
Sets the dof referred to by xdof_id to the value at xdof.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
An abstract space of Jacobians.
Definition: jcb_space.h:46
T::table_dofs_type & table_dofs(T &x0)
The table dofs pod type for x0 (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
An abstract section space of Jacobians.
Definition: sec_jcb_space.h:53
int d() const
The dimension.
An array representation of abstract class poset_dof_map.
static sec_jcb_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, const poset_path &xdomain_path, const poset_path &xrange_path, bool xauto_access)
Creates a new sec_jcb_space in namespace xns with path xpath, schema specified by xschema_path...
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
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 array_poset_dof_map & table_dof_map(bool xrequire_write_access=false)
The map from table dof client_ids to table dof values for this poset (mutable version) ...
virtual const scoped_index & member_id(bool xauto_access) const
An id in the member hub id space; intended for copying to initialize ids to the member id space...