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