SheafSystem  0.0.0.0
gl2.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/gl2.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/e2.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 GL2_LITE
40 //==============================================================================
41 
42 
43 //==============================================================================
44 // GL2 FACET OF CLASS GL2_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 gl2_lite(const gl2_lite& xother)
66 {
67  // Preconditions:
68 
69  require(unexecutable("The component matrix is the inverse of the basis matrix."));
70 
71  // Body:
72 
73  *this = xother;
74 
75  // Postconditions:
76 
77  ensure(invariant());
78 
79  // Exit:
80 }
81 
84 operator=(const gl2_lite& xother)
85 {
86  // Preconditions:
87 
88  require(unexecutable("The component matrix is the inverse of the basis matrix."));
89 
90  // Body:
91 
92  if(this == &xother)
93  return *this;
94 
95  _row_dofs = xother._row_dofs;
96 
97  // Postconditions:
98 
99  ensure(invariant());
100 
101  // Exit:
102 
103  return *this;
104 }
105 
108 {
109  // Preconditions:
110 
111  // Body:
112 
113  // Postconditions:
114 
115  // Exit:
116 
117 }
118 
120 gl2_lite(const row_dofs_type& xrow_dofs)
121 {
122  // Preconditions:
123 
124  require(unexecutable("The component matrix is the inverse of the basis matrix."));
125 
126  // Body:
127 
128  *this = xrow_dofs;
129 
130  // Postconditions:
131 
132  ensure(invariant());
133 
134  // Exit:
135 }
136 
139 operator=(const row_dofs_type& xrow_dofs)
140 {
141  // Preconditions:
142 
143  require(unexecutable("The component matrix is the inverse of the basis matrix."));
144 
145  // Body:
146 
147  _row_dofs = xrow_dofs;
148 
149  // Postconditions:
150 
151  ensure(invariant());
152 
153  // Exit:
154 
155  return *this;
156 
157 }
159 gl2_lite(const matrix_type& xmatrix)
160 {
161  // Preconditions:
162 
163  require(unexecutable("The component matrix is the inverse of the basis matrix."));
164 
165  // Body:
166 
167  *this = xmatrix;
168 
169  // Postconditions:
170 
171  ensure(invariant());
172 
173  // Exit:
174 }
175 
178 operator=(const matrix_type& xmatrix)
179 {
180  // Preconditions:
181 
182  require(unexecutable("The component matrix is the inverse of the basis matrix."));
183 
184  // Body:
185 
186  //_row_dofs = xmatrix;
187  _row_dofs = reinterpret_cast<const row_dofs_type&>(xmatrix);
188 
189  // Postconditions:
190 
191  ensure(invariant());
192 
193  // Exit:
194 
195  return *this;
196 
197 }
198 
199 fiber_bundle::gl2_lite::
201 {
202  // Preconditions:
203 
204  // Body:
205 
206  matrix_type& result = _row_dofs;
207 
208  // Postconditions:
209 
210  // Exit:
211 
212  return result;
213 }
214 
215 fiber_bundle::gl2_lite::
216 operator const gl2_lite::matrix_type& () const
217 {
218  // Preconditions:
219 
220  // Body:
221 
222  const matrix_type& result = _row_dofs;
223 
224  // Postconditions:
225 
226  // Exit:
227 
228  return result;
229 }
230 
231 fiber_bundle::gl2_lite::
233 {
234  // Preconditions:
235 
236  // Body:
237 
238  row_dofs_type& result = _row_dofs;
239 
240  // Postconditions:
241 
242  // Exit:
243 
244  return result;
245 }
246 
247 fiber_bundle::gl2_lite::
248 operator const gl2_lite::row_dofs_type& () const
249 {
250  // Preconditions:
251 
252  // Body:
253 
254  const row_dofs_type& result = _row_dofs;
255 
256  // Postconditions:
257 
258  // Exit:
259 
260  return result;
261 }
262 
266 {
267  // Preconditions:
268 
269  // Body:
270 
271  matrix_type& result = _row_dofs.basis_matrix();
272 
273  // Postconditions:
274 
275  // Exit:
276 
277  return result;
278 }
279 
283 {
284  // Preconditions:
285 
286  // Body:
287 
288  // Postconditions:
289 
290  const matrix_type& result = _row_dofs.basis_matrix();
291 
292  // Exit:
293 
294  return result;
295 }
296 
300 {
301  // Preconditions:
302 
303  // Body:
304 
305  matrix_type& result = _row_dofs.component_matrix();
306 
307  // Exit:
308 
309  return result;
310 }
311 
315 {
316  // Preconditions:
317 
318  // Body:
319 
320  const matrix_type& result = _row_dofs.component_matrix();
321 
322  // Postconditions:
323 
324  // Exit:
325 
326  return result;
327 }
328 
329 void
331 rescale(const value_type& xscale, const value_type& yscale)
332 {
333  // Preconditions:
334 
335  // Body:
336 
337  // Get the basis matrix.
338 
339  matrix_type& bm = basis_matrix();
340 
341  // Set the basis matrix for rescaling.
342 
343  bm[0][0] = xscale;
344  bm[0][1] = 0.0;
345  bm[1][0] = 0.0;
346  bm[1][1] = yscale;
347 
348  // Get the component matrix.
349 
350  matrix_type& cm = component_matrix();
351 
352  // Set the component matrix for rescaling.
353 
354  // The component matrix is the inverse of the basis matrix
355  // and the inverse is very simple in this case.
356 
357  cm[0][0] = 1.0/xscale;
358  cm[0][1] = 0.0;
359  cm[1][0] = 0.0;
360  cm[1][1] = 1.0/yscale;
361 
362  // Postconditions:
363 
364  // Exit:
365 }
366 
367 void
369 rotate_z(const value_type& xangle)
370 {
371  // Preconditions:
372 
373  // Body:
374 
375  // Set the basis matrix for rotation about the z-axis.
376 
377  matrix_type& bm = basis_matrix();
378 
379  value_type lcos = cos(xangle);
380  value_type lsin = sin(xangle);
381 
382  bm[0][0] = lcos;
383  bm[0][1] = lsin;
384  bm[1][0] = -lsin;
385  bm[1][1] = lcos;
386 
387  // Set component matrix to the inverse of the basis matrix.
388 
389  matrix_type& cm = component_matrix();
390 
391  cm[0][0] = lcos;
392  cm[0][1] = -lsin;
393  cm[1][0] = lsin;
394  cm[1][1] = lcos;
395 
396  // Postconditions:
397 
398  // Exit:
399 }
400 
401 void
404  value_type xb1[]) const
405 {
406  // Preconditions:
407 
408  require(unexecutable("Each xbi is a vector of length at least 2."));
409 
410  // Body:
411 
412  // The new basis vectors are the columns of the b matrix
413  // See comments in header file on matrix definition.
414 
415  xb0[0] = component(0); // bxx
416  xb1[0] = component(1); // bxy
417 
418  xb0[1] = component(2); // byx
419  xb1[1] = component(3); // byy
420 
421  // Postconditions:
422 
423  ensure(invariant());
424  ensure(unexecutable("Return values are set to the correct components"));
425 
426 
427  // Exit:
428 
429  return;
430 }
431 
432 void
434 put_basis(const value_type xb0[],
435  const value_type xb1[])
436 {
437  // Preconditions:
438 
439  require(unexecutable("Each xbi is a vector of length at least 2."));
440 
441  // Body:
442 
443  // The new basis vectors are the columns of the b matrix.
444  // See comments in header file on matrix definition.
445 
446  put_component(0, xb0[0]); // bxx
447  put_component(1, xb1[0]); // bxy
448 
449  put_component(2, xb0[1]); // byx
450  put_component(3, xb1[1]); // byy
451 
452  // Now make the component matrix the inverse of the basis matrix.
453 
454  component_matrix() = basis_matrix().inverse();
455 
456  // Postconditions:
457 
458  ensure(invariant());
459  ensure(unexecutable("Components are set to the correct basis values"));
460  ensure(unexecutable("The component matrix is the inverse of the basis matrix"));
461 
462  // Exit:
463 
464  return;
465 }
466 
467 void
469 get_matrix(row_dofs_type& xmatrix) const
470 {
471  // Preconditions:
472 
473  require(unexecutable("Each xbi is a vector of length at least 3."));
474 
475  // Body:
476 
477  // Copy the row dofs into xmatrix.
478 
479  xmatrix = _row_dofs;
480 
481  // Postconditions:
482 
483  ensure(invariant());
484  ensure_for_all(i, 0, d(), xmatrix.components[i] == component(i));
485 
486  // Exit:
487 
488  return;
489 }
490 
491 void
494 {
495  // Preconditions:
496 
497  require(xmatrix.basis_matrix().determinant() != 0);
498 
499  // Body:
500 
501  // Make the component part equal to the inverse of the basis part.
502 
503  xmatrix.component_matrix() = xmatrix.basis_matrix().inverse();
504 
505  // Copy the xmatrix into the row_dofs.
506 
507  _row_dofs = xmatrix;
508 
509  //put_components(xmatrix.components, xmatrix.d());
510 
511  // Postconditions:
512 
513  ensure(invariant());
514  ensure_for_all(i, 0, d(), component(i) == xmatrix.components[i]);
515  ensure(unexecutable("The component matrix is the inverse of the basis matrix"));
516 
517  // Exit:
518 
519  return;
520 }
521 
522 // PROTECTED MEMBER FUNCTIONS
523 
524 // PRIVATE MEMBER FUNCTIONS
525 
526 
527 //==============================================================================
528 // GLN FACET OF CLASS GL2_LITE
529 //==============================================================================
530 
531 // PUBLIC MEMBER FUNCTIONS
532 
533 int
535 n() const
536 {
537  // Preconditions:
538 
539  // Body:
540 
541  int result = 2;
542 
543  // Postconditions:
544 
545  ensure(invariant());
546  ensure(result == 2);
547 
548  // Exit:
549 
550  return result;
551 }
552 
553 // PROTECTED MEMBER FUNCTIONS
554 
555 // PRIVATE MEMBER FUNCTIONS
556 
557 
558 //==============================================================================
559 // GROUP FACET OF CLASS GL2_LITE
560 //==============================================================================
561 
562 // PUBLIC MEMBER FUNCTIONS
563 
564 // PROTECTED MEMBER FUNCTIONS
565 
566 // PRIVATE MEMBER FUNCTIONS
567 
568 
569 //==============================================================================
570 // ABSTRACT POSET MEMBER FACET OF CLASS GL2_LITE
571 //==============================================================================
572 
573 // PUBLIC MEMBER FUNCTIONS
574 
575 const std::string&
577 class_name() const
578 {
579  // Preconditions:
580 
581  // Body:
582 
583  const string& result = static_class_name();
584 
585  // Postconditions:
586 
587  ensure(!result.empty());
588 
589  // Exit:
590 
591  return result;
592 }
593 
594 const std::string&
597 {
598  // Preconditions:
599 
600  // Body:
601 
602  static const string result("gl2_lite");
603 
604  // Postconditions:
605 
606  ensure(!result.empty());
607 
608  // Exit:
609 
610  return result;
611 }
612 
615 clone() const
616 {
617  gl2_lite* result = 0;
618 
619  // Preconditions:
620 
621  // Body:
622 
623  result = new gl2_lite();
624 
625  // Postconditions:
626 
627  ensure(result != 0);
628  ensure(is_same_type(*result));
629 
630  // Exit:
631 
632  return result;
633 }
634 
635 // PROTECTED MEMBER FUNCTIONS
636 
637 // PRIVATE MEMBER FUNCTIONS
638 
639 
640 //==============================================================================
641 // ANY FACET OF CLASS GL2_LITE
642 //==============================================================================
643 
644 // PUBLIC MEMBER FUNCTIONS
645 
646 bool
648 is_ancestor_of(const any_lite& xother) const
649 {
650  // Preconditions:
651 
652  require(&xother != 0);
653 
654  // Body:
655 
656  // True if other conforms to this.
657 
658  bool result = dynamic_cast<const gl2_lite*>(&xother) != 0;
659 
660  // Postconditions:
661 
662  return result;
663 }
664 
665 bool
667 invariant() const
668 {
669  bool result = true;
670 
671  if(invariant_check())
672  {
673  // Prevent recursive calls to invariant.
674 
675  disable_invariant_check();
676 
677  // Must satisfy base class invariant.
678 
679  invariance(gln_lite::invariant());
680 
681  // Invariances for this class:
682 
683  // Finished, turn invariant checking back on.
684 
685  enable_invariant_check();
686  }
687 
688  // Exit
689 
690  return result;
691 }
692 
693 void*
696 {
697  return &_row_dofs;
698 }
699 
700 const void*
702 row_dofs() const
703 {
704  return &_row_dofs;
705 }
706 
707 // PROTECTED MEMBER FUNCTIONS
708 
709 // PRIVATE MEMBER FUNCTIONS
710 
711 
712 //==============================================================================
713 // CLASS GL2
714 //==============================================================================
715 
716 // ===========================================================
717 // HOST FACTORY FACET
718 // ===========================================================
719 
720 // PUBLIC MEMBER FUNCTIONS
721 
722 const sheaf::poset_path&
725 {
726  // Preconditions:
727 
728 
729  // Body:
730 
731  static const poset_path result(standard_schema_poset_name(), "gl2_schema");
732 
733  // Postconditions:
734 
735  // Exit:
736 
737  return result;
738 }
739 
740 void
743 {
744  // Preconditions:
745 
746  require(xns.state_is_read_write_accessible());
747  require(xns.contains_poset(standard_schema_poset_name()));
748  require(!xns.contains_poset_member(standard_schema_path()));
749 
750  // Body:
751 
752  string lmember_names = "bxx DOUBLE false ";
753  lmember_names += "bxy DOUBLE false ";
754  lmember_names += "byx DOUBLE false ";
755  lmember_names += "byy DOUBLE false ";
756  lmember_names += "cxx DOUBLE false ";
757  lmember_names += "cxy DOUBLE false ";
758  lmember_names += "cyx DOUBLE false ";
759  lmember_names += "cyy DOUBLE false";
760 
761  schema_poset_member lschema(xns,
762  standard_schema_path().member_name(),
763  gln::standard_schema_path(),
764  lmember_names,
765  false);
766 
767  lschema.detach_from_state();
768 
769  // Postconditions:
770 
771  ensure(xns.contains_poset_member(standard_schema_path()));
772 
773  // Exit:
774 
775  return;
776 }
777 
781  const poset_path& xhost_path,
782  const poset_path& xschema_path,
783  const poset_path& xvector_space_path,
784  bool xauto_access)
785 {
786  // cout << endl << "Entering gl2::new_host." << endl;
787 
788  // Preconditions:
789 
790  require(xns.state_is_auto_read_write_accessible(xauto_access));
791 
792  require(!xhost_path.empty());
793  require(!xns.contains_path(xhost_path, xauto_access));
794 
795  require(xschema_path.full());
796  require(xns.path_is_auto_read_accessible(xschema_path, xauto_access));
797  require(schema_poset_member::conforms_to(xns, xschema_path, standard_schema_path()));
798 
799  require(xns.path_is_auto_read_accessible(xvector_space_path, xauto_access));
800  require(xns.contains_poset<vector_space_type::host_type>(xvector_space_path, xauto_access));
801 
802  require(schema_poset_member::row_dof_ct(xns, xschema_path, xauto_access) == 8);
803 
804  // Body:
805 
806  host_type& result =
807  host_type::new_table(xns, xhost_path, xschema_path, xvector_space_path, xauto_access);
808 
809  // Postconditions:
810 
811  ensure(xns.owns(result, xauto_access));
812  ensure(result.path(true) == xhost_path);
813  ensure(result.state_is_not_read_accessible());
814  ensure(result.schema(true).path(xauto_access) == xschema_path);
815 
816  ensure(result.scalar_space_path(true) == xns.member_poset<vector_space_type::host_type>(xvector_space_path, xauto_access).scalar_space_path(xauto_access) );
817  ensure(result.n(true) == 2);
818  ensure(result.vector_space_path(true) == xvector_space_path );
819 
820  ensure(result.d(true) == 8);
821 
822  // Exit:
823 
824  // cout << "Leaving gl2::new_host." << endl;
825  return result;
826 }
827 
830 standard_host(namespace_type& xns, const std::string& xsuffix, bool xauto_access)
831 {
832  // cout << endl << "Entering gl2::new_host." << endl;
833 
834  // Preconditions:
835 
836  require(xns.state_is_auto_read_write_accessible(xauto_access));
837 
838  require(xsuffix.empty() || poset_path::is_valid_name(xsuffix));
839  require(standard_host_is_available<gl2>(xns, xsuffix, xauto_access));
840 
841  require(xns.path_is_auto_read_accessible(standard_schema_path(), xauto_access));
842 
843  require(xns.path_is_auto_read_available(vector_space_type::standard_host_path<vector_space_type>(xsuffix), xauto_access));
844 
845  // Body:
846 
847  // Create the vector space if necessary.
848 
849  poset_path lvector_space_path = vector_space_type::standard_host(xns, xsuffix, xauto_access).path(true);
850 
851  poset_path lpath(standard_host_path<gl2>(xsuffix));
852 
853  host_type* result_ptr;
854  if(xns.contains_path(lpath, xauto_access))
855  {
856  result_ptr = &xns.member_poset<host_type>(lpath, xauto_access);
857  }
858  else
859  {
860  result_ptr = &new_host(xns, lpath, standard_schema_path(), lvector_space_path, xauto_access);
861  }
862 
863  host_type& result = *result_ptr;
864 
865  // Postconditions:
866 
867  ensure(xns.owns(result, xauto_access));
868  ensure(result.path(true) == standard_host_path<gl2>(xsuffix));
869  ensure(result.state_is_not_read_accessible());
870  ensure(result.schema(true).path(xauto_access) == standard_schema_path());
871 
872  ensure(result.scalar_space_path(true) == vector_space_type::scalar_type::standard_host_path<vector_space_type::scalar_type>(xsuffix));
873  ensure(result.n(true) == 2);
874  ensure(result.vector_space_path(true) == vector_space_type::standard_host_path<vector_space_type>(xsuffix));
875 
876  ensure(result.d(true) == 8);
877 
878  // Exit:
879 
880  // cout << "Leaving gl2::new_host." << endl;
881  return result;
882 }
883 
884 // PROTECTED MEMBER FUNCTIONS
885 
886 // PRIVATE MEMBER FUNCTIONS
887 
888 
889 //==============================================================================
890 // GL2 FACET OF CLASS GL2
891 //==============================================================================
892 
893 // PUBLIC MEMBER FUNCTIONS
894 
897 {
898 
899  // Preconditions:
900 
901  // Body:
902 
903  // Postconditions:
904 
905  ensure(invariant());
906 
907  // Exit:
908 
909  return;
910 }
911 
913 gl2(const gl2& xother, bool xnew_jem)
914 {
915 
916  // Preconditions:
917 
918  require(xnew_jem ? xother.is_attached() : true);
919 
920  // Body:
921 
922  // Note: even though the code here is identical to that in
923  // the copy constructors of all descendants of abstract_poset_member,
924  // this can not just call its base class copy constructor
925  // because it must invoke versions defined in this class of virtual
926  // attach_to_state and virtual attach_handle_data_members
927  // (called from new_jem_state).
928 
929  if(xnew_jem)
930  {
931  new_jem_state(const_cast<gl2*>(&xother), true, true);
932  }
933  else
934  {
935  attach_to_state(&xother);
936  }
937 
938  // Postconditions:
939 
940  ensure(invariant());
941  ensure(is_attached() == xother.is_attached() );
942 }
943 
948 {
949  // Preconditions:
950 
951  require(is_ancestor_of(&xother));
952  require(precondition_of(attach_to_state(&xother)));
953 
954  // Body:
955 
956  attach_to_state(&xother);
957 
958  // Postconditions:
959 
960  ensure(postcondition_of(attach_to_state(&xother)));
961 
962  // Exit:
963 
964  return *this;
965 }
966 
970 operator=(const gl2& xother)
971 {
972  // Preconditions:
973 
974  require(precondition_of(attach_to_state(&xother)));
975 
976  // Body:
977 
978  attach_to_state(&xother);
979 
980  // Postconditions:
981 
982  ensure(postcondition_of(attach_to_state(&xother)));
983 
984  // Exit:
985 
986  return *this;
987 }
988 
991 {
992 
993  // Preconditions:
994 
995  // Body:
996 
997  // Postconditions:
998 
999  // Exit:
1000 
1001  return;
1002 }
1003 
1005 gl2(poset* xhost, bool xauto_access)
1006 {
1007 
1008  // Preconditions:
1009 
1010  require(precondition_of(new_jim_state(xhost, 0, false, xauto_access)));
1011 
1012  // Body:
1013 
1014  new_jim_state(xhost, 0, false, xauto_access);
1015 
1016  // Postconditions:
1017 
1018  ensure(postcondition_of(new_jim_state(xhost, 0, false, xauto_access)));
1019 
1020  // Exit:
1021 
1022  return;
1023 }
1024 
1027  const row_dofs_type& xrdt,
1028  bool xauto_access)
1029 {
1030 
1031  // Preconditions:
1032 
1033  require(precondition_of(new_jim_state(&xhost, 0, false, xauto_access)));
1034 
1035  // Body:
1036 
1037  new_jim_state(&xhost, 0, false, xauto_access);
1038 
1039  if(xauto_access)
1040  {
1041  xhost.get_read_write_access();
1042  }
1043 
1044  *this = xrdt;
1045 
1046  if(xauto_access)
1047  {
1048  xhost.release_access();
1049  }
1050 
1051  // Postconditions:
1052 
1053  ensure(postcondition_of(new_jim_state(&xhost, 0, false, xauto_access)));
1054 
1055  // Exit:
1056 
1057  return;
1058 }
1059 
1063 {
1064  // Preconditions:
1065 
1066  require(state_is_read_write_accessible());
1067 
1068  // Body:
1069 
1070  int ld = d();
1071 
1072  // Get the matrix
1073 
1074  for(int i=0; i<ld; ++i)
1075  {
1076  put_component(i, xrdt.components[i]);
1077  }
1078 
1079  // Postconditions:
1080 
1081  ensure_for_all(i, 0, d(), component(i) == xrdt.components[i]);
1082 
1083  // Exit:
1084 
1085  return *this;
1086 
1087 }
1088 
1089 // NEW HANDLE, EXISTING STATE CONSTRUCTORS
1090 
1092 gl2(const poset* xhost, pod_index_type xhub_id)
1093 {
1094  // Preconditions:
1095 
1096  require(xhost != 0);
1097  require(xhost->state_is_read_accessible());
1098  require(xhost->contains_member(xhub_id));
1099 
1100  // Body:
1101 
1102  attach_to_state(xhost, xhub_id);
1103 
1104  // Postconditions:
1105 
1106  ensure(invariant());
1107  ensure(is_attached());
1108  // ensure(host() == xhost);
1109  ensure(index() == xhub_id);
1110 }
1111 
1113 gl2(const poset* xhost, const scoped_index& xid)
1114 {
1115  // Preconditions:
1116 
1117  require(xhost != 0);
1118  require(xhost->state_is_read_accessible());
1119  require(xhost->contains_member(xid));
1120 
1121  // Body:
1122 
1123  attach_to_state(xhost, xid.hub_pod());
1124 
1125  // Postconditions:
1126 
1127  ensure(invariant());
1128  ensure(is_attached());
1129  // ensure(host() == xhost);
1130  ensure(index() ==~ xid);
1131 }
1132 
1134 gl2(const poset* xhost, const std::string& xname)
1135 {
1136 
1137  // Preconditions:
1138 
1139  require(xhost != 0);
1140  require(xhost->state_is_read_accessible());
1141  require(!xname.empty());
1142  require(xhost->contains_member(xname));
1143 
1144  // Body:
1145 
1146  attach_to_state(xhost, xname);
1147 
1148  // Postconditions:
1149 
1150  ensure(invariant());
1151  ensure(is_attached());
1152  // ensure(host() == xhost);
1153  ensure(name() == xname);
1154 
1155 }
1156 
1158 gl2(gl2* xother)
1159 {
1160 
1161  // Preconditions:
1162 
1163  require(xother != 0);
1164 
1165  // Body:
1166 
1167  attach_to_state(xother);
1168 
1169  // Postconditions:
1170 
1171  ensure(invariant());
1172  ensure(is_attached());
1173  ensure(is_same_state(xother));
1174 
1175 }
1176 
1177 fiber_bundle::gl2::
1179 {
1180  // Preconditions:
1181 
1182  // Body:
1183 
1184  row_dofs_type& result = sheaf::row_dofs(*this);
1185 
1186  // Postconditions:
1187 
1188  // Exit:
1189 
1190  return result;
1191 }
1192 
1193 fiber_bundle::gl2::
1194 operator const gl2::row_dofs_type& () const
1195 {
1196  // Preconditions:
1197 
1198  // Body:
1199 
1200  const row_dofs_type& result = sheaf::row_dofs(*this);
1201 
1202  // Postconditions:
1203 
1204  // Exit:
1205 
1206  return result;
1207 }
1208 
1209 void
1211 get_matrix(row_dofs_type& xmatrix) const
1212 {
1213  // Preconditions:
1214 
1215  require(state_is_read_accessible());
1216 
1217  // Body:
1218 
1219  xmatrix = *this;
1220 
1221  // Postconditions:
1222 
1223  ensure(invariant());
1224 
1225  // Exit:
1226 
1227  return;
1228 }
1229 
1230 void
1233 {
1234  // Preconditions:
1235 
1236  require(state_is_read_write_accessible());
1237  require(xmatrix.basis_matrix().determinant() != 0);
1238 
1239  // Body:
1240 
1241  // Make the component part equal to the inverse of the basis part.
1242 
1243  xmatrix.component_matrix() = xmatrix.basis_matrix().inverse();
1244 
1245  // Copy the xmatrix into the row_dofs.
1246 
1247  put_components(xmatrix.components, xmatrix.d());
1248 
1249  // Postconditions:
1250 
1251  ensure(invariant());
1252  ensure_for_all(i, 0, d(), component(i) == xmatrix.components[i]);
1253 
1254  // Exit:
1255 
1256  return;
1257 }
1258 
1262 lite_type() const
1263 {
1264  // Preconditions:
1265 
1266  // Body:
1267 
1268  volatile_type* result = new volatile_type(sheaf::row_dofs(*this));
1269 
1270  // Postconditions:
1271 
1272  // Exit:
1273 
1274  return result;
1275 }
1276 
1277 // PROTECTED MEMBER FUNCTIONS
1278 
1279 // PRIVATE MEMBER FUNCTIONS
1280 
1281 
1282 //==============================================================================
1283 // GLN FACET OF CLASS GL2
1284 //==============================================================================
1285 
1286 // PUBLIC MEMBER FUNCTIONS
1287 
1288 // PROTECTED MEMBER FUNCTIONS
1289 
1290 // PRIVATE MEMBER FUNCTIONS
1291 
1292 
1293 //==============================================================================
1294 // GROUP FACET OF CLASS GL2
1295 //==============================================================================
1296 
1297 // PUBLIC MEMBER FUNCTIONS
1298 
1299 // PROTECTED MEMBER FUNCTIONS
1300 
1301 // PRIVATE MEMBER FUNCTIONS
1302 
1303 
1304 //==============================================================================
1305 // ABSTRACT POSET MEMBER FACET OF CLASS GL2
1306 //==============================================================================
1307 
1308 // PUBLIC MEMBER FUNCTIONS
1309 
1310 const std::string&
1312 class_name() const
1313 {
1314  // Preconditions:
1315 
1316  // Body:
1317 
1318  const string& result = static_class_name();
1319 
1320  // Postconditions:
1321 
1322  ensure(!result.empty());
1323 
1324  // Exit:
1325 
1326  return result;
1327 }
1328 
1329 const std::string&
1332 {
1333  // Preconditions:
1334 
1335  // Body:
1336 
1337  static const string result("gl2");
1338 
1339  // Postconditions:
1340 
1341  ensure(!result.empty());
1342 
1343  // Exit:
1344 
1345  return result;
1346 }
1347 
1350 clone() const
1351 {
1352 
1353  // Preconditions:
1354 
1355  // Body:
1356 
1357  // Create new handle of the current class.
1358 
1359  gl2* result = new gl2();
1360 
1361  // Postconditions:
1362 
1363  ensure(result != 0);
1364  ensure(result->invariant());
1365 
1366  // Exit:
1367 
1368  return result;
1369 }
1370 
1371 // PROTECTED MEMBER FUNCTIONS
1372 
1373 // PRIVATE MEMBER FUNCTIONS
1374 
1375 
1376 //==============================================================================
1377 // ANY FACET OF CLASS GL2
1378 //==============================================================================
1379 
1380 // PUBLIC MEMBER FUNCTIONS
1381 
1382 bool
1384 invariant() const
1385 {
1386  bool result = true;
1387 
1388  // Preconditions:
1389 
1390  // Body:
1391 
1392  // Must satisfy base class invariant
1393 
1394  invariance(gln::invariant());
1395 
1396  if (invariant_check())
1397  {
1398  // Prevent recursive calls to invariant
1399 
1400  disable_invariant_check();
1401 
1402  invariance(state_is_read_accessible() ? n() == 2 : true);
1403 
1404  // Finished, turn invariant checking back on.
1405 
1406  enable_invariant_check();
1407  }
1408 
1409  // Postconditions:
1410 
1411  ensure(is_derived_query);
1412 
1413  // Exit:
1414 
1415  return result;
1416 }
1417 
1418 bool
1420 is_ancestor_of(const any* xother) const
1421 {
1422 
1423  // Preconditions:
1424 
1425  require(xother != 0);
1426 
1427  // Body:
1428 
1429  // True if other conforms to this.
1430 
1431  bool result = dynamic_cast<const gl2*>(xother) != 0;
1432 
1433  // Postconditions:
1434 
1435  // ensure(invariant());
1436 
1437  // Exit:
1438 
1439  return result;
1440 }
1441 
1442 // PROTECTED MEMBER FUNCTIONS
1443 
1444 // PRIVATE MEMBER FUNCTIONS
1445 
1446 
1447 //==============================================================================
1448 // NON-MEMBER FUNCTIONS
1449 //==============================================================================
1450 
1451 std::ostream& fiber_bundle::operator<<(std::ostream& xos, const gl2_lite& xlite)
1452 {
1453  xos << "basis" << endl;
1454  xos << " " << xlite[0] << " " << xlite[1] << endl;
1455  xos << " " << xlite[2] << " " << xlite[3] << endl;
1456 
1457  xos << endl;
1458 
1459  xos << "component:" << endl;
1460  xos << " " << xlite[4] << " " << xlite[5] << endl;
1461  xos << " " << xlite[6] << " " << xlite[7] << endl;
1462 
1463  return xos;
1464 }
1465 
1466 std::ostream& fiber_bundle::operator<<(std::ostream& xos, const gl2& xpersistent)
1467 {
1468  const gl2::row_dofs_type& lm = xpersistent;
1469 
1470  xos << "basis:" << endl;
1471  xos << " " << lm[0] << " " << lm[1] << endl;
1472  xos << " " << lm[2] << " " << lm[3] << endl;
1473  xos << endl;
1474 
1475  xos << "component:" << endl;
1476  xos << " " << lm[4] << " " << lm[5] << endl;
1477  xos << " " << lm[6] << " " << lm[7] << endl;
1478  xos << endl;
1479 
1480  return xos;
1481 }
1482 
1483 void
1484 fiber_bundle::inverse(const gl2_lite& xlite, gl2_lite& xresult)
1485 {
1486  // Preconditions:
1487 
1488  // Body:
1489 
1494 
1496 
1497  const gl2_lite::matrix_type& bm = xlite.basis_matrix();
1498  bm.inverse(xresult.basis_matrix());
1499 
1500  const gl2_lite::matrix_type& cm = xlite.component_matrix();
1501  cm.inverse(xresult.component_matrix());
1502 
1503  // Postconditions:
1504 
1505  ensure(unexecutable("xresult is the inverse of xgl"));
1506 
1507 
1508  // Exit:
1509 }
1510 
1511 void
1512 fiber_bundle::inverse(const gl2& xgl, gl2& xresult)
1513 {
1515 
1516  // Preconditions:
1517 
1518  require(xgl.state_is_read_accessible());
1519  require(xresult.state_is_read_accessible());
1520 
1521  // Body:
1522 
1527 
1529 
1530  typedef gl2::row_dofs_type row_dofs_type;
1531 
1532  const row_dofs_type& lrdt_gl = xgl;
1533  row_dofs_type& lrdt_result = xresult;
1534 
1535  lrdt_gl.basis_matrix().inverse(lrdt_result.basis_matrix());
1536  lrdt_gl.component_matrix().inverse(lrdt_result.component_matrix());
1537 
1538  // Postconditions:
1539 
1540  ensure(unexecutable("xresult is the inverse of xgl"));
1541 
1542  // Exit:
1543 }
1544 
void get_matrix(row_dofs_type &xmatrix) const
Copies row dof tuple into xmatrix.
Definition: gl2.cc:1211
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...
matrix_type & component_matrix()
The associated component transformation matrix (non const version).
Definition: gl2.cc:299
void determinant(T &xresult) const
The determinant of the matrix (pre-allocated).
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 ...
static void make_standard_schema(namespace_poset &xns)
Creates the standard schema for this class in namespace xns.
Definition: gl2.cc:742
static const poset_path & standard_schema_path()
The path to the standard schema for this class.
Definition: gl2.cc:724
bool full() const
True if both poset name and member name are not empty.
Definition: poset_path.cc:311
virtual bool is_ancestor_of(const any_lite &xother) const
Conformance test; true if other conforms to this.
Definition: gl2.cc:648
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: gl2.cc:1232
gl2_lite & operator=(const gl2_lite &xother)
Assignment operator.
Definition: gl2.cc:84
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.
virtual const std::string & class_name() const
The name of this class.
Definition: gl2.cc:1312
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual bool invariant() const
Class invariant.
Definition: gl2.cc:1384
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...
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.
void rescale(const value_type &xscale, const value_type &yscale)
Set this transform to rescale the x and y axes by xscale and yscale, respectively.
Definition: gl2.cc:331
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
row_dofs_type _row_dofs
Row_dofs_type.
Definition: gl2.h:335
STL namespace.
virtual ~gl2()
Destructor.
Definition: gl2.cc:990
virtual void * row_dofs()
The row dofs for this instance (mutable version).
Definition: gl2.cc:695
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.
gl2_row_dofs_type< double >::matrix_type matrix_type
The type of the associated matrix.
Definition: gl2.h:192
virtual gl2 * clone() const
Make a new handle, no state instance of current.
Definition: gl2.cc:1350
void put_basis(const value_type xb0[], const value_type xb1[])
Set this transformation to transform to the basis specified by component vectors xb0, xb1, where xbi gives the components of new basis vector i w.r.t. the old basis.
Definition: gl2.cc:434
virtual gl2 & operator=(const abstract_poset_member &xother)
Assignment operator; synonym for attach_to_state(&xother).
Definition: gl2.cc:947
T::row_dofs_type & row_dofs(T &x0)
The row dofs pod type for x0 (mutable version).
gl2_lite()
Default constructor.
Definition: gl2.cc:50
The mathematical group GL(2, R). The group of all invertible, linear transformations on the R2...
Definition: gl2.h:456
bool invariant() const
Class invariant.
Definition: gl2.cc:667
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 is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Definition: gl2.cc:1420
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: gl2.cc:780
virtual schema_poset_member & schema()
The schema for this poset (mutable version).
matrix_type & component_matrix()
The associated component transformation matrix (non const version).
Definition: gl2.impl.h:194
static const std::string & static_class_name()
The name of this class.
Definition: gl2.cc:1331
The mathematical group GL(2, R). The group of all invertible, linear transformations on the R2...
Definition: gl2.h:173
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: gl2.cc:493
A client handle for a mutable partially ordered set.
Definition: poset.h:40
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
bool 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
static int d()
The dimension of the row dof components.
Definition: gl2.impl.h:62
virtual bool is_attached() const
True if this handle is attached to a non-void state.
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
matrix_type & basis_matrix()
The associated basis transformation matrix (non const version).
Definition: gl2.impl.h:156
static host_type & standard_host(namespace_type &xns, const std::string &xsuffix, bool xauto_access)
The host with path standard_host_path<gl2>(xsuffix). Returns the host if it already exists...
Definition: gl2.cc:830
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. ...
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...
matrix_type & basis_matrix()
The associated basis transformation matrix (non const version).
Definition: gl2.cc:265
void rotate_z(const value_type &xangle)
Set this transform to a rotation about the z-axis by angle xangle, in radians.
Definition: gl2.cc:369
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
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
virtual const std::string & class_name() const
The name of this class.
Definition: gl2.cc:577
virtual ~gl2_lite()
Destructor.
Definition: gl2.cc:107
void basis(value_type xb0[], value_type xb1[]) const
The components of the new basis vectors w.r.t. the old basis, pre-allocated version.
Definition: gl2.cc:403
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
T components[8]
The dofs in the following order:
Definition: gl2.h:154
gl2()
Default constructor.
Definition: gl2.cc:896
An abstract client handle for a member of a poset.
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
Namespace for the fiber_bundles component of the sheaf system.
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
virtual volatile_type * lite_type() const
Virtual conversion to the associated volatile type.
Definition: gl2.cc:1262
static const std::string & static_class_name()
The name of this class.
Definition: gl2.cc:596
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.
void get_matrix(row_dofs_type &xmatrix) const
Copies the row dofs of this into xmatrix.
Definition: gl2.cc:469
virtual gl2_lite * clone() const
Virtual constructor, makes a new instance of the same type as this.
Definition: gl2.cc:615
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
virtual int n() const
Dimension of the representation space; n in GL(n, R).
Definition: gl2.cc:535
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
void inverse(general_matrix_2x2< T > &xresult) const
The inverse of the matrix (pre-allocated).
poset_path scalar_space_path() const
The path of the underlying scalar space.
Definition: gln_space.cc:254