SheafSystem  0.0.0.0
t2.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/t2.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/at1.h"
26 #include "SheafSystem/at1_space.h"
27 #include "SheafSystem/fiber_bundles_namespace.h"
28 #include "SheafSystem/schema_poset_member.h"
29 #include "SheafSystem/tp_space.h"
30 #include "SheafSystem/wsv_block.h"
31 
32 
33 using namespace std;
34 using namespace fiber_bundle; // Workaround for MS C++ bug.
35 
36 
37 //==============================================================================
38 // CLASS T2_LITE
39 //==============================================================================
40 
41 //==============================================================================
42 // T2 FACET OF CLASS T2_LITE
43 //==============================================================================
44 
45 // PUBLIC MEMBER FUNCTIONS
46 
49 {
50 
51  // Preconditions:
52 
53  // Body:
54 
55  // Postconditions:
56 
57  ensure(invariant());
58 
59  // Exit:
60 }
61 
63 t2_lite(const t2_lite& xother)
64 {
65  // Preconditions:
66 
67  // Body:
68 
69  *this = xother;
70 
71  // Postconditions:
72 
73  ensure(invariant());
74 
75  // Exit:
76 }
77 
80 operator=(const t2_lite& xother)
81 {
82 
83  // Preconditions:
84 
85  // Body:
86 
87  // Postconditions:
88 
89  ensure(invariant());
90 
91  // Exit:
92 
93  return *this;
94 }
95 
98 {
99  // Preconditions:
100 
101  // Body:
102 
103  // Postconditions:
104 
105  // Exit:
106 
107 }
108 
110 t2_lite(const row_dofs_type& xrow_dofs)
111 {
112  // Preconditions:
113 
114  // Body:
115 
116  *this = xrow_dofs;
117 
118  // Postconditions:
119 
120  ensure(invariant());
121 
122  // Exit:
123 }
124 
127 operator=(const row_dofs_type& xrow_dofs)
128 {
129  // Preconditions:
130 
131  // Body:
132 
133  vd_lite::operator=(xrow_dofs);
134 
135  // Postconditions:
136 
137  postcondition_of(vd_lite::operator=(xrow_dofs));
138 
139  // Exit:
140 
141  return *this;
142 
143 }
144 
147 component(int xrow, int xcolumn) const
148 {
149  // Preconditions:
150 
151  require(xrow >= 0 && xrow < dd());
152  require(xcolumn >= 0 && xcolumn < dd());
153 
154  // Body:
155 
156  value_type result = component(index_for_row_column(xrow, xcolumn));
157 
158  // Postconditions:
159 
160  ensure(invariant());
161 
162  // Exit:
163 
164  return result;
165 }
166 
167 void
169 put_component(int xrow, int xcolumn, value_type xcomp)
170 {
171  // Preconditions:
172 
173  require(xrow >= 0 && xrow < dd());
174  require(xcolumn >= 0 && xcolumn < dd());
175 
176  // Body:
177 
178  put_component(index_for_row_column(xrow, xcolumn), xcomp);
179 
180  // Postconditions:
181 
182  ensure(invariant());
183  ensure(isunordered_or_equals(component(index_for_row_column(xrow, xcolumn)), xcomp));
184 
185  // Exit:
186 
187  return;
188 }
189 
190 int
192 index_for_row_column(int xrow, int xcolumn) const
193 {
194  // Preconditions:
195 
196  require(0 <= xrow && xrow < dd());
197  require(0 <= xcolumn && xcolumn < dd());
198 
199  // Body:
200 
201  int result = xrow*dd() + xcolumn;
202 
203  // Postconditions:
204 
205  ensure(invariant());
206  ensure(result >= 0);
207  ensure(result < dd()*dd());
208 
209  // Exit:
210 
211  return result;
212 }
213 
214 // PROTECTED MEMBER FUNCTIONS
215 
216 // PRIVATE MEMBER FUNCTIONS
217 
218 
219 //==============================================================================
220 // TENSOR ALGEBRA (TP) FACET OF CLASS T2_LITE
221 //==============================================================================
222 
223 // PUBLIC MEMBER FUNCTIONS
224 
225 int
227 p() const
228 {
229  // Preconditions:
230 
231  // Body:
232 
233  int result = 2;
234 
235  // Postconditions:
236 
237  ensure(invariant());
238  ensure(result == 2);
239 
240  // Exit:
241 
242  return result;
243 }
244 
245 // PROTECTED MEMBER FUNCTIONS
246 
247 // PRIVATE MEMBER FUNCTIONS
248 
249 
250 //==============================================================================
251 // VECTOR ALGEBRA (VD) FACET OF CLASS T2_LITE
252 //==============================================================================
253 
254 // PUBLIC MEMBER FUNCTIONS
255 
256 int
258 d() const
259 {
260  // Preconditions:
261 
262  // Body:
263 
264  int result = static_cast<int>(dd()*dd());
265 
266  // Postconditions:
267 
268  ensure(invariant());
269  ensure(result == static_cast<int>(dd()*dd()));
270 
271  // Exit:
272 
273  return result;
274 }
275 
276 //==============================================================================
277 // CARTESIAN ALGEBRA (TUPLE) FACET OF CLASS T2_LITE
278 //==============================================================================
279 
280 // PUBLIC MEMBER FUNCTIONS
281 
282 // PROTECTED MEMBER FUNCTIONS
283 
284 // PRIVATE MEMBER FUNCTIONS
285 
286 
287 //==============================================================================
288 // ABSTRACT POSET MEMBER FACET OF CLASS T2_LITE
289 //==============================================================================
290 
291 // PUBLIC MEMBER FUNCTIONS
292 
293 const std::string&
295 class_name() const
296 {
297  // Preconditions:
298 
299  // Body:
300 
301  const string& result = static_class_name();
302 
303  // Postconditions:
304 
305  ensure(!result.empty());
306 
307  // Exit:
308 
309  return result;
310 }
311 
312 const std::string&
315 {
316  // Preconditions:
317 
318  // Body:
319 
320  static const string result("t2_lite");
321 
322  // Postconditions:
323 
324  ensure(!result.empty());
325 
326  // Exit:
327 
328  return result;
329 }
330 
333 clone() const
334 {
335  t2_lite* result = 0;
336 
337  // Preconditions:
338 
339  // Body:
340 
341  result = new t2_lite();
342 
343  // Postconditions:
344 
345  ensure(result != 0);
346  ensure(is_same_type(*result));
347 
348  // Exit:
349 
350  return result;
351 }
352 
353 // PROTECTED MEMBER FUNCTIONS
354 
355 // PRIVATE MEMBER FUNCTIONS
356 
357 
358 //==============================================================================
359 // ANY FACET OF CLASS T2_LITE
360 //==============================================================================
361 
362 // PUBLIC MEMBER FUNCTIONS
363 
364 bool
366 is_ancestor_of(const any_lite& xother) const
367 {
368  // Preconditions:
369 
370  require(&xother != 0);
371 
372  // Body:
373 
374  // True if other conforms to this.
375 
376  bool result = dynamic_cast<const t2_lite*>(&xother) != 0;
377 
378  // Postconditions:
379 
380  return result;
381 }
382 
383 bool
385 invariant() const
386 {
387  bool result = true;
388 
389  if(invariant_check())
390  {
391  // Prevent recursive calls to invariant.
392 
393  disable_invariant_check();
394 
395  // Must satisfy base class invariant.
396 
397  invariance(tp_lite::invariant());
398 
399  // Invariances for this class:
400 
401  // Finished, turn invariant checking back on.
402 
403  enable_invariant_check();
404  }
405 
406  // Exit
407 
408  return result;
409 }
410 
411 // PROTECTED MEMBER FUNCTIONS
412 
413 // PRIVATE MEMBER FUNCTIONS
414 
415 
416 //==============================================================================
417 // CLASS T2 OF CLASS T2
418 //==============================================================================
419 
420 // ===========================================================
421 // HOST FACTORY FACET
422 // ===========================================================
423 
424 // PUBLIC MEMBER FUNCTIONS
425 
426 const sheaf::poset_path&
429 {
430  // Preconditions:
431 
432 
433  // Body:
434 
435  static const poset_path result(standard_schema_poset_name(), "t2_schema");
436 
437  // Postconditions:
438 
439  // Exit:
440 
441  return result;
442 }
443 
444 void
447 {
448  // Preconditions:
449 
450  require(xns.state_is_read_write_accessible());
451  require(xns.contains_poset(standard_schema_poset_name()));
452  require(!xns.contains_poset_member(standard_schema_path()));
453 
454  // Body:
455 
456  schema_poset_member lschema(xns,
457  standard_schema_path().member_name(),
458  tp::standard_schema_path(),
459  "",
460  false);
461 
462  lschema.detach_from_state();
463 
464  // Postconditions:
465 
466  ensure(xns.contains_poset_member(standard_schema_path()));
467 
468  // Exit:
469 
470  return;
471 }
472 
476  const poset_path& xhost_path,
477  const poset_path& xschema_path,
478  const poset_path& xvector_space_path,
479  bool xauto_access)
480 {
481  // cout << endl << "Entering t2::new_host." << endl;
482 
483  // Preconditions:
484 
485  require(xns.state_is_auto_read_write_accessible(xauto_access));
486 
487  require(!xhost_path.empty());
488  require(!xns.contains_path(xhost_path, xauto_access));
489 
490  require(xschema_path.full());
491  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
492  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
493 
494  require(xns.path_is_auto_read_accessible(xvector_space_path, xauto_access));
495  require(xns.contains_poset<vector_space_type::host_type>(xvector_space_path, xauto_access));
496 
497  require(host_type::d(xns, xschema_path, xauto_access) == host_type::d(xns, 2, xvector_space_path, xauto_access));
498 
499  // Body:
500 
501  host_type& result =
502  host_type::new_table(xns, xhost_path, xschema_path, 2, xvector_space_path, xauto_access);
503 
504  // Postconditions:
505 
506  ensure(xns.owns(result, xauto_access));
507  ensure(result.path(true) == xhost_path);
508  ensure(result.state_is_not_read_accessible());
509  ensure(result.schema(true).path(xauto_access) == xschema_path);
510 
511  ensure(result.factor_ct(true) == result.d(true));
512  ensure(result.d(true) == schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access));
513  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path());
514  ensure(result.p(true) == 2);
515  ensure(result.dd(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).d());
516  ensure(result.vector_space_path(true) == xvector_space_path );
517 
518  // Exit:
519 
520  // cout << "Leaving t2::new_host." << endl;
521  return result;
522 }
523 
524 
525 // PROTECTED MEMBER FUNCTIONS
526 
527 // PRIVATE MEMBER FUNCTIONS
528 
529 
530 
531 //==============================================================================
532 // T2 FACET OF CLASS T2
533 //==============================================================================
534 
535 // PUBLIC MEMBER FUNCTIONS
536 
538 t2()
539 {
540 
541  // Preconditions:
542 
543  // Body:
544 
545  // Postconditions:
546 
547  ensure(invariant());
548 
549  // Exit:
550 
551  return;
552 }
553 
555 t2(const t2& xother)
556 {
557 
558  // Preconditions:
559 
560 
561  // Body:
562 
563  attach_to_state(&xother);
564 
565  // Postconditions:
566 
567  ensure(invariant());
568 
569  // Exit:
570 
571  return;
572 }
573 
578 {
579  // Preconditions:
580 
581  require(is_ancestor_of(&xother));
582  require(precondition_of(attach_to_state(&xother)));
583 
584  // Body:
585 
586  attach_to_state(&xother);
587 
588  // Postconditions:
589 
590  ensure(postcondition_of(attach_to_state(&xother)));
591 
592  // Exit:
593 
594  return *this;
595 }
596 
600 operator=(const t2& xother)
601 {
602  // Preconditions:
603 
604  require(precondition_of(attach_to_state(&xother)));
605 
606  // Body:
607 
608  attach_to_state(&xother);
609 
610  // Postconditions:
611 
612  ensure(postcondition_of(attach_to_state(&xother)));
613 
614  // Exit:
615 
616  return *this;
617 }
618 
621 {
622 
623  // Preconditions:
624 
625  // Body:
626 
627  // Postconditions:
628 
629  // Exit:
630 
631  return;
632 }
633 
637 {
638  // Preconditions:
639 
640  // Body:
641 
642  static const volatile_type result;
643 
644  // Postconditions:
645 
646  // Exit:
647 
648  return result;
649 }
650 
654 lite_type() const
655 {
656  // Preconditions:
657 
658  // Body:
659 
660  volatile_type* result = new volatile_type(sheaf::row_dofs(*this));
661 
662  // Postconditions:
663 
664  // Exit:
665 
666  return result;
667 }
668 
669 
671 t2(poset* xhost, bool xauto_access)
672 {
673 
674  // Preconditions:
675 
676  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
677 
678  // Body:
679 
680  new_jim_state(xhost, 0, false, xauto_access);
681 
682  // Postconditions:
683 
684  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
685 
686  // Exit:
687 
688  return;
689 }
690 
692 t2(const poset* xhost, pod_index_type xhub_id)
693 {
694  // Preconditions:
695 
696  require(xhost != 0);
697  require(xhost->state_is_read_accessible());
698  require(xhost->contains_member(xhub_id));
699 
700  // Body:
701 
702  attach_to_state(xhost, xhub_id);
703 
704  // Postconditions:
705 
706  ensure(invariant());
707  ensure(is_attached());
708  // ensure(host() == xhost);
709  ensure(index() == xhub_id);
710 }
711 
713 t2(const poset* xhost, const scoped_index& xid)
714 {
715  // Preconditions:
716 
717  require(xhost != 0);
718  require(xhost->state_is_read_accessible());
719  require(xhost->contains_member(xid));
720 
721  // Body:
722 
723  attach_to_state(xhost, xid.hub_pod());
724 
725  // Postconditions:
726 
727  ensure(invariant());
728  ensure(is_attached());
729  // ensure(host() == xhost);
730  ensure(index() ==~ xid);
731 }
732 
734 t2(const poset* xhost, const std::string& xname)
735 {
736 
737  // Preconditions:
738 
739  require(xhost != 0);
740  require(xhost->state_is_read_accessible());
741  require(!xname.empty());
742  require(xhost->contains_member(xname));
743 
744  // Body:
745 
746  attach_to_state(xhost, xname);
747 
748  // Postconditions:
749 
750  ensure(invariant());
751  ensure(is_attached());
752  // ensure(host() == xhost);
753  ensure(name() == xname);
754 
755 }
756 
757 int
759 index_for_row_column(int xrow, int xcolumn) const
760 {
761  // Preconditions:
762 
763  require(state_is_read_accessible());
764  require(0 <= xrow && xrow < dd());
765  require(0 <= xcolumn && xcolumn < dd());
766 
767  // Body:
768 
769  // Convert (xrow, xcolumn) into an index into linear component storage.
770 
771  int result = xrow*dd() + xcolumn;
772 
773  // Postconditions:
774 
775  //ensure(invariant());
776  ensure(result >= 0);
777  ensure(result < dd()*dd());
778 
779  // Exit:
780 
781  return result;
782 }
783 
784 // PROTECTED MEMBER FUNCTIONS
785 
786 // PRIVATE MEMBER FUNCTIONS
787 
788 
789 //==============================================================================
790 // TP FACET OF CLASS T2
791 //==============================================================================
792 
793 // PUBLIC MEMBER FUNCTIONS
794 
795 // PROTECTED MEMBER FUNCTIONS
796 
797 // PRIVATE MEMBER FUNCTIONS
798 
799 
800 //==============================================================================
801 // VD FACET OF CLASS T2
802 //==============================================================================
803 
804 // PUBLIC MEMBER FUNCTIONS
805 
808 component(int xrow, int xcolumn) const
809 {
810  // Preconditions:
811 
812  require(state_is_read_accessible());
813  require((0 <= xrow) && (xrow < dd()));
814  require((0 <= xcolumn) && (xcolumn < dd()));
815 
816  // Body:
817 
818  value_type result = component(index_for_row_column(xrow, xcolumn));
819 
820  // Postconditions:
821 
822  ensure(invariant());
823 
824  // Exit:
825 
826  return result;
827 }
828 
831 component(int xrow, int xcolumn, bool xauto_access) const
832 {
833  // Preconditions:
834 
835  require(state_is_auto_read_accessible(xauto_access));
836  require((0 <= xrow) && (xrow < dd(xauto_access)));
837  require((0 <= xcolumn) && (xcolumn < dd(xauto_access)));
838 
839  // Body:
840 
841  if(xauto_access)
842  {
843  get_read_access();
844  }
845 
846  value_type result = component(xrow, xcolumn);
847 
848  if(xauto_access)
849  {
850  release_access();
851  }
852 
853  // Postconditions:
854 
855  ensure(invariant());
856 
857  // Exit:
858 
859  return result;
860 }
861 
862 void
864 put_component(int xrow, int xcolumn, value_type xvalue)
865 {
866 
867  // Preconditions:
868 
869  require(state_is_read_write_accessible());
870  require((0 <= xrow) && (xrow < dd()));
871  require((0 <= xcolumn) && (xcolumn < dd()));
872 
873  // Body:
874 
875  put_component(index_for_row_column(xrow, xcolumn), xvalue);
876 
877  // Postconditions:
878 
879  ensure(invariant());
880  ensure(isunordered_or_equals(component(xrow, xcolumn), xvalue));
881 
882  // Exit:
883 
884  return;
885 }
886 
887 void
889 put_component(int xrow, int xcolumn, value_type xvalue, bool xauto_access)
890 {
891 
892  // Preconditions:
893 
894  require(state_is_auto_read_write_accessible(xauto_access));
895  require((0 <= xrow) && (xrow < dd(xauto_access)));
896  require((0 <= xcolumn) && (xcolumn < dd(xauto_access)));
897 
898  // Body:
899 
900  if(xauto_access)
901  {
902  get_read_write_access(true);
903  }
904 
905  put_component(index_for_row_column(xrow, xcolumn), xvalue);
906 
907  if(xauto_access)
908  {
909  release_access();
910  }
911 
912  // Postconditions:
913 
914  ensure(invariant());
915  ensure(isunordered_or_equals(component(xrow, xcolumn), xvalue));
916 
917  // Exit:
918 
919  return;
920 }
921 
922 // PROTECTED MEMBER FUNCTIONS
923 
924 // PRIVATE MEMBER FUNCTIONS
925 
926 
927 //==============================================================================
928 // TUPLE FACET OF CLASS T2
929 //==============================================================================
930 
931 // PUBLIC MEMBER FUNCTIONS
932 
933 // PROTECTED MEMBER FUNCTIONS
934 
935 // PRIVATE MEMBER FUNCTIONS
936 
937 
938 //==============================================================================
939 // ABSTRACT POSET MEMBER FACET OF CLASS T2
940 //==============================================================================
941 
942 // PUBLIC MEMBER FUNCTIONS
943 
944 const std::string&
946 class_name() const
947 {
948  // Preconditions:
949 
950  // Body:
951 
952  const string& result = static_class_name();
953 
954  // Postconditions:
955 
956  ensure(!result.empty());
957 
958  // Exit:
959 
960  return result;
961 }
962 
963 const std::string&
966 {
967  // Preconditions:
968 
969  // Body:
970 
971  static const string result("t2");
972 
973  // Postconditions:
974 
975  ensure(!result.empty());
976 
977  // Exit:
978 
979  return result;
980 }
981 
984 clone() const
985 {
986 
987  // Preconditions:
988 
989  // Body:
990 
991  // Create new handle of the current class.
992 
993  t2* result = new t2();
994 
995  // Postconditions:
996 
997  ensure(result != 0);
998  ensure(result->invariant());
999 
1000  // Exit:
1001 
1002  return result;
1003 
1004 }
1005 
1006 // PROTECTED MEMBER FUNCTIONS
1007 
1008 // PRIVATE MEMBER FUNCTIONS
1009 
1010 
1011 //==============================================================================
1012 // ANY FACET OF CLASS T2
1013 //==============================================================================
1014 
1015 // PUBLIC MEMBER FUNCTIONS
1016 
1017 bool
1019 invariant() const
1020 {
1021  bool result = true;
1022 
1023  // Body:
1024 
1025  if(invariant_check())
1026  {
1027  // Prevent recursive calls to invariant
1028 
1029  disable_invariant_check();
1030 
1031  // Must satisfy base class invariant
1032 
1033  invariance(tp::invariant());
1034 
1035  // Invariances for this class:
1036 
1037  invariance(state_is_read_accessible() ? p() == 2 : true);
1038  invariance(state_is_read_accessible() ? d() == dd()*dd() : true);
1039 
1040  // Finished, turn invariant checking back on.
1041 
1042  enable_invariant_check();
1043  }
1044 
1045  // Exit:
1046 
1047  return result;
1048 }
1049 
1050 bool
1052 is_ancestor_of(const any* xother) const
1053 {
1054  // Preconditions:
1055 
1056  require(xother != 0);
1057 
1058  // Body:
1059 
1060  // True if xother conforms to this.
1061 
1062  bool result = dynamic_cast<const t2*>(xother) != 0;
1063 
1064  // Postconditions:
1065 
1066  ensure(invariant());
1067 
1068  // Exit:
1069 
1070  return result;
1071 
1072 }
1073 
1074 // PROTECTED MEMBER FUNCTIONS
1075 
1076 // PRIVATE MEMBER FUNCTIONS
1077 
1078 
1079 //==============================================================================
1080 // NON-MEMBER FUNCTIONS
1081 //==============================================================================
1082 
1083 #include "SheafSystem/at0.h"
1084 #include "SheafSystem/at1.h"
1085 #include "SheafSystem/at2.h"
1086 #include "SheafSystem/st2.h"
1087 #include "SheafSystem/t2.h"
1088 
1089 void
1091 contract(const t2_lite& x0, int xp, int xq, at0_lite& xresult)
1092 {
1093  // Preconditions:
1094 
1095  require(xp != xq);
1096  require(xp >= 0 && xp < x0.p());
1097  require(xq >= 0 && xq < x0.p());
1098  require(xresult.p() == x0.p() - 2);
1099 
1100  // Body:
1101 
1102  // For t2 the result of the contraction is a scalar (the trace).
1103 
1104  vd_value_type lscalar = 0;
1105 
1106  int ldd = x0.dd();
1107  for(int i=0; i<ldd; ++i)
1108  {
1109  lscalar += x0.component(i, i);
1110  }
1111 
1112  xresult.put_component(0, lscalar);
1113 
1114  // Postconditions:
1115 
1116  //ensure();
1117 
1118  // Exit:
1119 
1120  return;
1121 }
1122 
1123 void
1125 contract(const t2& x0, int xp, int xq, at0& xresult, bool xauto_access)
1126 {
1127  // Preconditions:
1128 
1129  require(x0.state_is_auto_read_accessible(xauto_access));
1130  require(xresult.state_is_auto_read_accessible(xauto_access));
1131  require(xp != xq);
1132  require(xp >= 0 && xp < x0.p(xauto_access));
1133  require(xq >= 0 && xq < x0.p(xauto_access));
1134  require(x0.is_contravariant(xp, xauto_access) != \
1135  x0.is_contravariant(xq, xauto_access));
1136 
1137  // Body:
1138 
1139  if(xauto_access)
1140  {
1141  x0.get_read_access();
1142  xresult.get_read_write_access(true);
1143  }
1144 
1145  // For t2 the result of the contraction is a scalar (the trace).
1146 
1147  vd_value_type lscalar = 0;
1148 
1149  int ldd = x0.dd();
1150  for(int i=0; i<ldd; ++i)
1151  {
1152  lscalar += x0.component(i, i);
1153  }
1154 
1155  xresult.put_component(0, lscalar);
1156 
1157 
1158  if(xauto_access)
1159  {
1160  x0.release_access();
1161  xresult.release_access();
1162  }
1163 
1164  // Postconditions:
1165 
1166  //ensure(xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access));
1167 
1168  // Exit:
1169 
1170  return;
1171 }
1172 
1174 void
1176 alt(const t2_lite& x0, at2_lite& xresult)
1177 {
1178  // Preconditions:
1179 
1180  require(x0.dd() == xresult.dd());
1181 
1182  // Body:
1183 
1184  // Postconditions:
1185 
1186  int ldd = x0.dd();
1187 
1188  for(int i=0; i<ldd-1; ++i)
1189  {
1190  for(int j=i+1; j<ldd; ++j)
1191  {
1192  vd_value_type lvalue = 0.5*(x0.component(i, j) - x0.component(j, i));
1193  xresult.put_component(i, j, lvalue);
1194  }
1195  }
1196 
1197  // Postconditions:
1198 
1199  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1200 
1201  // Exit:
1202 
1203  return;
1204 }
1205 
1206 void
1208 alt(const t2& x0, at2& xresult, bool xauto_access)
1209 {
1210  // Preconditions:
1211 
1212  require(x0.state_is_auto_read_accessible(xauto_access));
1213  require(xresult.state_is_auto_read_accessible(xauto_access));
1214  require(!x0.variance(xauto_access).is_mixed());
1215 
1216  // $$SCRIBBLE: error
1217  // the variance of the output is the same as the variance of the input.
1218  // Since the output variance can't be mixed, neither can the input.
1219  // require(!x0.variance(xauto_access).is_mixed());
1220  // $$SCRIBBLE END
1221 
1222  // Body:
1223 
1224  if(xauto_access)
1225  {
1226  x0.get_read_access();
1227  xresult.get_read_write_access(true);
1228  }
1229 
1230  int ldd = x0.dd();
1231 
1232  for(int i=0; i<ldd-1; ++i)
1233  {
1234  for(int j=i+1; j<ldd; ++j)
1235  {
1236  vd_value_type lvalue = 0.5*(x0.component(i, j) - x0.component(j, i));
1237  xresult.put_component(i, j, lvalue);
1238  }
1239  }
1240 
1241  // Set the variance of the result.
1242 
1243  //
1244  // Variance of result is same as variance of x0.
1245  //
1246 
1247  xresult.put_variance(x0.variance(false), false);
1248 
1249  if(xauto_access)
1250  {
1251  x0.release_access();
1252  xresult.release_access();
1253  }
1254 
1255  // Postconditions:
1256 
1257  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
1258  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1259 
1260  // Exit:
1261 
1262  return;
1263 }
1264 
1266 void
1268 alt(const t2_lite& x0, t2_lite& xresult)
1269 {
1270  // Preconditions:
1271 
1272  require(x0.dd() == xresult.dd());
1273 
1274  // Body:
1275 
1276  // Postconditions:
1277 
1278  int ldd = x0.dd();
1279 
1280  for(int i=0; i<ldd; ++i)
1281  {
1282  for(int j=0; j<ldd; ++j)
1283  {
1284  vd_value_type lvalue = 0.5*(x0.component(i, j) - x0.component(j, i));
1285  xresult.put_component(i, j, lvalue);
1286  }
1287  }
1288 
1289  // Postconditions:
1290 
1291  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1292 
1293  // Exit:
1294 
1295  return;
1296 }
1297 
1299 void
1301 sym(const t2_lite& x0, st2_lite& xresult)
1302 {
1303  // Preconditions:
1304 
1305  require(x0.dd() == xresult.dd());
1306 
1307  // Body:
1308 
1309  // Postconditions:
1310 
1311  int ldd = x0.dd();
1312 
1313  for(int i=0; i<ldd; ++i)
1314  {
1315  for(int j=i; j<ldd; ++j)
1316  {
1317  vd_value_type lvalue = 0.5*(x0.component(i, j) + x0.component(j, i));
1318  xresult.put_component(i, j, lvalue);
1319  }
1320  }
1321 
1322  // Postconditions:
1323 
1324  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1325 
1326  // Exit:
1327 
1328  return;
1329 }
1330 
1332 void
1334 sym(const t2& x0, st2& xresult, bool xauto_access)
1335 {
1336  // Preconditions:
1337 
1338  require(x0.state_is_auto_read_accessible(xauto_access));
1339  require(xresult.state_is_auto_read_accessible(xauto_access));
1340  require(x0.dd(xauto_access) == xresult.dd(xauto_access));
1341  require(!x0.variance(xauto_access).is_mixed());
1342 
1343  // $$SCRIBBLE: error
1344  // the variance of the output is the same as the variance of the input.
1345  // Since the output variance can't be mixed, neither can the input.
1346  // require(!x0.variance(xauto_access).is_mixed());
1347  // $$SCRIBBLE END
1348 
1349  // Body:
1350 
1351  if(xauto_access)
1352  {
1353  x0.get_read_access();
1354  xresult.get_read_write_access(true);
1355  }
1356 
1357  int ldd = x0.dd();
1358 
1359  for(int i=0; i<ldd; ++i)
1360  {
1361  for(int j=i; j<ldd; ++j)
1362  {
1363  vd_value_type lvalue = 0.5*(x0.component(i, j) + x0.component(j, i));
1364  xresult.put_component(i, j, lvalue);
1365  }
1366  }
1367 
1368  // Set the variance of the result.
1369 
1370  //
1371  // Variance of result is same as variance of x0.
1372  //
1373 
1374  xresult.put_variance(x0.variance(false), false);
1375 
1376  if(xauto_access)
1377  {
1378  x0.release_access();
1379  xresult.release_access();
1380  }
1381 
1382  // Postconditions:
1383 
1384  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
1385  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1386 
1387  // Exit:
1388 
1389  return;
1390 }
1391 
1393 void
1395 sym(const t2_lite& x0, t2_lite& xresult)
1396 {
1397  // Preconditions:
1398 
1399  require(x0.dd() == xresult.dd());
1400 
1401  // Body:
1402 
1403  // Postconditions:
1404 
1405  int ldd = x0.dd();
1406 
1407  for(int i=0; i<ldd; ++i)
1408  {
1409  for(int j=0; j<ldd; ++j)
1410  {
1411  vd_value_type lvalue = 0.5*(x0.component(i, j) + x0.component(j, i));
1412  xresult.put_component(i, j, lvalue);
1413  }
1414  }
1415 
1416  // Postconditions:
1417 
1418  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1419 
1420  // Exit:
1421 
1422  return;
1423 }
1424 
1426 void
1428 sym(const t2& x0, t2& xresult, bool xauto_access)
1429 {
1430  // Preconditions:
1431 
1432  require(x0.state_is_auto_read_accessible(xauto_access));
1433  require(xresult.state_is_auto_read_accessible(xauto_access));
1434  require(x0.dd() == xresult.dd());
1435  require(!x0.variance(xauto_access).is_mixed());
1436 
1437  // $$SCRIBBLE
1438  // sym part is multiple of identity if variance is mixed; should we allow mixed variance input?
1439  // require(!x0.variance(xauto_access).is_mixed());
1440  //
1441  // $$SCRIBBLE END
1442 
1443  // Body:
1444 
1445  if(xauto_access)
1446  {
1447  x0.get_read_access();
1448  xresult.get_read_write_access(true);
1449  }
1450 
1451  int ldd = x0.dd();
1452 
1453  for(int i=0; i<ldd; ++i)
1454  {
1455  for(int j=0; j<ldd; ++j)
1456  {
1457  vd_value_type lvalue = 0.5*(x0.component(i, j) + x0.component(j, i));
1458  xresult.put_component(i, j, lvalue);
1459  }
1460  }
1461 
1462  // Set the variance of the result.
1463 
1464  //
1465  // Variance of result is same as variance of x0.
1466  //
1467  xresult.put_variance(x0.variance(false), false);
1468 
1469  if(xauto_access)
1470  {
1471  x0.release_access();
1472  xresult.release_access();
1473  }
1474 
1475  // Postconditions:
1476 
1477  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
1478  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1479 
1480  // Exit:
1481 
1482  return;
1483 }
1484 
1486 void
1488 tensor(const at1_lite& x0, const at1_lite& x1, t2_lite& xresult)
1489 {
1490  // Preconditions:
1491 
1492  require(x1.dd() == x0.dd());
1493  require(xresult.dd() == x0.dd());
1494 
1495  // Body:
1496 
1497  int ldd = x0.dd();
1498 
1499  for(int i=0; i<ldd; ++i)
1500  {
1501  vd_value_type lcomp_i = x0.component(i);
1502 
1503  for(int j=0; j<ldd; ++j)
1504  {
1505  vd_value_type lcomp_j = x1.component(j);
1506  vd_value_type lcomp_ij = lcomp_i * lcomp_j;
1507  xresult.put_component(i, j, lcomp_ij);
1508  }
1509  }
1510 
1511  // Postconditions:
1512 
1513  //ensure();
1514 
1515  // Exit:
1516 
1517  return;
1518 }
1519 
1521 void
1523 tensor(const at1& x0, const at1& x1, t2& xresult, bool xauto_access)
1524 {
1525  // Preconditions:
1526 
1527  require(x0.state_is_auto_read_accessible(xauto_access));
1528  require(x1.state_is_auto_read_accessible(xauto_access));
1529  require(xresult.state_is_auto_read_accessible(xauto_access));
1530  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1531  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1532 
1533  // Body:
1534 
1535  if(xauto_access)
1536  {
1537  x0.get_read_access();
1538  x1.get_read_access();
1539  xresult.get_read_write_access(true);
1540  }
1541 
1542  int ldd = x0.dd();
1543 
1544  for(int i=0; i<ldd; ++i)
1545  {
1546  vd_value_type lcomp_i = x0.component(i);
1547 
1548  for(int j=0; j<ldd; ++j)
1549  {
1550  vd_value_type lcomp_j = x1.component(j);
1551  vd_value_type lcomp_ij = lcomp_i * lcomp_j;
1552  xresult.put_component(i, j, lcomp_ij);
1553  }
1554  }
1555 
1556  // Set the variance of the result.
1557 
1558  xresult.put_variance(
1559  tensor_product(x0.variance(false), x1.variance(false)), false);
1560 
1561  if(xauto_access)
1562  {
1563  x0.release_access();
1564  x1.release_access();
1565  xresult.release_access();
1566  }
1567 
1568  // Postconditions:
1569 
1570  ensure(xresult.variance(xauto_access) ==
1571  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
1572 
1573  // Exit:
1574 
1575  return;
1576 }
1577 
virtual bool is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: t2.cc:366
virtual int dd() const
Dimension of the underlying vector space.
Definition: tp.cc:166
virtual bool is_contravariant(bool xauto_access) const
True if and only if all tensor index positions are contravariant.
Definition: tp.cc:1160
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 ...
t2_lite & operator=(const t2_lite &xother)
Assignment operator.
Definition: t2.cc:80
SHEAF_DLL_SPEC void alt(const t2_lite &x0, at2_lite &xresult)
The alternating (antisymmetric) part of tensor x0 (pre-allocated version for volatile types)...
Definition: t2.cc:1176
vd_value_type value_type
The type of component in the fiber; the scalar type in the fiber vector space.
Definition: vd.h:129
virtual void put_component(int xrow, int xcolumn, value_type xcomp)
Sets value of a component in a specified row and column.
Definition: at2.cc:187
virtual int dd() const
Dimension of the underlying vector space.
Definition: tp.cc:788
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
void put_variance(const tensor_variance &xvariance, bool xauto_access)
Sets the variance to xvariance.
Definition: tp.cc:1039
virtual int p() const
The degree of the tensors in host(); the sum of the contravariant and covariant degrees.
Definition: tp.cc:735
virtual t2_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: t2.cc:333
virtual const std::string & class_name() const
The name of this class.
Definition: t2.cc:295
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.
A general antisymmetric tensor of degree 1 over an abstract vector space (persistent version)...
Definition: at1.h:211
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
virtual volatile_type * lite_type() const
Virtual conversion to the associated volatile type.
Definition: t2.cc:654
A general antisymmetric tensor of degree 1 over an abstract vector space (volatile version)...
Definition: at1.h:44
bool contains_poset_member(pod_index_type xposet_hub_id, pod_index_type xmember_hub_id, bool xauto_access=true) const
True if this contains a poset with hub id xposet_hub_id which contains a member with hub id xmember_h...
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...
SHEAF_DLL_SPEC void sym(const t2_lite &x0, st2_lite &xresult)
The symmetric part of tensor x0 (pre-allocated version for volatile types).
Definition: t2.cc:1301
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
value_type component(int xrow, int xcolumn) const
The value of the component in a specified row and column.
Definition: t2.cc:147
STL namespace.
value_type component(int xindex) const
The xindex-th component.
Definition: vd.cc:209
virtual int p() const
The degree of the tensor; the sum of the contravariant and covariant degrees.
Definition: t2.cc:227
virtual int d() const
Dimension of this as a vector space.
Definition: t2.cc:258
virtual void get_read_access() const
Get read access to the state associated with this.
virtual t2 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: t2.cc:577
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.
virtual const std::string & class_name() const
The name of this class.
Definition: t2.cc:946
static const std::string & static_class_name()
The name of this class.
Definition: t2.cc:965
SHEAF_DLL_SPEC tensor_variance tensor_product(const tensor_variance &x0, const tensor_variance &x1)
The variance of the tensor product of tensors with variance x0 and x1.
T::row_dofs_type & row_dofs(T &x0)
The row dofs pod type for x0 (mutable version).
virtual void put_component(int xrow, int xcolumn, value_type xcomp)
Sets value of a component in a specified row and column.
Definition: st2.cc:167
bool is_mixed() const
True if and only if there exists at least one index that is covariant and at least one that is contra...
virtual t2 * clone() const
Make a new handle, no state instance of current.
Definition: t2.cc:984
A tensor of degree 2 over an abstract vector space (volatile version).
Definition: t2.h:43
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 volatile objects.
Definition: any_lite.h:48
void put_component(int xrow, int xcolumn, value_type xvalue)
Sets the component with row index xrow and column index xcolumn to xvalue.
Definition: t2.cc:864
Abstract base class with useful features for all objects.
Definition: any.h:39
A general symmetric tensor of degree 2 over an abstract vector space (volatile version).
Definition: st2.h:43
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
t2()
Default constructor.
Definition: t2.cc:538
static host_type & new_host(namespace_type &xns, const poset_path &xhost_path, const poset_path &xschema_path, const poset_path &xvector_space_path, bool xauto_access)
Creates a new host table for members of this type. The poset is created in namespace xns with path xh...
Definition: t2.cc:475
virtual int index_for_row_column(int xrow, int xcolumn) const
The index into linear storage of the component in a specified row and column.
Definition: t2.cc:759
A client handle for a mutable partially ordered set.
Definition: poset.h:40
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
bool invariant() const
Class invariant.
Definition: t2.cc:385
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
A scalar viewed as an antisymmetric tensor of degree 0. As the degree is 0 there is nothing to be sym...
Definition: at0.h:424
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
Antisymetric tensor of degree 0 (volatile version).
Definition: at0.h:127
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
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
virtual value_type component(int xindex) const
The value of the xi-th component.
Definition: vd.cc:1115
virtual bool invariant() const
Class invariant.
Definition: t2.cc:1019
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
void put_component(int xrow, int xcolumn, value_type xvalue)
Sets the component with row index xrow and column index xcolumn to xvalue.
Definition: st2.cc:807
value_type component(int xrow, int xcolumn) const
The component with row index xrow and column index xcolumn.
Definition: t2.cc:808
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
virtual int index_for_row_column(int xrow, int xcolumn) const
The index into linear storage of the component in a specified row and column.
Definition: t2.cc:192
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Definition: t2.cc:1052
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
static const std::string & static_class_name()
The name of this class.
Definition: t2.cc:314
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
An abstract vector space viewed as an antisymmetric tensor space of degree 1.
Definition: at1_space.h:42
virtual int p() const
Degree of this as an antisymmetric tensor space.
Definition: at0.cc:449
virtual void put_component(value_type xcomp)
Set value of (the only) component to xcomp.
Definition: at0.cc:270
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
virtual ~t2_lite()
Destructor.
Definition: t2.cc:97
virtual const volatile_type & lite_prototype() const
Virtual constructor for the associated volatile type.
Definition: t2.cc:636
static int factor_ct(int xd)
Factor_ct() as a function of dimension xd.
Definition: vd_space.cc:167
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
vd_value_type value_type
The POD ("plain old data") type of scalar in the vector space of this.
Definition: vd.h:423
int dd() const
The dimension of the underlying ("domain") vector space.
Definition: tp_space.cc:317
virtual tensor_variance variance(bool xauto_access) const
The variance.
Definition: tp.cc:1001
A general antisymmetric tensor of degree 2 over an abstract vector space (volatile version)...
Definition: at2.h:43
virtual ~t2()
Destructor.
Definition: t2.cc:620
An abstract client handle for a member of a poset.
void put_component(int xrow, int xcolumn, value_type xcomp)
Sets value of a component in a specified row and column.
Definition: t2.cc:169
virtual void put_component(int xindex, value_type xvalue)
Sets the value of the xindex-th component to xvalue.
Definition: vd.cc:1169
An abstract tensor space of degree p.
Definition: tp_space.h:47
void put_component(int xrow, int xcolumn, value_type xvalue)
Sets the component with row index xrow and column index xcolumn to xvalue.
Definition: at2.cc:851
SHEAF_DLL_SPEC void tensor(const at1_lite &x0, const at1_lite &x1, t2_lite &xresult)
Tensor product (pre-allocated version for volatile types).
Definition: t2.cc:1488
Namespace for the fiber_bundles component of the sheaf system.
A general symmetric tensor of degree 2 over an abstract vector space (persistent version).
Definition: st2.h:234
t2_lite()
Default constructor.
Definition: t2.cc:48
Row dofs type for class vd.
Definition: vd.h:61
A general antisymmetric tensor of degree 2 over an abstract vector space.
Definition: at2.h:233
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: t2.cc:428
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...
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: t2.cc:446
A client handle for a poset member which has been prepared for use as a schema.
double vd_value_type
The type of component in the fiber; the scalar type in the fiber vector space.
Definition: fiber_bundle.h:63
SHEAF_DLL_SPEC void contract(const t2_lite &x0, int xp, int xq, at0_lite &xresult)
Contraction on contravariant index xp and covariant index xq (pre-allocated version for volatime type...
Definition: t2.cc:1091
A tensor of degree 2 over an abstract vector space (persistent version).
Definition: t2.h:226
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
SHEAF_DLL_SPEC bool isunordered_or_equals(float x1, float x2)
True if isunordered(x1, x2) or x1 == x2.
Definition: sheaf.cc:102