SheafSystem  0.0.0.0
sec_tp_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_tp_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_tp.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/tp.h"
38 #include "SheafSystem/tp_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_TP_SPACE FACET
47 //==============================================================================
48 
49 // PUBLIC MEMBER FUNCTIONS
50 
51 bool
54  const poset_path& xschema_path,
55  const poset_path& xvector_space_path,
56  bool xauto_access)
57 {
58  // cout << endl << "Entering sec_tp_space::same_vector_fiber_space." << endl;
59 
60  // Preconditions:
61 
62  require(xns.state_is_auto_read_accessible(xauto_access));
63  require(xns.path_is_auto_read_accessible<section_space_schema_poset>(xschema_path, xauto_access));
64  require(xns.path_is_auto_read_accessible<vector_space_type::host_type>(xvector_space_path, xauto_access));
65 
66  // Body:
67 
68  section_space_schema_poset& lschema_host = xns.member_poset<section_space_schema_poset>(xschema_path, xauto_access);
69  vector_space_type::host_type& lvector_host = xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access);
70 
71  fiber_type::host_type* lfiber_space = dynamic_cast<fiber_type::host_type*>(&lschema_host.fiber_space());
72  bool result = false;
73  if(lfiber_space != 0)
74  {
75  result = lfiber_space->vector_space_path(xauto_access) == lvector_host.schema().fiber_space().path(xauto_access);
76  }
77 
78  // Postconditions:
79 
80 
81  // Exit:
82 
83  // cout << "Leaving sec_tp_space::same_vector_fiber_space." << endl;
84  return result;
85 }
86 
87 
91  const poset_path& xpath,
92  const poset_path& xschema_path,
93  const poset_path& xvector_space_path,
94  bool xauto_access)
95 {
96  // cout << endl << "Entering sec_tp_space::new_table." << endl;
97 
98  // Preconditions:
99 
100 
101  require(!xpath.empty());
102  require(!xns.contains_path(xpath, xauto_access));
103 
104  require(xschema_path.full());
105  require(xns.path_is_auto_read_accessible<schema_type::host_type>(xschema_path, xauto_access));
106  require(fiber_space_conforms<fiber_type::host_type>(xns, xschema_path, xauto_access));
107 
108  require(xns.path_is_auto_read_accessible<vector_space_type::host_type>(xvector_space_path, xauto_access));
109 
110  require(same_vector_fiber_space(xns, xschema_path, xvector_space_path, xauto_access));
111 
112  // Body:
113 
114  // Create the table; have to new it because namespace keeps a pointer.
115 
116  typedef sec_tp_space table_type;
117 
118  table_type& result = *(new table_type());
119 
120  // Create a handle of the right type for the schema member.
121 
122  schema_type lschema(xns, xschema_path, xauto_access);
123 
124  if(xauto_access)
125  {
126  lschema.get_read_access();
127  }
128 
129  // Get the section scalar space path from the section vector space.
130 
131  poset_path lscalar_space_path =
132  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access);
133 
134  // Create the table dof map.
135 
136  array_poset_dof_map& lmap = *(new array_poset_dof_map(&lschema, true));
137 
138  // The table dofs are mostly the same as the fiber schema,
139  // so just copy them from the fiber schema.
140  // Can't use copy constructor because schema objects are different.
141 
142  array_poset_dof_map& lfiber_map = lschema.fiber_space().table_dof_map();
143  lmap.copy_dof_tuple(lfiber_map);
144 
145  // Replace the fiber scalar space path with the section scalar space path.
146 
147  lmap.put_dof("scalar_space_path", lscalar_space_path);
148 
149  // Replace the fiber vector space path with the section vector space path.
150 
151  lmap.put_dof("vector_space_path", xvector_space_path);
152 
153  // Create the state.
154 
155  result.new_state(xns, xpath, lschema, lmap);
156 
157  if(xauto_access)
158  {
159  lschema.release_access();
160  }
161 
162  // Postconditions:
163 
164  ensure(xns.owns(result, xauto_access));
165  ensure(result.path(true) == xpath);
166  ensure(result.state_is_not_read_accessible());
167  ensure(result.schema(true).path(xauto_access) == xschema_path);
168 
169  ensure(result.factor_ct(true) == result.schema(true).fiber_space<fiber_type::host_type>().factor_ct(xauto_access));
170  ensure(result.d(true) == result.schema(true).fiber_space<fiber_type::host_type>().d(xauto_access));
171  ensure(result.scalar_space_path(true) ==
172  xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access));
173  ensure(result.p(true) == result.schema(true).fiber_space<fiber_type::host_type>().p(xauto_access));
174  ensure(result.dd(true) == result.schema(true).fiber_space<fiber_type::host_type>().dd(xauto_access));
175  ensure(result.vector_space_path(true) == xvector_space_path);
176 
177  // Exit:
178 
179  // cout << "Leaving sec_tp_space::new_table." << endl;
180  return result;
181 }
182 
183 
184 //==============================================================================
185 // TABLE DOFS
186 //==============================================================================
187 
188 int
190 d(int xp, int xdd) const
191 {
192  return static_cast<int>(pow(static_cast<double>(xdd), xp));
193 }
194 
195 int
197 p() const
198 {
199  // Preconditions:
200 
201  require(state_is_read_accessible());
202 
203  // Body:
204 
205  int result = sheaf::table_dofs(*this).p;
206 
207  // Postconditions:
208 
209  // Exit:
210 
211  return result;
212 }
213 
214 int
216 p(bool xauto_access) const
217 {
218  // Preconditions:
219 
220  require(state_is_auto_read_accessible(xauto_access));
221 
222  // Body:
223 
224  if(xauto_access)
225  {
226  get_read_access();
227  }
228 
229  int result = sheaf::table_dofs(*this).p;
230 
231  if(xauto_access)
232  {
233  release_access();
234  }
235 
236  // Postconditions:
237 
238  // Exit:
239 
240  return result;
241 }
242 
243 int
245 dd() const
246 {
247  // Preconditions:
248 
249  require(state_is_read_accessible());
250 
251  // Body:
252 
253  int result = sheaf::table_dofs(*this).dd;
254 
255  // Postconditions:
256 
257  // Exit:
258 
259  return result;
260 }
261 
262 int
264 dd(bool xauto_access) const
265 {
266  // Preconditions:
267 
268  require(state_is_auto_read_accessible(xauto_access));
269 
270  // Body:
271 
272  if(xauto_access)
273  {
274  get_read_access();
275  }
276 
277  int result = sheaf::table_dofs(*this).dd;
278 
279  if(xauto_access)
280  {
281  release_access();
282  }
283 
284  // Postconditions:
285 
286  // Exit:
287 
288  return result;
289 }
290 
294 {
295  // Preconditions:
296 
297  require(state_is_read_accessible());
298 
299  // Body:
300 
301  poset_path result(sheaf::table_dofs(*this).vector_space_path);
302 
303  // Postconditions:
304 
305  ensure(!result.empty());
306 
307  // Exit:
308 
309  return result;
310 }
311 
314 vector_space_path(bool xauto_access) const
315 {
316  // Preconditions:
317 
318  require(state_is_auto_read_accessible(xauto_access));
319 
320  // Body:
321 
322  if(xauto_access)
323  {
324  get_read_access();
325  }
326 
327  poset_path result(sheaf::table_dofs(*this).vector_space_path);
328 
329  if(xauto_access)
330  {
331  release_access();
332  }
333 
334  // Postconditions:
335 
336  ensure(!result.empty());
337 
338  // Exit:
339 
340  return result;
341 }
342 
345 variance(pod_index_type xmbr_id, bool xauto_access) const
346 {
347  // Preconditions:
348 
349  require(state_is_auto_read_accessible(xauto_access));
350  require(contains_member(xmbr_id, xauto_access));
351  require(contains_variance_subposets(xauto_access));
352 
353  // Body:
354 
355  if(xauto_access)
356  {
357  get_read_access();
358  }
359 
360  int lp = p();
361  tensor_variance result(lp);
362 
363  for(int i=0; i<lp; ++i)
364  {
365  result.put_variance(i, is_covariant(xmbr_id, i, false));
366  }
367 
368  if(xauto_access)
369  {
370  release_access();
371  }
372 
373  // Postconditions:
374 
375  // Exit:
376 
377  return result;
378 }
379 
382 variance(const scoped_index& xmbr_id, bool xauto_access) const
383 {
384  // Preconditions:
385 
386  require(state_is_auto_read_accessible(xauto_access));
387  require(contains_member(xmbr_id, xauto_access));
388  require(contains_variance_subposets(xauto_access));
389 
390  // Body:
391 
392  return variance(xmbr_id.hub_pod(), xauto_access);
393 }
394 
395 bool
397 variance(pod_index_type xmbr_id, int xi, bool xauto_access) const
398 {
399  // Preconditions:
400 
401  require(state_is_auto_read_accessible(xauto_access));
402  require(contains_member(xmbr_id, xauto_access));
403 
404  // Body:
405 
406  bool result = is_covariant(xmbr_id, xi, xauto_access);
407 
408  // Postconditions:
409 
410  // Exit:
411 
412  return result;
413 }
414 
415 bool
417 variance(const scoped_index& xmbr_id, int xi, bool xauto_access) const
418 {
419  // Preconditions:
420 
421  require(state_is_auto_read_accessible(xauto_access));
422  require(contains_member(xmbr_id, xauto_access));
423 
424  // Body:
425 
426  return variance(xmbr_id.hub_pod(), xi, xauto_access);
427 }
428 
429 void
431 put_variance(pod_index_type xmbr_id, const tensor_variance& xvariance, bool xauto_access)
432 {
433  // Preconditions:
434 
435  require(state_is_auto_read_write_accessible(xauto_access));
436  require(contains_member(xmbr_id, xauto_access));
437  require(xvariance.p() == p(xauto_access));
438 
439  // Body:
440 
441  if(xauto_access)
442  {
443  get_read_write_access(true);
444  }
445 
446  int lct = covariant_subposet_ct();
447 
448  for(int i=0; i<lct; ++i)
449  {
450  put_variance(xmbr_id, i, xvariance.variance(i), false);
451  }
452 
453  if(xauto_access)
454  {
455  release_access();
456  }
457 
458  // Postconditions:
459 
460  ensure(variance(xmbr_id, xauto_access) == round_variance(xvariance));
461 
462  // Exit:
463 
464  return;
465 }
466 
467 void
469 put_variance(const scoped_index& xmbr_id, const tensor_variance& xvariance, bool xauto_access)
470 {
471  // Preconditions:
472 
473  require(state_is_auto_read_write_accessible(xauto_access));
474  require(contains_member(xmbr_id, xauto_access));
475  require(xvariance.p() == p(xauto_access));
476 
477  // Body:
478 
479  put_variance(xmbr_id.hub_pod(), xvariance, xauto_access);
480 
481  // Postconditions:
482 
483  ensure(variance(xmbr_id, xauto_access) == round_variance(xvariance));
484 
485  // Exit:
486 
487  return;
488 }
489 
490 void
492 put_variance(pod_index_type xmbr_id, int xi, bool xvariance, bool xauto_access)
493 {
494  // Preconditions:
495 
496  require(state_is_auto_read_write_accessible(xauto_access));
497  require(contains_member(xmbr_id, xauto_access));
498  require((0 <= xi) && (xi < p(xauto_access)));
499 
500  // Body:
501 
502  if(xvariance)
503  {
504  put_is_covariant(xmbr_id, xi, xauto_access);
505  }
506  else
507  {
508  put_is_contravariant(xmbr_id, xi, xauto_access);
509  }
510 
511  // Postconditions:
512 
513  ensure(variance(xmbr_id, xi, xauto_access) == xvariance);
514 
515  // Exit:
516 
517  return;
518 }
519 
520 void
522 put_variance(const scoped_index& xmbr_id, int xi, bool xvariance, bool xauto_access)
523 {
524  // Preconditions:
525 
526  require(state_is_auto_read_write_accessible(xauto_access));
527  require(contains_member(xmbr_id, xauto_access));
528  require((0 <= xi) && (xi < p(xauto_access)));
529 
530  // Body:
531 
532  put_variance(xmbr_id.hub_pod(), xi, xvariance, xauto_access);
533 
534  // Postconditions:
535 
536  ensure(variance(xmbr_id, xi, xauto_access) == xvariance);
537 
538  // Exit:
539 
540  return;
541 }
542 
545 round_variance(const tensor_variance& xvariance) const
546 {
547  // Preconditions:
548 
549  // Body:
550 
551  // Postconditions:
552 
553  // Exit:
554 
555  return xvariance;
556 }
557 
558 bool
560 is_covariant(pod_index_type xmbr_id, bool xauto_access) const
561 {
562  // Preconditions:
563 
564  require(state_is_auto_read_accessible(xauto_access));
565  require(contains_member(xmbr_id, xauto_access));
566 
567  // Body:
568 
569  if(xauto_access)
570  {
571  get_read_access();
572  }
573 
574  bool result = true;
575  int lp = covariant_subposet_ct();
576  for(int i=0; i<lp && result; ++i)
577  {
578  subposet lsp(this, covariant_subposet_name(i));
579  bool result = lsp.contains_member(xmbr_id);
580  lsp.detach_from_state();
581  }
582 
583  // The above implementation returns the correct result for p == 0.
584 
585  assertion(p() == 0 ? result : true);
586 
587  if(xauto_access)
588  {
589  release_access();
590  }
591 
592  // Postconditions:
593 
594 
595  // Exit:
596 
597  return result;
598 }
599 
600 bool
602 is_covariant(const scoped_index& xmbr_id, bool xauto_access) const
603 {
604  // Preconditions:
605 
606  require(state_is_auto_read_accessible(xauto_access));
607  require(contains_member(xmbr_id, xauto_access));
608 
609  // Body:
610 
611  return is_covariant(xmbr_id.hub_pod(), xauto_access);
612 }
613 
614 bool
616 is_covariant(pod_index_type xmbr_id, int xi, bool xauto_access) const
617 {
618  // Preconditions:
619 
620  require(state_is_auto_read_accessible(xauto_access));
621  require(contains_member(xmbr_id, xauto_access));
622  require((0 <= xi) && (xi < p(xauto_access)));
623  require(contains_variance_subposets(xauto_access));
624 
625  // Body:
626 
627  if(xauto_access)
628  {
629  get_read_access();
630  }
631 
632  // Since precondition ensures xi >= 0 and xi < p; p can not be 0.
633  // So covaraint_subposet_ct() is either p or 1. If only 1,
634  // then we have either an stp or an atp and setting the variance
635  // of any index is equivalent to setting them all.
636 
637  int lxi = (covariant_subposet_ct() > 1) ? xi : 0;
638 
642 
643  subposet lsp(this, covariant_subposet_name(lxi));
644  bool result = lsp.contains_member(xmbr_id);
645  lsp.detach_from_state();
646 
647  if(xauto_access)
648  {
649  release_access();
650  }
651 
652  // Postconditions:
653 
654 
655  // Exit:
656 
657  return result;
658 }
659 
660 bool
662 is_covariant(const scoped_index& xmbr_id, int xi, bool xauto_access) const
663 {
664  // Preconditions:
665 
666  require(state_is_auto_read_accessible(xauto_access));
667  require(contains_member(xmbr_id, xauto_access));
668  require((0 <= xi) && (xi < p(xauto_access)));
669  require(contains_variance_subposets(xauto_access));
670 
671  // Body:
672 
673  return is_covariant(xmbr_id.hub_pod(), xi, xauto_access);
674 }
675 
676 void
678 put_is_covariant(pod_index_type xmbr_id, bool xauto_access)
679 {
680  // Preconditions:
681 
682  require(state_is_auto_read_write_accessible(xauto_access));
683  require(contains_member(xmbr_id, xauto_access));
684 
685  // Body:
686 
687  if(xauto_access)
688  {
689  get_read_write_access(true);
690  }
691 
692  int lp = covariant_subposet_ct();
693  for(int i=0; i<lp; ++i)
694  {
695  subposet lcovariant(this, covariant_subposet_name(i));
696  lcovariant.insert_member(xmbr_id);
697  lcovariant.detach_from_state();
698  }
699 
700  if(xauto_access)
701  {
702  release_access();
703  }
704 
705  // Postconditions:
706 
707  ensure(is_covariant(xmbr_id, xauto_access));
708 
709  // Exit:
710 
711  return;
712 }
713 
714 void
716 put_is_covariant(const scoped_index& xmbr_id, bool xauto_access)
717 {
718  // Preconditions:
719 
720  require(state_is_auto_read_write_accessible(xauto_access));
721  require(contains_member(xmbr_id, xauto_access));
722 
723  // Body:
724 
725  put_is_covariant(xmbr_id.hub_pod(), xauto_access);
726 
727  // Postconditions:
728 
729  ensure(is_covariant(xmbr_id, xauto_access));
730 
731  // Exit:
732 
733  return;
734 }
735 
736 void
738 put_is_covariant(pod_index_type xmbr_id, int xi, bool xauto_access)
739 {
740  // Preconditions:
741 
742  require(state_is_auto_read_write_accessible(xauto_access));
743  require(contains_member(xmbr_id, xauto_access));
744  require((0 <= xi) && (xi < p(xauto_access)));
745 
746  // Body:
747 
748  if(xauto_access)
749  {
750  get_read_write_access(true);
751  }
752 
753  // Since precondition ensures xi >= 0 and xi < p; p can not be 0.
754  // So covaraint_subposet_ct() is either p or 1. If only 1,
755  // then we have either an stp or an atp and setting the variance
756  // of any index is equivalent to setting them all.
757 
758  int lxi = (covariant_subposet_ct() > 1) ? xi : 0;
759 
760  // $$SCRIBBLE: access by name lookup is not terribly efficient,
761  // but it will have to do until we get id spaces for subposets working
762  // or devise some other mechanism.
763 
764  subposet lsp(this, covariant_subposet_name(lxi));
765  lsp.insert_member(xmbr_id);
766  lsp.detach_from_state();
767 
768  if(xauto_access)
769  {
770  release_access();
771  }
772 
773  // Postconditions:
774 
775  ensure(is_covariant(xmbr_id, xi, xauto_access));
776 
777  // Exit:
778 
779  return;
780 }
781 
782 void
784 put_is_covariant(const scoped_index& xmbr_id, int xi, bool xauto_access)
785 {
786  // Preconditions:
787 
788  require(state_is_auto_read_write_accessible(xauto_access));
789  require(contains_member(xmbr_id, xauto_access));
790  require((0 <= xi) && (xi < p(xauto_access)));
791 
792  // Body:
793 
794  put_is_covariant(xmbr_id.hub_pod(), xi, xauto_access);
795 
796  // Postconditions:
797 
798  ensure(is_covariant(xmbr_id, xi, xauto_access));
799 
800  // Exit:
801 
802  return;
803 }
804 
805 bool
807 is_contravariant(pod_index_type xmbr_id, bool xauto_access) const
808 {
809  // Preconditions:
810 
811  require(state_is_auto_read_accessible(xauto_access));
812  require(contains_member(xmbr_id, xauto_access));
813 
814  // Body:
815 
816  if(xauto_access)
817  {
818  get_read_access();
819  }
820 
821  bool result = true;
822  int lp = covariant_subposet_ct();
823  for(int i=0; i<lp && result; ++i)
824  {
825  subposet lsp(this, covariant_subposet_name(i));
826  bool result = !lsp.contains_member(xmbr_id);
827  lsp.detach_from_state();
828  }
829 
830  // The above implementation returns the correct result for p == 0.
831 
832  assertion(p() == 0 ? result : true);
833 
834  if(xauto_access)
835  {
836  release_access();
837  }
838 
839  // Postconditions:
840 
841  // Can not ensure result == !is_covariant because at0 is both co- and contra-variant.
842 
843  // Exit:
844 
845  return result;
846 }
847 
848 bool
850 is_contravariant(const scoped_index& xmbr_id, bool xauto_access) const
851 {
852  // Preconditions:
853 
854  require(state_is_auto_read_accessible(xauto_access));
855  require(contains_member(xmbr_id, xauto_access));
856 
857  // Body:
858 
859  return is_contravariant(xmbr_id.hub_pod(), xauto_access);
860 }
861 
862 bool
864 is_contravariant(pod_index_type xmbr_id, int xi, bool xauto_access) const
865 {
866  // Preconditions:
867 
868  require(state_is_auto_read_accessible(xauto_access));
869  require(contains_member(xmbr_id, xauto_access));
870  require((0 <= xi) && (xi < p(xauto_access)));
871 
872  // Body:
873 
874  bool result = !is_covariant(xmbr_id, xi, xauto_access);
875 
876  // Postconditions:
877 
878  // Can ensure result == !is_covariant because although
879  // at0 is both co- and contra-variant, at0::p() == 0 so this
880  // function can not be invoked. But to be consistent,
881  // let's just not ensure it.
882 
883  // ensure(result == !is_covariant(xmbr_id, xi, xauto_access));
884 
885  // Exit:
886 
887  return result;
888 }
889 
890 bool
892 is_contravariant(const scoped_index& xmbr_id, int xi, bool xauto_access) const
893 {
894  // Preconditions:
895 
896  require(state_is_auto_read_accessible(xauto_access));
897  require(contains_member(xmbr_id, xauto_access));
898  require((0 <= xi) && (xi < p(xauto_access)));
899 
900  // Body:
901 
902  return is_contravariant(xmbr_id.hub_pod(), xi, xauto_access);
903 }
904 
905 void
907 put_is_contravariant(pod_index_type xmbr_id, bool xauto_access)
908 {
909  // Preconditions:
910 
911  require(state_is_auto_read_write_accessible(xauto_access));
912  require(contains_member(xmbr_id, xauto_access));
913 
914  // Body:
915 
916  if(xauto_access)
917  {
918  get_read_write_access(true);
919  }
920 
921  int lp = covariant_subposet_ct();
922  for(int i=0; i<lp; ++i)
923  {
924  subposet lcovariant(this, covariant_subposet_name(i));
925  lcovariant.remove_member(xmbr_id);
926  lcovariant.detach_from_state();
927  }
928 
929  if(xauto_access)
930  {
931  release_access();
932  }
933 
934  // Postconditions:
935 
936  ensure(is_contravariant(xmbr_id, xauto_access));
937 
938  // Exit:
939 
940  return;
941 }
942 
943 void
945 put_is_contravariant(const scoped_index& xmbr_id, bool xauto_access)
946 {
947  // Preconditions:
948 
949  require(state_is_auto_read_write_accessible(xauto_access));
950  require(contains_member(xmbr_id, xauto_access));
951 
952  // Body:
953 
954  put_is_contravariant(xmbr_id.hub_pod(), xauto_access);
955 
956  // Postconditions:
957 
958  ensure(is_contravariant(xmbr_id, xauto_access));
959 
960  // Exit:
961 
962  return;
963 }
964 
965 void
967 put_is_contravariant(pod_index_type xmbr_id, int xi, bool xauto_access)
968 {
969  // Preconditions:
970 
971  require(state_is_auto_read_write_accessible(xauto_access));
972  require(contains_member(xmbr_id, xauto_access));
973  require((0 <= xi) && (xi < p(xauto_access)));
974 
975  // Body:
976 
977  if(xauto_access)
978  {
979  get_read_write_access(true);
980  }
981 
982  // Since precondition ensures xi >= 0 and xi < p; p can not be 0.
983  // So covaraint_subposet_ct() is either p or 1. If only 1,
984  // then we have either an stp or an atp and setting the variance
985  // of any index is equivalent to setting them all.
986 
987  int lxi = (covariant_subposet_ct() > 1) ? xi : 0;
988 
989  // $$SCRIBBLE: access by name lookup is not terribly efficient,
990  // but it will have to do until we get id spaces for subposets working
991  // or devise some other mechanism.
992 
993  subposet lsp(this, covariant_subposet_name(lxi));
994  lsp.remove_member(xmbr_id);
995  lsp.detach_from_state();
996 
997  if(xauto_access)
998  {
999  release_access();
1000  }
1001 
1002  // Postconditions:
1003 
1004  ensure(is_contravariant(xmbr_id, xi, xauto_access));
1005 
1006  // Exit:
1007 
1008  return;
1009 }
1010 
1011 void
1013 put_is_contravariant(const scoped_index& xmbr_id, int xi, bool xauto_access)
1014 {
1015  // Preconditions:
1016 
1017  require(state_is_auto_read_write_accessible(xauto_access));
1018  require(contains_member(xmbr_id, xauto_access));
1019  require((0 <= xi) && (xi < p(xauto_access)));
1020 
1021  // Body:
1022 
1023  put_is_contravariant(xmbr_id.hub_pod(), xi, xauto_access);
1024 
1025  // Postconditions:
1026 
1027  ensure(is_contravariant(xmbr_id, xi, xauto_access));
1028 
1029  // Exit:
1030 
1031  return;
1032 }
1033 
1034 // PROTECTED MEMBER FUNCTIONS
1035 
1038  : sec_vd_space(new sec_tp, new sec_tp)
1039 {
1040  // Preconditions:
1041 
1042  // Body:
1043 
1044  // Nothing to do, handled by base class
1045 
1046  // Postconditions:
1047 
1048  ensure(postcondition_of(sec_vd_space::sec_vd_space()));
1049 }
1050 
1053 {
1054  // Preconditions:
1055 
1056  // Body:
1057 
1058  // Postconditions:
1059 
1060  // Exit
1061 
1062  return;
1063 }
1064 
1066 sec_tp_space(sec_tp* xtop, sec_tp* xbottom)
1067  : sec_vd_space(xtop, xbottom)
1068 {
1069  // Preconditions:
1070 
1071  require(xtop != 0);
1072  require(xbottom != 0);
1073 
1074  // Body:
1075 
1076  // Nothing to do.
1077 
1078  // Postconditions:
1079 
1080  ensure(postcondition_of(poset_state_handle::poset_state_handle(xtop, xbottom)));
1081 
1082  // Exit:
1083 
1084  return;
1085 }
1086 
1087 // PRIVATE MEMBER FUNCTIONS
1088 
1089 
1090 // ===========================================================
1091 // SEC_VD_SPACE FACET
1092 // ===========================================================
1093 
1094 // PUBLIC MEMBER FUNCTIONS
1095 
1096 // PROTECTED MEMBER FUNCTIONS
1097 
1101 {
1102  // Preconditions:
1103 
1104  require(state_is_read_accessible());
1105 
1106  // Body:
1107 
1108  size_type result = p();
1109 
1110  // Postconditions:
1111 
1112  // Exit:
1113 
1114  return result;
1115 }
1116 
1117 // PRIVATE MEMBER FUNCTIONS
1118 
1119 
1120 // ===========================================================
1121 // SEC_TUPLE_SPACE FACET
1122 // ===========================================================
1123 
1124 // PUBLIC MEMBER FUNCTIONS
1125 
1126 // PROTECTED MEMBER FUNCTIONS
1127 
1128 // PRIVATE MEMBER FUNCTIONS
1129 
1130 
1131 // ===========================================================
1132 // SEC_REP_SPACE FACET
1133 // ===========================================================
1134 
1135 // PUBLIC MEMBER FUNCTIONS
1136 
1137 // PROTECTED MEMBER FUNCTIONS
1138 
1139 // PRIVATE MEMBER FUNCTIONS
1140 
1141 bool
1142 fiber_bundle::sec_tp_space::
1143 make_prototype()
1144 {
1145  bool result = false;
1146 
1147  // Preconditions:
1148 
1149  // Body:
1150 
1151  sec_tp_space* lproto = new sec_tp_space;
1152  poset_type ltype = lproto->type_id();
1153 
1154  factory().insert_prototype(lproto);
1155  factory().insert_prototype(ltype, lproto);
1156 
1157  // Postconditions:
1158 
1159  // Exit:
1160 
1161  return result;
1162 }
1163 
1164 
1165 //==============================================================================
1166 // POSET_STATE_HANDLE FACET
1167 //==============================================================================
1168 
1169 // PUBLIC MEMBER FUNCTIONS
1170 
1173 type_id() const
1174 {
1175  return SEC_TP_SPACE_ID;
1176 }
1177 
1180 
1181 const char*
1183 class_name() const
1184 {
1185  // Preconditions:
1186 
1187  // Body:
1188 
1189  static const char* result = "sec_tp_space";
1190 
1191  // Postconditions:
1192 
1193  // Exit:
1194 
1195  return result;
1196 }
1197 
1200 prereq_id(int xi) const
1201 {
1202  // Preconditions:
1203 
1204  require(state_is_read_accessible());
1205  require(name_space()->state_is_read_accessible());
1206 
1207  // Body:
1208 
1209  pod_index_type result;
1210 
1211  switch(xi)
1212  {
1213  case 0:
1214 
1215  // The first prerequisite is always the schema.
1216 
1217  result = schema().host()->index().pod();
1218  break;
1219 
1220  case 1:
1221 
1222  // The vector space over which this tensor space is built.
1223 
1224  result = name_space()->member_id(vector_space_path().poset_name(), false);
1225  break;
1226 
1227  default:
1228 
1229  // No other prerequisites.
1230 
1231  result = invalid_pod_index();
1232  break;
1233  }
1234 
1235  // Postconditions:
1236 
1237  // Exit:
1238 
1239  return result;
1240 }
1241 
1242 // PROTECTED MEMBER FUNCTIONS
1243 
1244 // PRIVATE MEMBER FUNCTIONS
1245 
1246 
1247 //==============================================================================
1248 // READ_WRITE_MONITOR_HANDLE FACET
1249 //==============================================================================
1250 
1251 // PUBLIC MEMBER FUNCTIONS
1252 
1253 // PROTECTED MEMBER FUNCTIONS
1254 
1255 // PRIVATE MEMBER FUNCTIONS
1256 
1257 
1258 //==============================================================================
1259 // ANY FACET
1260 //==============================================================================
1261 
1262 // PUBLIC MEMBER FUNCTIONS
1263 
1264 bool
1266 is_ancestor_of(const any* xother) const
1267 {
1268  bool result;
1269 
1270  // Preconditions:
1271 
1272  // Body:
1273 
1274  result = dynamic_cast<const sec_tp_space*>(xother) != 0;
1275 
1276  // Postconditions:
1277 
1278  // Exit
1279 
1280  return result;
1281 }
1282 
1285 clone() const
1286 {
1287  sec_tp_space* result;
1288 
1289  // Preconditions:
1290 
1291  // Body:
1292 
1293  result = new sec_tp_space;
1294 
1295  // Postconditions:
1296 
1297  ensure(result != 0);
1298  ensure(is_same_type(result));
1299  ensure(!result->is_attached());
1300 
1301  // Exit
1302 
1303  return result;
1304 }
1305 
1306 bool
1308 invariant() const
1309 {
1310  bool result = true;
1311 
1312 
1313  if(invariant_check())
1314  {
1316 
1317  invariance(sec_vd_space::invariant());
1318 
1319  invariance(state_is_read_accessible() ? factor_ct() == d() : true);
1320 
1322  }
1323 
1324  return result;
1325 }
1326 
1327 // PROTECTED MEMBER FUNCTIONS
1328 
1329 // PRIVATE MEMBER FUNCTIONS
1330 
1331 
void put_variance(pod_index_type xmbr_id, const tensor_variance &xvariance, bool xauto_access)
Sets the variance of the member with id xmbr_id to xvariance.
A client handle for a subposet.
Definition: subposet.h:86
virtual void put_is_contravariant(pod_index_type xmbr_id, bool xauto_access)
Sets all tensor index positions of the member with id xmbr_id to contravariant.
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
int p() const
The tensor degree.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
Definition: scoped_index.h:672
The "type" of a tensor; specifies the degree and the co- or contra-variance for each index of a tenso...
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
static bool same_vector_fiber_space(const namespace_poset &xns, const poset_path &xschema_path, const poset_path &xvector_space_path, bool xauto_access)
True if and only if vector space of fiber space == fiber space of vector space. More precisely...
Definition: sec_tp_space.cc:53
The default name space; a poset which contains other posets as members.
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
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
sec_tp_space()
Default constructor; creates a new sec_tp_space handle not attached to any state. ...
void put_variance(int xi, bool xvalue)
Sets the variance of the xi-th index to xvalue.
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
virtual bool invariant() const
Class invariant.
poset_path vector_space_path() const
The path of the underlying vector space.
virtual bool contains_member(pod_index_type xmbr_hub_id) const
True if this poset contains poset member with hub id xmbr_hub_id.
Definition: subposet.cc:955
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 ...
An abstract vector section space of dimension d.
Definition: sec_vd_space.h:52
virtual sec_tp_space * clone() const
Virtual constructor; creates a new handle of the same actual type as this, attached to the same state...
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.
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
int p() const
The tensor degree of this space.
poset & fiber_space()
The fiber space for section spaces on this schema.
virtual section_space_schema_member & schema()
The schema for this poset (mutable version)
virtual tensor_variance variance(pod_index_type xmbr_id, bool xauto_access) const
The variance of the member with id xmbr_id.
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)
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual tensor_variance round_variance(const tensor_variance &xvariance) const
"Rounds" xvariance up or down to a supported value. Version defined in this class just returns xvaria...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual void insert_member(pod_index_type xmbr_hub_id)
Inserts the member of host() with hub id xmbr_hub_id.
Definition: subposet.cc:1091
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_tp_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_tp_space in namespace xns with path xpath, schema specified by xschema_path, and vector space specified by xvector_space_path.
Definition: sec_tp_space.cc:90
virtual void put_is_covariant(pod_index_type xmbr_id, bool xauto_access)
Sets all tensor index positions of the member with id xmbr_id to covariant.
int dd() const
The dimension of the underlying ("domain") vector space.
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
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.
sec_vd_space()
Default constructor; creates a new sec_vd_space handle not attached to any state. ...
static poset_handle_factory & factory()
The poset handle factory.
virtual bool is_contravariant(pod_index_type xmbr_id, bool xauto_access) const
True if and only if all tensor index positions of the member with id xmbr_id are contravariant.
virtual void detach_from_state()
Detach this handle from its state, if any.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual bool is_attached() const
True if this is attached to a state.
int factor_ct() const
The number of factors in this product.
virtual const char * class_name() const
The name of this class.
An abstract schema poset for a section space. A Cartesian product subspace of the tensor product of a...
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 pod_index_type prereq_id(int xi) const
The id of the xi-th prerequisite poset for this.
virtual bool is_covariant(pod_index_type xmbr_id, bool xauto_access) const
True if and only if all tensor index positions of the member with id xmbr_id are covariant.
virtual void remove_member(pod_index_type xmbr_hub_id)
Removes the member of host() with hub id xmbr_hub_id.
Definition: subposet.cc:1209
T::table_dofs_type & table_dofs(T &x0)
The table dofs pod type for x0 (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual size_type covariant_subposet_ct() const
The number of covariant subposets.
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.
int d() const
The dimension.
std::string path() const
The full path as a string.
Definition: poset_path.cc:450
An array representation of abstract class poset_dof_map.
An abstract tensor space of degree p.
Definition: tp_space.h:47
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC void pow(const sec_at0 &x0, const vd_value_type &xexponent, sec_at0 &xresult, bool xauto_access)
Compute x0 to power xexponent (pow(x0, xexponent)) (pre-allocated version).
Definition: sec_at0.cc:1495
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
virtual ~sec_tp_space()
Destructor.
A section of a bundle with fiber type tp.
Definition: sec_tp.h:49
virtual poset_type type_id() const
Identifier for the type of this poset.
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...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710