SheafSystem  0.0.0.0
at1_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 at1_space.
19 
20 #include "SheafSystem/at1_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/fiber_bundles_namespace.h"
27 #include "SheafSystem/namespace_poset.impl.h"
28 #include "SheafSystem/namespace_poset_member.h"
29 #include "SheafSystem/poset_handle_factory.h"
30 
31 using namespace std;
32 using namespace fiber_bundle; // Workaround for MS C++ bug.
33 
34 //#define DIAGNOSTIC_OUTPUT
35 
36 //==============================================================================
37 // AT1_SPACE FACET public member functions
38 //==============================================================================
39 
41 const std::string&
44 {
45  // Preconditions:
46 
47 
48  // Body:
49 
50  static const string& result = at1::standard_schema_poset_name();
51 
52  // Postconditions:
53 
54  ensure(!result.empty());
55 
56  // Exit:
57 
58  return result;
59 }
60 
62 const sheaf::poset_path&
65 {
66  // Preconditions:
67 
68 
69  // Body:
70 
71  static const poset_path& result = at1::standard_schema_path();
72 
73  // Postconditions:
74 
75  ensure(result.full());
76  ensure(result.poset_name() == standard_schema_poset_name());
77 
78  // Exit:
79 
80  return result;
81 }
82 
86  const poset_path& xpath,
87  const poset_path& xschema_path,
88  const poset_path& xscalar_space_path,
89  bool xauto_access)
90 {
91  // cout << endl << "Entering at1_space::new_table." << endl;
92 
93  // Preconditions:
94 
95  require(xns.state_is_auto_read_write_accessible(xauto_access));
96 
97  require(!xpath.empty());
98  require(!xns.contains_path(xpath, xauto_access));
99 
100  require(xschema_path.full());
101  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
102  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
103 
104  require(xns.path_is_auto_read_accessible<scalar_space_type>(xscalar_space_path, xauto_access));
105 
106  // Body:
107 
108  // Create the table; have to new it because namespace keeps a pointer.
109 
110  typedef at1_space table_type;
111 
112  table_type* ltable = new table_type();
113 
114  // Create a handle of the right type for the schema member.
115 
116  schema_poset_member lschema(&xns, xschema_path, xauto_access);
117 
118  if(xauto_access)
119  {
120  lschema.get_read_access();
121  }
122 
123  // Get the dimension (== number of row dofs) defined by the schema.
124 
125  int ld = lschema.row_dof_ct();
126 
127  // Get the dimension of the domain vector space.
128  // For AT1, the tensor space and the domain vector space are the same thing.
129 
130  int ldd = ld;
131 
132  // The tensor degree is 1
133 
134  int lp = 1;
135 
136  // Create the table dof map and set dof values;
137  // must be newed because poset_state::_table keep a pointer to it.
138 
139  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
140  lmap->put_dof("factor_ct", ld);
141  lmap->put_dof("d", ld);
142  lmap->put_dof("scalar_space_path", xscalar_space_path);
143  lmap->put_dof("p", lp);
144  lmap->put_dof("dd", ldd);
145  lmap->put_dof("vector_space_path", xpath);
146 
147  // Create the state.
148 
149  ltable->new_state(xns, xpath, lschema, *lmap);
150 
151  if(xauto_access)
152  {
153  lschema.release_access();
154  }
155 
156  at1_space& result = *ltable;
157 
158  // Postconditions:
159 
160  ensure(xns.owns(result, xauto_access));
161  ensure(result.path(true) == xpath);
162  ensure(result.state_is_not_read_accessible());
163  ensure(result.schema(true).path(xauto_access) == xschema_path);
164 
165  ensure(result.factor_ct(true) == result.d(true));
166  ensure(result.d(true) == schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access));
167  ensure(result.scalar_space_path(true) == xscalar_space_path);
168  ensure(result.p(true) == 1);
169  ensure(result.dd(true) == result.d(true));
170  ensure(result.vector_space_path(true) == xpath );
171 
172  // Exit:
173 
174  // cout << "Leaving at1_space::new_table." << endl;
175  return result;
176 }
177 
178 // ===========================================================
179 // AT1_SPACE FACET protected member functions
180 // ===========================================================
181 
184  : atp_space(new at1, new at1)
185 {
186  // Preconditions:
187 
188  // Body:
189 
190  // Nothing to do, handled by base class
191 
192  // Postconditions:
193 
194  ensure(postcondition_of(atp_space::atp_space()));
195 }
196 
199 {
200  // Preconditions:
201 
202  // Body:
203 
204  // Postconditions:
205 
206  // Exit
207 
208  return;
209 }
210 
212 at1_space(at1* xtop, at1* xbottom)
213  : atp_space(xtop, xbottom)
214 {
215  // Preconditions:
216 
217  require(xtop != 0);
218  require(xbottom != 0);
219 
220  // Body:
221 
222  // Nothing to do.
223 
224  // Postconditions:
225 
226  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
227 
228  // Exit:
229 
230  return;
231 }
232 
233 // ===========================================================
234 // TP_SPACE FACET public member functions
235 // ===========================================================
236 
237 
238 // ===========================================================
239 // TP_SPACE FACET protected member functions
240 // ===========================================================
241 
242 
243 // ===========================================================
244 // POSET FACET
245 // ===========================================================
246 
247 bool
248 fiber_bundle::at1_space::
249 make_prototype()
250 {
251  bool result = false;
252 
253  // Preconditions:
254 
255  // Body:
256 
257 
258  at1_space* lproto = new at1_space;
259  poset_type ltype = lproto->type_id();
260 
261  factory().insert_prototype(lproto);
262  factory().insert_prototype(ltype, lproto);
263 
264  // Postconditions:
265 
266  // Exit:
267 
268  return result;
269 }
270 
271 //==============================================================================
272 // POSET_STATE_HANDLE FACET
273 //==============================================================================
274 
275 
276 
279 type_id() const
280 {
281  return AT1_SPACE_ID;
282 }
283 
286 
287 const char*
289 class_name() const
290 {
291  // Preconditions:
292 
293 
294  // Body:
295 
296  static const char* result = "at1_space";
297 
298  // Postconditions:
299 
300  // Exit:
301 
302  return result;
303 }
304 
308 prereq_id(int xi) const
309 {
310  // Preconditions:
311 
312  require(state_is_read_accessible());
313  require(name_space()->state_is_read_accessible());
314 
315  // Body:
316 
317  pod_index_type result;
318 
319  switch(xi)
320  {
321  case 0:
322 
323  // The first prerequisite is always the schema.
324 
325  result = schema().host()->index().pod();
326  break;
327 
328  case 1:
329 
330  // The vector space over which this tensor space is built.
331 
332  result = name_space()->member_id(scalar_space_path().poset_name(), false);
333  break;
334 
335  default:
336 
337  // No other prerequisites.
338 
339  result = invalid_pod_index();
340  break;
341  }
342 
343  // Postconditions:
344 
345 
346  // Exit:
347 
348  return result;
349 }
350 
351 //==============================================================================
352 // ANY FACET
353 //==============================================================================
354 
355 bool
357 is_ancestor_of(const any* xother) const
358 {
359  bool result;
360 
361  // Preconditions:
362 
363  // Body:
364 
365  result = dynamic_cast<const at1_space*>(xother) != 0;
366 
367  // Postconditions:
368 
369  // Exit
370 
371  return result;
372 }
373 
376 clone() const
377 {
378  at1_space* result;
379 
380  // Preconditions:
381 
382  // Body:
383 
384  result = new at1_space;
385 
386  // Postconditions:
387 
388  ensure(result != 0);
389  ensure(is_same_type(result));
390  ensure(!result->is_attached());
391 
392  // Exit
393 
394  return result;
395 }
396 
397 bool
399 invariant() const
400 {
401  bool result = true;
402 
403 
404  if(invariant_check())
405  {
407 
408  invariance(atp_space::invariant());
409 
410  invariance(state_is_read_accessible() ? p() == 1 : true);
411  invariance(state_is_read_accessible() ? vector_space_path().poset_name() == name() : true);
412 
414  }
415 
416  return result;
417 }
418 
419 
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 ...
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: at1_space.cc:357
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
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...
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
Definition: at1_space.cc:308
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.
A general antisymmetric tensor of degree 1 over an abstract vector space (persistent version)...
Definition: at1.h:211
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
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.
int p() const
The tensor degree of this space.
Definition: tp_space.cc:269
virtual ~at1_space()
Destructor.
Definition: at1_space.cc:198
virtual bool invariant() const
Class invariant.
Definition: at1_space.cc:399
at1_space()
Default constructor; creates a new at1_space handle not attached to any state.
Definition: at1_space.cc:183
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 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)
virtual bool invariant() const
Class invariant.
Definition: atp_space.cc:589
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 at1_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: at1_space.cc:376
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...
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
poset_state_handle()
Default constructor.
static at1_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, const poset_path &xscalar_space_path, bool xauto_access)
Creates a new at1_space in namespace xns with path xpath, schema specified by xschema_path, and table attribute scalar_space_path specified by xscalar_space_path.
Definition: at1_space.cc:85
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.
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
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
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
virtual const char * class_name() const
The name of this class.
Definition: at1_space.cc:289
int dd() const
The dimension of the underlying ("domain") vector space.
Definition: tp_space.cc:317
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: at1_space.cc:43
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
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: at1_space.cc:64
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
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 poset_type type_id() const
Identifier for the type of this poset.
Definition: at1_space.cc:279
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...