SheafSystem  0.0.0.0
section_evaluator.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class section_evaluator
19 
20 #include "SheafSystem/section_evaluator.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/block.h"
24 #include "SheafSystem/sec_vd.h"
25 
26 using namespace fiber_bundle; // Workaround for MS C++ bug.
27 
28 // ===========================================================
29 // SECTION_EVALUATOR FACET
30 // ===========================================================
31 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  // No action required.
41 
42  // Postconditions:
43 
44  ensure(invariant());
45 
46  return;
47 }
48 
52 {
53  // Preconditions:
54 
55  // Body:
56 
57  // Postconditions:
58 
59  ensure(invariant());
60 
61  return;
62 }
63 
67 {
68  // Preconditions:
69 
70  // Body:
71 
72  // Postconditions:
73 
74  ensure(invariant());
75 
76  return;
77 }
78 
79 // ===========================================================
80 // DOMAIN FACET
81 // ===========================================================
82 
84 int
86 db() const
87 {
88  int result = -1;
89 
90  // Preconditions:
91 
92 
93  // Body:
94 
95  is_abstract();
96 
97  // Postconditions:
98 
99  ensure(result >= -1);
100 
101  // Exit:
102 
103  return result;
104 }
105 
106 
108 void
111  coord_type xresult[],
112  size_type xresult_ub) const
113 {
114  // Preconditions:
115 
116  require((0 <= xindex) && (xindex < dof_ct()));
117  require(xresult_ub >= db());
118 
119  // Body:
120 
121  is_abstract();
122 
123  // Postconditions:
124 
125  ensure(in_standard_domain(xresult, xresult_ub));
126 
127  // Exit:
128 
129  return;
130 }
131 
132 
134 void
137 {
138  // Preconditions:
139 
140  require(precondition_of(local_coordinates(xindex, xresult.base(), xresult.ub())));
141 
142  // Body:
143 
144  local_coordinates(xindex, xresult.base(), xresult.ub());
145  xresult.set_ct(db());
146 
147  // Postconditions:
148 
149  ensure(postcondition_of(local_coordinates(xindex, xresult.base(), xresult.ub())));
150  ensure(xresult.ct() == db());
151 
152  // Exit:
153 
154  return;
155 }
156 
158 void
160 center(coord_type xresult[], size_type xresult_ub) const
161 {
162  // Preconditions:
163 
164  require(xresult != 0);
165  require(xresult_ub >= db());
166 
167  // Body:
168 
169  // The following implementation is correct for the box-like base spaces,
170  // but not for the simplex base space. It must be overridden in those classes.
171 
172  for(size_type i=0; i<db(); ++i)
173  {
174  xresult[i] = 0.0;
175  }
176 
177  // Postconditions:
178 
179 
180  // Exit:
181 
182  return;
183 }
184 
186 void
188 center(block<coord_type>& xresult) const
189 {
190  // Preconditions:
191 
192  require(precondition_of(center(xresult.base(), xresult.ub())));
193 
194  // Body:
195 
196  center(xresult.base(), xresult.ub());
197  xresult.set_ct(db());
198 
199  // Postconditions:
200 
201  ensure(postcondition_of(center(xresult.base(), xresult.ub())));
202  ensure(xresult.ct() == db());
203 
204  // Exit:
205 
206  return;
207 }
208 
210 bool
212 in_standard_domain(const dof_type xlocal_coords[],
213  size_type xlocal_coords_ub) const
214 {
215  bool result = true;
216 
217  // Preconditions:
218 
219  require(xlocal_coords != 0);
220  require(xlocal_coords_ub >= db());
221 
222  // Body:
223 
224  is_abstract();
225 
226  // Postconditions:
227 
228  ensure(invariant());
229 
230  return result;
231 }
232 
234 bool
236 in_standard_domain(const block<dof_type>& xlocal_coords) const
237 {
238  bool result;
239 
240  // Preconditions:
241 
242  require(precondition_of(in_standard_domain(xlocal_coords.base(), xlocal_coords.ct())));
243 
244  // Body:
245 
246  result = in_standard_domain(xlocal_coords.base(), xlocal_coords.ct());
247 
248  // Postconditions:
249 
250  ensure(postcondition_of(in_standard_domain(xlocal_coords.base(), xlocal_coords.ct())));
251 
252  // Exit:
253 
254  return result;
255 }
256 
257 // ===========================================================
258 // EVALUATION FACET
259 // ===========================================================
260 
264 dof_ct() const
265 {
266  int result = 0;
267 
268  // Preconditions:
269 
270 
271  // Body:
272 
273  is_abstract();
274 
275  // Postconditions:
276 
277  ensure(result >= 0);
278 
279  // Exit:
280 
281  return result;
282 }
283 
284 bool
287 {
288  // Preconditions:
289 
290 
291  // Body:
292 
293  bool result = (df() == 0);
294 
295  // Postconditions:
296 
297  ensure(result == (df() == 0));
298 
299  // Exit:
300 
301  return result;
302 }
303 
304 int
306 df() const
307 {
308  // Preconditions:
309 
310 
311  // Body:
312 
313 
314  // Assume the fiber dimension is variable;
315  // redefine in descendants with fixed fiber dimension.
316 
317  int result = 0;
318 
319  // Postconditions:
320 
321  ensure(result >= 0);
322 
323  // Exit:
324 
325  return result;
326 }
327 
332  const block<dof_type>& xlocal_coords) const
333 {
334  dof_type result;
335 
336  // Preconditions:
337 
338  require(df_is_variable());
339  require(precondition_of(value_at_coord(xdofs.base(), xdofs.ct(), xlocal_coords.base(), xlocal_coords.ct());));
340 
341  // Body:
342 
343  result = value_at_coord(xdofs.base(),
344  xdofs.ct(),
345  xlocal_coords.base(),
346  xlocal_coords.ct());
347 
348  // Postconditions:
349 
350  ensure(postcondition_of(value_at_coord(xdofs.base(), xdofs.ct(), xlocal_coords.base(), xlocal_coords.ct());));
351 
352  // Exit:
353 
354  return result;
355 }
356 
360 value_at_coord(const dof_type xdofs[],
361  size_type xdofs_ub,
362  const dof_type xlocal_coords[],
363  size_type xlocal_coords_ub) const
364 {
365  // Preconditions:
366 
367  require(df_is_variable());
368  require(xdofs != 0);
369  require(xdofs_ub >= dof_ct());
370  require(unexecutable(xdofs must be interleaved));
371  require(xlocal_coords != 0);
372  require(xlocal_coords_ub >= db());
373 
374  // Body:
375 
376  dof_type result;
377  value_at_coord(xdofs, xdofs_ub, xlocal_coords, xlocal_coords_ub, &result, 1);
378 
379  // Postconditions:
380 
381  ensure(invariant());
382 
383  return result;
384 
385 }
386 
388 void
391  const block<dof_type>& xlocal_coords,
392  block<dof_type>& xresult) const
393 {
394  // Preconditions:
395 
396  require(precondition_of(value_at_coord(xdofs.base(),
397  xdofs.ct(),
398  xlocal_coords.base(),
399  xlocal_coords.ct(),
400  xresult.base(),
401  xresult.ct());));
402 
403  // Body:
404 
405  value_at_coord(xdofs.base(),
406  xdofs.ct(),
407  xlocal_coords.base(),
408  xlocal_coords.ct(),
409  xresult.base(),
410  xresult.ct());
411 
412  // Postconditions:
413 
414  ensure(postcondition_of(value_at_coord(xdofs.base(),
415  xdofs.ct(),
416  xlocal_coords.base(),
417  xlocal_coords.ct(),
418  xresult.base(),
419  xresult.ct());));
420 
421  // Exit:
422 
423  return;
424 }
425 
426 void
428 coord_at_value(const dof_type xdofs[],
429  size_type xdofs_ub,
430  const dof_type xvalue[],
431  size_type xvalue_ub,
432  dof_type xlocal_coords[],
433  size_type xlocal_coords_ub) const
434 {
435  // Preconditions:
436 
438 
439  // Body:
440 
441  is_abstract();
442 
443  // Postconditions:
444 
445  ensure(invariant());
446 }
447 
449 void
452  const block<dof_type>& xvalue,
453  block<dof_type>& xlocal_coords) const
454 {
455  // Preconditions:
456 
457  require(precondition_of(coord_at_value(xdofs.base(),
458  xdofs.ct(),
459  xvalue.base(),
460  xvalue.ct(),
461  xlocal_coords.base(),
462  xlocal_coords.ub())));
463 
464  // Body:
465 
466  coord_at_value(xdofs.base(),
467  xdofs.ct(),
468  xvalue.base(),
469  xvalue.ct(),
470  xlocal_coords.base(),
471  xlocal_coords.ub());
472 
473  xlocal_coords.set_ct(db());
474 
475 
476  // Postconditions:
477 
478  ensure(postcondition_of(coord_at_value(xdofs.base(),
479  xdofs.ct(),
480  xvalue.base(),
481  xvalue.ub(),
482  xlocal_coords.base(),
483  xlocal_coords.ub())));
484  ensure(xlocal_coords.ct() == db());
485 
486  // Exit:
487 
488  return;
489 }
490 
494 min(const dof_type xdofs[], size_type xdofs_ub) const
495 {
496  // Preconditions:
497 
498  require(df_is_variable());
499  require(xdofs != 0);
500  require(xdofs_ub > 0);
501 
502  // Body:
503 
504  //cout << "section_evaluator::min()" << endl;
505 
506  dof_type result = xdofs[0];
507 
508  for(int i=1; i<xdofs_ub; ++i)
509  {
510  dof_type x = xdofs[i];
511  if(x < result)
512  result = x;
513  }
514 
515  // Postconditions:
516 
517  return result;
518 }
519 
523 min(const block<dof_type>& xdofs) const
524 {
525  // Preconditions:
526 
527  require(precondition_of(min(xdofs.base(), xdofs.ct())));
528 
529  // Body:
530 
531  dof_type result = min(xdofs.base(), xdofs.ct());
532 
533  // Postconditions:
534 
535  ensure(postcondition_of(min(xdofs.base(), xdofs.ct())));
536 
537  // Exit:
538 
539  return result;
540 }
541 
543 void
545 min(const dof_type xdofs[],
546  size_type xdofs_ub,
547  dof_type xresult[],
548  size_type xresult_ub) const
549 {
550  // Preconditions:
551 
552  require(xdofs != 0);
553  require(xdofs_ub > 0);
554  require(xresult != 0);
555  require(xresult_ub > 0);
556 
557  // Body:
558 
559  // Here we assume that xresult_ub is the number of components
560  // and that the components are interleaved in xdofs (ie; x,y,z,...).
561 
562  for(int j=0; j<xresult_ub; ++j)
563  {
564  xresult[j] = xdofs[j];
565  }
566 
567  for(int i=0; i<xdofs_ub; i+=xresult_ub)
568  {
569  for(int j=0; j<xresult_ub; ++j)
570  {
571  dof_type x = xdofs[i+j];
572 
573  if(x < xresult[j])
574  xresult[j] = x;
575  }
576  }
577 
578  // Postconditions:
579 
580 }
581 
583 void
585 min(const block<dof_type>& xdofs, block<dof_type>& xresult) const
586 {
587  // Preconditions:
588 
589  require(precondition_of(min(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct())));
590 
591  // Body:
592 
593  min(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct());
594 
595  // Postconditions:
596 
597  ensure(postcondition_of(min(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct())));
598  ensure(xresult.ct() == xresult.ct());
599 
600  // Exit:
601 
602  return;
603 }
604 
608 max(const dof_type xdofs[], size_type xdofs_ub) const
609 {
610  // Preconditions:
611 
612  require(df_is_variable());
613  require(xdofs != 0);
614  require(xdofs_ub > 0);
615 
616  // Body:
617 
618  dof_type result = xdofs[0];
619 
620  for(int i=1; i<xdofs_ub; ++i)
621  {
622  dof_type x = xdofs[i];
623  if(x > result)
624  result = x;
625  }
626 
627  // Postconditions:
628 
629  return result;
630 }
631 
635 max(const block<dof_type>& xdofs) const
636 {
637  // Preconditions:
638 
639  require(precondition_of(max(xdofs.base(), xdofs.ct())));
640 
641  // Body:
642 
643  dof_type result = max(xdofs.base(), xdofs.ct());
644 
645  // Postconditions:
646 
647  ensure(postcondition_of(max(xdofs.base(), xdofs.ct())));
648 
649  // Exit:
650 
651  return result;
652 }
653 
655 void
657 max(const dof_type xdofs[],
658  size_type xdofs_ub,
659  dof_type xresult[],
660  size_type xresult_ub) const
661 {
662  // Preconditions:
663 
664  require(xdofs != 0);
665  require(xdofs_ub > 0);
666  require(xresult != 0);
667  require(xresult_ub > 0);
668 
669  // Body:
670 
671  // Here we assume that xresult_ub is the number of components
672  // and that the components are interleaved in xdofs (ie; x,y,z,...).
673 
674  for(int j=0; j<xresult_ub; ++j)
675  {
676  xresult[j] = xdofs[j];
677  }
678 
679  for(int i=0; i<xdofs_ub; i+=xresult_ub)
680  {
681  for(int j=0; j<xresult_ub; ++j)
682  {
683  dof_type x = xdofs[i+j];
684 
685  if(x > xresult[j])
686  xresult[j] = x;
687  }
688  }
689 
690  // Postconditions:
691 
692 }
693 
695 void
697 max(const block<dof_type>& xdofs, block<dof_type>& xresult) const
698 {
699  // Preconditions:
700 
701  require(precondition_of(max(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct())));
702 
703  // Body:
704 
705  max(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct());
706 
707  // Postconditions:
708 
709  ensure(postcondition_of(max(xdofs.base(), xdofs.ct(), xresult.base(), xresult.ct())));
710 
711  // Exit:
712 
713  return;
714 }
715 
716 // ===========================================================
717 // ANY FACET
718 // ===========================================================
719 
723 clone() const
724 {
725  section_evaluator* result = 0;
726 
727  // Preconditions:
728 
729  // Body:
730 
731  is_abstract();
732 
733  // Postconditions:
734 
735  ensure(result != 0);
736  ensure(is_same_type(result));
737 
738  // Exit:
739 
740  return result;
741 }
742 
743 
748 {
749  // Preconditions:
750 
751  require(is_ancestor_of(&xother));
752 
753  // Body:
754 
755  not_implemented();
756 
757  // Postconditions:
758 
759  ensure(invariant());
760 
761  // Exit
762 
763  return *this;
764 }
765 
767 bool
769 invariant() const
770 {
771  bool result = true;
772 
773  // Preconditions:
774 
775  // Body:
776 
777  // Must satisfy base class invariant.
778 
779  result = result && any::invariant();
780 
781  if(invariant_check())
782  {
783  // Prevent recursive calls to invariant.
784 
785  disable_invariant_check();
786 
787  // Finished, turn invariant checking back on.
788 
789  enable_invariant_check();
790  }
791 
792  // Postconditions:
793 
794  return result;
795 }
796 
798 bool
800 is_ancestor_of(const any* xother) const
801 {
802 
803  // Preconditions:
804 
805  require(xother != 0);
806 
807  // Body:
808 
809  // True if other conforms to this
810 
811  bool result = dynamic_cast<const section_evaluator*>(xother) != 0;
812 
813  // Postconditions:
814 
815  return result;
816 
817 }
818 
819 // ===========================================================
820 // NON-MEMBER FUNCTIONS
821 // ===========================================================
822 
823 size_t
824 fiber_bundle::
825 deep_size(const section_evaluator& xe, bool xinclude_shallow)
826 {
827  size_t result;
828 
829  // Preconditions:
830 
831  // Body:
832 
835 
836  result = 0;
837 
838  // Postconditions:
839 
840  ensure(result == 0);
841  //ensure(result >= 0);
842 
843  // Exit
844 
845  return result;
846 }
847 
848 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
bool df_is_variable() const
True if and only if the fiber dimension (number of components of the dependent variable) is variable...
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
sec_vd_dof_type dof_type
The type of degree of freedom.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual dof_type value_at_coord(const dof_type xdofs[], size_type xdofs_ub, const dof_type xlocal_coords[], size_type xlocal_coords_ub) const
Value at a specified local_coordinate. Single component version.
virtual bool in_standard_domain(const dof_type xlocal_coords[], size_type xlocal_coords_ub) const =0
True if the specified local coordinates are in the "standard" domain.
virtual ~section_evaluator()
Destructor.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual dof_type max(const dof_type xdofs[], size_type xdofs_ub) const
The maximum value of the scalar or component section defined by xdofs.
virtual size_type dof_ct() const =0
The number of dofs required for each component of the dependent variable.
pointer_type base() const
The underlying storage array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual void coord_at_value(const dof_type xdofs[], size_type xdofs_ub, const dof_type xvalue[], size_type xvalue_ub, dof_type xlocal_coords[], size_type xlocal_coords_ub) const =0
The local coordinates of a point at which the field has the value xvalue. The dofs are assumed to be ...
virtual void center(coord_type xresult[], size_type xresult_ub) const
The local coordinates at the center of the evaluator.
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
virtual bool invariant() const
Class invariant.
SHEAF_DLL_SPEC void max(const vd &x0, vd_value_type &xresult, bool xauto_access)
Maximum component of x0, pre-allocated version.
Definition: vd.cc:2097
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
SHEAF_DLL_SPEC void min(const vd &x0, vd_value_type &xresult, bool xauto_access)
Minimum component of x0, pre-allocated version.
Definition: vd.cc:2161
virtual int df() const
The fiber dimension (number of components of dependent variable).
virtual section_evaluator * clone() const =0
Virtual constructor, makes a new instance of the same type as this.
virtual section_evaluator & operator=(const section_evaluator &xother)
Assignment operator.
virtual dof_type min(const dof_type xdofs[], size_type xdofs_ub) const
The minimum value of the scalar or component section defined by xdofs.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual int db() const =0
The base dimension; the dimension of the local coordinates (independent variable).
double sec_vd_dof_type
The type of degree of freedom in the section space.
Definition: fiber_bundle.h:78
virtual void local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const =0
The local coordinates of the dof with local index xindex.
An auto_block with a no-initialization initialization policy.
Namespace for the fiber_bundles component of the sheaf system.
void local_coordinates(pod_index_type xindex, block< coord_type > &xresult) const
The local coordinates of the dof with local index xindex.
section_evaluator()
Default constructor.