SheafSystem  0.0.0.0
stp_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 stp_space.
19 
20 #include "SheafSystem/stp_space.h"
21 
22 #include "SheafSystem/abstract_poset_member.impl.h"
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/at1_space.h"
25 #include "SheafSystem/stp.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 using namespace fiber_bundle::vd_algebra;
34 
35 //#define DIAGNOSTIC_OUTPUT
36 
37 //==============================================================================
38 // STP_SPACE FACET public member functions
39 //==============================================================================
40 
42 const std::string&
45 {
46  // Preconditions:
47 
48 
49  // Body:
50 
51  static const string& result = stp::standard_schema_poset_name();
52 
53  // Postconditions:
54 
55  ensure(!result.empty());
56 
57  // Exit:
58 
59  return result;
60 }
61 
63 const sheaf::poset_path&
66 {
67  // Preconditions:
68 
69 
70  // Body:
71 
72  static const poset_path& result = stp::standard_schema_path();
73 
74  // Postconditions:
75 
76  ensure(result.full());
77  ensure(result.poset_name() == standard_schema_poset_name());
78 
79  // Exit:
80 
81  return result;
82 }
83 
84 int
86 d(const namespace_poset& xns, int xp, const poset_path& xvector_space_path, bool xauto_access)
87 {
88  // Preconditions:
89 
90  require(xp >= 0);
91 
92  require(xns.path_is_auto_read_accessible<vector_space_type>(xvector_space_path, xauto_access));
93 
94  // Body:
95 
96  int ldd = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d();
97 
98  stp_space ltmp;
99  int result = ltmp.d(xp, ldd);
100 
101  // Postconditions:
102 
103  ensure(result >= 0);
104 
105  // Exit:
106 
107  return result;
108 }
109 
113  const poset_path& xpath,
114  const poset_path& xschema_path,
115  int xp,
116  const poset_path& xvector_space_path,
117  bool xauto_access)
118 {
119  // cout << endl << "Entering stp_space::new_table." << endl;
120 
121  // Preconditions:
122 
123  require(xns.state_is_auto_read_write_accessible(xauto_access));
124 
125  require(!xpath.empty());
126  require(!xns.contains_path(xpath, xauto_access));
127 
128  require(xschema_path.full());
129  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
130  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path(), xauto_access));
131 
132  require(xns.path_is_auto_read_accessible<vector_space_type>(xvector_space_path, xauto_access));
133 
134  require(d(xns, xschema_path, xauto_access) == d(xns, xp, xvector_space_path, xauto_access));
135 
136  // Body:
137 
138  // Create the table; have to new it because namespace keeps a pointer.
139 
140  typedef stp_space table_type;
141 
142  table_type* ltable = new table_type();
143 
144  // Create a handle of the right type for the schema member.
145 
146  schema_poset_member lschema(&xns, xschema_path, xauto_access);
147 
148  if(xauto_access)
149  {
150  lschema.get_read_access();
151  }
152 
153  // Get the dimension (== number of row dofs) defined by the schema.
154 
155  int ld = lschema.row_dof_ct();
156 
157  // Get the dimension of the domain vector space.
158 
159  int ldd = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d();
160 
161  // Get the scalar space path from the domain vector space.
162 
163  poset_path lscalar_space_path = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
164 
165  // Create the table dof map and set dof values;
166  // must be newed because poset_state::_table keep a pointer to it.
167 
168  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
169  lmap->put_dof("factor_ct", ld);
170  lmap->put_dof("d", ld);
171  lmap->put_dof("scalar_space_path", lscalar_space_path);
172  lmap->put_dof("p", xp);
173  lmap->put_dof("dd", ldd);
174  lmap->put_dof("vector_space_path", xvector_space_path);
175 
176  // Create the state.
177 
178  ltable->new_state(xns, xpath, lschema, *lmap);
179 
180  if(xauto_access)
181  {
182  lschema.release_access();
183  }
184 
185  stp_space& result = *ltable;
186 
187  // Postconditions:
188 
189  ensure(xns.owns(result, xauto_access));
190  ensure(result.path(true) == xpath);
191  ensure(result.state_is_not_read_accessible());
192  ensure(result.schema(true).path(xauto_access) == xschema_path);
193 
194  ensure(result.factor_ct(true) == result.d(true));
195  ensure(result.d(true) == d(xns, xschema_path, xauto_access));
196  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access) );
197  ensure(result.p(true) == xp);
198  ensure(result.dd(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d());
199  ensure(result.vector_space_path(true) == xvector_space_path );
200 
201  // Exit:
202 
203  // cout << "Leaving stp_space::new_table." << endl;
204  return result;
205 }
206 
207 // ===========================================================
208 // STP_SPACE FACET protected member functions
209 // ===========================================================
210 
213  : tp_space(new stp, new stp)
214 {
215  // Preconditions:
216 
217  // Body:
218 
219  // Nothing to do, handled by base class
220 
221  // Postconditions:
222 
223  ensure(postcondition_of(tp_space::tp_space()));
224 }
225 
228 {
229  // Preconditions:
230 
231  // Body:
232 
233  // Postconditions:
234 
235  // Exit
236 
237  return;
238 }
239 
241 stp_space(stp* xtop, stp* xbottom)
242  : tp_space(xtop, xbottom)
243 {
244  // Preconditions:
245 
246  require(xtop != 0);
247  require(xbottom != 0);
248 
249  // Body:
250 
251  // Nothing to do.
252 
253  // Postconditions:
254 
255  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
256 
257  // Exit:
258 
259  return;
260 }
261 
262 // ===========================================================
263 // TP_SPACE FACET public member functions
264 // ===========================================================
265 
266 int
268 d(int xp, int xdd) const
269 {
270  return static_cast<int>(binomial_coefficient(xdd+xp-1, xp));
271 }
272 
276 round_variance(const tensor_variance& xvariance) const
277 {
278  // Preconditions:
279 
280  // Body:
281 
282  tensor_variance result(xvariance);
283  result.purify();
284 
285  // Postconditions:
286 
287  ensure(result.is_pure());
288  ensure_for_all(i, 0, result.p(), result.variance(i) == xvariance.variance(0));
289 
290  // Exit:
291 
292  return xvariance;
293 }
294 
295 
296 // ===========================================================
297 // TP_SPACE FACET protected member functions
298 // ===========================================================
299 
303 {
304  return 1;
305 }
306 
307 
308 // ===========================================================
309 // POSET FACET
310 // ===========================================================
311 
312 bool
313 fiber_bundle::stp_space::
314 make_prototype()
315 {
316  bool result = false;
317 
318  // Preconditions:
319 
320  // Body:
321 
322 
323  stp_space* lproto = new stp_space;
324  poset_type ltype = lproto->type_id();
325 
326  factory().insert_prototype(lproto);
327  factory().insert_prototype(ltype, lproto);
328 
329  // Postconditions:
330 
331  // Exit:
332 
333  return result;
334 }
335 
336 //==============================================================================
337 // POSET_STATE_HANDLE FACET
338 //==============================================================================
339 
340 
341 
344 type_id() const
345 {
346  return STP_SPACE_ID;
347 }
348 
351 
352 const char*
354 class_name() const
355 {
356  // Preconditions:
357 
358 
359  // Body:
360 
361  static const char* result = "stp_space";
362 
363  // Postconditions:
364 
365  // Exit:
366 
367  return result;
368 }
369 
370 //==============================================================================
371 // ANY FACET
372 //==============================================================================
373 
374 bool
376 is_ancestor_of(const any* xother) const
377 {
378  bool result;
379 
380  // Preconditions:
381 
382  // Body:
383 
384  result = dynamic_cast<const stp_space*>(xother) != 0;
385 
386  // Postconditions:
387 
388  // Exit
389 
390  return result;
391 }
392 
395 clone() const
396 {
397  stp_space* result;
398 
399  // Preconditions:
400 
401  // Body:
402 
403  result = new stp_space;
404 
405  // Postconditions:
406 
407  ensure(result != 0);
408  ensure(is_same_type(result));
409  ensure(!result->is_attached());
410 
411  // Exit
412 
413  return result;
414 }
415 
416 bool
418 invariant() const
419 {
420  bool result = true;
421 
422 
423  if(invariant_check())
424  {
426 
427  invariance(tp_space::invariant());
428 
430  }
431 
432  return result;
433 }
434 
435 
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 ...
bool is_pure() const
True if and only if all indices are covariant or all indices are contravariant.
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
A symmetric tensor of degree p over an abstract vector space.
Definition: stp.h:190
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
int p() const
The tensor degree.
virtual size_type covariant_subposet_ct() const
The number of covariant subposets.
Definition: stp_space.cc:302
The "type" of a tensor; specifies the degree and the co- or contra-variance for each index of a tenso...
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 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
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.
SHEAF_DLL_SPEC unsigned int binomial_coefficient(unsigned int xi, unsigned int xj)
Binomial coefficient (xi, xj).
Definition: vd.cc:2673
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: stp_space.cc:65
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: stp_space.cc:86
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 ~stp_space()
Destructor.
Definition: stp_space.cc:227
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)
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
stp_space()
Default constructor; creates a new stp_space handle not attached to any state.
Definition: stp_space.cc:212
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 bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: stp_space.cc:376
virtual stp_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: stp_space.cc:395
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 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
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 dd() const
The dimension of the underlying ("domain") vector space.
Definition: tp_space.cc:317
bool variance(int xi) const
The variance of the xi-th index; covariant if true, contravariant if false.
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: stp_space.cc:44
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: stp_space.cc:344
tp_space()
Default constructor; creates a new tp_space handle not attached to any state.
Definition: tp_space.cc:1112
void purify()
Sets all indices the same as index 0.
virtual tensor_variance round_variance(const tensor_variance &xvariance) const
"Rounds" xvariance up or down to a supported value; either pure covariant or pure contravariant...
Definition: stp_space.cc:276
virtual bool invariant() const
Class invariant.
Definition: tp_space.cc:1336
An array representation of abstract class poset_dof_map.
An abstract tensor space of degree p.
Definition: tp_space.h:47
Namespace containing the vector algrebra functions for the fiber_bundles component of the sheaf syste...
Definition: e3.h:1135
An abstract symmetric tensor space of degree p.
Definition: stp_space.h:42
Namespace for the fiber_bundles component of the sheaf system.
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 const char * class_name() const
The name of this class.
Definition: stp_space.cc:354
virtual bool invariant() const
Class invariant.
Definition: stp_space.cc:418
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.
static stp_space & new_table(namespace_type &xhost, const poset_path &xpath, const poset_path &xschema_path, int xp, const poset_path &xvector_space_path, bool xauto_access)
Creates a new stp_space in namespace xns with path xpath, schema specified by xschema_path, and table attributes p and vector_space_path specified by xp and xvector_space_path, respectively.
Definition: stp_space.cc:112