SheafSystem  0.0.0.0
atp_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 atp_space.
19 
20 #include "SheafSystem/atp_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/atp.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 // ATP_SPACE FACET public member functions
39 //==============================================================================
40 
42 const std::string&
45 {
46  // Preconditions:
47 
48 
49  // Body:
50 
51  static const string& result = atp::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 = atp::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  atp_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 atp_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(xp >= 0);
133 
134  require(xns.path_is_auto_read_accessible<vector_space_type>(xvector_space_path, xauto_access));
135 
136  require(d(xns, xschema_path, xauto_access) == d(xns, xp, xvector_space_path, xauto_access));
137 
138  // Body:
139 
140  // Create the table; have to new it because namespace keeps a pointer.
141 
142  typedef atp_space table_type;
143 
144  table_type* ltable = new table_type();
145 
146  // Create a handle of the right type for the schema member.
147 
148  schema_poset_member lschema(&xns, xschema_path, xauto_access);
149 
150  if(xauto_access)
151  {
152  lschema.get_read_access();
153  }
154 
155  // Get the dimension (== number of row dofs) defined by the schema.
156 
157  int ld = lschema.row_dof_ct();
158 
159  // Get the dimension of the domain vector space.
160 
161  int ldd = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d();
162 
163  // Get the scalar space path from the domain vector space.
164 
165  poset_path lscalar_space_path = xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
166 
167  // Create the table dof map and set dof values;
168  // must be newed because poset_state::_table keep a pointer to it.
169 
170  array_poset_dof_map* lmap = new array_poset_dof_map(&lschema, true);
171  lmap->put_dof("factor_ct", ld);
172  lmap->put_dof("d", ld);
173  lmap->put_dof("scalar_space_path", lscalar_space_path);
174  lmap->put_dof("p", xp);
175  lmap->put_dof("dd", ldd);
176  lmap->put_dof("vector_space_path", xvector_space_path);
177 
178  // Create the state.
179 
180  ltable->new_state(xns, xpath, lschema, *lmap);
181 
182  if(xauto_access)
183  {
184  lschema.release_access();
185  }
186 
187  atp_space& result = *ltable;
188 
189  // Postconditions:
190 
191  ensure(xns.owns(result, xauto_access));
192  ensure(result.path(true) == xpath);
193  ensure(result.state_is_not_read_accessible());
194  ensure(result.schema(true).path(xauto_access) == xschema_path);
195 
196  ensure(result.factor_ct(true) == result.d(true));
197  ensure(result.d(true) == d(xns, xschema_path, xauto_access));
198  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access) );
199  ensure(result.p(true) == xp);
200  ensure(result.dd(true) == xns.member_poset<vector_space_type>(xvector_space_path, xauto_access).d());
201  ensure(result.vector_space_path(true) == xvector_space_path );
202 
203  // Exit:
204 
205  // cout << "Leaving atp_space::new_table." << endl;
206  return result;
207 }
208 
209 bool
211 is_p_form(pod_index_type xmbr_id, bool xauto_access) const
212 {
213 
214  // Preconditions:
215 
216  require(state_is_auto_read_accessible(xauto_access));
217  require(contains_member(xmbr_id, xauto_access));
218  require(contains_variance_subposets(xauto_access));
219 
220  // Body:
221 
222  bool result = is_covariant(xmbr_id, xauto_access);
223 
224  // Postconditions:
225 
226  // Exit:
227 
228  return result;
229 
230 }
231 
232 bool
234 is_p_form(const scoped_index& xmbr_id, bool xauto_access) const
235 {
236 
237  // Preconditions:
238 
239  require(state_is_auto_read_accessible(xauto_access));
240  require(contains_member(xmbr_id, xauto_access));
241  require(contains_variance_subposets(xauto_access));
242 
243  // Body:
244 
245  return is_p_form(xmbr_id.hub_pod(), xauto_access);
246 }
247 
248 void
250 put_is_p_form(pod_index_type xmbr_id, bool xauto_access)
251 {
252  // Preconditions:
253 
254  require(state_is_auto_read_write_accessible(xauto_access));
255  require(contains_member(xmbr_id, xauto_access));
256  require(contains_variance_subposets(xauto_access));
257 
258  // Body:
259 
260  put_is_covariant(xmbr_id, xauto_access);
261 
262  // Postconditions:
263 
264  ensure(is_p_form(xmbr_id, xauto_access));
265 
266  // Exit:
267 
268  return;
269 }
270 
271 void
273 put_is_p_form(const scoped_index& xmbr_id, bool xauto_access)
274 {
275  // Preconditions:
276 
277  require(state_is_auto_read_write_accessible(xauto_access));
278  require(contains_member(xmbr_id, xauto_access));
279  require(contains_variance_subposets(xauto_access));
280 
281  // Body:
282 
283  put_is_p_form(xmbr_id.hub_pod(), xauto_access);
284 
285  // Postconditions:
286 
287  ensure(is_p_form(xmbr_id, xauto_access));
288 
289  // Exit:
290 
291  return;
292 }
293 
294 bool
296 is_p_vector(pod_index_type xmbr_id, bool xauto_access) const
297 {
298 
299  // Preconditions:
300 
301  require(state_is_auto_read_accessible(xauto_access));
302  require(contains_member(xmbr_id, xauto_access));
303  require(contains_variance_subposets(xauto_access));
304 
305  // Body:
306 
307  bool result = is_contravariant(xmbr_id, xauto_access);
308 
309  // Postconditions:
310 
311  // Exit:
312 
313  return result;
314 }
315 
316 bool
318 is_p_vector(const scoped_index& xmbr_id, bool xauto_access) const
319 {
320 
321  // Preconditions:
322 
323  require(state_is_auto_read_accessible(xauto_access));
324  require(contains_member(xmbr_id, xauto_access));
325  require(contains_variance_subposets(xauto_access));
326 
327  // Body:
328 
329  return is_p_vector(xmbr_id.hub_pod(), xauto_access);
330 }
331 
332 void
334 put_is_p_vector(pod_index_type xmbr_id, bool xauto_access)
335 {
336  // Preconditions:
337 
338  require(state_is_auto_read_write_accessible(xauto_access));
339  require(contains_member(xmbr_id, xauto_access));
340  require(contains_variance_subposets(xauto_access));
341 
342  // Body:
343 
344  put_is_contravariant(xmbr_id, xauto_access);
345 
346  // Postconditions:
347 
348  ensure(is_p_vector(xmbr_id, xauto_access));
349 
350  // Exit:
351 
352  return;
353 }
354 
355 void
357 put_is_p_vector(const scoped_index& xmbr_id, bool xauto_access)
358 {
359  // Preconditions:
360 
361  require(state_is_auto_read_write_accessible(xauto_access));
362  require(contains_member(xmbr_id, xauto_access));
363  require(contains_variance_subposets(xauto_access));
364 
365  // Body:
366 
367  put_is_p_vector(xmbr_id.hub_pod(), xauto_access);
368 
369  // Postconditions:
370 
371  ensure(is_p_vector(xmbr_id, xauto_access));
372 
373  // Exit:
374 
375  return;
376 }
377 
378 // ===========================================================
379 // ATP_SPACE FACET protected member functions
380 // ===========================================================
381 
384  : tp_space(new atp, new atp)
385 {
386  // Preconditions:
387 
388  // Body:
389 
390  // Nothing to do, handled by base class
391 
392  // Postconditions:
393 
394  ensure(postcondition_of(tp_space::tp_space()));
395 }
396 
399 {
400  // Preconditions:
401 
402  // Body:
403 
404  // Postconditions:
405 
406  // Exit
407 
408  return;
409 }
410 
412 atp_space(atp* xtop, atp* xbottom)
413  : tp_space(xtop, xbottom)
414 {
415  // Preconditions:
416 
417  require(xtop != 0);
418  require(xbottom != 0);
419 
420  // Body:
421 
422  // Nothing to do.
423 
424  // Postconditions:
425 
426  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
427 
428  // Exit:
429 
430  return;
431 }
432 
433 // ===========================================================
434 // TP_SPACE FACET public member functions
435 // ===========================================================
436 
437 int
439 d(int xp, int xdd) const
440 {
441  return static_cast<int>(binomial_coefficient(xdd, xp));
442 }
443 
447 round_variance(const tensor_variance& xvariance) const
448 {
449  // Preconditions:
450 
451  // Body:
452 
453  tensor_variance result(xvariance);
454  result.purify();
455 
456  // Postconditions:
457 
458  ensure(result.is_pure());
459  ensure_for_all(i, 0, result.p(), result.variance(i) == xvariance.variance(0));
460 
461  // Exit:
462 
463  return xvariance;
464 }
465 
466 
467 // ===========================================================
468 // TP_SPACE FACET protected member functions
469 // ===========================================================
470 
474 {
475  return 1;
476 }
477 
478 
479 // ===========================================================
480 // POSET FACET
481 // ===========================================================
482 
483 bool
484 fiber_bundle::atp_space::
485 make_prototype()
486 {
487  bool result = false;
488 
489  // Preconditions:
490 
491  // Body:
492 
493 
494  atp_space* lproto = new atp_space;
495  poset_type ltype = lproto->type_id();
496 
497  factory().insert_prototype(lproto);
498  factory().insert_prototype(ltype, lproto);
499 
500  // Postconditions:
501 
502  // Exit:
503 
504  return result;
505 }
506 
507 //==============================================================================
508 // POSET_STATE_HANDLE FACET
509 //==============================================================================
510 
511 
512 
515 type_id() const
516 {
517  return ATP_SPACE_ID;
518 }
519 
522 
523 const char*
525 class_name() const
526 {
527  // Preconditions:
528 
529 
530  // Body:
531 
532  static const char* result = "atp_space";
533 
534  // Postconditions:
535 
536  // Exit:
537 
538  return result;
539 }
540 
541 //==============================================================================
542 // ANY FACET
543 //==============================================================================
544 
545 bool
547 is_ancestor_of(const any* xother) const
548 {
549  bool result;
550 
551  // Preconditions:
552 
553  // Body:
554 
555  result = dynamic_cast<const atp_space*>(xother) != 0;
556 
557  // Postconditions:
558 
559  // Exit
560 
561  return result;
562 }
563 
566 clone() const
567 {
568  atp_space* result;
569 
570  // Preconditions:
571 
572  // Body:
573 
574  result = new atp_space;
575 
576  // Postconditions:
577 
578  ensure(result != 0);
579  ensure(is_same_type(result));
580  ensure(!result->is_attached());
581 
582  // Exit
583 
584  return result;
585 }
586 
587 bool
589 invariant() const
590 {
591  bool result = true;
592 
593 
594  if(invariant_check())
595  {
597 
598  invariance(tp_space::invariant());
599 
601  }
602 
603  return result;
604 }
605 
606 
607 
virtual const char * class_name() const
The name of this class.
Definition: atp_space.cc:525
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.
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.
The "type" of a tensor; specifies the degree and the co- or contra-variance for each index of a tenso...
An antisymmetric tensor of degree p.
Definition: atp.h:190
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
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
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).
An abstract antisymmetric tensor space of degree p.
Definition: atp_space.h:42
static atp_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 atp_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: atp_space.cc:112
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)
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool invariant() const
Class invariant.
Definition: atp_space.cc:589
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 is_p_form(pod_index_type xmbr_id, bool xauto_access) const
True if the member with id xmbr_id is a p-form; synonym for is_covariant(xmbr_id, xauto_access)...
Definition: atp_space.cc:211
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
void put_is_p_form(pod_index_type xmbr_id, bool xauto_access)
Sets is_p_form for the member with id xmbr_id to true; synonym for put_is_covariant(xmbr_id, xauto_access).
Definition: atp_space.cc:250
static const std::string & standard_schema_poset_name()
The name of the standard schema poset for this class.
Definition: atp_space.cc:44
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
atp_space()
Default constructor; creates a new atp_space handle not attached to any state.
Definition: atp_space.cc:383
void put_is_p_vector(pod_index_type xmbr_id, bool xauto_access)
Sets is_p_vector for the member with id xmbr_id to true. synonym for put_is_contravariant(xmbr_id, xauto_access).
Definition: atp_space.cc:334
poset_state_handle()
Default constructor.
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
Definition: atp_space.cc:547
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_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual atp_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
Definition: atp_space.cc:566
virtual poset_type type_id() const
Identifier for the type of this poset.
Definition: atp_space.cc:515
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 poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: atp_space.cc:65
tp_space()
Default constructor; creates a new tp_space handle not attached to any state.
Definition: tp_space.cc:1112
virtual size_type covariant_subposet_ct() const
The number of covariant subposets.
Definition: atp_space.cc:473
void purify()
Sets all indices the same as index 0.
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
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
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 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: atp_space.cc:447
virtual ~atp_space()
Destructor.
Definition: atp_space.cc:398
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
bool is_p_vector(pod_index_type xmbr_id, bool xauto_access) const
True if the member with id xmbr_id is a p-vector; synonym for is_contravariant(xmbr_id, xauto_access).
Definition: atp_space.cc:296