SheafSystem  0.0.0.0
t3.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/t3.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 // #include "SheafSystem/abstract_poset_member.impl.h"
33 // #include "SheafSystem/assert_contract.h"
34 // #include "SheafSystem/at0.h"
35 // #include "SheafSystem/at0_space.h"
36 // #include "SheafSystem/at1.h"
37 // #include "SheafSystem/at1_space.h"
38 // #include "SheafSystem/tp_space.h"
39 // #include "SheafSystem/fiber_bundles_namespace.h"
40 // #include "SheafSystem/namespace_poset.impl.h"
41 // #include "SheafSystem/poset.h"
42 // #include "SheafSystem/schema_descriptor.h"
43 // #include "SheafSystem/tp_space.h"
44 // #include "SheafSystem/wsv_block.h"
45 
46 
47 using namespace std;
48 using namespace fiber_bundle; // Workaround for MS C++ bug.
49 
50 
51 //==============================================================================
52 // CLASS T3_LITE
53 //==============================================================================
54 
55 //==============================================================================
56 // T3 FACET OF CLASS T3_LITE
57 //==============================================================================
58 
59 // PUBLIC MEMBER FUNCTIONS
60 
63 {
64 
65  // Preconditions:
66 
67  // Body:
68 
69  // Postconditions:
70 
71  ensure(invariant());
72 
73  // Exit:
74 }
75 
77 t3_lite(const t3_lite& xother)
78 {
79  // Preconditions:
80 
81  // Body:
82 
83  *this = xother;
84 
85  // Postconditions:
86 
87  ensure(invariant());
88 
89  // Exit:
90 }
91 
94 operator=(const t3_lite& xother)
95 {
96 
97  // Preconditions:
98 
99  // Body:
100 
101  // Postconditions:
102 
103  ensure(invariant());
104 
105  // Exit:
106 
107  return *this;
108 }
109 
112 {
113  // Preconditions:
114 
115  // Body:
116 
117  // Postconditions:
118 
119  // Exit:
120 
121 }
122 
124 t3_lite(const row_dofs_type& xrow_dofs)
125 {
126  // Preconditions:
127 
128  // Body:
129 
130  *this = xrow_dofs;
131 
132  // Postconditions:
133 
134  ensure(invariant());
135 
136  // Exit:
137 }
138 
141 operator=(const row_dofs_type& xrow_dofs)
142 {
143  // Preconditions:
144 
145  // Body:
146 
147  vd_lite::operator=(xrow_dofs);
148 
149  // Postconditions:
150 
151  postcondition_of(vd_lite::operator=(xrow_dofs));
152 
153  // Exit:
154 
155  return *this;
156 
157 }
158 
159 // PROTECTED MEMBER FUNCTIONS
160 
161 // PRIVATE MEMBER FUNCTIONS
162 
163 
164 //==============================================================================
165 // TENSOR ALGEBRA (TP) FACET OF CLASS T3_LITE
166 //==============================================================================
167 
168 // PUBLIC MEMBER FUNCTIONS
169 
170 int
172 p() const
173 {
174  // Preconditions:
175 
176  // Body:
177 
178  int result = 3;
179 
180  // Postconditions:
181 
182  ensure(invariant());
183  ensure(result == 3);
184 
185  // Exit:
186 
187  return result;
188 }
189 
190 // PROTECTED MEMBER FUNCTIONS
191 
192 // PRIVATE MEMBER FUNCTIONS
193 
194 
195 //==============================================================================
196 // VECTOR ALGEBRA (VD) FACET OF CLASS T3_LITE
197 //==============================================================================
198 
199 // PUBLIC MEMBER FUNCTIONS
200 
201 int
203 d() const
204 {
205  // Preconditions:
206 
207  // Body:
208 
209  int result = static_cast<int>(dd()*dd()*dd());
210 
211  // Postconditions:
212 
213  ensure(invariant());
214  ensure(result == static_cast<int>(dd()*dd()*dd()));
215 
216  // Exit:
217 
218  return result;
219 }
220 
223 component(int xi, int xj, int xk) const
224 {
225  // Preconditions:
226 
227  require((0 <= xi) && (xi < dd()));
228  require((0 <= xj) && (xj < dd()));
229  require((0 <= xk) && (xk < dd()));
230 
231  // Body:
232 
233  value_type result = component(index_for_ijk(xi, xj, xk));
234 
235  // Postconditions:
236 
237  ensure(invariant());
238 
239  // Exit:
240 
241  return result;
242 }
243 
244 void
246 put_component(int xi, int xj, int xk, value_type xvalue)
247 {
248  // Preconditions:
249 
250  require((0 <= xi) && (xi < dd()));
251  require((0 <= xj) && (xj < dd()));
252  require((0 <= xk) && (xk < dd()));
253 
254  // Body:
255 
256  put_component(index_for_ijk(xi, xj, xk), xvalue);
257 
258  // Postconditions:
259 
260  ensure(isunordered_or_equals(component(xi, xj, xk), xvalue));
261 
262  // Exit:
263 
264  return;
265 }
266 
267 
268 int
270 index_for_ijk(int xi, int xj, int xk) const
271 {
272  // Preconditions:
273 
274  require((0 <= xi) && (xi < dd()));
275  require((0 <= xj) && (xj < dd()));
276  require((0 <= xk) && (xk < dd()));
277 
278  // Body:
279 
280  int ldd = dd();
281  int result = (xi*ldd + xj)*ldd + xk;
282 
283  // Postconditions:
284 
285  ensure(result >= 0);
286  ensure(result < d());
287 
288  // Exit:
289 
290  return result;
291 }
292 
293 // PROTECTED MEMBER FUNCTIONS
294 
295 // PRIVATE MEMBER FUNCTIONS
296 
297 
298 //==============================================================================
299 // CARTESIAN ALGEBRA (TUPLE) FACET OF CLASS T3_LITE
300 //==============================================================================
301 
302 // PUBLIC MEMBER FUNCTIONS
303 
304 // PROTECTED MEMBER FUNCTIONS
305 
306 // PRIVATE MEMBER FUNCTIONS
307 
308 
309 //==============================================================================
310 // ABSTRACT POSET MEMBER FACET OF CLASS T3_LITE
311 //==============================================================================
312 
313 // PUBLIC MEMBER FUNCTIONS
314 
315 const std::string&
317 class_name() const
318 {
319  // Preconditions:
320 
321  // Body:
322 
323  const string& result = static_class_name();
324 
325  // Postconditions:
326 
327  ensure(!result.empty());
328 
329  // Exit:
330 
331  return result;
332 }
333 
334 const std::string&
337 {
338  // Preconditions:
339 
340  // Body:
341 
342  static const string result("t3_lite");
343 
344  // Postconditions:
345 
346  ensure(!result.empty());
347 
348  // Exit:
349 
350  return result;
351 }
352 
355 clone() const
356 {
357  t3_lite* result = 0;
358 
359  // Preconditions:
360 
361  // Body:
362 
363  result = new t3_lite();
364 
365  // Postconditions:
366 
367  ensure(result != 0);
368  ensure(is_same_type(*result));
369 
370  // Exit:
371 
372  return result;
373 }
374 
375 // PROTECTED MEMBER FUNCTIONS
376 
377 // PRIVATE MEMBER FUNCTIONS
378 
379 
380 //==============================================================================
381 // ANY FACET OF CLASS T3_LITE
382 //==============================================================================
383 
384 // PUBLIC MEMBER FUNCTIONS
385 
386 bool
388 is_ancestor_of(const any_lite& xother) const
389 {
390  // Preconditions:
391 
392  require(&xother != 0);
393 
394  // Body:
395 
396  // True if other conforms to this.
397 
398  bool result = dynamic_cast<const t3_lite*>(&xother) != 0;
399 
400  // Postconditions:
401 
402  return result;
403 }
404 
405 bool
407 invariant() const
408 {
409  bool result = true;
410 
411  if(invariant_check())
412  {
413  // Prevent recursive calls to invariant.
414 
415  disable_invariant_check();
416 
417  // Must satisfy base class invariant.
418 
419  invariance(tp_lite::invariant());
420 
421  // Invariances for this class:
422 
423  // Finished, turn invariant checking back on.
424 
425  enable_invariant_check();
426  }
427 
428  // Exit
429 
430  return result;
431 }
432 
433 // PROTECTED MEMBER FUNCTIONS
434 
435 // PRIVATE MEMBER FUNCTIONS
436 
437 
438 //==============================================================================
439 // CLASS T3
440 //==============================================================================
441 
442 // ===========================================================
443 // HOST FACTORY FACET OF CLASS T3
444 // ===========================================================
445 
446 // PUBLIC MEMBER FUNCTIONS
447 
448 const sheaf::poset_path&
451 {
452  // Preconditions:
453 
454 
455  // Body:
456 
457  static const poset_path result(standard_schema_poset_name(), "t3_schema");
458 
459  // Postconditions:
460 
461  // Exit:
462 
463  return result;
464 }
465 
466 void
469 {
470  // Preconditions:
471 
472  require(xns.state_is_read_write_accessible());
473  require(xns.contains_poset(standard_schema_poset_name()));
474  require(!xns.contains_poset_member(standard_schema_path()));
475 
476  // Body:
477 
478  schema_poset_member lschema(xns,
479  standard_schema_path().member_name(),
480  tp::standard_schema_path(),
481  "",
482  false);
483 
484  lschema.detach_from_state();
485 
486  // Postconditions:
487 
488  ensure(xns.contains_poset_member(standard_schema_path()));
489 
490  // Exit:
491 
492  return;
493 }
494 
498  const poset_path& xhost_path,
499  const poset_path& xschema_path,
500  const poset_path& xvector_space_path,
501  bool xauto_access)
502 {
503  // cout << endl << "Entering t3::new_host." << endl;
504 
505  // Preconditions:
506 
507  require(xns.state_is_auto_read_write_accessible(xauto_access));
508 
509  require(!xhost_path.empty());
510  require(!xns.contains_path(xhost_path, xauto_access));
511 
512  require(xschema_path.full());
513  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
514  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
515 
516  require(xns.path_is_auto_read_accessible(xvector_space_path, xauto_access));
517  require(xns.contains_poset<vector_space_type::host_type>(xvector_space_path, xauto_access));
518 
519  require(host_type::d(xns, xschema_path, xauto_access) == host_type::d(xns, 3, xvector_space_path, xauto_access));
520 
521  // Body:
522 
523  host_type& result =
524  host_type::new_table(xns, xhost_path, xschema_path, 3, xvector_space_path, xauto_access);
525 
526  // Postconditions:
527 
528  ensure(xns.owns(result, xauto_access));
529  ensure(result.path(true) == xhost_path);
530  ensure(result.state_is_not_read_accessible());
531  ensure(result.schema(true).path(xauto_access) == xschema_path);
532 
533  ensure(result.factor_ct(true) == result.d(true));
534  ensure(result.d(true) == schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access));
535  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path());
536  ensure(result.p(true) == 3);
537  ensure(result.dd(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).d());
538  ensure(result.vector_space_path(true) == xvector_space_path );
539 
540  // Exit:
541 
542  // cout << "Leaving t3::new_host." << endl;
543  return result;
544 }
545 
546 
547 // PROTECTED MEMBER FUNCTIONS
548 
549 // PRIVATE MEMBER FUNCTIONS
550 
551 
552 //==============================================================================
553 // T3 FACET OF CLASS T3
554 //==============================================================================
555 
556 // PUBLIC MEMBER FUNCTIONS
557 
559 t3()
560 {
561 
562  // Preconditions:
563 
564  // Body:
565 
566  // Postconditions:
567 
568  ensure(invariant());
569 
570  // Exit:
571 
572  return;
573 }
574 
576 t3(const t3& xother)
577 {
578 
579  // Preconditions:
580 
581 
582  // Body:
583 
584  attach_to_state(&xother);
585 
586  // Postconditions:
587 
588  ensure(invariant());
589 
590  // Exit:
591 
592  return;
593 }
594 
599 {
600  // Preconditions:
601 
602  require(is_ancestor_of(&xother));
603  require(precondition_of(attach_to_state(&xother)));
604 
605  // Body:
606 
607  attach_to_state(&xother);
608 
609  // Postconditions:
610 
611  ensure(postcondition_of(attach_to_state(&xother)));
612 
613  // Exit:
614 
615  return *this;
616 }
617 
621 operator=(const t3& xother)
622 {
623  // Preconditions:
624 
625  require(precondition_of(attach_to_state(&xother)));
626 
627  // Body:
628 
629  attach_to_state(&xother);
630 
631  // Postconditions:
632 
633  ensure(postcondition_of(attach_to_state(&xother)));
634 
635  // Exit:
636 
637  return *this;
638 }
639 
642 {
643 
644  // Preconditions:
645 
646  // Body:
647 
648  // Postconditions:
649 
650  // Exit:
651 
652  return;
653 }
654 
658 {
659  // Preconditions:
660 
661  // Body:
662 
663  static const volatile_type result;
664 
665  // Postconditions:
666 
667  // Exit:
668 
669  return result;
670 }
671 
675 lite_type() const
676 {
677  // Preconditions:
678 
679  // Body:
680 
681  volatile_type* result = new volatile_type(sheaf::row_dofs(*this));
682 
683  // Postconditions:
684 
685  // Exit:
686 
687  return result;
688 }
689 
690 // NEW HANDLE, NEW STATE CONSTRUCTORS
691 
693 t3(poset* xhost, bool xauto_access)
694 {
695 
696  // Preconditions:
697 
698  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
699 
700  // Body:
701 
702  new_jim_state(xhost, 0, false, xauto_access);
703 
704  // Postconditions:
705 
706  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
707 
708  // Exit:
709 
710  return;
711 }
712 
713 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
714 
716 t3(const poset* xhost, pod_index_type xhub_id)
717 {
718  // Preconditions:
719 
720  require(xhost != 0);
721  require(xhost->state_is_read_accessible());
722  require(xhost->contains_member(xhub_id));
723 
724  // Body:
725 
726  attach_to_state(xhost, xhub_id);
727 
728  // Postconditions:
729 
730  ensure(invariant());
731  ensure(is_attached());
732  // ensure(host() == xhost);
733  ensure(index() == xhub_id);
734 }
735 
737 t3(const poset* xhost, const scoped_index& xid)
738 {
739  // Preconditions:
740 
741  require(xhost != 0);
742  require(xhost->state_is_read_accessible());
743  require(xhost->contains_member(xid));
744 
745  // Body:
746 
747  attach_to_state(xhost, xid.hub_pod());
748 
749  // Postconditions:
750 
751  ensure(invariant());
752  ensure(is_attached());
753  // ensure(host() == xhost);
754  ensure(index() ==~ xid);
755 }
756 
758 t3(const poset* xhost, const std::string& xname)
759 {
760 
761  // Preconditions:
762 
763  require(xhost != 0);
764  require(xhost->state_is_read_accessible());
765  require(!xname.empty());
766  require(xhost->contains_member(xname));
767 
768  // Body:
769 
770  attach_to_state(xhost, xname);
771 
772  // Postconditions:
773 
774  ensure(invariant());
775  ensure(is_attached());
776  // ensure(host() == xhost);
777  ensure(name() == xname);
778 
779 }
780 
781 // PROTECTED MEMBER FUNCTIONS
782 
783 // PRIVATE MEMBER FUNCTIONS
784 
785 
786 //==============================================================================
787 // TP FACET OF CLASS T3
788 //==============================================================================
789 
790 // PUBLIC MEMBER FUNCTIONS
791 
792 // PROTECTED MEMBER FUNCTIONS
793 
794 // PRIVATE MEMBER FUNCTIONS
795 
796 
797 //==============================================================================
798 // VD FACET OF CLASS T3
799 //==============================================================================
800 
801 // PUBLIC MEMBER FUNCTIONS
802 
805 component(int xi, int xj, int xk) const
806 {
807  // Preconditions:
808 
809  require(state_is_read_accessible());
810  require((0 <= xi) && (xi < dd()));
811  require((0 <= xj) && (xj < dd()));
812  require((0 <= xk) && (xk < dd()));
813 
814  // Body:
815 
816  value_type result = component(index_for_ijk(xi, xj, xk));
817 
818  // Postconditions:
819 
820  ensure(invariant());
821 
822  // Exit:
823 
824  return result;
825 }
826 
829 component(int xi, int xj, int xk, bool xauto_access) const
830 {
831  // Preconditions:
832 
833  require(state_is_auto_read_accessible(xauto_access));
834  require((0 <= xi) && (xi < dd(xauto_access)));
835  require((0 <= xj) && (xj < dd(xauto_access)));
836  require((0 <= xk) && (xk < dd(xauto_access)));
837 
838  // Body:
839 
840  if(xauto_access)
841  {
842  get_read_access();
843  }
844 
845  value_type result = component(index_for_ijk(xi, xj, xk));
846 
847  if(xauto_access)
848  {
849  release_access();
850  }
851 
852  // Postconditions:
853 
854  ensure(invariant());
855 
856  // Exit:
857 
858  return result;
859 }
860 
861 
862 void
864 put_component(int xi, int xj, int xk, value_type xvalue)
865 {
866 
867  // Preconditions:
868 
869  require(state_is_read_write_accessible());
870  require((0 <= xi) && (xi < dd()));
871  require((0 <= xj) && (xj < dd()));
872  require((0 <= xk) && (xk < dd()));
873 
874  // Body:
875 
876  put_component(index_for_ijk(xi, xj, xk), xvalue);
877 
878  // Postconditions:
879 
880  ensure(isunordered_or_equals(component(xi, xj, xk), xvalue));
881 
882  // Exit:
883 
884  return;
885 }
886 
887 void
889 put_component(int xi, int xj, int xk, value_type xvalue, bool xauto_access)
890 {
891  // Preconditions:
892 
893  require(state_is_auto_read_write_accessible(xauto_access));
894  require((0 <= xi) && (xi < dd()));
895  require((0 <= xj) && (xj < dd()));
896  require((0 <= xk) && (xk < dd()));
897 
898  // Body:
899 
900  if(xauto_access)
901  {
902  get_read_write_access(true);
903  }
904 
905  put_component(index_for_ijk(xi, xj, xk), xvalue);
906 
907  if(xauto_access)
908  {
909  release_access();
910  }
911 
912  // Postconditions:
913 
914  ensure(isunordered_or_equals(component(xi, xj, xk), xvalue));
915 
916  // Exit:
917 
918  return;
919 }
920 
921 int
923 index_for_ijk(int xi, int xj, int xk) const
924 {
925  // Preconditions:
926 
927  require(state_is_read_write_accessible());
928  require((0 <= xi) && (xi < dd()));
929  require((0 <= xj) && (xj < dd()));
930  require((0 <= xk) && (xk < dd()));
931 
932  // Body:
933 
934  int ldd = dd();
935  int result = (xi*ldd + xj)*ldd + xk;
936 
937  // Postconditions:
938 
939  ensure(result >= 0);
940  ensure(result < d());
941 
942  // Exit:
943 
944  return result;
945 }
946 
947 // PROTECTED MEMBER FUNCTIONS
948 
949 // PRIVATE MEMBER FUNCTIONS
950 
951 
952 //==============================================================================
953 // TUPLE FACET OF CLASS T3
954 //==============================================================================
955 
956 // PUBLIC MEMBER FUNCTIONS
957 
958 // PROTECTED MEMBER FUNCTIONS
959 
960 // PRIVATE MEMBER FUNCTIONS
961 
962 
963 //==============================================================================
964 // ABSTRACT POSET MEMBER FACET OF CLASS T3
965 //==============================================================================
966 
967 // PUBLIC MEMBER FUNCTIONS
968 
969 const std::string&
971 class_name() const
972 {
973  // Preconditions:
974 
975  // Body:
976 
977  const string& result = static_class_name();
978 
979  // Postconditions:
980 
981  ensure(!result.empty());
982 
983  // Exit:
984 
985  return result;
986 }
987 
988 const std::string&
991 {
992  // Preconditions:
993 
994  // Body:
995 
996  static const string result("t3");
997 
998  // Postconditions:
999 
1000  ensure(!result.empty());
1001 
1002  // Exit:
1003 
1004  return result;
1005 }
1006 
1009 clone() const
1010 {
1011 
1012  // Preconditions:
1013 
1014  // Body:
1015 
1016  // Create new handle of the current class.
1017 
1018  t3 *result = new t3();
1019 
1020  // Postconditions:
1021 
1022  ensure(result != 0);
1023  ensure(result->invariant());
1024 
1025  // Exit:
1026 
1027  return result;
1028 
1029 }
1030 
1031 // PROTECTED MEMBER FUNCTIONS
1032 
1033 // PRIVATE MEMBER FUNCTIONS
1034 
1035 
1036 //==============================================================================
1037 // ANY FACET OF CLASS T3
1038 //==============================================================================
1039 
1040 // PUBLIC MEMBER FUNCTIONS
1041 
1042 bool
1044 invariant() const
1045 {
1046  bool result = true;
1047 
1048  // Body:
1049 
1050  if(invariant_check())
1051  {
1052  // Prevent recursive calls to invariant.
1053 
1054  disable_invariant_check();
1055 
1056  // Must satisfy base class invariant.
1057 
1058  invariance(tp::invariant());
1059 
1060  // Invariances for this class:
1061 
1062  invariance(state_is_read_accessible() ? p() == 3 : true);
1063  invariance(state_is_read_accessible() ? d() == dd()*dd()*dd() : true);
1064 
1065  // Finished, turn invariant checking back on.
1066 
1067  enable_invariant_check();
1068  }
1069 
1070  // Exit:
1071 
1072  return result;
1073 }
1074 
1075 bool
1077 is_ancestor_of(const any* xother) const
1078 {
1079  // Preconditions:
1080 
1081  require(xother != 0);
1082 
1083  // Body:
1084 
1085  // True if other conforms to this
1086 
1087  bool result = dynamic_cast<const t3*>(xother) != 0;
1088 
1089  // Postconditions:
1090 
1091  ensure(invariant());
1092 
1093  // Exit:
1094 
1095  return result;
1096 
1097 }
1098 
1099 // PROTECTED MEMBER FUNCTIONS
1100 
1101 // PRIVATE MEMBER FUNCTIONS
1102 
1103 
1104 //==============================================================================
1105 // NON-MEMBER FUNCTIONS
1106 //==============================================================================
1107 
1108 #include "SheafSystem/at1.h"
1109 #include "SheafSystem/at2.h"
1110 #include "SheafSystem/at3.h"
1111 #include "SheafSystem/st2.h"
1112 #include "SheafSystem/st3.h"
1113 #include "SheafSystem/t2.h"
1114 
1115 //==============================================================================
1116 // TP FACET:
1117 //==============================================================================
1118 
1119 void
1121 contract(const t3_lite& x0, int xp, int xq, at1_lite& xresult)
1122 {
1123  // Preconditions:
1124 
1125  require(xp != xq);
1126  require(xp >= 0 && xp < x0.p());
1127  require(xq >= 0 && xq < x0.p());
1128  require(xresult.p() == x0.p() - 2);
1129 
1130  // Body:
1131 
1132  // For t3 the result of the contracton is an at1.
1133  // Well not really; but we use at1 in place of t1.
1134 
1135  int ldd = x0.dd();
1136 
1137  for(int n=0; n<ldd; ++n)
1138  {
1139  vd_value_type lsum = 0;
1140  for(int i=0; i<ldd; ++i)
1141  {
1142  int lindex;
1143  if(xp+xq == 1) // xp==0 and xq==1 or xp==1 and xq==0
1144  {
1145  lindex = x0.index_for_ijk(i, i, n);
1146  }
1147  else if(xp+xq == 2) // xp==0 and xq==2 or xp==2 and xq==0
1148  {
1149  lindex = x0.index_for_ijk(i, n, i);
1150  }
1151  else if(xp+xq == 3) // xp==1 and xq==2 or xp==2 and xq==1
1152  {
1153  lindex = x0.index_for_ijk(n, i, i);
1154  }
1155 
1156  lsum += x0.component(lindex);
1157  }
1158  xresult.put_component(n, lsum);
1159  }
1160 
1161  // Postconditions:
1162 
1163  ensure(unexecutable("xresult is the contraction of x0 on indices xp and xq"));
1164 
1165  // Exit:
1166 
1167  return;
1168 }
1169 
1170 void
1172 contract(const t3& x0, int xp, int xq, at1& xresult, bool xauto_access)
1173 {
1174  // Preconditions:
1175 
1176  require(x0.state_is_auto_read_accessible(xauto_access));
1177  require(xresult.state_is_auto_read_accessible(xauto_access));
1178  require(xp != xq);
1179  require(xp >= 0 && xp < x0.p(xauto_access));
1180  require(xq >= 0 && xq < x0.p(xauto_access));
1181  require(x0.is_contravariant(xp, xauto_access) != \
1182  x0.is_contravariant(xq, xauto_access));
1183 
1184  // Body:
1185 
1186  if(xauto_access)
1187  {
1188  x0.get_read_access();
1189  xresult.get_read_write_access(true);
1190  }
1191 
1192  // For t3 the result of the contraction is an at1.
1193 
1194  int ldd = x0.dd();
1195  int lsum_pq = xp+xq;
1196 
1197  for(int n=0; n<ldd; ++n)
1198  {
1199  vd_value_type lsum = 0;
1200  for(int i=0; i<ldd; ++i)
1201  {
1202  int lindex;
1203  if(lsum_pq == 1) // xp==0 and xq==1 or xp==1 and xq==0
1204  {
1205  lindex = x0.index_for_ijk(i, i, n);
1206  }
1207  else if(lsum_pq == 2) // xp==0 and xq==2 or xp==2 and xq==0
1208  {
1209  lindex = x0.index_for_ijk(i, n, i);
1210  }
1211  else if(lsum_pq == 3) // xp==1 and xq==2 or xp==2 and xq==1
1212  {
1213  lindex = x0.index_for_ijk(n, i, i);
1214  }
1215 
1216  lsum += x0.component(lindex);
1217  }
1218  xresult.put_component(n, lsum);
1219  }
1220 
1221  // Set the variance of the result.
1222 
1223  xresult.put_variance(contract(x0.variance(false), xp, xq), false);
1224 
1225  if(xauto_access)
1226  {
1227  x0.release_access();
1228  xresult.release_access();
1229  }
1230 
1231  // Postconditions:
1232 
1233  ensure(unexecutable("xresult is the contraction of x0 on indices xp and xq"));
1234  ensure(xresult.variance(xauto_access) == contract(x0.variance(false), xp, xq));
1235 
1236  // Exit:
1237 
1238  return;
1239 }
1240 
1241 void
1243 alt(const t3_lite& x0, t3_lite& xresult)
1244 {
1245  // Preconditions:
1246 
1247  require(x0.dd() == xresult.dd());
1248 
1249  // Body:
1250 
1251  int ldd = x0.dd();
1252 
1253  for(int i=0; i<ldd; ++i)
1254  {
1255  for(int j=0; j<ldd; ++j)
1256  {
1257  for(int k=0; k<ldd; ++k)
1258  {
1259  vd_value_type lvalue = x0.component(i, j, k)
1260  + x0.component(j, k, i)
1261  + x0.component(k, i, j)
1262  - x0.component(j, i, k)
1263  - x0.component(k, j, i)
1264  - x0.component(i, k, j);
1265 
1266  lvalue /= 6.0; // 3!
1267  xresult.put_component(i, j, k, lvalue);
1268  }
1269  }
1270  }
1271 
1272  // Postconditions:
1273 
1274  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1275 
1276  // Exit:
1277 
1278  return;
1279 }
1280 
1281 void
1283 alt(const t3_lite& x0, at3_lite& xresult)
1284 {
1285  // Preconditions:
1286 
1287  require(x0.dd() == xresult.dd());
1288 
1289  // Body:
1290 
1291  int ldd = x0.dd();
1292 
1293  for(int i=0; i<ldd; ++i)
1294  {
1295  for(int j=0; j<ldd; ++j)
1296  {
1297  for(int k=0; k<ldd; ++k)
1298  {
1299  vd_value_type lvalue = x0.component(i, j, k)
1300  + x0.component(j, k, i)
1301  + x0.component(k, i, j)
1302  - x0.component(j, i, k)
1303  - x0.component(k, j, i)
1304  - x0.component(i, k, j);
1305 
1306  lvalue /= 6.0; // 3!
1307  xresult.put_component(i, j, k, lvalue);
1308  }
1309  }
1310  }
1311 
1312  // Postconditions:
1313 
1314  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1315 
1316  // Exit:
1317 
1318  return;
1319 }
1320 
1321 void
1323 alt(const t3& x0, at3& xresult, bool xauto_access)
1324 {
1325  // Preconditions:
1326 
1327  require(x0.state_is_auto_read_accessible(xauto_access));
1328  require(xresult.state_is_auto_read_accessible(xauto_access));
1329  require(x0.dd(xauto_access) == xresult.dd(xauto_access));
1330  require(!x0.variance(xauto_access).is_mixed());
1331 
1332  // Body:
1333 
1334  if(xauto_access)
1335  {
1336  x0.get_read_access();
1337  xresult.get_read_write_access(true);
1338  }
1339 
1340  int ldd = x0.dd();
1341 
1342  for(int i=0; i<ldd; ++i)
1343  {
1344  for(int j=0; j<ldd; ++j)
1345  {
1346  for(int k=0; k<ldd; ++k)
1347  {
1348  vd_value_type lvalue = x0.component(i, j, k)
1349  + x0.component(j, k, i)
1350  + x0.component(k, i, j)
1351  - x0.component(j, i, k)
1352  - x0.component(k, j, i)
1353  - x0.component(i, k, j);
1354 
1355  lvalue /= 6.0; // 3!
1356  xresult.put_component(i, j, k, lvalue);
1357  }
1358  }
1359  }
1360 
1361  // Set the variance of the result.
1362 
1363  xresult.put_variance(x0.variance(false), false);
1364 
1365  if(xauto_access)
1366  {
1367  x0.release_access();
1368  xresult.release_access();
1369  }
1370 
1371  // Postconditions:
1372 
1373  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
1374  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1375 
1376  // Exit:
1377 
1378  return;
1379 }
1380 
1381 void
1383 sym(const t3_lite& x0, t3_lite& xresult)
1384 {
1385  // Preconditions:
1386 
1387  require(x0.dd() == xresult.dd());
1388 
1389  // Body:
1390 
1391  int ldd = x0.dd();
1392 
1393  for(int i=0; i<ldd; ++i)
1394  {
1395  for(int j=0; j<ldd; ++j)
1396  {
1397  for(int k=0; k<ldd; ++k)
1398  {
1399  vd_value_type lvalue = x0.component(i, j, k)
1400  + x0.component(j, k, i)
1401  + x0.component(k, i, j)
1402  + x0.component(j, i, k)
1403  + x0.component(k, j, i)
1404  + x0.component(i, k, j);
1405  lvalue /= 6.0; // 3!
1406  xresult.put_component(i, j, k, lvalue);
1407  }
1408  }
1409  }
1410 
1411  // Postconditions:
1412 
1413  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1414 
1415  // Exit:
1416 
1417  return;
1418 }
1419 
1420 void
1422 sym(const t3_lite& x0, st3_lite& xresult)
1423 {
1424  // Preconditions:
1425 
1426  require(x0.dd() == xresult.dd());
1427 
1428  // Body:
1429 
1430  int ldd = x0.dd();
1431 
1432  for(int i=0; i<ldd; ++i)
1433  {
1434  for(int j=0; j<ldd; ++j)
1435  {
1436  for(int k=0; k<ldd; ++k)
1437  {
1438  vd_value_type lvalue = x0.component(i, j, k)
1439  + x0.component(j, k, i)
1440  + x0.component(k, i, j)
1441  + x0.component(j, i, k)
1442  + x0.component(k, j, i)
1443  + x0.component(i, k, j);
1444  lvalue /= 6.0; // 3!
1445  xresult.put_component(i, j, k, lvalue);
1446  }
1447  }
1448  }
1449 
1450  // Postconditions:
1451 
1452  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
1453 
1454  // Exit:
1455 
1456  return;
1457 }
1458 
1459 void
1461 sym(const t3& x0, st3& xresult, bool xauto_access)
1462 {
1463  // Preconditions:
1464 
1465  require(x0.state_is_auto_read_accessible(xauto_access));
1466  require(xresult.state_is_auto_read_accessible(xauto_access));
1467  require(x0.dd(xauto_access) == xresult.dd(xauto_access));
1468  require(!x0.variance(xauto_access).is_mixed());
1469 
1470  // Body:
1471 
1472  if(xauto_access)
1473  {
1474  x0.get_read_access();
1475  xresult.get_read_write_access(true);
1476  }
1477 
1478  int ldd = x0.dd();
1479 
1480  for(int i=0; i<ldd; ++i)
1481  {
1482  for(int j=0; j<ldd; ++j)
1483  {
1484  for(int k=0; k<ldd; ++k)
1485  {
1486  vd_value_type lvalue = x0.component(i, j, k)
1487  + x0.component(j, k, i)
1488  + x0.component(k, i, j)
1489  + x0.component(j, i, k)
1490  + x0.component(k, j, i)
1491  + x0.component(i, k, j);
1492 
1493  lvalue /= 6.0; // 3!
1494  xresult.put_component(i, j, k, lvalue);
1495  }
1496  }
1497  }
1498 
1499  // Set the variance of the result.
1500 
1501  xresult.put_variance(x0.variance(false), false);
1502 
1503  if(xauto_access)
1504  {
1505  x0.release_access();
1506  xresult.release_access();
1507  }
1508 
1509  // Postconditions:
1510 
1511  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
1512  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
1513 
1514  // Exit:
1515 
1516  return;
1517 }
1518 
1519 void
1521 tensor(const t2_lite& x0, const at1_lite& x1, t3_lite& xresult)
1522 {
1523  // Preconditions:
1524 
1525  require(x1.dd() == x0.dd());
1526  require(xresult.dd() == x0.dd());
1527 
1528  // Body:
1529 
1530  int ldd = x0.dd();
1531 
1532  for(int i=0; i<ldd; ++i)
1533  {
1534  for(int j=0; j<ldd; ++j)
1535  {
1536  vd_value_type lcomp_ij = x0.component(i, j);
1537 
1538  for(int k=0; k<ldd; ++k)
1539  {
1540  vd_value_type lcomp_k = x1.component(k);
1541  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1542  xresult.put_component(i, j, k, lcomp_ijk);
1543  }
1544  }
1545  }
1546 
1547  // Postconditions:
1548 
1549  //ensure();
1550 
1551  // Exit:
1552 
1553  return;
1554 }
1555 
1556 void
1558 tensor(const t2& x0, const at1& x1, t3& xresult, bool xauto_access)
1559 {
1560  // Preconditions:
1561 
1562  require(x0.state_is_auto_read_accessible(xauto_access));
1563  require(x1.state_is_auto_read_accessible(xauto_access));
1564  require(xresult.state_is_auto_read_accessible(xauto_access));
1565  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1566  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1567 
1568  // Body:
1569 
1570  if(xauto_access)
1571  {
1572  x0.get_read_access();
1573  x1.get_read_access();
1574  xresult.get_read_write_access(true);
1575  }
1576 
1577  int ldd = x0.dd();
1578 
1579  for(int i=0; i<ldd; ++i)
1580  {
1581  for(int j=0; j<ldd; ++j)
1582  {
1583  vd_value_type lcomp_ij = x0.component(i, j);
1584 
1585  for(int k=0; k<ldd; ++k)
1586  {
1587  vd_value_type lcomp_k = x1.component(k);
1588  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1589  xresult.put_component(i, j, k, lcomp_ijk);
1590  }
1591  }
1592  }
1593 
1594  // Set the variance of the result.
1595 
1596  xresult.put_variance(
1597  tensor_product(x0.variance(false), x1.variance(false)), false);
1598 
1599 
1600  if(xauto_access)
1601  {
1602  x0.release_access();
1603  x1.release_access();
1604  xresult.release_access();
1605  }
1606 
1607  // Postconditions:
1608 
1609  ensure(xresult.variance(xauto_access) == \
1610  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
1611 
1612  // Exit:
1613 
1614  return;
1615 }
1616 
1617 void
1619 tensor(const at1_lite& x0, const t2_lite& x1, t3_lite& xresult)
1620 {
1621  // Preconditions:
1622 
1623  require(x1.dd() == x0.dd());
1624  require(xresult.dd() == x0.dd());
1625 
1626  // Body:
1627 
1628  int ldd = x0.dd();
1629 
1630  for(int i=0; i<ldd; ++i)
1631  {
1632  vd_value_type lcomp_i = x0.component(i);
1633 
1634  for(int j=0; j<ldd; ++j)
1635  {
1636  for(int k=0; k<ldd; ++k)
1637  {
1638  vd_value_type lcomp_jk = x1.component(j, k);
1639  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
1640  xresult.put_component(i, j, k, lcomp_ijk);
1641  }
1642  }
1643  }
1644 
1645  // Postconditions:
1646 
1647  //ensure();
1648 
1649  // Exit:
1650 
1651  return;
1652 }
1653 
1654 void
1656 tensor(const at1& x0, const t2& x1, t3& xresult, bool xauto_access)
1657 {
1658  // Preconditions:
1659 
1660  require(x0.state_is_auto_read_accessible(xauto_access));
1661  require(x1.state_is_auto_read_accessible(xauto_access));
1662  require(xresult.state_is_auto_read_accessible(xauto_access));
1663  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1664  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1665 
1666  // Body:
1667 
1668  if(xauto_access)
1669  {
1670  x0.get_read_access();
1671  x1.get_read_access();
1672  xresult.get_read_write_access(true);
1673  }
1674 
1675  int ldd = x0.dd();
1676 
1677  for(int i=0; i<ldd; ++i)
1678  {
1679  vd_value_type lcomp_i = x0.component(i);
1680 
1681  for(int j=0; j<ldd; ++j)
1682  {
1683  for(int k=0; k<ldd; ++k)
1684  {
1685  vd_value_type lcomp_jk = x1.component(j, k);
1686  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
1687  xresult.put_component(i, j, k, lcomp_ijk);
1688  }
1689  }
1690  }
1691 
1692  // Set the variance of the result.
1693 
1694  xresult.put_variance(
1695  tensor_product(x0.variance(false), x1.variance(false)), false);
1696 
1697 
1698  if(xauto_access)
1699  {
1700  x0.release_access();
1701  x1.release_access();
1702  xresult.release_access();
1703  }
1704 
1705  // Postconditions:
1706 
1707  ensure(xresult.variance(xauto_access) == \
1708  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
1709 
1710  // Exit:
1711 
1712  return;
1713 }
1714 
1715 //==============================================================================
1716 // atp versions of tensor:
1717 //==============================================================================
1718 
1720 void
1722 tensor(const at2_lite& x0, const at1_lite& x1, t3_lite& xresult)
1723 {
1724  // Preconditions:
1725 
1726  require(x1.dd() == x0.dd());
1727  require(xresult.dd() == x0.dd());
1728 
1729  // Body:
1730 
1731  int ldd = x0.dd();
1732 
1733  for(int i=0; i<ldd; ++i)
1734  {
1735  for(int j=0; j<ldd; ++j)
1736  {
1737  vd_value_type lcomp_ij = x0.component(i, j);
1738 
1739  for(int k=0; k<ldd; ++k)
1740  {
1741  vd_value_type lcomp_k = x1.component(k);
1742  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1743  xresult.put_component(i, j, k, lcomp_ijk);
1744  }
1745  }
1746  }
1747 
1748  // Postconditions:
1749 
1750  // Exit:
1751 
1752  return;
1753 }
1754 
1756 void
1758 tensor(const at2& x0, const at1& x1, t3& xresult, bool xauto_access)
1759 {
1760  // Preconditions:
1761 
1762  require(x0.state_is_auto_read_accessible(xauto_access));
1763  require(x1.state_is_auto_read_accessible(xauto_access));
1764  require(xresult.state_is_auto_read_accessible(xauto_access));
1765  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1766  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1767 
1768  // Body:
1769 
1770  if(xauto_access)
1771  {
1772  x0.get_read_access();
1773  x1.get_read_access();
1774  xresult.get_read_write_access(true);
1775  }
1776 
1777  int ldd = x0.dd();
1778 
1779  for(int i=0; i<ldd; ++i)
1780  {
1781  for(int j=0; j<ldd; ++j)
1782  {
1783  vd_value_type lcomp_ij = x0.component(i, j);
1784 
1785  for(int k=0; k<ldd; ++k)
1786  {
1787  vd_value_type lcomp_k = x1.component(k);
1788  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1789  xresult.put_component(i, j, k, lcomp_ijk);
1790  }
1791  }
1792  }
1793 
1794  // Set the variance of the result.
1795 
1796  xresult.put_variance(
1797  tensor_product(x0.variance(false), x1.variance(false)), false);
1798 
1799 
1800  if(xauto_access)
1801  {
1802  x0.release_access();
1803  x1.release_access();
1804  xresult.release_access();
1805  }
1806 
1807  // Postconditions:
1808 
1809  ensure(xresult.variance(xauto_access) == \
1810  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
1811 
1812  // Exit:
1813 
1814  return;
1815 }
1816 
1818 void
1820 tensor(const at1_lite& x0, const at2_lite& x1, t3_lite& xresult)
1821 {
1822  // Preconditions:
1823 
1824  require(x1.dd() == x0.dd());
1825  require(xresult.dd() == x0.dd());
1826 
1827  // Body:
1828 
1829  int ldd = x0.dd();
1830 
1831  for(int i=0; i<ldd; ++i)
1832  {
1833  vd_value_type lcomp_i = x0.component(i);
1834 
1835  for(int j=0; j<ldd; ++j)
1836  {
1837  for(int k=0; k<ldd; ++k)
1838  {
1839  vd_value_type lcomp_jk = x1.component(j, k);
1840 
1841  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
1842  xresult.put_component(i, j, k, lcomp_ijk);
1843  }
1844  }
1845  }
1846 
1847  // Postconditions:
1848 
1849  //ensure();
1850 
1851  // Exit:
1852 
1853  return;
1854 }
1855 
1857 void
1859 tensor(const at1& x0, const at2& x1, t3& xresult, bool xauto_access)
1860 {
1861  // Preconditions:
1862 
1863  require(x0.state_is_auto_read_accessible(xauto_access));
1864  require(x1.state_is_auto_read_accessible(xauto_access));
1865  require(xresult.state_is_auto_read_accessible(xauto_access));
1866  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1867  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1868 
1869  // Body:
1870 
1871  if(xauto_access)
1872  {
1873  x0.get_read_access();
1874  x1.get_read_access();
1875  xresult.get_read_write_access(true);
1876  }
1877 
1878  int ldd = x0.dd();
1879 
1880  for(int i=0; i<ldd; ++i)
1881  {
1882  vd_value_type lcomp_i = x0.component(i);
1883 
1884  for(int j=0; j<ldd; ++j)
1885  {
1886  for(int k=0; k<ldd; ++k)
1887  {
1888  vd_value_type lcomp_jk = x1.component(j, k);
1889 
1890  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
1891  xresult.put_component(i, j, k, lcomp_ijk);
1892  }
1893  }
1894  }
1895 
1896  // Set the variance of the result.
1897 
1898  xresult.put_variance(
1899  tensor_product(x0.variance(false), x1.variance(false)), false);
1900 
1901  if(xauto_access)
1902  {
1903  x0.release_access();
1904  x1.release_access();
1905  xresult.release_access();
1906  }
1907 
1908  // Postconditions:
1909 
1910  ensure(xresult.variance(xauto_access) == \
1911  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
1912 
1913  // Exit:
1914 
1915  return;
1916 }
1917 
1918 //==============================================================================
1919 // stp versions of tensor:
1920 //==============================================================================
1921 
1923 void
1925 tensor(const st2_lite& x0, const at1_lite& x1, t3_lite& xresult)
1926 {
1927  // Preconditions:
1928 
1929  require(x1.dd() == x0.dd());
1930  require(xresult.dd() == x0.dd());
1931 
1932  // Body:
1933 
1934  int ldd = x0.dd();
1935 
1936  for(int i=0; i<ldd; ++i)
1937  {
1938  for(int j=0; j<ldd; ++j)
1939  {
1940  vd_value_type lcomp_ij = x0.component(i, j);
1941 
1942  for(int k=0; k<ldd; ++k)
1943  {
1944  vd_value_type lcomp_k = x1.component(k);
1945  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1946  xresult.put_component(i, j, k, lcomp_ijk);
1947  }
1948  }
1949  }
1950 
1951  // Postconditions:
1952 
1953  //ensure();
1954 
1955  // Exit:
1956 
1957  return;
1958 }
1959 
1961 void
1963 tensor(const st2& x0, const at1& x1, t3& xresult, bool xauto_access)
1964 {
1965  // Preconditions:
1966 
1967  require(x0.state_is_auto_read_accessible(xauto_access));
1968  require(x1.state_is_auto_read_accessible(xauto_access));
1969  require(xresult.state_is_auto_read_accessible(xauto_access));
1970  require(x1.dd(xauto_access) == x0.dd(xauto_access));
1971  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
1972 
1973  // Body:
1974 
1975  if(xauto_access)
1976  {
1977  x0.get_read_access();
1978  x1.get_read_access();
1979  xresult.get_read_write_access(true);
1980  }
1981 
1982  int ldd = x0.dd();
1983 
1984  for(int i=0; i<ldd; ++i)
1985  {
1986  for(int j=0; j<ldd; ++j)
1987  {
1988  vd_value_type lcomp_ij = x0.component(i, j);
1989 
1990  for(int k=0; k<ldd; ++k)
1991  {
1992  vd_value_type lcomp_k = x1.component(k);
1993  vd_value_type lcomp_ijk = lcomp_ij * lcomp_k;
1994  xresult.put_component(i, j, k, lcomp_ijk);
1995  }
1996  }
1997  }
1998 
1999  // Set the variance of the result.
2000 
2001  xresult.put_variance(
2002  tensor_product(x0.variance(false), x1.variance(false)), false);
2003 
2004  if(xauto_access)
2005  {
2006  x0.release_access();
2007  x1.release_access();
2008  xresult.release_access();
2009  }
2010 
2011  // Postconditions:
2012 
2013  ensure(xresult.variance(xauto_access) == \
2014  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
2015 
2016  // Exit:
2017 
2018  return;
2019 }
2020 
2022 void
2024 tensor(const at1_lite& x0, const st2_lite& x1, t3_lite& xresult)
2025 {
2026  // Preconditions:
2027 
2028  require(x1.dd() == x0.dd());
2029  require(xresult.dd() == x0.dd());
2030 
2031  // Body:
2032 
2033  int ldd = x0.dd();
2034 
2035  for(int i=0; i<ldd; ++i)
2036  {
2037  vd_value_type lcomp_i = x0.component(i);
2038 
2039  for(int j=0; j<ldd; ++j)
2040  {
2041  for(int k=0; k<ldd; ++k)
2042  {
2043  vd_value_type lcomp_jk = x1.component(j, k);
2044  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
2045  xresult.put_component(i, j, k, lcomp_ijk);
2046  }
2047  }
2048  }
2049 
2050  // Postconditions:
2051 
2052  //ensure();
2053 
2054  // Exit:
2055 
2056  return;
2057 }
2058 
2060 void
2062 tensor(const at1& x0, const st2& x1, t3& xresult, bool xauto_access)
2063 {
2064  // Preconditions:
2065 
2066  require(x0.state_is_auto_read_accessible(xauto_access));
2067  require(x1.state_is_auto_read_accessible(xauto_access));
2068  require(xresult.state_is_auto_read_accessible(xauto_access));
2069 
2070  require(x1.dd(xauto_access) == x0.dd(xauto_access));
2071  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
2072  require(xresult.p(xauto_access) == x0.p(xauto_access) + x1.p(xauto_access));
2073 
2074  // Body:
2075 
2076  if(xauto_access)
2077  {
2078  x0.get_read_access();
2079  x1.get_read_access();
2080  xresult.get_read_write_access(true);
2081  }
2082 
2083  int ldd = x0.dd();
2084 
2085  for(int i=0; i<ldd; ++i)
2086  {
2087  vd_value_type lcomp_i = x0.component(i);
2088 
2089  for(int j=0; j<ldd; ++j)
2090  {
2091  for(int k=0; k<ldd; ++k)
2092  {
2093  vd_value_type lcomp_jk = x1.component(j, k);
2094  vd_value_type lcomp_ijk = lcomp_i * lcomp_jk;
2095  xresult.put_component(i, j, k, lcomp_ijk);
2096  }
2097  }
2098  }
2099 
2100  // Set the variance of the result.
2101 
2102  xresult.put_variance(
2103  tensor_product(x0.variance(false), x1.variance(false)), false);
2104 
2105  if(xauto_access)
2106  {
2107  x0.release_access();
2108  x1.release_access();
2109  xresult.release_access();
2110  }
2111 
2112  // Postconditions:
2113 
2114  ensure(xresult.variance(xauto_access) == \
2115  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
2116 
2117  // Exit:
2118 
2119  return;
2120 }
2121 
A tensor of degree 3 over an abstract vector space (volatile version).
Definition: t3.h:43
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 int index_for_ijk(int xi, int xj, int xk) const
The index into linear storage of the component for specified indices xi, xj, xk.
Definition: t3.cc:270
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 ...
An antisymmetric rank 3 tensor over an abstract vector space (volatile version).
Definition: at3.h:43
virtual const std::string & class_name() const
The name of this class.
Definition: t3.cc:971
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 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 bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Definition: t3.cc:1077
virtual const std::string & class_name() const
The name of this class.
Definition: t3.cc:317
virtual int d() const
Dimension of this as a vector space.
Definition: t3.cc:203
static const std::string & static_class_name()
The name of this class.
Definition: t3.cc:336
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...
virtual volatile_type * lite_type() const
Virtual conversion to the associated volatile type.
Definition: t3.cc:675
A tensor of degree 3 over an abstract vector space (persistent version).
Definition: t3.h:222
poset_path vector_space_path() const
The path of the underlying vector space.
Definition: tp_space.cc:365
virtual value_type component(int xi, int xj, int xk) const
The component with indices xi, xj, xk.
Definition: t3.cc:805
bool invariant() const
Class invariant.
Definition: t3.cc:407
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
virtual bool invariant() const
Class invariant.
Definition: t3.cc:1044
static const std::string & static_class_name()
The name of this class.
Definition: t3.cc:990
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 void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: st3.cc:822
virtual value_type component(int xrow, int xcolumn) const
The value of the component in a specified row and column.
Definition: st2.cc:145
virtual void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: t3.cc:246
virtual void get_read_access() const
Get read access to the state associated with this.
poset_state_handle & member_poset(pod_index_type xhub_id, bool xauto_access=true) const
The poset_state_handle object referred to by hub id xhub_id.
SHEAF_DLL_SPEC 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.
virtual ~t3()
Destructor.
Definition: t3.cc:641
T::row_dofs_type & row_dofs(T &x0)
The row dofs pod type for x0 (mutable version).
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...
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
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
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: t3.cc:497
virtual int index_for_ijk(int xi, int xj, int xk) const
The index into linear storage of the component for specified indices xi, xj, xk.
Definition: t3.cc:923
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
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...
virtual void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: at3.cc:228
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_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: t3.cc:388
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
virtual void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: st3.cc:213
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
A symmetric rank 3 tensor over an abstract vector space (persistent version).
Definition: st3.h:230
virtual t3 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: t3.cc:598
virtual value_type component(int xindex) const
The value of the xi-th component.
Definition: vd.cc:1115
virtual t3 * clone() const
Make a new handle, no state instance of current.
Definition: t3.cc:1009
A symmetric rank 3 tensor over an abstract vector space. (volatile version).
Definition: st3.h:43
An antisymmetric rank 3 tensor over an abstract vector space (volatile version).
Definition: at3.h:230
virtual const volatile_type & lite_prototype() const
Virtual constructor for the associated volatile type.
Definition: t3.cc:657
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
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 p() const
The degree of the tensor; the sum of the contravariant and covariant degrees.
Definition: t3.cc:172
poset_path scalar_space_path() const
The path of the underlying space of scalars.
Definition: vd_space.cc:250
virtual void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: t3.cc:864
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...
void put_component(int xindex, value_type xcomp)
Set the xindex-th component to xcomp.
Definition: vd.cc:230
An abstract vector space viewed as an antisymmetric tensor space of degree 1.
Definition: at1_space.h:42
t3_lite()
Default constructor.
Definition: t3.cc:62
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
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
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: t3.cc:450
virtual ~t3_lite()
Destructor.
Definition: t3.cc:111
virtual value_type component(int xi, int xj, int xk) const
The component with indices xi, xj, xk.
Definition: t3.cc:223
t3_lite & operator=(const t3_lite &xother)
Assignment operator.
Definition: t3.cc:94
virtual tensor_variance variance(bool xauto_access) const
The variance.
Definition: tp.cc:1001
virtual void put_component(int xi, int xj, int xk, value_type xvalue)
Sets the component with indices xi, xj, xk to xvalue.
Definition: at3.cc:842
A general antisymmetric tensor of degree 2 over an abstract vector space (volatile version)...
Definition: at2.h:43
virtual value_type component(int xrow, int xcolumn) const
The value of the component in a specified row and column.
Definition: at2.cc:148
t3()
Default constructor.
Definition: t3.cc:559
An abstract client handle for a member of a poset.
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: t3.cc:468
value_type component(int xrow, int xcolumn) const
The component with row index xrow and column index xcolumn.
Definition: at2.cc:787
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
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
value_type component(int xrow, int xcolumn) const
The component with row index xrow and column index xcolumn.
Definition: st2.cc:751
virtual t3_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: t3.cc:355
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
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.
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
virtual int p() const
Degree of this as an antisymmetric tensor space.
Definition: at1.cc:156
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