SheafSystem  0.0.0.0
gl3.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/gl3.impl.h"
22 
23 #include "SheafSystem/abstract_poset_member.impl.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/at0.h"
26 #include "SheafSystem/at1_space.h"
27 #include "SheafSystem/e3.h"
28 #include "SheafSystem/gln_space.h"
29 #include "SheafSystem/fiber_bundles_namespace.h"
30 #include "SheafSystem/schema_poset_member.h"
31 #include "SheafSystem/std_cmath.h"
32 #include "SheafSystem/wsv_block.h"
33 
34 using namespace std;
35 using namespace fiber_bundle; // Workaround for MS C++ bug.
36 
37 
38 //==============================================================================
39 // CLASS GL3_LITE
40 //==============================================================================
41 
42 
43 //==============================================================================
44 // GL3 FACET OF CLASS GL3_LITE
45 //==============================================================================
46 
47 // PUBLIC MEMBER FUNCTIONS
48 
51 {
52 
53  // Preconditions:
54 
55  // Body:
56 
57  // Postconditions:
58 
59  ensure(invariant());
60 
61  // Exit:
62 }
63 
65 gl3_lite(const gl3_lite& xother)
66 {
67  // Preconditions:
68 
69  // Body:
70 
71  *this = xother;
72 
73  // Postconditions:
74 
75  ensure(invariant());
76 
77  // Exit:
78 }
79 
82 operator=(const gl3_lite& xother)
83 {
84  // Preconditions:
85 
86  // Body:
87 
88  if(this == &xother)
89  return *this;
90 
91  _row_dofs = xother._row_dofs;
92 
93  // Postconditions:
94 
95  ensure(invariant());
96 
97  // Exit:
98 
99  return *this;
100 }
101 
104 {
105  // Preconditions:
106 
107  // Body:
108 
109  // Postconditions:
110 
111  // Exit:
112 
113 }
114 
116 gl3_lite(const row_dofs_type& xrow_dofs)
117 {
118  // Preconditions:
119 
120  // Body:
121 
122  *this = xrow_dofs;
123 
124  // Postconditions:
125 
126  ensure(invariant());
127 
128  // Exit:
129 }
130 
133 operator=(const row_dofs_type& xrow_dofs)
134 {
135  // Preconditions:
136 
137  // Body:
138 
139  _row_dofs = xrow_dofs;
140 
141  // Postconditions:
142 
143  ensure(invariant());
144 
145  // Exit:
146 
147  return *this;
148 
149 }
150 
152 gl3_lite(const matrix_type& xmatrix)
153 {
154  // Preconditions:
155 
156  // Body:
157 
158  *this = xmatrix;
159 
160  // Postconditions:
161 
162  ensure(invariant());
163 
164  // Exit:
165 }
166 
169 operator=(const matrix_type& xmatrix)
170 {
171  // Preconditions:
172 
173  // Body:
174 
175  //_row_dofs = xmatrix;
176  _row_dofs = reinterpret_cast<const row_dofs_type&>(xmatrix);
177 
178  // Postconditions:
179 
180  ensure(invariant());
181 
182  // Exit:
183 
184  return *this;
185 
186 }
187 
188 fiber_bundle::gl3_lite::
190 {
191  // Preconditions:
192 
193  // Body:
194 
195  matrix_type& result = _row_dofs;
196 
197  // Postconditions:
198 
199  // Exit:
200 
201  return result;
202 }
203 
204 fiber_bundle::gl3_lite::
205 operator const gl3_lite::matrix_type& () const
206 {
207  // Preconditions:
208 
209  // Body:
210 
211  const matrix_type& result = _row_dofs;
212 
213  // Postconditions:
214 
215  // Exit:
216 
217  return result;
218 }
219 
220 fiber_bundle::gl3_lite::
222 {
223  // Preconditions:
224 
225  // Body:
226 
227  row_dofs_type& result = _row_dofs;
228 
229  // Postconditions:
230 
231  // Exit:
232 
233  return result;
234 }
235 
236 fiber_bundle::gl3_lite::
237 operator const gl3_lite::row_dofs_type& () const
238 {
239  // Preconditions:
240 
241  // Body:
242 
243  const row_dofs_type& result = _row_dofs;
244 
245  // Postconditions:
246 
247  // Exit:
248 
249  return result;
250 }
251 
255 {
256  // Preconditions:
257 
258  // Body:
259 
260  matrix_type& result = _row_dofs.basis_matrix();
261 
262  // Postconditions:
263 
264  // Exit:
265 
266  return result;
267 }
268 
272 {
273  // Preconditions:
274 
275  // Body:
276 
277  // Postconditions:
278 
279  const matrix_type& result = _row_dofs.basis_matrix();
280 
281  // Exit:
282 
283  return result;
284 }
285 
289 {
290  // Preconditions:
291 
292  // Body:
293 
294  matrix_type& result = _row_dofs.component_matrix();
295 
296  // Exit:
297 
298  return result;
299 }
300 
304 {
305  // Preconditions:
306 
307  // Body:
308 
309  const matrix_type& result = _row_dofs.component_matrix();
310 
311  // Postconditions:
312 
313  // Exit:
314 
315  return result;
316 }
317 
318 void
320 rescale(const value_type& xscale,
321  const value_type& yscale,
322  const value_type& zscale)
323 {
324  // Preconditions:
325 
326  // Body:
327 
328  // Get the basis matrix.
329 
330  matrix_type& bm = basis_matrix();
331 
332  // Set the basis matrix for rescaling.
333 
334  bm.assign(0.0);
335 
336  bm[0][0] = xscale;
337  bm[1][1] = yscale;
338  bm[2][2] = zscale;
339 
340  // Get the component matrix.
341 
342  matrix_type& cm = component_matrix();
343 
344  // Set the component matrix for rescaling.
345 
346  // The component matrix is the inverse of the basis matrix
347  // and the inverse is very simple in this case.
348 
349  cm.assign(0.0);
350 
351  cm[0][0] = 1.0/xscale;
352  cm[1][1] = 1.0/yscale;
353  cm[2][2] = 1.0/zscale;
354 
355  // Postconditions:
356 
357  ensure(invariant());
358 
359  // Exit:
360 
361 }
362 
363 void
365 rotate_x(const value_type& xangle)
366 {
367  // Preconditions:
368 
369  // Body:
370 
371  // Set the basis matrix for rotation about the x-asis.
372 
373  matrix_type& bm = basis_matrix();
374 
375  value_type lcos = cos(xangle);
376  value_type lsin = sin(xangle);
377 
378  bm[0][0] = 1.0;
379  bm[0][1] = 0.0;
380  bm[0][2] = 0.0;
381 
382  bm[1][0] = 0.0;
383  bm[1][1] = lcos;
384  bm[1][2] = -lsin;
385 
386  bm[2][0] = 0.0;
387  bm[2][1] = lsin;
388  bm[2][2] = lcos;
389 
390  // Set component matrix to the inverse of the basis matrix.
391 
392  bm.inverse(component_matrix());
393 
394  // Postconditions:
395 
396  ensure(invariant());
397 
398  // Exit:
399 }
400 
401 void
403 rotate_y(const value_type& xangle)
404 {
405  // Preconditions:
406 
407  // Body:
408 
409  // Set the basis matrix for rotation about the y-axis.
410 
411  matrix_type& bm = basis_matrix();
412 
413  value_type lcos = cos(xangle);
414  value_type lsin = sin(xangle);
415 
416  bm[0][0] = lcos;
417  bm[0][1] = 0.0;
418  bm[0][2] = lsin;
419 
420  bm[1][0] = 0.0;
421  bm[1][1] = 1.0;
422  bm[1][2] = 0.0;
423 
424  bm[2][0] = -lsin;
425  bm[2][1] = 0.0;
426  bm[2][2] = lcos;
427 
428  // Set component matrix to the inverse of the basis matrix.
429 
430  bm.inverse(component_matrix());
431 
432  // Postconditions:
433 
434  ensure(invariant());
435 
436  // Exit:
437 }
438 
439 void
441 rotate_z(const value_type& xangle)
442 {
443  // Preconditions:
444 
445  // Body:
446 
447  // Set the basis matrix for rotation about the z-axis.
448 
449  matrix_type& bm = basis_matrix();
450 
451  value_type lcos = cos(xangle);
452  value_type lsin = sin(xangle);
453 
454  bm[0][0] = lcos;
455  bm[0][1] = -lsin;
456  bm[0][2] = 0.0;
457 
458  bm[1][0] = lsin;
459  bm[1][1] = lcos;
460  bm[1][2] = 0.0;
461 
462  bm[2][0] = 0.0;
463  bm[2][1] = 0.0;
464  bm[2][2] = 1.0;
465 
466  // Set component matrix to the inverse of the basis matrix.
467 
468  bm.inverse(component_matrix());
469 
470  // Postconditions:
471 
472  ensure(invariant());
473 
474  // Exit:
475 }
476 
477 void
479 rotate_euler(const value_type& xalpha,
480  const value_type& xbeta,
481  const value_type& xgamma)
482 {
483  // Preconditions:
484 
485  // Body:
486 
487  // Set the basis matrix for rotation through the euler angles.
488 
489  matrix_type& bm = basis_matrix();
490 
491  value_type cos_alpha = cos(xalpha);
492  value_type sin_alpha = sin(xalpha);
493 
494  value_type cos_beta = cos(xbeta);
495  value_type sin_beta = sin(xbeta);
496 
497  value_type cos_gamma = cos(xgamma);
498  value_type sin_gamma = sin(xgamma);
499 
500  // Formula taken from G. Arfken, Math. Methods for Physicists,
501  // 3rd ed. p 200.
502 
503  bm[0][0] = cos_gamma*cos_beta*cos_alpha - sin_gamma*sin_alpha;
504  bm[0][1] = -sin_gamma*cos_beta*cos_alpha - cos_gamma*sin_alpha;
505  bm[0][2] = sin_beta*cos_alpha;
506 
507  bm[1][0] = cos_gamma*cos_beta*sin_alpha + sin_gamma*cos_alpha;
508  bm[1][1] = -sin_gamma*cos_beta*sin_alpha + cos_gamma*cos_alpha;
509  bm[1][2] = sin_beta*sin_alpha;
510 
511  bm[2][0] = -cos_gamma*sin_beta;
512  bm[2][1] = sin_gamma*sin_beta;
513  bm[2][2] = cos_beta;
514 
515  // Set component matrix to the inverse of the basis matrix.
516 
517  bm.inverse(component_matrix());
518 
519 
520  // Postconditions:
521 
522  ensure(invariant());
523 
524  // Exit:
525 
526 }
527 
528 void
531  value_type xb1[],
532  value_type xb2[]) const
533 {
534  // Preconditions:
535 
536  require(unexecutable("Each xbi is a vector of length at least 2."));
537 
538  // Body:
539 
540  // The new basis vectors are the columns of the b matrix
541  // See comments in header file on matrix definition.
542 
543  xb0[0] = component(0); // bxx
544  xb1[0] = component(1); // bxy
545  xb2[0] = component(2); // bxz
546 
547  xb0[1] = component(3); // byx
548  xb1[1] = component(4); // byy
549  xb2[1] = component(5); // byz
550 
551  xb0[2] = component(6); // bzx
552  xb1[2] = component(7); // bzy
553  xb2[2] = component(8); // bzz
554 
555  // Postconditions:
556 
557  ensure(invariant());
558  ensure(unexecutable("Return values are set to the correct components"));
559 
560  // Exit:
561 
562  return;
563 }
564 
565 void
567 put_basis(const value_type xb0[],
568  const value_type xb1[],
569  const value_type xb2[])
570 {
571  // Preconditions:
572 
573  require(unexecutable("Each xbi is a vector of length at least 3."));
574 
575  // Body:
576 
577  // The new basis vectors are the columns of the b matrix.
578  // See comments in header file on matrix definition.
579 
580  put_component(0, xb0[0]); // bxx
581  put_component(1, xb1[0]); // bxy
582  put_component(2, xb2[0]); // bxz
583 
584  put_component(3, xb0[1]); // byx
585  put_component(4, xb1[1]); // byy
586  put_component(5, xb2[1]); // byz
587 
588  put_component(6, xb0[2]); // bzx
589  put_component(7, xb1[2]); // bzy
590  put_component(8, xb2[2]); // bzz
591 
592  // Now make the component matrix the inverse of the basis matrix.
593 
594  component_matrix() = basis_matrix().inverse();
595 
596  // Postconditions:
597 
598  ensure(invariant());
599  ensure(unexecutable("Components are set to the correct basis values"));
600  ensure(unexecutable("The component matrix is the inverse of the basis matrix"));
601 
602  // Exit:
603 
604  return;
605 }
606 
607 void
609 get_matrix(row_dofs_type& xmatrix) const
610 {
611  // Preconditions:
612 
613  require(unexecutable("Each xbi is a vector of length at least 3."));
614 
615  // Body:
616 
617  // Copy the row dofs into xmatrix.
618 
619  xmatrix = _row_dofs;
620 
621  // Postconditions:
622 
623  ensure(invariant());
624  ensure_for_all(i, 0, d(), xmatrix.components[i] == component(i));
625 
626  // Exit:
627 
628  return;
629 }
630 
631 void
634 {
635  // Preconditions:
636 
637  // Body:
638 
639  // Make the component part equal to the inverse of the basis part.
640 
641  xmatrix.component_matrix() = xmatrix.basis_matrix().inverse();
642 
643  // Copy the xmatrix into the row_dofs.
644 
645  _row_dofs = xmatrix;
646 
647  // Postconditions:
648 
649  ensure(invariant());
650  ensure_for_all(i, 0, d(), component(i) == xmatrix.components[i]);
651  ensure(unexecutable("The component matrix is the inverse of the basis matrix"));
652 
653  // Exit:
654 
655  return;
656 }
657 
658 // PROTECTED MEMBER FUNCTIONS
659 
660 // PRIVATE MEMBER FUNCTIONS
661 
662 
663 //==============================================================================
664 // GLN FACET OF CLASS GL3_LITE
665 //==============================================================================
666 
667 // PUBLIC MEMBER FUNCTIONS
668 
669 int
671 n() const
672 {
673  // Preconditions:
674 
675  // Body:
676 
677  int result = 3;
678 
679  // Postconditions:
680 
681  ensure(invariant());
682  ensure(result == 3);
683 
684  // Exit:
685 
686  return result;
687 }
688 
689 // PROTECTED MEMBER FUNCTIONS
690 
691 // PRIVATE MEMBER FUNCTIONS
692 
693 
694 //==============================================================================
695 // GROUP FACET OF CLASS GL3_LITE
696 //==============================================================================
697 
698 // PUBLIC MEMBER FUNCTIONS
699 
700 // PROTECTED MEMBER FUNCTIONS
701 
702 // PRIVATE MEMBER FUNCTIONS
703 
704 
705 //==============================================================================
706 // ABSTRACT POSET MEMBER FACET OF CLASS GL3_LITE
707 //==============================================================================
708 
709 // PUBLIC MEMBER FUNCTIONS
710 
711 const std::string&
713 class_name() const
714 {
715  // Preconditions:
716 
717  // Body:
718 
719  const string& result = static_class_name();
720 
721  // Postconditions:
722 
723  ensure(!result.empty());
724 
725  // Exit:
726 
727  return result;
728 }
729 
730 const std::string&
733 {
734  // Preconditions:
735 
736  // Body:
737 
738  static const string result("gl3_lite");
739 
740  // Postconditions:
741 
742  ensure(!result.empty());
743 
744  // Exit:
745 
746  return result;
747 }
748 
751 clone() const
752 {
753  gl3_lite* result = 0;
754 
755  // Preconditions:
756 
757  // Body:
758 
759  result = new gl3_lite();
760 
761  // Postconditions:
762 
763  ensure(result != 0);
764  ensure(is_same_type(*result));
765 
766  // Exit:
767 
768  return result;
769 }
770 
771 // PROTECTED MEMBER FUNCTIONS
772 
773 // PRIVATE MEMBER FUNCTIONS
774 
775 
776 //==============================================================================
777 // ANY FACET OF CLASS GL3_LITE
778 //==============================================================================
779 
780 // PUBLIC MEMBER FUNCTIONS
781 
782 bool
784 is_ancestor_of(const any_lite& xother) const
785 {
786  // Preconditions:
787 
788  require(&xother != 0);
789 
790  // Body:
791 
792  // True if other conforms to this.
793 
794  bool result = dynamic_cast<const gl3_lite*>(&xother) != 0;
795 
796  // Postconditions:
797 
798  return result;
799 }
800 
801 
802 bool
804 invariant() const
805 {
806  bool result = true;
807 
808  if(invariant_check())
809  {
810  // Prevent recursive calls to invariant.
811 
812  disable_invariant_check();
813 
814  // Must satisfy base class invariant.
815 
816  invariance(gln_lite::invariant());
817 
818  // Invariances for this class:
819 
820  // Finished, turn invariant checking back on.
821 
822  enable_invariant_check();
823  }
824 
825  // Exit
826 
827  return result;
828 }
829 
830 void*
833 {
834  return &_row_dofs;
835 }
836 
837 const void*
839 row_dofs() const
840 {
841  return &_row_dofs;
842 }
843 
844 // PROTECTED MEMBER FUNCTIONS
845 
846 // PRIVATE MEMBER FUNCTIONS
847 
848 
849 //==============================================================================
850 // CLASS GL3
851 //==============================================================================
852 
853 // ===========================================================
854 // HOST FACTORY FACET
855 // ===========================================================
856 
857 // PUBLIC MEMBER FUNCTIONS
858 
859 const sheaf::poset_path&
862 {
863  // Preconditions:
864 
865 
866  // Body:
867 
868  static const poset_path result(standard_schema_poset_name(), "gl3_schema");
869 
870  // Postconditions:
871 
872  // Exit:
873 
874  return result;
875 }
876 
877 void
880 {
881  // Preconditions:
882 
883  require(xns.state_is_read_write_accessible());
884  require(xns.contains_poset(standard_schema_poset_name()));
885  require(!xns.contains_poset_member(standard_schema_path()));
886 
887  // Body:
888 
889  string lmember_names = "bxx DOUBLE false bxy DOUBLE false bxz DOUBLE false ";
890  lmember_names += "byx DOUBLE false byy DOUBLE false byz DOUBLE false ";
891  lmember_names += "bzx DOUBLE false bzy DOUBLE false bzz DOUBLE false ";
892 
893  lmember_names += "cxx DOUBLE false cxy DOUBLE false cxz DOUBLE false ";
894  lmember_names += "cyx DOUBLE false cyy DOUBLE false cyz DOUBLE false ";
895  lmember_names += "czx DOUBLE false czy DOUBLE false czz DOUBLE false";
896 
897  schema_poset_member lschema(xns,
898  standard_schema_path().member_name(),
899  gln::standard_schema_path(),
900  lmember_names,
901  false);
902 
903  lschema.detach_from_state();
904 
905  // Postconditions:
906 
907  ensure(xns.contains_poset_member(standard_schema_path()));
908 
909  // Exit:
910 
911  return;
912 }
913 
917  const poset_path& xhost_path,
918  const poset_path& xschema_path,
919  const poset_path& xvector_space_path,
920  bool xauto_access)
921 {
922  // cout << endl << "Entering gl3::new_host." << endl;
923 
924  // Preconditions:
925 
926  require(xns.state_is_auto_read_write_accessible(xauto_access));
927 
928  require(!xhost_path.empty());
929  require(!xns.contains_path(xhost_path, xauto_access));
930 
931  require(xschema_path.full());
932  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
933  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
934 
935  require(xns.path_is_auto_read_accessible(xvector_space_path, xauto_access));
936  require(xns.contains_poset<vector_space_type::host_type>(xvector_space_path, xauto_access));
937 
938  require(schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access) == 18);
939 
940  // Body:
941 
942  host_type& result =
943  host_type::new_table(xns, xhost_path, xschema_path, xvector_space_path, xauto_access);
944 
945  // Postconditions:
946 
947  ensure(xns.owns(result, xauto_access));
948  ensure(result.path(true) == xhost_path);
949  ensure(result.state_is_not_read_accessible());
950  ensure(result.schema(true).path(xauto_access) == xschema_path);
951 
952  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access) );
953  ensure(result.n(true) == 3);
954  ensure(result.vector_space_path(true) == xvector_space_path );
955 
956  ensure(result.d(true) == 18);
957 
958  // Exit:
959 
960  // cout << "Leaving gl3::new_host." << endl;
961  return result;
962 }
963 
966 standard_host(namespace_type& xns, const std::string& xsuffix, bool xauto_access)
967 {
968  // cout << endl << "Entering gl3::new_host." << endl;
969 
970  // Preconditions:
971 
972  require(xns.state_is_auto_read_write_accessible(xauto_access));
973 
974  require(xsuffix.empty() || poset_path::is_valid_name(xsuffix));
975  require(standard_host_is_available<gl3>(xns, xsuffix, xauto_access));
976 
977  require(xns.path_is_auto_read_accessible(standard_schema_path(), xauto_access));
978 
979  require(xns.path_is_auto_read_available(vector_space_type::standard_host_path<vector_space_type>(xsuffix), xauto_access));
980 
981  // Body:
982 
983  // Create the vector space if necessary.
984 
985  poset_path lvector_space_path = vector_space_type::standard_host(xns, xsuffix, xauto_access).path(true);
986 
987  poset_path lpath(standard_host_path<gl3>(xsuffix));
988 
989  host_type* result_ptr;
990  if(xns.contains_path(lpath, xauto_access))
991  {
992  result_ptr = &xns.member_poset<host_type>(lpath, xauto_access);
993  }
994  else
995  {
996  result_ptr = &new_host(xns, lpath, standard_schema_path(), lvector_space_path, xauto_access);
997  }
998 
999  host_type& result = *result_ptr;
1000 
1001  // Postconditions:
1002 
1003  ensure(xns.owns(result, xauto_access));
1004  ensure(result.path(true) == standard_host_path<gl3>(xsuffix));
1005  ensure(result.state_is_not_read_accessible());
1006  ensure(result.schema(true).path(xauto_access) == standard_schema_path());
1007 
1008  ensure(result.scalar_space_path(true) == vector_space_type::scalar_type::standard_host_path<vector_space_type::scalar_type>(xsuffix));
1009  ensure(result.n(true) == 3);
1010  ensure(result.vector_space_path(true) == vector_space_type::standard_host_path<vector_space_type>(xsuffix));
1011 
1012  ensure(result.d(true) == 18);
1013 
1014  // Exit:
1015 
1016  // cout << "Leaving gl3::new_host." << endl;
1017  return result;
1018 }
1019 
1020 // PROTECTED MEMBER FUNCTIONS
1021 
1022 // PRIVATE MEMBER FUNCTIONS
1023 
1024 
1025 //==============================================================================
1026 // GL3 FACET OF CLASS GL3
1027 //==============================================================================
1028 
1029 // PUBLIC MEMBER FUNCTIONS
1030 
1033 {
1034 
1035  // Preconditions:
1036 
1037  // Body:
1038 
1039  // Postconditions:
1040 
1041  ensure(invariant());
1042 
1043  // Exit:
1044 }
1045 
1047 gl3(const gl3& xother, bool xnew_jem)
1048 {
1049 
1050  // Preconditions:
1051 
1052  require(xnew_jem ? xother.is_attached() : true);
1053 
1054  // Body:
1055 
1056  // Note: even though the code here is identical to that in
1057  // the copy constructors of all descendants of abstract_poset_member,
1058  // this can not just call its base class copy constructor
1059  // because it must invoke versions defined in this class of virtual
1060  // attach_to_state and virtual attach_handle_data_members
1061  // (called from new_jem_state).
1062 
1063  if(xnew_jem)
1064  {
1065  new_jem_state(const_cast<gl3*>(&xother), true, true);
1066  }
1067  else
1068  {
1069  attach_to_state(&xother);
1070  }
1071 
1072  // Postconditions:
1073 
1074  ensure(invariant());
1075  ensure(is_attached() == xother.is_attached() );
1076 }
1077 
1082 {
1083  // Preconditions:
1084 
1085  require(is_ancestor_of(&xother));
1086  require(precondition_of(attach_to_state(&xother)));
1087 
1088  // Body:
1089 
1090  attach_to_state(&xother);
1091 
1092  // Postconditions:
1093 
1094  ensure(postcondition_of(attach_to_state(&xother)));
1095 
1096  // Exit:
1097 
1098  return *this;
1099 }
1100 
1104 operator=(const gl3& xother)
1105 {
1106  // Preconditions:
1107 
1108  require(precondition_of(attach_to_state(&xother)));
1109 
1110  // Body:
1111 
1112  attach_to_state(&xother);
1113 
1114  // Postconditions:
1115 
1116  ensure(postcondition_of(attach_to_state(&xother)));
1117 
1118  // Exit:
1119 
1120  return *this;
1121 }
1122 
1125 {
1126 
1127  // Preconditions:
1128 
1129  // Body:
1130 
1131  // Postconditions:
1132 
1133  // Exit:
1134 
1135  return;
1136 }
1137 
1139 gl3(poset* xhost, bool xauto_access)
1140 {
1141 
1142  // Preconditions:
1143 
1144  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
1145 
1146  // Body:
1147 
1148  new_jim_state(xhost, 0, false, xauto_access);
1149 
1150  // Postconditions:
1151 
1152  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
1153 
1154  // Exit:
1155 
1156  return;
1157 }
1158 
1161  const row_dofs_type& xrdt,
1162  bool xauto_access)
1163 {
1164 
1165  // Preconditions:
1166 
1167  require(precondition_of(new_jim_state(&xhost, 0, false, xauto_access)));
1168 
1169  // Body:
1170 
1171  new_jim_state(&xhost, 0, false, xauto_access);
1172 
1173  if(xauto_access)
1174  {
1175  xhost.get_read_write_access();
1176  }
1177 
1178  *this = xrdt;
1179 
1180  if(xauto_access)
1181  {
1182  xhost.release_access();
1183  }
1184 
1185  // Postconditions:
1186 
1187  ensure(postcondition_of(new_jim_state(&xhost, 0, false, xauto_access)));
1188 
1189  // Exit:
1190 
1191  return;
1192 }
1193 
1197 {
1198  // Preconditions:
1199 
1200  require(state_is_read_write_accessible());
1201 
1202  // Body:
1203 
1204  int ld = d();
1205 
1206  for(int i=0; i<ld; ++i)
1207  {
1208  put_component(i, xrdt.components[i]);
1209  }
1210 
1211  // Postconditions:
1212 
1213  ensure_for_all(i, 0, d(), component(i) == xrdt.components[i]);
1214 
1215  // Exit:
1216 
1217  return *this;
1218 
1219 }
1220 
1222 gl3(const poset* xhost, pod_index_type xhub_id)
1223 {
1224  // Preconditions:
1225 
1226  require(xhost != 0);
1227  require(xhost->state_is_read_accessible());
1228  require(xhost->contains_member(xhub_id));
1229 
1230  // Body:
1231 
1232  attach_to_state(xhost, xhub_id);
1233 
1234  // Postconditions:
1235 
1236  ensure(invariant());
1237  ensure(is_attached());
1238  // ensure(host() == xhost);
1239  ensure(index() == xhub_id);
1240 }
1241 
1243 gl3(const poset* xhost, const scoped_index& xid)
1244 {
1245  // Preconditions:
1246 
1247  require(xhost != 0);
1248  require(xhost->state_is_read_accessible());
1249  require(xhost->contains_member(xid));
1250 
1251  // Body:
1252 
1253  attach_to_state(xhost, xid.hub_pod());
1254 
1255  // Postconditions:
1256 
1257  ensure(invariant());
1258  ensure(is_attached());
1259  // ensure(host() == xhost);
1260  ensure(index() ==~ xid);
1261 }
1262 
1264 gl3(const poset* xhost, const std::string& xname)
1265 {
1266 
1267  // Preconditions:
1268 
1269  require(xhost != 0);
1270  require(xhost->state_is_read_accessible());
1271  require(!xname.empty());
1272  require(xhost->contains_member(xname));
1273 
1274  // Body:
1275 
1276  attach_to_state(xhost, xname);
1277 
1278  // Postconditions:
1279 
1280  ensure(invariant());
1281  ensure(is_attached());
1282  // ensure(host() == xhost);
1283  ensure(name() == xname);
1284 
1285 }
1286 
1288 gl3(gl3* xother)
1289 {
1290 
1291  // Preconditions:
1292 
1293  require(xother != 0);
1294 
1295  // Body:
1296 
1297  attach_to_state(xother);
1298 
1299  // Postconditions:
1300 
1301  ensure(invariant());
1302  ensure(is_attached());
1303  ensure(is_same_state(xother));
1304 
1305 }
1306 
1307 fiber_bundle::gl3::
1309 {
1310  // Preconditions:
1311 
1312  // Body:
1313 
1314  row_dofs_type& result = sheaf::row_dofs(*this);
1315 
1316  // Postconditions:
1317 
1318  // Exit:
1319 
1320  return result;
1321 }
1322 
1323 fiber_bundle::gl3::
1324 operator const gl3::row_dofs_type& () const
1325 {
1326  // Preconditions:
1327 
1328  // Body:
1329 
1330  const row_dofs_type& result = sheaf::row_dofs(*this);
1331 
1332  // Postconditions:
1333 
1334  // Exit:
1335 
1336  return result;
1337 }
1338 
1339 void
1341 get_matrix(row_dofs_type& xmatrix) const
1342 {
1343  // Preconditions:
1344 
1345  require(state_is_read_accessible());
1346 
1347  // Body:
1348 
1349  xmatrix = *this;
1350 
1351  // Postconditions:
1352 
1353  ensure(invariant());
1354 
1355  // Exit:
1356 
1357  return;
1358 }
1359 
1360 void
1363 {
1364  // Preconditions:
1365 
1366  require(state_is_read_write_accessible());
1367  require(xmatrix.basis_matrix().determinant() != 0);
1368 
1369  // Body:
1370 
1371  // Make the component part equal to the inverse of the basis part.
1372 
1373  xmatrix.component_matrix() = xmatrix.basis_matrix().inverse();
1374 
1375  // Copy the xmatrix into the row_dofs.
1376 
1377  put_components(xmatrix.components, xmatrix.d());
1378 
1379  // Postconditions:
1380 
1381  ensure(invariant());
1382  ensure_for_all(i, 0, d(), component(i) == xmatrix.components[i]);
1383 
1384  // Exit:
1385 
1386  return;
1387 }
1388 
1392 lite_type() const
1393 {
1394  // Preconditions:
1395 
1396  // Body:
1397 
1398  volatile_type* result = new volatile_type(sheaf::row_dofs(*this));
1399 
1400  // Postconditions:
1401 
1402  // Exit:
1403 
1404  return result;
1405 }
1406 
1407 // PROTECTED MEMBER FUNCTIONS
1408 
1409 // PRIVATE MEMBER FUNCTIONS
1410 
1411 
1412 //==============================================================================
1413 // GLN FACET OF CLASS GL3
1414 //==============================================================================
1415 
1416 // PUBLIC MEMBER FUNCTIONS
1417 
1418 // PROTECTED MEMBER FUNCTIONS
1419 
1420 // PRIVATE MEMBER FUNCTIONS
1421 
1422 
1423 //==============================================================================
1424 // GROUP FACET
1425 //==============================================================================
1426 
1427 // PUBLIC MEMBER FUNCTIONS
1428 
1429 // PROTECTED MEMBER FUNCTIONS
1430 
1431 // PRIVATE MEMBER FUNCTIONS
1432 
1433 
1434 //==============================================================================
1435 // ABSTRACT POSET MEMBER FACET OF CLASS GL3
1436 //==============================================================================
1437 
1438 // PUBLIC MEMBER FUNCTIONS
1439 
1440 const std::string&
1442 class_name() const
1443 {
1444  // Preconditions:
1445 
1446  // Body:
1447 
1448  const string& result = static_class_name();
1449 
1450  // Postconditions:
1451 
1452  ensure(!result.empty());
1453 
1454  // Exit:
1455 
1456  return result;
1457 }
1458 
1459 const std::string&
1462 {
1463  // Preconditions:
1464 
1465  // Body:
1466 
1467  static const string result("gl3");
1468 
1469  // Postconditions:
1470 
1471  ensure(!result.empty());
1472 
1473  // Exit:
1474 
1475  return result;
1476 }
1477 
1480 clone() const
1481 {
1482 
1483  // Preconditions:
1484 
1485  // Body:
1486 
1487  // Create new handle of the current class.
1488 
1489  gl3* result = new gl3();
1490 
1491  // Postconditions:
1492 
1493  ensure(result != 0);
1494  ensure(result->invariant());
1495 
1496  // Exit:
1497 
1498  return result;
1499 
1500 }
1501 
1502 // PROTECTED MEMBER FUNCTIONS
1503 
1504 // PRIVATE MEMBER FUNCTIONS
1505 
1506 
1507 //==============================================================================
1508 // ANY FACET OF CLASS GL3
1509 //==============================================================================
1510 
1511 // PUBLIC MEMBER FUNCTIONS
1512 
1513 bool
1515 invariant() const
1516 {
1517  bool result = true;
1518 
1519  // Preconditions:
1520 
1521  // Body:
1522 
1523  // Must satisfy base class invariant.
1524 
1525  invariance(gln::invariant());
1526 
1527  if (invariant_check())
1528  {
1529  // Prevent recursive calls to invariant.
1530 
1531  disable_invariant_check();
1532 
1533  invariance(state_is_read_accessible() ? n() == 3 : true);
1534 
1535  // Finished, turn invariant checking back on.
1536 
1537  enable_invariant_check();
1538  }
1539 
1540  // Postconditions:
1541 
1542  ensure(is_derived_query);
1543 
1544  // Exit:
1545 
1546  return result;
1547 }
1548 
1549 bool
1551 is_ancestor_of(const any* xother) const
1552 {
1553 
1554  // Preconditions:
1555 
1556  require(xother != 0);
1557 
1558  // Body:
1559 
1560  // True if other conforms to this.
1561 
1562  bool result = dynamic_cast<const gl3*>(xother) != 0;
1563 
1564  // Postconditions:
1565 
1566  // ensure(invariant());
1567 
1568  // Exit:
1569 
1570  return result;
1571 
1572 }
1573 
1574 // PROTECTED MEMBER FUNCTIONS
1575 
1576 // PRIVATE MEMBER FUNCTIONS
1577 
1578 
1579 //==============================================================================
1580 // NON-MEMBER FUNCTIONS
1581 //==============================================================================
1582 
1583 std::ostream&
1585 operator<<(std::ostream& xos, const gl3_lite& xlite)
1586 {
1587  xos << "basis:" << endl;
1588  xos << " " << xlite[0] << " " << xlite[1] << " " << xlite[2] << endl;
1589  xos << " " << xlite[3] << " " << xlite[4] << " " << xlite[5] << endl;
1590  xos << " " << xlite[6] << " " << xlite[7] << " " << xlite[8] << endl;
1591 
1592  xos << endl;
1593 
1594  xos << "component:" << endl;
1595  xos << " " << xlite[ 9] << " " << xlite[10] << " " << xlite[11] << endl;
1596  xos << " " << xlite[12] << " " << xlite[13] << " " << xlite[14] << endl;
1597  xos << " " << xlite[15] << " " << xlite[16] << " " << xlite[17] << endl;
1598 
1599  return xos;
1600 }
1601 
1602 std::ostream&
1604 operator<< (std::ostream& xos, const gl3& xpersistent)
1605 {
1606  const gl3::row_dofs_type& lm = xpersistent;
1607 
1608  xos << "basis:" << endl;
1609  xos << " " << lm[0] << " " << lm[1] << " " << lm[2] << endl;
1610  xos << " " << lm[3] << " " << lm[4] << " " << lm[5] << endl;
1611  xos << " " << lm[6] << " " << lm[7] << " " << lm[8] << endl;
1612 
1613  xos << endl;
1614 
1615  xos << "component:" << endl;
1616  xos << " " << lm[ 9] << " " << lm[10] << " " << lm[11] << endl;
1617  xos << " " << lm[12] << " " << lm[13] << " " << lm[14] << endl;
1618  xos << " " << lm[15] << " " << lm[16] << " " << lm[17] << endl;
1619 
1620  return xos;
1621 }
1622 
1623 void
1625 inverse(const gl3_lite& xlite, gl3_lite& xresult)
1626 {
1627  // Preconditions:
1628 
1629  // Body:
1630 
1635 
1637 
1638  const gl3_lite::matrix_type& bm = xlite.basis_matrix();
1639  bm.inverse(xresult.basis_matrix());
1640 
1641  const gl3_lite::matrix_type& cm = xlite.component_matrix();
1642  cm.inverse(xresult.component_matrix());
1643 
1644  // Postconditions:
1645 
1646  ensure(unexecutable("xresult is the inverse of xgl"));
1647 
1648 
1649  // Exit:
1650 }
1651 
1652 void
1654 inverse(const gl3& xgl, gl3& xresult)
1655 {
1657 
1658  // Preconditions:
1659 
1660  require(xgl.state_is_read_accessible());
1661  require(xresult.state_is_read_accessible());
1662 
1663  // Body:
1664 
1669 
1671 
1672  typedef gl3::row_dofs_type row_dofs_type;
1673 
1674  const row_dofs_type& lrdt_gl = xgl;
1675  row_dofs_type& lrdt_result = xresult;
1676 
1677  lrdt_gl.basis_matrix().inverse(lrdt_result.basis_matrix());
1678  lrdt_gl.component_matrix().inverse(lrdt_result.component_matrix());
1679 
1680  // Postconditions:
1681 
1682  ensure(unexecutable("xresult is the inverse of xgl"));
1683 
1684  // Exit:
1685 }
1686 
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 basis(value_type xb0[], value_type xb1[], value_type xb2[]) const
The components of the new basis vectors w.r.t. the old basis, pre-allocated version.
Definition: gl3.cc:530
virtual int n() const
Dimension of the representation space; n in GL(n, R).
Definition: gl3.cc:671
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 ...
matrix_type & basis_matrix()
The associated basis transformation matrix (non const version).
Definition: gl3.cc:254
void determinant(T &xresult) const
The determinant of the matrix (pre-allocated).
void inverse(general_matrix_3x3< T > &xresult) const
The inverse of the matrix (pre-allocated).
virtual gl3 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: gl3.cc:1081
void rotate_x(const value_type &xangle)
Set this transform to a rotation about the x-axis by angle xangle, in radians.
Definition: gl3.cc:365
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual ~gl3()
Destructor.
Definition: gl3.cc:1124
gl3_lite & operator=(const gl3_lite &xother)
Assignment operator.
Definition: gl3.cc:82
virtual gl3 * clone() const
Make a new handle, no state instance of current.
Definition: gl3.cc:1480
row_dofs_type _row_dofs
Row_dofs_type.
Definition: gl3.h:381
poset_path path(bool xauto_access=true) const
A path to this component.
virtual const std::string & class_name() const
The name of this class.
Definition: gl3.cc:1442
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
bool path_is_auto_read_accessible(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath exists and is auto read accessible.
The standard fiber bundles name space; extends the standard sheaves namespace by defining base space...
void get_matrix(row_dofs_type &xmatrix) const
Copies the row dofs of this into xmatrix.
Definition: gl3.cc:609
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...
A client handle for a general, abstract partially order set.
poset_path vector_space_path() const
The path of the underlying vector space.
Definition: gln_space.cc:306
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
STL namespace.
void put_basis(const value_type xb0[], const value_type xb1[], const value_type xb2[])
Set this transformation to transform to the basis specified by component vectors xb0, xb1, xb2, where xbi gives the components of new basis vector i w.r.t. the old basis.
Definition: gl3.cc:567
static const std::string & static_class_name()
The name of this class.
Definition: gl3.cc:1461
void rotate_y(const value_type &xangle)
Set this transform to a rotation about the y-axis by angle xangle, in radians. See note under rotate_...
Definition: gl3.cc:403
static int d()
The dimension of the row dof components.
Definition: gl3.impl.h:62
static host_type & standard_host(namespace_type &xns, const std::string &xsuffix, bool xauto_access)
The host with path standard_host_path<gl3>(xsuffix). Returns the host if it already exists...
Definition: gl3.cc:966
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.
matrix_type & component_matrix()
The associated component transformation matrix (non const version).
Definition: gl3.cc:288
T::row_dofs_type & row_dofs(T &x0)
The row dofs pod type for x0 (mutable version).
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: gl3.cc:879
void rescale(const value_type &xscale, const value_type &yscale, const value_type &zscale)
Set this transform to rescale the x, y, and z axes by xscale, yscale, and zscale, respectively...
Definition: gl3.cc:320
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
virtual bool invariant() const
Class invariant.
Definition: gl3.cc:1515
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: gl3.cc:916
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
void put_matrix(row_dofs_type &xmatrix)
Updates the component matrix part of xmatrix to be the inverse of the basis part and then copies xmat...
Definition: gl3.cc:633
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 volatile_type * lite_type() const
Virtual conversion to the associated volatile type.
Definition: gl3.cc:1392
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 void detach_from_state()
Detach this handle from its state, if any.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool is_attached() const
True if this handle is attached to a non-void state.
gl3()
Default constructor.
Definition: gl3.cc:1032
void rotate_z(const value_type &xangle)
Set this transform to a rotation about the z-axis by angle xangle, in radians. See note under rotate_...
Definition: gl3.cc:441
bool contains_path(const poset_path &xpath, bool xauto_access=true) const
True if this contains the poset or poset member specified by xpath.
vd_value_type value_type
The type of component in the fiber; the scalar type in the fiber vector space.
Definition: gln.h:121
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. ...
void put_matrix(row_dofs_type &xmatrix)
Updates the component matrix part of xmatrix to be the inverse of the basis part and then copies xmat...
Definition: gl3.cc:1362
gl3_row_dofs_type< double >::matrix_type matrix_type
The type of the associated matrix.
Definition: gl3.h:202
void rotate_euler(const value_type &xalpha, const value_type &xbeta, const value_type &xgamma)
Set this transform to a rotation through the Euler angles alpha, beta, and gamma. It is equivalent to...
Definition: gl3.cc:479
bool empty() const
True if both poset name and member name are empty.
Definition: poset_path.cc:291
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...
The mathematical group GL(3, R). The group of all invertible, linear transformations on the R3...
Definition: gl3.h:183
bool contains_poset(pod_index_type xhub_id, bool xauto_access=true) const
True if this contains a poset with hub id xhub_id..
bool path_is_auto_read_available(const poset_path &xpath, bool xauto_access) const
True if the state referred to xpath does not exist or exists and is auto read accessible.
A Cartesian product space.
Definition: gln_space.h:52
virtual bool is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: gl3.cc:784
virtual gl3_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: gl3.cc:751
SHEAF_DLL_SPEC void cos(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute cos of x0 (cos(x0)) (pre-allocated version).
Definition: sec_at0.cc:1270
An abstract vector space viewed as an antisymmetric tensor space of degree 1.
Definition: at1_space.h:42
matrix_type & basis_matrix()
The associated basis transformation matrix (non const version).
Definition: gl3.impl.h:160
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: gl3.cc:861
matrix_type & component_matrix()
The associated component transformation matrix (non const version).
Definition: gl3.impl.h:198
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Definition: gl3.cc:1551
virtual ~gl3_lite()
Destructor.
Definition: gl3.cc:103
virtual void * row_dofs()
The row dofs for this instance (mutable version).
Definition: gl3.cc:832
An abstract client handle for a member of a poset.
void get_matrix(row_dofs_type &xmatrix) const
Copies row dof tuple into xmatrix.
Definition: gl3.cc:1341
std::string path() const
The full path as a string.
Definition: poset_path.cc:450
static int d(const namespace_poset &xns, const poset_path &xvector_space_path, bool xauto_access)
The dimension of the representation space; n in GL(n, R) implied by the vector space specified by xve...
Definition: gln_space.cc:84
bool invariant() const
Class invariant.
Definition: gl3.cc:804
static const std::string & static_class_name()
The name of this class.
Definition: gl3.cc:732
Namespace for the fiber_bundles component of the sheaf system.
virtual const std::string & class_name() const
The name of this class.
Definition: gl3.cc:713
SHEAF_DLL_SPEC void inverse(const gl2_lite &xlite, gl2_lite &xresult)
Inverse (pre-allocated version for volatile type).
Definition: gl2.cc:1484
SHEAF_DLL_SPEC void sin(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute sin of x0 (sin(x0)) (pre-allocated version).
Definition: sec_at0.cc:1516
int n() const
Dimension of the representation space; n in GL(n, R).
Definition: gln_space.cc:202
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.
The mathematical group GL(3, R). The group of all invertible, linear transformations on the R3...
Definition: gl3.h:503
gl3_lite()
Default constructor.
Definition: gl3.cc:50
T components[18]
The dofs in the following order:
Definition: gl3.h:164
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const binary_index &xbi)
Insert binary_index& xbi into ostream& os.
Definition: binary_index.cc:35
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
poset_path scalar_space_path() const
The path of the underlying scalar space.
Definition: gln_space.cc:254