SheafSystem  0.0.0.0
jcb_space.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 // Implementation for class jcb_space.
19 
20 #include "SheafSystem/jcb_space.h"
21 
22 #include "SheafSystem/abstract_poset_member.impl.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/at0_space.h"
25 #include "SheafSystem/at1.h"
26 #include "SheafSystem/at1_space.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/namespace_poset.impl.h"
29 #include "SheafSystem/namespace_poset_member.h"
30 #include "SheafSystem/poset_handle_factory.h"
31 #include "SheafSystem/jcb.h"
32 
33 using namespace std;
34 using namespace fiber_bundle; // Workaround for MS C++ bug.
35 
36 //#define DIAGNOSTIC_OUTPUT
37 
38 //==============================================================================
39 // JCB_SPACE FACET public member functions
40 //==============================================================================
41 
43 const std::string&
46 {
47  // Preconditions:
48 
49 
50  // Body:
51 
52  static const string& result = jcb::standard_schema_poset_name();
53 
54  // Postconditions:
55 
56  ensure(!result.empty());
57 
58  // Exit:
59 
60  return result;
61 }
62 
64 const sheaf::poset_path&
67 {
68  // Preconditions:
69 
70 
71  // Body:
72 
73  static const poset_path& result = jcb::standard_schema_path();
74 
75  // Postconditions:
76 
77  ensure(result.full());
78  ensure(result.poset_name() == standard_schema_poset_name());
79 
80  // Exit:
81 
82  return result;
83 }
84 
85 int
87 d(const namespace_poset& xns, const poset_path& xschema_path, bool xauto_access)
88 {
89  // Preconditions:
90 
91  require(xschema_path.full());
92  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
93 
94  // Body:
95 
96  int result = schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access);
97 
98  // Postconditions:
99 
100  ensure(result == schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access));
101 
102  // Exit:
103 
104  return result;
105 }
106 
107 int
109 d(const namespace_poset& xns, const poset_path& xdomain_space_path, const poset_path& xrange_space_path, bool xauto_access)
110 {
111  // Preconditions:
112 
113  require(xns.path_is_auto_read_accessible<domain_space_type>(xdomain_space_path, xauto_access));
114  require(xns.path_is_auto_read_accessible<range_space_type>(xrange_space_path, xauto_access));
115 
116  // Body:
117 
118  int ldd = xns.member_poset<domain_space_type>(xdomain_space_path, xauto_access).d();
119  int ldr = xns.member_poset<range_space_type>(xrange_space_path, xauto_access).d();
120 
121  int result = d(ldd, ldr);
122 
123  // Postconditions:
124 
125  ensure(result >= 0);
126 
127  // Exit:
128 
129  return result;
130 }
131 
132 int
134 d(int xdd, int xdr)
135 {
136  return xdd*xdr;
137 }
138 
142  const poset_path& xpath,
143  const poset_path& xschema_path,
144  const poset_path& xdomain_path,
145  const poset_path& xrange_path,
146  bool xauto_access)
147 {
148  // cout << endl << "Entering jcb_space::new_table." << endl;
149 
150  // Preconditions:
151 
152  require(xns.state_is_auto_read_write_accessible(xauto_access));
153 
154  require(!xpath.empty());
155  require(!xns.contains_path(xpath, xauto_access));
156 
157  require(xschema_path.full());
158  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
159  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
160 
161  require(xns.path_is_auto_read_accessible<domain_space_type>(xdomain_path, xauto_access));
162  require(xns.path_is_auto_read_accessible<range_space_type>(xrange_path, xauto_access));
163 
164  require(d(xns, xschema_path, xauto_access) == d(xns, xdomain_path, xrange_path, xauto_access));
165 
166  require(xns.member_poset<domain_space_type>(xdomain_path, xauto_access).scalar_space_path(xauto_access) ==
167  xns.member_poset<range_space_type>(xrange_path, xauto_access).scalar_space_path(xauto_access));
168 
169  // Body:
170 
171  // Create the table; have to new it because namespace keeps a pointer.
172 
173  typedef jcb_space table_type;
174 
175  table_type* ltable = new table_type();
176 
177  // Create a handle of the right type for the schema member.
178 
179  schema_poset_member lschema(&xns, xschema_path, xauto_access);
180 
181  if(xauto_access)
182  {
183  lschema.get_read_access();
184  }
185 
186  // Get the dimension (== number of row dofs) defined by the schema.
187 
188  int ld = lschema.row_dof_ct();
189  int ldd = xns.member_poset<domain_space_type>(xdomain_path, xauto_access).d();
190  int ldr = xns.member_poset<range_space_type>(xrange_path, xauto_access).d();
191 
192  poset_path lscalar_space_path =
193  xns.member_poset<domain_space_type>(xdomain_path, xauto_access).scalar_space_path(xauto_access);
194 
195  // Create the table dof map and set dof values;
196  // must be newed because poset_state::_table keep a pointer to it.
197 
198  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
199  lmap->put_dof("factor_ct", ld);
200  lmap->put_dof("d", ld);
201  lmap->put_dof("scalar_space_path", lscalar_space_path);
202  lmap->put_dof("domain_path", xdomain_path);
203  lmap->put_dof("dd", ldd);
204  lmap->put_dof("range_path", xrange_path);
205  lmap->put_dof("dr", ldr);
206 
207  // Create the state.
208 
209  ltable->new_state(xns, xpath, lschema, *lmap);
210 
211  if(xauto_access)
212  {
213  lschema.release_access();
214  }
215 
216  jcb_space& result = *ltable;
217 
218  // Postconditions:
219 
220  ensure(xns.owns(result, xauto_access));
221  ensure(result.path(true) == xpath);
222  ensure(result.state_is_not_read_accessible());
223  ensure(result.schema(true).path(xauto_access) == xschema_path);
224 
225  ensure(result.factor_ct(true) == result.d(true));
226  ensure(result.d(true) == d(xns, xschema_path, xauto_access));
227 
228  ensure(result.domain_path(true) == xdomain_path);
229  ensure(result.dd(true) == xns.member_poset<domain_space_type>(xdomain_path, xauto_access).d());
230 
231  ensure(result.range_path(true) == xrange_path);
232  ensure(result.dr(true) == xns.member_poset<range_space_type>(xrange_path, xauto_access).d());
233 
234  ensure(result.scalar_space_path(true) ==
235  xns.member_poset<domain_space_type>(xdomain_path, xauto_access).scalar_space_path(xauto_access) );
236  ensure(result.scalar_space_path(true) ==
237  xns.member_poset<range_space_type>(xrange_path, xauto_access).scalar_space_path(xauto_access) );
238 
239  // Exit:
240 
241  // cout << "Leaving jcb_space::new_table." << endl;
242  return result;
243 }
244 
245 
246 int
248 dd() const
249 {
250  // Preconditions:
251 
252  require(state_is_read_accessible());
253 
254  // Body:
255 
256  int result = sheaf::table_dofs(*this).dd;
257 
258  // Postconditions:
259 
260  // Exit:
261 
262  return result;
263 }
264 
265 int
267 dd(bool xauto_access) const
268 {
269  // Preconditions:
270 
271  require(state_is_auto_read_accessible(xauto_access));
272 
273  // Body:
274 
275  if(xauto_access)
276  {
277  get_read_access();
278  }
279 
280  int result = sheaf::table_dofs(*this).dd;
281 
282  if(xauto_access)
283  {
284  release_access();
285  }
286 
287  // Postconditions:
288 
289  // Exit:
290 
291  return result;
292 }
293 
296 domain_path() const
297 {
298  // Preconditions:
299 
300  require(state_is_read_accessible());
301 
302  // Body:
303 
304  poset_path result(sheaf::table_dofs(*this).domain_path);
305 
306  // Postconditions:
307 
308  ensure(!result.empty());
309 
310  // Exit:
311 
312  return result;
313 }
314 
317 domain_path(bool xauto_access) const
318 {
319  // Preconditions:
320 
321  require(state_is_auto_read_accessible(xauto_access));
322 
323  // Body:
324 
325  if(xauto_access)
326  {
327  get_read_access();
328  }
329 
330  poset_path result(sheaf::table_dofs(*this).domain_path);
331 
332  if(xauto_access)
333  {
334  release_access();
335  }
336 
337  // Postconditions:
338 
339  ensure(!result.empty());
340 
341  // Exit:
342 
343  return result;
344 }
345 
346 int
348 dr() const
349 {
350  // Preconditions:
351 
352  require(state_is_read_accessible());
353 
354  // Body:
355 
356  int result = sheaf::table_dofs(*this).dr;
357 
358  // Postconditions:
359 
360  // Exit:
361 
362  return result;
363 }
364 
365 int
367 dr(bool xauto_access) const
368 {
369  // Preconditions:
370 
371  require(state_is_auto_read_accessible(xauto_access));
372 
373  // Body:
374 
375  if(xauto_access)
376  {
377  get_read_access();
378  }
379 
380  int result = sheaf::table_dofs(*this).dr;
381 
382  if(xauto_access)
383  {
384  release_access();
385  }
386 
387  // Postconditions:
388 
389  // Exit:
390 
391  return result;
392 }
393 
396 range_path() const
397 {
398  // Preconditions:
399 
400  require(state_is_read_accessible());
401 
402  // Body:
403 
404  poset_path result(sheaf::table_dofs(*this).range_path);
405 
406  // Postconditions:
407 
408  ensure(!result.empty());
409 
410  // Exit:
411 
412  return result;
413 }
414 
417 range_path(bool xauto_access) const
418 {
419  // Preconditions:
420 
421  require(state_is_auto_read_accessible(xauto_access));
422 
423  // Body:
424 
425  if(xauto_access)
426  {
427  get_read_access();
428  }
429 
430  poset_path result(sheaf::table_dofs(*this).range_path);
431 
432  if(xauto_access)
433  {
434  release_access();
435  }
436 
437  // Postconditions:
438 
439  ensure(!result.empty());
440 
441  // Exit:
442 
443  return result;
444 }
445 
446 // ===========================================================
447 // JCB_SPACE FACET protected member functions
448 // ===========================================================
449 
452  : vd_space(new jcb, new jcb)
453 {
454  // Preconditions:
455 
456  // Body:
457 
458  // Nothing to do, handled by base class
459 
460  // Postconditions:
461 
462  ensure(postcondition_of(vd_space::vd_space()));
463 }
464 
467 {
468  // Preconditions:
469 
470  // Body:
471 
472  // Postconditions:
473 
474  // Exit
475 
476  return;
477 }
478 
480 jcb_space(jcb* xtop, jcb* xbottom)
481  : vd_space(xtop, xbottom)
482 {
483  // Preconditions:
484 
485  require(xtop != 0);
486  require(xbottom != 0);
487 
488  // Body:
489 
490  // Nothing to do.
491 
492  // Postconditions:
493 
494  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
495 
496  // Exit:
497 
498  return;
499 }
500 
501 // ===========================================================
502 // POSET FACET
503 // ===========================================================
504 
505 bool
506 fiber_bundle::jcb_space::
507 make_prototype()
508 {
509  bool result = false;
510 
511  // Preconditions:
512 
513  // Body:
514 
515 
516  jcb_space* lproto = new jcb_space;
517  poset_type ltype = lproto->type_id();
518 
519  factory().insert_prototype(lproto);
520  factory().insert_prototype(ltype, lproto);
521 
522  // Postconditions:
523 
524  // Exit:
525 
526  return result;
527 }
528 
529 //==============================================================================
530 // POSET_STATE_HANDLE FACET
531 //==============================================================================
532 
533 
534 
537 type_id() const
538 {
539  return JCB_SPACE_ID;
540 }
541 
544 
545 const char*
547 class_name() const
548 {
549  // Preconditions:
550 
551 
552  // Body:
553 
554  static const char* result = "jcb_space";
555 
556  // Postconditions:
557 
558  // Exit:
559 
560  return result;
561 }
562 
566 prereq_id(int xi) const
567 {
568  // Preconditions:
569 
570  require(state_is_read_accessible());
571  require(name_space()->state_is_read_accessible());
572 
573  // Body:
574 
575  pod_index_type result;
576 
577  switch(xi)
578  {
579  case 0:
580 
581  // The first prerequisite is always the schema.
582 
583  result = schema().host()->index().pod();
584  break;
585 
586  case 1:
587 
588  // The domain vector space.
589 
590  result = name_space()->member_id(domain_path().poset_name(), false);
591  break;
592 
593  case 2:
594 
595  // The range vector space.
596 
597  result = name_space()->member_id(range_path().poset_name(), false);
598  break;
599 
600  default:
601 
602  // No other prerequisites.
603 
604  result = invalid_pod_index();
605  break;
606  }
607 
608  // Postconditions:
609 
610 
611  // Exit:
612 
613  return result;
614 }
615 
616 //==============================================================================
617 // ANY FACET
618 //==============================================================================
619 
620 bool
622 is_ancestor_of(const any* xother) const
623 {
624  bool result;
625 
626  // Preconditions:
627 
628  // Body:
629 
630  result = dynamic_cast<const jcb_space*>(xother) != 0;
631 
632  // Postconditions:
633 
634  // Exit
635 
636  return result;
637 }
638 
641 clone() const
642 {
643  jcb_space* result;
644 
645  // Preconditions:
646 
647  // Body:
648 
649  result = new jcb_space;
650 
651  // Postconditions:
652 
653  ensure(result != 0);
654  ensure(is_same_type(result));
655  ensure(!result->is_attached());
656 
657  // Exit
658 
659  return result;
660 }
661 
662 bool
664 invariant() const
665 {
666  bool result = true;
667 
668 
669  if(invariant_check())
670  {
672 
673  invariance(vd_space::invariant());
674 
675  invariance(state_is_read_accessible() ? factor_ct() == d() : true);
676 
678  }
679 
680  return result;
681 }
682 
683 
poset_state_handle * host() const
The poset which this is a handle to a component of.
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 ...
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
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
virtual const char * class_name() const
The name of this class.
Definition: jcb_space.cc:547
static 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 jcb_space in namespace xns with path xpath, schema specified by xschema_path, and table attributes domain_path, range_path, and scalar_space_path specified by xdomain_path and xrange_path, respectively.
Definition: jcb_space.cc:141
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: jcb_space.cc:45
const scoped_index & index() const
The member index of this poset within the namespace host()
int dd() const
The dimension of the underlying ("domain") vector space.
Definition: jcb_space.cc:248
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.
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
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 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.
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
Definition: jcb_space.cc:566
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
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
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)
std::string poset_name() const
The poset name part of the path.
Definition: poset_path.cc:473
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
static int row_dof_ct(const namespace_poset &xns, const poset_path &xpath, bool xauto_access=true)
The number of row dofs defined by the schema specified by xns and xpath. Synonym for dof_ct(xns...
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.
poset_path domain_path() const
The path of the domain vector space.
Definition: jcb_space.cc:296
Abstract jacobian class.
Definition: jcb.h:229
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
jcb_space()
Default constructor; creates a new jcb_space handle not attached to any state.
Definition: jcb_space.cc:451
static poset_handle_factory & factory()
The poset handle factory.
int d() const
The dimension.
Definition: vd_space.cc:174
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
An abstract vector space viewed as an antisymmetric tensor space of degree 1.
Definition: at1_space.h:42
static int d(const namespace_poset &xns, const poset_path &xschema_path, bool xauto_access)
The jacobian dimension implied by the schema specified by xschema_path.
Definition: jcb_space.cc:87
An abstract vector space of dimension d.
Definition: vd_space.h:47
virtual jcb_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: jcb_space.cc:641
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
poset_path range_path() const
The path of the range vector space.
Definition: jcb_space.cc:396
An abstract space of Jacobians.
Definition: jcb_space.h:46
static int factor_ct(int xd)
Factor_ct() as a function of dimension xd.
Definition: vd_space.cc:167
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
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: jcb_space.cc:537
virtual bool invariant() const
Class invariant.
Definition: vd_space.cc:938
virtual ~jcb_space()
Destructor.
Definition: jcb_space.cc:466
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: jcb_space.cc:66
virtual int dr() const
Dimension of the range.
Definition: jcb_space.cc:348
vd_space()
Default constructor; creates a new vd_space handle not attached to any state.
Definition: vd_space.cc:626
An array representation of abstract class poset_dof_map.
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
virtual bool invariant() const
Class invariant.
Definition: jcb_space.cc:664
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
int factor_ct() const
The number of factors in this product.
Definition: tuple_space.cc:152
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: jcb_space.cc:622
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...
A client handle for a poset member which has been prepared for use as a schema.
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...