SheafSystem  0.0.0.0
sec_atp_space.cc
Go to the documentation of this file.
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 
20 
21 #include "SheafSystem/sec_atp_space.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/binary_section_space_schema_member.impl.h"
26 #include "SheafSystem/binary_section_space_schema_poset.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/namespace_poset.impl.h"
29 #include "SheafSystem/namespace_poset_member.h"
30 #include "SheafSystem/poset_handle_factory.h"
31 #include "SheafSystem/sec_at1.h"
32 #include "SheafSystem/sec_at1_space.h"
33 #include "SheafSystem/sec_atp.h"
34 #include "SheafSystem/sec_tuple_space.impl.h"
35 #include "SheafSystem/section_space_schema_member.impl.h"
36 #include "SheafSystem/section_space_schema_poset.h"
37 #include "SheafSystem/atp.h"
38 #include "SheafSystem/atp_space.h"
39 
40 using namespace std;
41 using namespace fiber_bundle; // Workaround for MS C++ bug.
42 using namespace fiber_bundle::vd_algebra;
43 
44 //#define DIAGNOSTIC_OUTPUT
45 
46 //==============================================================================
47 // SEC_ATP_SPACE FACET
48 //==============================================================================
49 
50 // PUBLIC MEMBER FUNCTIONS
51 
55  const poset_path& xpath,
56  const poset_path& xschema_path,
57  const poset_path& xvector_space_path,
58  bool xauto_access)
59 {
60  // cout << endl << "Entering sec_atp_space::new_table." << endl;
61 
62  // Preconditions:
63 
64 
65  require(!xpath.empty());
66  require(!xns.contains_path(xpath, xauto_access));
67 
68  require(xschema_path.full());
69  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
70  require(fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
71 
72  require(xns.path_is_auto_read_accessible<vector_space_type::host_type>(xvector_space_path, xauto_access));
73 
74  require(same_vector_fiber_space(xns, xschema_path, xvector_space_path, xauto_access));
75 
76  // Body:
77 
78  // Create the table; have to new it because namespace keeps a pointer.
79 
80  typedef sec_atp_space table_type;
81 
82  table_type& result = *(new table_type());
83 
84  // Create a handle of the right type for the schema member.
85 
86  schema_type lschema(xns, xschema_path, xauto_access);
87 
88  if(xauto_access)
89  {
90  lschema.get_read_access();
91  }
92 
93  // Get the section scalar space path from the section vector space.
94 
95  poset_path lscalar_space_path =
96  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
97 
98  // Create the table dof map.
99 
100  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
101 
102  // The table dofs are mostly the same as the fiber schema,
103  // so just copy them from the fiber schema.
104  // Can't use copy constructor because schema objects are different.
105 
106  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
107  lmap.copy_dof_tuple(lfiber_map);
108 
109  // Replace the fiber scalar space path with the section scalar space path.
110 
111  lmap.put_dof("scalar_space_path", lscalar_space_path);
112 
113  // Replace the fiber vector space path with the section vector space path.
114 
115  lmap.put_dof("vector_space_path", xvector_space_path);
116 
117  // Create the state.
118 
119  result.new_state(xns, xpath, lschema, lmap);
120 
121  if(xauto_access)
122  {
123  lschema.release_access();
124  }
125 
126  // Postconditions:
127 
128  ensure(xns.owns(result, xauto_access));
129  ensure(result.path(true) == xpath);
130  ensure(result.state_is_not_read_accessible());
131  ensure(result.schema(true).path(xauto_access) == xschema_path);
132 
133  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
134  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
135  ensure(result.scalar_space_path(true) ==
136  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access));
137  ensure(result.p(true) == result.schema(true).fiber_space<fiber_type::host_type>().p(xauto_access));
138  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
139  ensure(result.vector_space_path(true) == xvector_space_path);
140 
141  // Exit:
142 
143  // cout << "Leaving sec_atp_space::new_table." << endl;
144  return result;
145 }
146 
147 
148 bool
150 is_p_form(pod_index_type xmbr_id, bool xauto_access) const
151 {
152 
153  // Preconditions:
154 
155  require(state_is_auto_read_accessible(xauto_access));
156  require(contains_member(xmbr_id, xauto_access));
157  require(contains_variance_subposets(xauto_access));
158 
159  // Body:
160 
161  bool result = is_covariant(xmbr_id, xauto_access);
162 
163  // Postconditions:
164 
165  // Exit:
166 
167  return result;
168 }
169 
170 bool
172 is_p_form(const scoped_index& xmbr_id, bool xauto_access) const
173 {
174 
175  // Preconditions:
176 
177  require(state_is_auto_read_accessible(xauto_access));
178  require(contains_member(xmbr_id, xauto_access));
179  require(contains_variance_subposets(xauto_access));
180 
181  // Body:
182 
183  return is_p_form(xmbr_id.hub_pod(), xauto_access);
184 }
185 
186 void
188 put_is_p_form(pod_index_type xmbr_id, bool xauto_access)
189 {
190  // Preconditions:
191 
192  require(state_is_auto_read_write_accessible(xauto_access));
193  require(contains_member(xmbr_id, xauto_access));
194  require(contains_variance_subposets(xauto_access));
195 
196  // Body:
197 
198  put_is_covariant(xmbr_id, xauto_access);
199 
200  // Postconditions:
201 
202  ensure(is_p_form(xmbr_id, xauto_access));
203 
204  // Exit:
205 
206  return;
207 }
208 
209 void
211 put_is_p_form(const scoped_index& xmbr_id, bool xauto_access)
212 {
213  // Preconditions:
214 
215  require(state_is_auto_read_write_accessible(xauto_access));
216  require(contains_member(xmbr_id, xauto_access));
217  require(contains_variance_subposets(xauto_access));
218 
219  // Body:
220 
221  put_is_p_form(xmbr_id.hub_pod(), xauto_access);
222 
223  // Postconditions:
224 
225  ensure(is_p_form(xmbr_id, xauto_access));
226 
227  // Exit:
228 
229  return;
230 }
231 
232 bool
234 is_p_vector(pod_index_type 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  bool result = is_contravariant(xmbr_id, xauto_access);
246 
247  // Postconditions:
248 
249  // Exit:
250 
251  return result;
252 }
253 
254 bool
256 is_p_vector(const scoped_index& xmbr_id, bool xauto_access) const
257 {
258 
259  // Preconditions:
260 
261  require(state_is_auto_read_accessible(xauto_access));
262  require(contains_member(xmbr_id, xauto_access));
263  require(contains_variance_subposets(xauto_access));
264 
265  // Body:
266 
267  return is_p_vector(xmbr_id.hub_pod(), xauto_access);
268 }
269 
270 void
272 put_is_p_vector(pod_index_type xmbr_id, bool xauto_access)
273 {
274  // Preconditions:
275 
276  require(state_is_auto_read_write_accessible(xauto_access));
277  require(contains_member(xmbr_id, xauto_access));
278  require(contains_variance_subposets(xauto_access));
279 
280  // Body:
281 
282  put_is_contravariant(xmbr_id, xauto_access);
283 
284  // Postconditions:
285 
286  ensure(is_p_vector(xmbr_id, xauto_access));
287 
288  // Exit:
289 
290  return;
291 }
292 
293 void
295 put_is_p_vector(const scoped_index& xmbr_id, bool xauto_access)
296 {
297  // Preconditions:
298 
299  require(state_is_auto_read_write_accessible(xauto_access));
300  require(contains_member(xmbr_id, xauto_access));
301  require(contains_variance_subposets(xauto_access));
302 
303  // Body:
304 
305  put_is_p_vector(xmbr_id.hub_pod(), xauto_access);
306 
307  // Postconditions:
308 
309  ensure(is_p_vector(xmbr_id, xauto_access));
310 
311  // Exit:
312 
313  return;
314 }
315 
316 // PROTECTED MEMBER FUNCTIONS
317 
320  : sec_tp_space(new sec_atp, new sec_atp)
321 {
322  // Preconditions:
323 
324  // Body:
325 
326  // Nothing to do, handled by base class
327 
328  // Postconditions:
329 
330  ensure(postcondition_of(sec_tp_space::sec_tp_space()));
331 }
332 
335 {
336  // Preconditions:
337 
338  // Body:
339 
340  // Postconditions:
341 
342  // Exit
343 
344  return;
345 }
346 
348 sec_atp_space(sec_atp* xtop, sec_atp* xbottom)
349  : sec_tp_space(xtop, xbottom)
350 {
351  // Preconditions:
352 
353  require(xtop != 0);
354  require(xbottom != 0);
355 
356  // Body:
357 
358  // Nothing to do.
359 
360  // Postconditions:
361 
362  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
363 
364  // Exit:
365 
366  return;
367 }
368 
369 // PRIVATE MEMBER FUNCTIONS
370 
371 
372 // ===========================================================
373 // SEC_TP_SPACE FACET
374 // ===========================================================
375 
376 // PUBLIC MEMBER FUNCTIONS
377 
378 int
380 d(int xp, int xdd) const
381 {
382  return static_cast<int>(binomial_coefficient(xdd, xp));
383 }
384 
387 round_variance(const tensor_variance& xvariance) const
388 {
389  // Preconditions:
390 
391  // Body:
392 
393  tensor_variance result(xvariance);
394  result.purify();
395 
396  // Postconditions:
397 
398  ensure(result.is_pure());
399  ensure_for_all(i, 0, result.p(), result.variance(i) == xvariance.variance(0));
400 
401  // Exit:
402 
403  return xvariance;
404 }
405 
406 // PROTECTED MEMBER FUNCTIONS
407 
411 {
412  return 1;
413 }
414 
415 // PRIVATE MEMBER FUNCTIONS
416 
417 
418 // ===========================================================
419 // SEC_VD_SPACE FACET
420 // ===========================================================
421 
422 // PUBLIC MEMBER FUNCTIONS
423 
424 // PROTECTED MEMBER FUNCTIONS
425 
426 // PRIVATE MEMBER FUNCTIONS
427 
428 
429 // ===========================================================
430 // SEC_TUPLE_SPACE FACET
431 // ===========================================================
432 
433 // PUBLIC MEMBER FUNCTIONS
434 
435 // PROTECTED MEMBER FUNCTIONS
436 
437 // PRIVATE MEMBER FUNCTIONS
438 
439 
440 // ===========================================================
441 // SEC_REP_SPACE FACET
442 // ===========================================================
443 
444 // PUBLIC MEMBER FUNCTIONS
445 
446 // PROTECTED MEMBER FUNCTIONS
447 
448 // PRIVATE MEMBER FUNCTIONS
449 
450 bool
451 fiber_bundle::sec_atp_space::
452 make_prototype()
453 {
454  bool result = false;
455 
456  // Preconditions:
457 
458  // Body:
459 
460  sec_atp_space* lproto = new sec_atp_space;
461  poset_type ltype = lproto->type_id();
462 
463  factory().insert_prototype(lproto);
464  factory().insert_prototype(ltype, lproto);
465 
466  // Postconditions:
467 
468  // Exit:
469 
470  return result;
471 }
472 
473 
474 //==============================================================================
475 // POSET_STATE_HANDLE FACET
476 //==============================================================================
477 
478 // PUBLIC MEMBER FUNCTIONS
479 
482 type_id() const
483 {
484  return SEC_ATP_SPACE_ID;
485 }
486 
489 
490 const char*
492 class_name() const
493 {
494  // Preconditions:
495 
496  // Body:
497 
498  static const char* result = "sec_atp_space";
499 
500  // Postconditions:
501 
502  // Exit:
503 
504  return result;
505 }
506 
507 // PROTECTED MEMBER FUNCTIONS
508 
509 // PRIVATE MEMBER FUNCTIONS
510 
511 
512 //==============================================================================
513 // READ_WRITE_MONITOR_HANDLE FACET
514 //==============================================================================
515 
516 // PUBLIC MEMBER FUNCTIONS
517 
518 // PROTECTED MEMBER FUNCTIONS
519 
520 // PRIVATE MEMBER FUNCTIONS
521 
522 
523 //==============================================================================
524 // ANY FACET
525 //==============================================================================
526 
527 // PUBLIC MEMBER FUNCTIONS
528 
529 bool
531 is_ancestor_of(const any* xother) const
532 {
533  bool result;
534 
535  // Preconditions:
536 
537  // Body:
538 
539  result = dynamic_cast<const sec_atp_space*>(xother) != 0;
540 
541  // Postconditions:
542 
543  // Exit
544 
545  return result;
546 }
547 
550 clone() const
551 {
552  sec_atp_space* result;
553 
554  // Preconditions:
555 
556  // Body:
557 
558  result = new sec_atp_space;
559 
560  // Postconditions:
561 
562  ensure(result != 0);
563  ensure(is_same_type(result));
564  ensure(!result->is_attached());
565 
566  // Exit
567 
568  return result;
569 }
570 
571 bool
573 invariant() const
574 {
575  bool result = true;
576 
577 
578  if(invariant_check())
579  {
581 
582  invariance(sec_tp_space::invariant());
583 
585  }
586 
587  return result;
588 }
589 
590 // PROTECTED MEMBER FUNCTIONS
591 
592 // PRIVATE MEMBER FUNCTIONS
593 
594 
595 
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 client handle for a poset member which has been prepared for use as a schema for a section space...
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...
A space of scalars viewed as an antisymmetric tensor section space of degree 1.
Definition: sec_at1_space.h:48
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_type
Identifiers for poset types.
Definition: poset_type.h:41
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...
sec_tp_space()
Default constructor; creates a new sec_tp_space handle not attached to any state. ...
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 bool invariant() const
Class invariant.
A schema poset for a section space. A binary Cartesian product subspace of the binary tensor product ...
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
void copy_dof_tuple(const poset_dof_map &xother)
Copies the dof tuple of xother into this.
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).
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)...
virtual ~sec_atp_space()
Destructor.
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...
sec_atp_space()
Default constructor; creates a new sec_atp_space handle not attached to any state.
Abstract base class with useful features for all objects.
Definition: any.h:39
An abstract antisymmetric tensor section space of degree p.
Definition: sec_atp_space.h:47
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).
An abstract antisymmetric tensor space of degree p.
Definition: atp_space.h:42
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
An abstract tensor section space of degree p.
Definition: sec_tp_space.h:53
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 const char * class_name() const
The name of this class.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
A section of a bundle with fiber type atp.
Definition: sec_atp.h:48
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
static sec_atp_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 sec_atp_space in namespace xns with path xpath, schema specified by xschema_path...
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.
virtual poset_type type_id() const
Identifier for the type of this poset.
static poset_handle_factory & factory()
The poset handle factory.
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.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual bool invariant() const
Class invariant.
virtual sec_atp_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
bool variance(int xi) const
The variance of the xi-th index; covariant if true, contravariant if false.
void purify()
Sets all indices the same as index 0.
int d() const
The dimension.
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).
An array representation of abstract class poset_dof_map.
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
virtual size_type covariant_subposet_ct() const
The number of covariant subposets.
virtual array_poset_dof_map & table_dof_map(bool xrequire_write_access=false)
The map from table dof client_ids to table dof values for this poset (mutable version) ...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710