SheafSystem  0.0.0.0
sec_stp_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_stp_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_stp.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/stp_space.h"
38 
39 using namespace std;
40 using namespace fiber_bundle; // Workaround for MS C++ bug.
41 using namespace fiber_bundle::vd_algebra;
42 
43 //#define DIAGNOSTIC_OUTPUT
44 
45 //==============================================================================
46 // SEC_STP_SPACE FACET
47 //==============================================================================
48 
49 // PUBLIC MEMBER FUNCTIONS
50 
54  const poset_path& xpath,
55  const poset_path& xschema_path,
56  const poset_path& xvector_space_path,
57  bool xauto_access)
58 {
59  // cout << endl << "Entering sec_stp_space::new_table." << endl;
60 
61  // Preconditions:
62 
63 
64  require(!xpath.empty());
65  require(!xns.contains_path(xpath, xauto_access));
66 
67  require(xschema_path.full());
68  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
69  require(fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
70 
71  require(xns.path_is_auto_read_accessible<vector_space_type::host_type>(xvector_space_path, xauto_access));
72 
73  require(same_vector_fiber_space(xns, xschema_path, xvector_space_path, xauto_access));
74 
75  // Body:
76 
77  // Create the table; have to new it because namespace keeps a pointer.
78 
79  typedef sec_stp_space table_type;
80 
81  table_type& result = *(new table_type());
82 
83  // Create a handle of the right type for the schema member.
84 
85  schema_type lschema(xns, xschema_path, xauto_access);
86 
87  if(xauto_access)
88  {
89  lschema.get_read_access();
90  }
91 
92  // Get the section scalar space path from the section vector space.
93 
94  poset_path lscalar_space_path =
95  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
96 
97  // Create the table dof map.
98 
99  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
100 
101  // The table dofs are mostly the same as the fiber schema,
102  // so just copy them from the fiber schema.
103  // Can't use copy constructor because schema objects are different.
104 
105  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
106  lmap.copy_dof_tuple(lfiber_map);
107 
108  // Replace the fiber scalar space path with the section scalar space path.
109 
110  lmap.put_dof("scalar_space_path", lscalar_space_path);
111 
112  // Replace the fiber vector space path with the section vector space path.
113 
114  lmap.put_dof("vector_space_path", xvector_space_path);
115 
116  // Create the state.
117 
118  result.new_state(xns, xpath, lschema, lmap);
119 
120  if(xauto_access)
121  {
122  lschema.release_access();
123  }
124 
125  // Postconditions:
126 
127  ensure(xns.owns(result, xauto_access));
128  ensure(result.path(true) == xpath);
129  ensure(result.state_is_not_read_accessible());
130  ensure(result.schema(true).path(xauto_access) == xschema_path);
131 
132  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
133  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
134  ensure(result.scalar_space_path(true) ==
135  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access));
136  ensure(result.p(true) == result.schema(true).fiber_space<fiber_type::host_type>().p(xauto_access));
137  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
138  ensure(result.vector_space_path(true) == xvector_space_path);
139 
140  // Exit:
141 
142  // cout << "Leaving sec_stp_space::new_table." << endl;
143  return result;
144 }
145 
146 // PROTECTED MEMBER FUNCTIONS
147 
150  : sec_tp_space(new sec_stp, new sec_stp)
151 {
152  // Preconditions:
153 
154  // Body:
155 
156  // Nothing to do, handled by base class
157 
158  // Postconditions:
159 
160  ensure(postcondition_of(sec_tp_space::sec_tp_space()));
161 }
162 
165 {
166  // Preconditions:
167 
168  // Body:
169 
170  // Postconditions:
171 
172  // Exit
173 
174  return;
175 }
176 
178 sec_stp_space(sec_stp* xtop, sec_stp* xbottom)
179  : sec_tp_space(xtop, xbottom)
180 {
181  // Preconditions:
182 
183  require(xtop != 0);
184  require(xbottom != 0);
185 
186  // Body:
187 
188  // Nothing to do.
189 
190  // Postconditions:
191 
192  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
193 
194  // Exit:
195 
196  return;
197 }
198 
199 // ===========================================================
200 // SEC_TP_SPACE FACET
201 // ===========================================================
202 
203 // PUBLIC MEMBER FUNCTIONS
204 
205 int
207 d(int xp, int xdd) const
208 {
209  return static_cast<int>(binomial_coefficient(xdd+xp-1, xp));
210 }
211 
214 round_variance(const tensor_variance& xvariance) const
215 {
216  // Preconditions:
217 
218  // Body:
219 
220  tensor_variance result(xvariance);
221  result.purify();
222 
223  // Postconditions:
224 
225  ensure(result.is_pure());
226  ensure_for_all(i, 0, result.p(), result.variance(i) == xvariance.variance(0));
227 
228  // Exit:
229 
230  return xvariance;
231 }
232 
233 // PROTECTED MEMBER FUNCTIONS
234 
238 {
239  return 1;
240 }
241 
242 // PRIVATE MEMBER FUNCTIONS
243 
244 
245 // ===========================================================
246 // SEC_VD_SPACE FACET
247 // ===========================================================
248 
249 // PUBLIC MEMBER FUNCTIONS
250 
251 // PROTECTED MEMBER FUNCTIONS
252 
253 // PRIVATE MEMBER FUNCTIONS
254 
255 
256 // ===========================================================
257 // SEC_TUPLE_SPACE FACET
258 // ===========================================================
259 
260 // PUBLIC MEMBER FUNCTIONS
261 
262 // PROTECTED MEMBER FUNCTIONS
263 
264 // PRIVATE MEMBER FUNCTIONS
265 
266 
267 // ===========================================================
268 // SEC_REP_SPACE FACET
269 // ===========================================================
270 
271 // PUBLIC MEMBER FUNCTIONS
272 
273 // PROTECTED MEMBER FUNCTIONS
274 
275 // PRIVATE MEMBER FUNCTIONS
276 
277 bool
278 fiber_bundle::sec_stp_space::
279 make_prototype()
280 {
281  bool result = false;
282 
283  // Preconditions:
284 
285  // Body:
286 
287  sec_stp_space* lproto = new sec_stp_space;
288  poset_type ltype = lproto->type_id();
289 
290  factory().insert_prototype(lproto);
291  factory().insert_prototype(ltype, lproto);
292 
293  // Postconditions:
294 
295  // Exit:
296 
297  return result;
298 }
299 
300 
301 //==============================================================================
302 // POSET_STATE_HANDLE FACET
303 //==============================================================================
304 
305 // PUBLIC MEMBER FUNCTIONS
306 
309 type_id() const
310 {
311  return SEC_STP_SPACE_ID;
312 }
313 
316 
317 const char*
319 class_name() const
320 {
321  // Preconditions:
322 
323  // Body:
324 
325  static const char* result = "sec_stp_space";
326 
327  // Postconditions:
328 
329  // Exit:
330 
331  return result;
332 }
333 
334 // PROTECTED MEMBER FUNCTIONS
335 
336 // PRIVATE MEMBER FUNCTIONS
337 
338 
339 //==============================================================================
340 // READ_WRITE_MONITOR_HANDLE FACET
341 //==============================================================================
342 
343 // PUBLIC MEMBER FUNCTIONS
344 
345 // PROTECTED MEMBER FUNCTIONS
346 
347 // PRIVATE MEMBER FUNCTIONS
348 
349 
350 //==============================================================================
351 // ANY FACET
352 //==============================================================================
353 
354 // PUBLIC MEMBER FUNCTIONS
355 
356 bool
358 is_ancestor_of(const any* xother) const
359 {
360  bool result;
361 
362  // Preconditions:
363 
364  // Body:
365 
366  result = dynamic_cast<const sec_stp_space*>(xother) != 0;
367 
368  // Postconditions:
369 
370  // Exit
371 
372  return result;
373 }
374 
377 clone() const
378 {
379  sec_stp_space* result;
380 
381  // Preconditions:
382 
383  // Body:
384 
385  result = new sec_stp_space;
386 
387  // Postconditions:
388 
389  ensure(result != 0);
390  ensure(is_same_type(result));
391  ensure(!result->is_attached());
392 
393  // Exit
394 
395  return result;
396 }
397 
398 bool
400 invariant() const
401 {
402  bool result = true;
403 
404 
405  if(invariant_check())
406  {
408 
409  invariance(sec_tp_space::invariant());
410 
412  }
413 
414  return result;
415 }
416 
417 // PROTECTED MEMBER FUNCTIONS
418 
419 // PRIVATE MEMBER FUNCTIONS
420 
421 
422 
bool is_pure() const
True if and only if all indices are covariant or all indices are contravariant.
virtual ~sec_stp_space()
Destructor.
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
An abstract symmetric tensor section space of degree p.
Definition: sec_stp_space.h:47
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...
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.
virtual bool invariant() const
Class invariant.
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
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
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
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.
static sec_stp_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...
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.
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 size_type covariant_subposet_ct() const
The number of covariant subposets.
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 sec_stp_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual poset_type type_id() const
Identifier for the type of this poset.
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
A section of a bundle with fiber type stp.
Definition: sec_stp.h:48
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.
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
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
sec_stp_space()
Default constructor; creates a new sec_stp_space handle not attached to any state.
bool variance(int xi) const
The variance of the xi-th index; covariant if true, contravariant if false.
virtual const char * class_name() const
The name of this class.
void purify()
Sets all indices the same as index 0.
int d() const
The dimension.
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
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 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) ...