SheafSystem  0.0.0.0
at0_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 at0_space.
19 
20 #include "SheafSystem/at0_space.h"
21 
22 #include "SheafSystem/abstract_poset_member.impl.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/at0.h"
25 #include "SheafSystem/fiber_bundles_namespace.h"
26 #include "SheafSystem/namespace_poset.impl.h"
27 #include "SheafSystem/namespace_poset_member.h"
28 #include "SheafSystem/poset_handle_factory.h"
29 
30 using namespace std;
31 using namespace fiber_bundle; // Workaround for MS C++ bug.
32 
33 //#define DIAGNOSTIC_OUTPUT
34 
35 //==============================================================================
36 // AT0_SPACE FACET public member functions
37 //==============================================================================
38 
40 const std::string&
43 {
44  // Preconditions:
45 
46 
47  // Body:
48 
49  static const string& result = at0::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 = at0::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 
85  const poset_path& xpath,
86  const poset_path& xschema_path,
87  bool xauto_access)
88 {
89  // cout << endl << "Entering at0_space::new_table." << endl;
90 
91  // Preconditions:
92 
93  require(xns.state_is_auto_read_write_accessible(xauto_access));
94 
95  require(!xpath.empty());
96  require(!xns.contains_path(xpath, xauto_access));
97 
98  require(xschema_path.full());
99  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
100  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
101  require(schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access) == 1);
102 
103  // Body:
104 
105  // Create the table; have to new it because namespace keeps a pointer.
106 
107  typedef at0_space table_type;
108 
109  table_type* ltable = new table_type();
110 
111  // Create a handle of the right type for the schema member.
112 
113  schema_poset_member lschema(&xns, xschema_path, xauto_access);
114 
115  if(xauto_access)
116  {
117  lschema.get_read_access();
118  }
119 
120 
121  // Get the dimension of the domain vector space.
122  // For AT0, the tensor space, the domain vector space,
123  // and the scalar space are all the same thing.
124 
125  int ld = 1;
126  int ldd = ld;
127  int lp = 0;
128 
129  // Create the table dof map and set dof values;
130  // must be newed because poset_state::_table keep a pointer to it.
131 
132  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
133  lmap->put_dof("factor_ct", ld);
134  lmap->put_dof("d", ld);
135  lmap->put_dof("scalar_space_path", xpath);
136  lmap->put_dof("p", lp);
137  lmap->put_dof("dd", ldd);
138  lmap->put_dof("vector_space_path", xpath);
139 
140  // Create the state.
141 
142  ltable->new_state(xns, xpath, lschema, *lmap);
143 
144  if(xauto_access)
145  {
146  lschema.release_access();
147  }
148 
149  at0_space& result = *ltable;
150 
151  // Postconditions:
152 
153  ensure(xns.owns(result, xauto_access));
154  ensure(result.path(true) == xpath);
155  ensure(result.state_is_not_read_accessible());
156  ensure(result.schema(true).path(xauto_access) == xschema_path);
157 
158  ensure(result.factor_ct(true) == 1);
159  ensure(result.d(true) == 1);
160  ensure(result.scalar_space_path(true) == xpath);
161  ensure(result.p(true) == 0);
162  ensure(result.dd(true) == 1);
163  ensure(result.vector_space_path(true) == xpath );
164 
165  // Exit:
166 
167  // cout << "Leaving at0_space::new_table." << endl;
168  return result;
169 }
170 
171 // ===========================================================
172 // AT0_SPACE FACET protected member functions
173 // ===========================================================
174 
177  : atp_space(new at0, new at0)
178 {
179  // Preconditions:
180 
181  // Body:
182 
183  // Nothing to do, handled by base class
184 
185  // Postconditions:
186 
187  ensure(postcondition_of(atp_space::atp_space()));
188 }
189 
192 {
193  // Preconditions:
194 
195  // Body:
196 
197  // Postconditions:
198 
199  // Exit
200 
201  return;
202 }
203 
205 at0_space(at0* xtop, at0* xbottom)
206  : atp_space(xtop, xbottom)
207 {
208  // Preconditions:
209 
210  require(xtop != 0);
211  require(xbottom != 0);
212 
213  // Body:
214 
215  // Nothing to do.
216 
217  // Postconditions:
218 
219  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
220 
221  // Exit:
222 
223  return;
224 }
225 
226 // ===========================================================
227 // TP_SPACE FACET public member functions
228 // ===========================================================
229 
230 
231 // ===========================================================
232 // TP_SPACE FACET protected member functions
233 // ===========================================================
234 
235 
239 {
240  return 0;
241 }
242 
243 // ===========================================================
244 // VD_SPACE FACET
245 // ===========================================================
246 
247 
248 bool
250 is_vector(pod_index_type xmbr_id, bool xauto_access) const
251 {
252 
259 
260  bool result = true;
261 
262  // Postconditions:
263 
264  ensure(result);
265 
266  // Exit:
267 
268  return result;
269 }
270 
271 void
273 put_is_vector(pod_index_type xmbr_id, bool xauto_access)
274 {
275  // Preconditions:
276 
277  // Body:
278 
279  // Do nothing.
280 
281  // Postconditions:
282 
283  ensure(is_vector(xmbr_id, xauto_access));
284 
285  // Exit:
286 
287  return;
288 }
289 
290 bool
292 is_covector(pod_index_type xmbr_id, bool xauto_access) const
293 {
294  // Preconditions:
295 
296  // Body:
297 
298  bool result = true;
299 
300  // Postconditions:
301 
302  ensure(result);
303 
304  // Exit:
305 
306  return result;
307 }
308 
309 void
311 put_is_covector(pod_index_type xmbr_id, bool xauto_access)
312 {
313  // Preconditions:
314 
315  // Body:
316 
317  // Do nothing.
318 
319  // Postconditions:
320 
321  ensure(is_covector(xmbr_id, xauto_access));
322 
323  // Exit:
324 
325  return;
326 }
327 
328 // ===========================================================
329 // POSET FACET
330 // ===========================================================
331 
332 bool
333 fiber_bundle::at0_space::
334 make_prototype()
335 {
336  bool result = false;
337 
338  // Preconditions:
339 
340  // Body:
341 
342 
343  at0_space* lproto = new at0_space;
344  poset_type ltype = lproto->type_id();
345 
346  factory().insert_prototype(lproto);
347  factory().insert_prototype(ltype, lproto);
348 
349  // Postconditions:
350 
351  // Exit:
352 
353  return result;
354 }
355 
356 //==============================================================================
357 // POSET_STATE_HANDLE FACET
358 //==============================================================================
359 
360 
361 
364 type_id() const
365 {
366  return AT0_SPACE_ID;
367 }
368 
371 
372 const char*
374 class_name() const
375 {
376  // Preconditions:
377 
378 
379  // Body:
380 
381  static const char* result = "at0_space";
382 
383  // Postconditions:
384 
385  // Exit:
386 
387  return result;
388 }
389 
393 prereq_id(int xi) const
394 {
395  // Preconditions:
396 
397  require(state_is_read_accessible());
398  require(name_space()->state_is_read_accessible());
399 
400  // Body:
401 
402  pod_index_type result;
403 
404  switch(xi)
405  {
406  case 0:
407 
408  // The first prerequisite is always the schema.
409 
410  result = schema().host()->index().pod();
411  break;
412 
413  default:
414 
415  // No other prerequisites.
416 
417  result = invalid_pod_index();
418  break;
419  }
420 
421  // Postconditions:
422 
423 
424  // Exit:
425 
426  return result;
427 }
428 
429 //==============================================================================
430 // ANY FACET
431 //==============================================================================
432 
433 bool
435 is_ancestor_of(const any* xother) const
436 {
437  bool result;
438 
439  // Preconditions:
440 
441  // Body:
442 
443  result = dynamic_cast<const at0_space*>(xother) != 0;
444 
445  // Postconditions:
446 
447  // Exit
448 
449  return result;
450 }
451 
454 clone() const
455 {
456  at0_space* result;
457 
458  // Preconditions:
459 
460  // Body:
461 
462  result = new at0_space;
463 
464  // Postconditions:
465 
466  ensure(result != 0);
467  ensure(is_same_type(result));
468  ensure(!result->is_attached());
469 
470  // Exit
471 
472  return result;
473 }
474 
475 bool
477 invariant() const
478 {
479  bool result = true;
480 
481 
482  if(invariant_check())
483  {
485 
486  invariance(atp_space::invariant());
487 
488  invariance(state_is_read_accessible() ? dd() == d() : true);
489  invariance(state_is_read_accessible() ? vector_space_path().poset_name() == name() : true);
490  invariance(state_is_read_accessible() ? p() == 0 : true);
491  invariance(state_is_read_accessible() ? scalar_space_path().poset_name() == name() : true);
492  invariance(state_is_read_accessible() ? d() == 1 : true);
493  invariance(state_is_read_accessible() ? factor_ct() == d() : true);
494 
496  }
497 
498  return result;
499 }
500 
501 
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
static int d(const namespace_poset &xns, int xp, const poset_path &xvector_space_path, bool xauto_access)
The tensor dimension implied by tensor degree xp and the dimension of the domain vector space specifi...
Definition: atp_space.cc:86
virtual bool is_vector(pod_index_type xmbr_id, bool xauto_access) const
True if and only if the member with id xmbr_id is a vector (as opposed to a covector).
Definition: at0_space.cc:250
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.
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_path vector_space_path() const
The path of the underlying vector space.
Definition: tp_space.cc:365
poset_type
Identifiers for poset types.
Definition: poset_type.h:41
virtual void put_is_vector(pod_index_type xmbr_id, bool xauto_access)
Sets is_vector true for the member with id xmbr_id.
Definition: at0_space.cc:273
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 size_type covariant_subposet_ct() const
The number of covariant subposets.
Definition: at0_space.cc:238
virtual void put_is_covector(pod_index_type xmbr_id, bool xauto_access)
Sets is_covector true for the member with id xmbr_id.
Definition: at0_space.cc:311
virtual ~at0_space()
Destructor.
Definition: at0_space.cc:191
virtual void get_read_access() const
Get read access to the state associated with this.
int p() const
The tensor degree of this space.
Definition: tp_space.cc:269
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
Definition: at0_space.cc:393
at0_space()
Default constructor; creates a new at0_space handle not attached to any state.
Definition: at0_space.cc:176
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).
virtual bool invariant() const
Class invariant.
Definition: at0_space.cc:477
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: at0_space.cc:63
A space of scalars viewed as an antisymmetric tensor space of degree 0.
Definition: at0_space.h:42
An abstract antisymmetric tensor space of degree p.
Definition: atp_space.h:42
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)
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: at0_space.cc:42
virtual bool invariant() const
Class invariant.
Definition: atp_space.cc:589
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: at0_space.cc:435
A scalar viewed as an antisymmetric tensor of degree 0. As the degree is 0 there is nothing to be sym...
Definition: at0.h:424
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
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.
int p(int xd, int xdd) const
Tensor degree as a function of tensor dimension xd and domain dimension xdd.
Definition: tp_space.cc:235
virtual std::string name() const
The name of this poset.
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
atp_space()
Default constructor; creates a new atp_space handle not attached to any state.
Definition: atp_space.cc:383
virtual bool is_covector(pod_index_type xmbr_id, bool xauto_access) const
True if and only if the member with id xmbr_id is a covector.
Definition: at0_space.cc:292
poset_state_handle()
Default constructor.
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
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.
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.
virtual const char * class_name() const
The name of this class.
Definition: at0_space.cc:374
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
static int factor_ct(int xd)
Factor_ct() as a function of dimension xd.
Definition: vd_space.cc:167
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
int dd() const
The dimension of the underlying ("domain") vector space.
Definition: tp_space.cc:317
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
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: at0_space.cc:364
int factor_ct() const
The number of factors in this product.
Definition: tuple_space.cc:152
static at0_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, bool xauto_access)
Creates a new at0_space in namespace xns with path xpath, and schema specified by xschema_path...
Definition: at0_space.cc:84
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 at0_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: at0_space.cc:454