SheafSystem  0.0.0.0
gln_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 gln_space.
19 
20 #include "SheafSystem/gln_space.h"
21 
22 #include "SheafSystem/abstract_poset_member.impl.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/gln.h"
25 #include "SheafSystem/namespace_poset.impl.h"
26 #include "SheafSystem/namespace_poset_member.h"
27 #include "SheafSystem/poset_handle_factory.h"
28 #include "SheafSystem/vd_space.h"
29 
30 using namespace std;
31 using namespace fiber_bundle; // Workaround for MS C++ bug.
32 
33 //#define DIAGNOSTIC_OUTPUT
34 
35 //==============================================================================
36 // GLN_SPACE FACET
37 //==============================================================================
38 
40 const std::string&
43 {
44  // Preconditions:
45 
46 
47  // Body:
48 
49  static const string& result = gln::standard_schema_poset_name();
50 
51  // Postconditions:
52 
53  ensure(!result.empty());
54 
55  // Exit:
56 
57  return result;
58 }
59 
61 const sheaf::poset_path&
64 {
65  // Preconditions:
66 
67 
68  // Body:
69 
70  static const poset_path& result = gln::standard_schema_path();
71 
72  // Postconditions:
73 
74  ensure(result.full());
75  ensure(result.poset_name() == standard_schema_poset_name());
76 
77  // Exit:
78 
79  return result;
80 }
81 
82 int
84 d(const namespace_poset& xns,const poset_path& xvector_space_path, bool xauto_access)
85 {
86  // Preconditions:
87 
88  require(xns.path_is_auto_read_accessible<vector_space_type>(xvector_space_path, xauto_access));
89 
90  // Body:
91 
92  int ln = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d();
93 
94  int result = d(ln);
95 
96  // Postconditions:
97 
98  ensure(result >= 0);
99 
100  // Exit:
101 
102  return result;
103 }
104 
105 int
107 d(int xn)
108 {
109  return 2*xn*xn;
110 }
111 
115  const poset_path& xpath,
116  const poset_path& xschema_path,
117  const poset_path& xvector_space_path,
118  bool xauto_access)
119 {
120  // cout << endl << "Entering gln_space::new_table." << endl;
121 
122  // Preconditions:
123 
124  require(xns.state_is_auto_read_write_accessible(xauto_access));
125 
126  require(!xpath.empty());
127  require(!xns.contains_path(xpath, xauto_access));
128 
129  require(xschema_path.full());
130  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
131  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
132 
133  require(xns.path_is_auto_read_accessible<vector_space_type>(xvector_space_path, xauto_access));
134 
135  require(schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access) == d(xns, xvector_space_path, xauto_access));
136 
137  // Body:
138 
139  // Create the table; have to new it because namespace keeps a pointer.
140 
141  typedef gln_space table_type;
142 
143  table_type* ltable = new table_type();
144 
145  // Create a handle of the right type for the schema member.
146 
147  schema_poset_member lschema(&xns, xschema_path, xauto_access);
148 
149  if(xauto_access)
150  {
151  lschema.get_read_access();
152  }
153 
154  // Get the dimension of the vector space.
155 
156  int ln = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d();
157 
158  // Get the scalar space path from the domain vector space.
159 
160  poset_path lscalar_space_path = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
161 
162  // Create the table dof map and set dof values;
163  // must be newed because poset_state::_table keep a pointer to it.
164 
165  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
166  lmap->put_dof("scalar_space_path", lscalar_space_path);
167  lmap->put_dof("n", ln);
168  lmap->put_dof("vector_space_path", xvector_space_path);
169 
170  // Create the state.
171 
172  ltable->new_state(xns, xpath, lschema, *lmap);
173 
174  if(xauto_access)
175  {
176  lschema.release_access();
177  }
178 
179  gln_space& result = *ltable;
180 
181  // Postconditions:
182 
183  ensure(xns.owns(result, xauto_access));
184  ensure(result.path(true) == xpath);
185  ensure(result.state_is_not_read_accessible());
186  ensure(result.schema(true).path(xauto_access) == xschema_path);
187 
188  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access) );
189  ensure(result.n(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d());
190  ensure(result.vector_space_path(true) == xvector_space_path );
191 
192  ensure(result.d(true) == d(xns, xvector_space_path, xauto_access));
193 
194  // Exit:
195 
196  // cout << "Leaving gln_space::new_table." << endl;
197  return result;
198 }
199 
200 int
202 n() const
203 {
204  // Preconditions:
205 
206  require(state_is_read_accessible());
207 
208  // Body:
209 
210  int result = sheaf::table_dofs(*this).n;
211 
212  // Postconditions:
213 
214  ensure(result >= 0);
215 
216  // Exit:
217 
218  return result;
219 }
220 
221 int
223 n(bool xauto_access) const
224 {
225  // Preconditions:
226 
227  require(state_is_auto_read_accessible(xauto_access));
228 
229  // Body:
230 
231  if(xauto_access)
232  {
233  get_read_access();
234  }
235 
236  int result = n();
237 
238  if(xauto_access)
239  {
240  release_access();
241  }
242 
243  // Postconditions:
244 
245  ensure(result >= 0);
246 
247  // Exit:
248 
249  return result;
250 }
251 
255 {
256  // Preconditions:
257 
258  require(state_is_read_accessible());
259 
260  // Body:
261 
262  poset_path result(sheaf::table_dofs(*this).scalar_space_path);
263 
264  // Postconditions:
265 
266  ensure(!result.empty());
267 
268  // Exit:
269 
270  return result;
271 }
272 
275 scalar_space_path(bool xauto_access) const
276 {
277  // Preconditions:
278 
279  require(state_is_auto_read_accessible(xauto_access));
280 
281  // Body:
282 
283  if(xauto_access)
284  {
285  get_read_access();
286  }
287 
288  poset_path result(sheaf::table_dofs(*this).scalar_space_path);
289 
290  if(xauto_access)
291  {
292  release_access();
293  }
294 
295  // Postconditions:
296 
297  ensure(!result.empty());
298 
299  // Exit:
300 
301  return result;
302 }
303 
307 {
308  // Preconditions:
309 
310  require(state_is_read_accessible());
311 
312  // Body:
313 
314  poset_path result(sheaf::table_dofs(*this).vector_space_path);
315 
316  // Postconditions:
317 
318  ensure(!result.empty());
319 
320  // Exit:
321 
322  return result;
323 }
324 
327 vector_space_path(bool xauto_access) const
328 {
329  // Preconditions:
330 
331  require(state_is_auto_read_accessible(xauto_access));
332 
333  // Body:
334 
335  if(xauto_access)
336  {
337  get_read_access();
338  }
339 
340  poset_path result(sheaf::table_dofs(*this).vector_space_path);
341 
342  if(xauto_access)
343  {
344  release_access();
345  }
346 
347  // Postconditions:
348 
349  ensure(!result.empty());
350 
351  // Exit:
352 
353  return result;
354 }
355 
356 int
358 d() const
359 {
360  // Preconditions:
361 
362  require(state_is_read_accessible());
363 
364  // Body:
365 
366  int result = d(n());
367 
368  // Postconditions:
369 
370  ensure(result >= 0);
371 
372  // Exit:
373 
374  return result;
375 }
376 
377 int
379 d(bool xauto_access) const
380 {
381  // Preconditions:
382 
383  require(state_is_auto_read_accessible(xauto_access));
384 
385  // Body:
386 
387  if(xauto_access)
388  {
389  get_read_access();
390  }
391 
392  int result = d();
393 
394  if(xauto_access)
395  {
396  release_access();
397  }
398 
399  // Postconditions:
400 
401  ensure(result >= 0);
402 
403  // Exit:
404 
405  return result;
406 }
407 
410  : poset(new gln, new gln)
411 {
412  // Preconditions:
413 
414  // Body:
415 
416  // Nothing to do, handled by base class
417 
418  // Postconditions:
419 
420  ensure(postcondition_of(poset::poset()));
421 }
422 
425 {
426  // Preconditions:
427 
428  // Body:
429 
430  // Postconditions:
431 
432  // Exit
433 
434  return;
435 }
436 
438 gln_space(gln* xtop, gln* xbottom)
439  : poset(xtop, xbottom)
440 {
441  // Preconditions:
442 
443  require(xtop != 0);
444  require(xbottom != 0);
445 
446  // Body:
447 
448  // Nothing to do.
449 
450  // Postconditions:
451 
452  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
453 
454  // Exit:
455 
456  return;
457 }
458 
459 // ===========================================================
460 // POSET FACET
461 // ===========================================================
462 
463 bool
464 fiber_bundle::gln_space::
465 make_prototype()
466 {
467  bool result = false;
468 
469  // Preconditions:
470 
471  // Body:
472 
473 
474  gln_space* lproto = new gln_space;
475  poset_type ltype = lproto->type_id();
476 
477  factory().insert_prototype(lproto);
478  factory().insert_prototype(ltype, lproto);
479 
480  // Postconditions:
481 
482  // Exit:
483 
484  return result;
485 }
486 
487 //==============================================================================
488 // POSET_STATE_HANDLE FACET
489 //==============================================================================
490 
491 
492 
495 type_id() const
496 {
497  return GLN_SPACE_ID;
498 }
499 
500 
501 
502 
503 
506 
507 const char*
509 class_name() const
510 {
511  // Preconditions:
512 
513 
514  // Body:
515 
516  static const char* result = "gln_space";
517 
518  // Postconditions:
519 
520  // Exit:
521 
522  return result;
523 }
524 
525 
529 prereq_id(int xi) const
530 {
531  // Preconditions:
532 
533  require(state_is_read_accessible());
534  require(name_space()->state_is_read_accessible());
535 
536  // Body:
537 
538  // The result must be scoped if it is valid because
539  // namespace_poset_member::put_poset_prereq_id must be
540  // able to map it to the namespace member id space.
541  // The vector_space_index is just a pod, so we have to
542  // pick some id space for it and make sure we consistently
543  // use it. The obvious choice is the internal id space,
544  // so initialize result to internal scope.
545 
546  pod_index_type result;
547 
548  switch(xi)
549  {
550  case 0:
551 
552  // The first prerequisite is always the schema.
553 
554  result = schema().host()->index().pod();
555  break;
556 
557  case 1:
558 
559  // The underlying vector space.
560 
561  result = name_space()->member_id(vector_space_path().poset_name(), false);
562  break;
563 
564  default:
565 
566  // No other prerequisites.
567 
568  result = invalid_pod_index();
569  break;
570  }
571 
572  // Postconditions:
573 
574 
575  // Exit:
576 
577  return result;
578 }
579 
580 //==============================================================================
581 // ANY FACET
582 //==============================================================================
583 
584 bool
586 is_ancestor_of(const any* xother) const
587 {
588  bool result;
589 
590  // Preconditions:
591 
592  // Body:
593 
594  result = dynamic_cast<const gln_space*>(xother) != 0;
595 
596  // Postconditions:
597 
598  // Exit
599 
600  return result;
601 }
602 
605 clone() const
606 {
607  gln_space* result;
608 
609  // Preconditions:
610 
611  // Body:
612 
613  result = new gln_space;
614 
615  // Postconditions:
616 
617  ensure(result != 0);
618  ensure(is_same_type(result));
619  ensure(!result->is_attached());
620 
621  // Exit
622 
623  return result;
624 }
625 
626 bool
628 invariant() const
629 {
630  bool result = true;
631 
632 
633  if(invariant_check())
634  {
636 
637  invariance(poset::invariant());
638 
641 
643  }
644 
645  return result;
646 }
647 
648 
649 
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.
virtual bool invariant() const
Class invariant.
Definition: poset.cc:440
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual ~gln_space()
Destructor.
Definition: gln_space.cc:424
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
const scoped_index & index() const
The member index of this poset within the namespace host()
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 gln_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: gln_space.cc:605
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: gln_space.cc:495
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.
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: gln_space.cc:42
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
poset_path vector_space_path() const
The path of the underlying vector space.
Definition: gln_space.cc:306
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: gln_space.cc:63
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.
The mathematical group GL(n, R). GL(n,R) is the group of general, invertible, linear transformations ...
Definition: gln.h:289
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.
poset()
Default constructor; creates a new poset handle not attached to any state.
Definition: poset.cc:107
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).
A client handle for a mutable partially ordered set.
Definition: poset.h:40
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
Definition: gln_space.cc:529
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)
virtual bool invariant() const
Class invariant.
Definition: gln_space.cc:628
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: gln_space.cc:586
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.
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.
static poset_handle_factory & factory()
The poset handle factory.
virtual int d() const
Dimension of this as a vector space.
Definition: gln_space.cc:358
namespace_poset * name_space() const
The namespace this poset resides in.
A Cartesian product space.
Definition: gln_space.h:52
virtual bool is_attached() const
True if this is attached to a state.
An abstract vector space of dimension d.
Definition: vd_space.h:47
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
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
static gln_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, const poset_path &xvector_space_path, bool xauto_access)
Creates a new tp_space in namespace xns with path xpath, schema specified by xschema_path, and table attribute vector_space_path specified by xvector_space_path.
Definition: gln_space.cc:114
gln_space()
Default constructor; creates a new gln_space handle not attached to any state.
Definition: gln_space.cc:409
virtual const char * class_name() const
The name of this class.
Definition: gln_space.cc:509
static int d(const namespace_poset &xns, const poset_path &xvector_space_path, bool xauto_access)
The dimension of the representation space; n in GL(n, R) implied by the vector space specified by xve...
Definition: gln_space.cc:84
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
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
int n() const
Dimension of the representation space; n in GL(n, R).
Definition: gln_space.cc:202
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...
poset_path scalar_space_path() const
The path of the underlying scalar space.
Definition: gln_space.cc:254