SheafSystem  0.0.0.0
sec_at1_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_at1_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_at0.h"
32 #include "SheafSystem/sec_at0_space.h"
33 #include "SheafSystem/sec_at1.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/at1.h"
38 #include "SheafSystem/at1_space.h"
39 
40 using namespace std;
41 using namespace fiber_bundle; // Workaround for MS C++ bug.
42 
43 //#define DIAGNOSTIC_OUTPUT
44 
45 //==============================================================================
46 // SEC_AT1_SPACE FACET
47 //==============================================================================
48 
49 // PUBLIC MEMBER FUNCTIONS
50 
54  const poset_path& xpath,
55  const poset_path& xschema_path,
56  const poset_path& xscalar_space_path,
57  bool xauto_access)
58 {
59  // cout << endl << "Entering sec_at1_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<scalar_type::host_type>(xscalar_space_path, xauto_access));
72 
73  require(same_scalar_fiber_space(xns, xschema_path, xscalar_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_at1_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  // Create the table dof map.
93 
94  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
95 
96  // The table dofs are mostly the same as the fiber schema,
97  // so just copy them from the fiber schema.
98  // Can't use copy constructor because schema objects are different.
99 
100  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
101  lmap.copy_dof_tuple(lfiber_map);
102 
103  // Replace the fiber scalar space path with the section scalar space path.
104 
105  lmap.put_dof("scalar_space_path", xscalar_space_path);
106 
107  // Replace the fiber vector space path with the section vector space path.
108  // sec_at1 is its own vector section space.
109 
110  lmap.put_dof("vector_space_path", xpath);
111 
112  // Create the state.
113 
114  result.new_state(xns, xpath, lschema, lmap);
115 
116  if(xauto_access)
117  {
118  lschema.release_access();
119  }
120 
121  // Postconditions:
122 
123  ensure(xns.owns(result, xauto_access));
124  ensure(result.path(true) == xpath);
125  ensure(result.state_is_not_read_accessible());
126  ensure(result.schema(true).path(xauto_access) == xschema_path);
127 
128  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
129  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
130  ensure(result.d(true) == result.dd(true));
131  ensure(result.scalar_space_path(true) == xscalar_space_path);
132  ensure(result.p(true) == result.schema(true).fiber_space<fiber_type::host_type>().p(xauto_access));
133  ensure(result.p(true) == 1);
134  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
135  ensure(result.vector_space_path(true) == xpath);
136 
137  // Exit:
138 
139  // cout << "Leaving sec_at1_space::new_table." << endl;
140  return result;
141 }
142 
143 // PROTECTED MEMBER FUNCTIONS
144 
147  : sec_atp_space(new sec_at1, new sec_at1)
148 {
149  // Preconditions:
150 
151  // Body:
152 
153  // Nothing to do, handled by base class
154 
155  // Postconditions:
156 
157  ensure(postcondition_of(sec_atp_space::sec_atp_space()));
158 }
159 
162 {
163  // Preconditions:
164 
165  // Body:
166 
167  // Postconditions:
168 
169  // Exit
170 
171  return;
172 }
173 
175 sec_at1_space(sec_at1* xtop, sec_at1* xbottom)
176  : sec_atp_space(xtop, xbottom)
177 {
178  // Preconditions:
179 
180  require(xtop != 0);
181  require(xbottom != 0);
182 
183  // Body:
184 
185  // Nothing to do.
186 
187  // Postconditions:
188 
189  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
190 
191  // Exit:
192 
193  return;
194 }
195 
196 // PRIVATE MEMBER FUNCTIONS
197 
198 
199 // ===========================================================
200 // SEC_ATP_SPACE FACET
201 // ===========================================================
202 
203 // PUBLIC MEMBER FUNCTIONS
204 
205 // PROTECTED MEMBER FUNCTIONS
206 
207 // PRIVATE MEMBER FUNCTIONS
208 
209 
210 // ===========================================================
211 // SEC_TP_SPACE FACET
212 // ===========================================================
213 
214 // PUBLIC MEMBER FUNCTIONS
215 
216 // PROTECTED MEMBER FUNCTIONS
217 
218 // PRIVATE MEMBER FUNCTIONS
219 
220 
221 // ===========================================================
222 // SEC_VD_SPACE FACET
223 // ===========================================================
224 
225 // PUBLIC MEMBER FUNCTIONS
226 
227 // PROTECTED MEMBER FUNCTIONS
228 
229 // PRIVATE MEMBER FUNCTIONS
230 
231 
232 // ===========================================================
233 // SEC_TUPLE_SPACE FACET
234 // ===========================================================
235 
236 // PUBLIC MEMBER FUNCTIONS
237 
238 // PROTECTED MEMBER FUNCTIONS
239 
240 // PRIVATE MEMBER FUNCTIONS
241 
242 
243 // ===========================================================
244 // SEC_REP_SPACE FACET
245 // ===========================================================
246 
247 // PUBLIC MEMBER FUNCTIONS
248 
249 // PROTECTED MEMBER FUNCTIONS
250 
251 // PRIVATE MEMBER FUNCTIONS
252 
253 bool
254 fiber_bundle::sec_at1_space::
255 make_prototype()
256 {
257  bool result = false;
258 
259  // Preconditions:
260 
261  // Body:
262 
263  sec_at1_space* lproto = new sec_at1_space;
264  poset_type ltype = lproto->type_id();
265 
266  factory().insert_prototype(lproto);
267  factory().insert_prototype(ltype, lproto);
268 
269  // Postconditions:
270 
271  // Exit:
272 
273  return result;
274 }
275 
276 
277 //==============================================================================
278 // POSET_STATE_HANDLE FACET
279 //==============================================================================
280 
281 // PUBLIC MEMBER FUNCTIONS
282 
285 type_id() const
286 {
287  return SEC_AT1_SPACE_ID;
288 }
289 
292 
293 const char*
295 class_name() const
296 {
297  // Preconditions:
298 
299  // Body:
300 
301  static const char* result = "sec_at1_space";
302 
303  // Postconditions:
304 
305  // Exit:
306 
307  return result;
308 }
309 
312 prereq_id(int xi) const
313 {
314  // Preconditions:
315 
316  require(state_is_read_accessible());
317  require(name_space()->state_is_read_accessible());
318 
319  // Body:
320 
321  pod_index_type result;
322 
323  switch(xi)
324  {
325  case 0:
326 
327  // The first prerequisite is always the schema.
328 
329  result = schema().host()->index().pod();
330  break;
331 
332  case 1:
333 
334  // The vector space over which this tensor space is built.
335 
336  result = name_space()->member_id(scalar_space_path().poset_name(), false);
337  break;
338 
339  default:
340 
341  // No other prerequisites.
342 
343  result = invalid_pod_index();
344  break;
345  }
346 
347  // Postconditions:
348 
349  // Exit:
350 
351  return result;
352 }
353 
354 // PROTECTED MEMBER FUNCTIONS
355 
356 // PRIVATE MEMBER FUNCTIONS
357 
358 
359 //==============================================================================
360 // READ_WRITE_MONITOR_HANDLE FACET
361 //==============================================================================
362 
363 // PUBLIC MEMBER FUNCTIONS
364 
365 // PROTECTED MEMBER FUNCTIONS
366 
367 // PRIVATE MEMBER FUNCTIONS
368 
369 
370 //==============================================================================
371 // ANY FACET
372 //==============================================================================
373 
374 // PUBLIC MEMBER FUNCTIONS
375 
376 bool
378 is_ancestor_of(const any* xother) const
379 {
380  bool result;
381 
382  // Preconditions:
383 
384  // Body:
385 
386  result = dynamic_cast<const sec_at1_space*>(xother) != 0;
387 
388  // Postconditions:
389 
390  // Exit
391 
392  return result;
393 }
394 
397 clone() const
398 {
399  sec_at1_space* result;
400 
401  // Preconditions:
402 
403  // Body:
404 
405  result = new sec_at1_space;
406 
407  // Postconditions:
408 
409  ensure(result != 0);
410  ensure(is_same_type(result));
411  ensure(!result->is_attached());
412 
413  // Exit
414 
415  return result;
416 }
417 
418 bool
420 invariant() const
421 {
422  bool result = true;
423 
424 
425  if(invariant_check())
426  {
428 
429  invariance(sec_atp_space::invariant());
430 
431  invariance(state_is_read_accessible() ? p() == 1 : true);
432  invariance(state_is_read_accessible() ? vector_space_path().poset_name() == name() : true);
433 
435  }
436 
437  return result;
438 }
439 
440 // PROTECTED MEMBER FUNCTIONS
441 
442 // PRIVATE MEMBER FUNCTIONS
443 
444 
445 
void insert_prototype(const poset_state_handle *xprototype)
Sets xprototype as the prototype for its client class.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
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
A Cartesian product section space.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
const scoped_index & index() const
The member index of this poset within the namespace host()
A space of scalars viewed as an antisymmetric tensor section space of degree 1.
Definition: sec_at1_space.h:48
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
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
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
poset_path vector_space_path() const
The path of the underlying vector space.
STL namespace.
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.
A section of a bundle with fiber type at1.
Definition: sec_at1.h:48
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...
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
int p() const
The tensor degree of this space.
An abstract antisymmetric tensor section space of degree p.
Definition: sec_atp_space.h:47
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
virtual const char * class_name() const
The name of this class.
virtual bool invariant() const
Class invariant.
virtual pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
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)
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
virtual ~sec_at1_space()
Destructor.
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
poset_state_handle()
Default constructor.
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
virtual poset_type type_id() const
Identifier for the type of this poset.
virtual bool invariant() const
Class invariant.
virtual sec_at1_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_path scalar_space_path() const
The path of the underlying space of scalars.
poset & fiber_space()
The fiber space for section spaces on this schema (mutable version).
sec_at1_space()
Default constructor; creates a new sec_at1_space handle not attached to any state.
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
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
static sec_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 sec_at1_space in namespace xns with path xpath, schema specified by xschema_path...
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) ...
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...