SheafSystem  0.0.0.0
quadratic_2d.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 quadratic_2d
19 
20 #include "SheafSystem/quadratic_2d.h"
21 #include "SheafSystem/assert_contract.h"
22 #include "SheafSystem/std_cmath.h"
23 #include "SheafSystem/std_iostream.h"
24 #include "SheafSystem/std_limits.h"
25 
26 using namespace std;
27 using namespace fiber_bundle; // Workaround for MS C++ bug.
28 
29 // ===========================================================
30 // QUADRATIC_2D FACET
31 // ===========================================================
32 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  _basis_values = _basis_value_buffer;
42  _basis_deriv_values = _basis_deriv_value_buffer;
43  _jacobian_values = _jacobian_value_buffer;
44 
45  // Postconditions:
46 
47  ensure(invariant());
48 
49  return;
50 }
51 
52 
55 quadratic_2d(const quadratic_2d& xother)
56 {
57  // Preconditions:
58 
59  // Body:
60 
61  _basis_values = _basis_value_buffer;
62  _basis_deriv_values = _basis_deriv_value_buffer;
63  _jacobian_values = _jacobian_value_buffer;
64 
65  // Postconditions:
66 
67  ensure(invariant());
68 
69  return;
70 }
71 
75 {
76  // Preconditions:
77 
78  // Body:
79 
80  // Postconditions:
81 
82  ensure(invariant());
83 
84  return;
85 }
86 
87 // ===========================================================
88 // LINEAR_FCN_SPACE FACET
89 // ===========================================================
90 
92 int
94 dl() const
95 {
96  int result;
97 
98  // Preconditions:
99 
100 
101  // Body:
102 
103  result = DL;
104 
105  // Postconditions:
106 
107  ensure(result == 6);
108 
109  // Exit:
110 
111  return result;
112 }
113 
115 void
117 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
118 {
119  // Preconditions:
120 
121  require(xlocal_coord != 0);
122  require(xlocal_coord_ub >= db());
123  require(basis_values() != 0);
124 
125  // Body:
126 
127  // Evaluate the interpolation functions.
128 
129  double l0 = xlocal_coord[0];
130  double l1 = xlocal_coord[1];
131  double l2 = 1.0 - (l0 + l1);
132 
133  // corner nodes:
134 
135  _basis_values[0] = (2.0*l0-1.0)*l0;
136  _basis_values[1] = (2.0*l1-1.0)*l1;
137  _basis_values[2] = (2.0*l2-1.0)*l2;
138 
139  // midside nodes:
140 
141  _basis_values[3] = 4.0*l0*l1;
142  _basis_values[4] = 4.0*l1*l2;
143  _basis_values[5] = 4.0*l2*l0;
144 
145  // Postconditions:
146 
147  ensure(invariant());
148 }
149 
151 void
153 basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
154 {
155  // Preconditions:
156 
157  require(xlocal_coord != 0);
158  require(xlocal_coord_ub >= db());
159  require(basis_deriv_values() != 0);
160 
161  // Body:
162 
164 
165  not_implemented();
166 
167  // Postconditions:
168 
169  ensure(invariant());
170 
171  // Exit:
172 
173  return;
174 }
175 
176 // ===========================================================
177 // INTEGRABLE_SECTION_EVALUATOR FACET
178 // ===========================================================
179 
183 jacobian_determinant(const dof_type xcoord_dofs[],
184  size_type xcoord_dofs_ub,
185  size_type xdf,
186  const coord_type xlocal_coords[],
187  size_type xlocal_coords_ub)
188 {
189  // Preconditions:
190 
191  require(xcoord_dofs != 0);
192  require(xcoord_dofs_ub >= db()*dl());
193  require(xlocal_coords != 0);
194  require(xlocal_coords_ub >= db());
195  //require(jacobian_values() != 0);
196 
197  // Body:
198 
199  not_implemented();
200 
202 
203  value_type result = 0.0;
204 
205  // Postconditions:
206 
207  ensure(invariant());
208 
209  // Exit:
210 
211  return result;
212 }
213 
217 volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
218 {
219  // Preconditions:
220 
221  require(xcoord_dofs != 0);
222  require(xcoord_dofs_ub >= dl()*db());
223  require(xdf == 2 || xdf == 3);
224 
225  // Body:
226 
228 
229  not_implemented();
230 
231  value_type result = 0.0;
232 
233  // Postconditions:
234 
235  ensure(invariant());
236 
237  // Exit:
238 
239  return result;
240 }
241 
243 void
245 integrate(const dof_type xcoord_dofs[],
246  size_type xcoord_dofs_ub,
247  size_type xdf,
248  const dof_type xintegrands[],
249  size_type xintegrands_ub,
250  value_type xresult_integrals[],
251  size_type xresult_integrals_ub)
252 {
254 
255  // Preconditions:
256 
257  require(xcoord_dofs != 0);
258  require(xcoord_dofs_ub >= dl()*db());
259  require(xintegrands != 0);
260  require(xintegrands_ub >= dl());
261  require(xresult_integrals != 0);
262  require(xresult_integrals_ub > 0);
263 
264  // Body:
265 
266  not_implemented();
267 
269 
270  // Postconditions:
271 
272  ensure(invariant());
273 
274  // Exit:
275 
276  return;
277 }
278 
280 void
282 integrate(const dof_type xcoord_dofs[],
283  size_type xcoord_dofs_ub,
284  size_type xdf,
285  const dof_type xintegrand,
286  value_type xresult_integrals[],
287  size_type xresult_integrals_ub)
288 {
290 
291  // Preconditions:
292 
293  require(xcoord_dofs != 0);
294  require(xcoord_dofs_ub >= dl()*db());
295  require(xresult_integrals != 0);
296  require(xresult_integrals_ub >= dl());
297 
298  // Body:
299 
300  not_implemented();
301 
303 
304  // Postconditions:
305 
306  ensure(invariant());
307 
308  // Exit:
309 
310  return;
311 }
312 
314 void
317  coord_type xresult[],
318  size_type xresult_ub)
319 {
320  // Preconditions:
321 
322  require((0 <= xindex) && (xindex < dof_ct()));
323  require(xresult_ub >= db());
324 
325  // Body:
326 
327  not_implemented();
328 
330 
331  // Postconditions:
332 
333  ensure(in_standard_domain(xresult, xresult_ub));
334  ensure(invariant());
335 
336  // Exit:
337 
338  return;
339 }
340 
341 // ===========================================================
342 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
343 // ===========================================================
344 
346 void
348 dxi_local(size_type xlocal_coord_index,
349  const dof_type xsource_dofs[],
350  size_type xsource_dofs_ub,
351  dof_type xresult_dofs[],
352  size_type xresult_dofs_ub) const
353 {
354  // Preconditions:
355 
356  require(xlocal_coord_index < db());
357  require(xsource_dofs != 0);
358  //require(xsource_dofs_ub >= dof_ct());
359  require(xresult_dofs != 0);
360  //require(xresult_dofs_ub >= dof_ct());
361 
362  // Body:
363 
364  // The 1st derivatives are constant for linear 2d.
365 
366  dof_type derivative = xsource_dofs[xlocal_coord_index] - xsource_dofs[2];
367 
368  for(int i=0; i<3; ++i)
369  xresult_dofs[i] = derivative;
370 
371  // Postconditions:
372 
373  // Exit:
374 
375  return;
376 }
377 
379 void
381 jacobian(const dof_type xcoord_dofs[],
382  size_type xcoord_dofs_ub,
383  size_type xdf,
384  const dof_type xlocal_coords[],
385  size_type xlocal_coords_ub)
386 {
387  // Preconditions:
388 
389  require(xcoord_dofs != 0);
390  require(xcoord_dofs_ub >= db()*dl());
391  require(xlocal_coords != 0);
392  require(xlocal_coords_ub >= db());
393  require(jacobian_values() != 0);
394 
395  // Body:
396 
397  not_implemented();
398 
400 
401  // Postconditions:
402 
403  ensure(invariant());
404 
405  // Exit:
406 
407  return;
408 }
409 
410 // ===========================================================
411 // DOMAIN FACET
412 // ===========================================================
413 
415 int
417 db() const
418 {
419  int result;
420 
421  // Preconditions:
422 
423 
424  // Body:
425 
426  result = 2;
427 
428  // Postconditions:
429 
430  ensure(result == 2);
431 
432  // Exit:
433 
434  return result;
435 }
436 
437 
439 void
441 local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const
442 {
443  // Preconditions:
444 
445  require((0 <= xindex) && (xindex < dof_ct()));
446  require(xresult_ub >= db());
447 
448  // Body:
449 
450  static const coord_type lcoords[6][2] =
451  {
452  {
453  1.0, 0.0
454  }
455  , {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.5}, {0.0, 0.5}, {0.5, 0.0}
456  };
457 
458  xresult[0] = lcoords[xindex][0];
459  xresult[1] = lcoords[xindex][1];
460 
461  // Postconditions:
462 
463  ensure(in_standard_domain(xresult, xresult_ub));
464 
465  // Exit:
466 
467  return;
468 }
469 
471 bool
473 in_standard_domain(const dof_type xlocal_coords[],
474  size_type xlocal_coords_ub) const
475 {
476  // Preconditions:
477 
478  require(xlocal_coords != 0);
479  require(xlocal_coords_ub >= 2);
480 
481  // Body:
482 
483  dof_type u = xlocal_coords[0];
484  dof_type v = xlocal_coords[1];
485 
486  // "Extend" the bounds by the dof type epsilon (attempting
487  // to ensure that the boundary is included in the domain).
488 
489  dof_type zero = 0.0 - 1000.0*numeric_limits<dof_type>::epsilon();
490  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
491 
492  bool result = (u >= zero) && (u <= one) && (v >= zero) && (v <= one);
493 
494  // Postconditions:
495 
496  // Exit:
497 
498  return result;
499 
500 }
501 
502 // ===========================================================
503 // EVALUATION FACET
504 // ===========================================================
505 
507 void
509 coord_at_value(const dof_type xdofs[],
510  size_type xdofs_ub,
511  const dof_type xglobal_coords[],
512  size_type xglobal_coord_ub,
513  dof_type xlocal_coords[],
514  size_type xlocal_coords_ub) const
515 {
516  // Preconditions:
517 
518  require(xdofs != 0);
519  require(xdofs_ub >= 12);
520  require(xglobal_coords != 0);
521  require(xglobal_coord_ub >= 2);
522  require(xlocal_coords != 0);
523  require(xlocal_coords_ub >= 2);
524 
525  // Body:
526 
527  cout << "quadratic_2d::coord_at_value()" << endl;
528 
529  // Dofs are assumed to be interleaved (x0, y0, x1, y1, x2, y2, ...).
530 
531 
534 
535  // Note: The local ids for the corner nodes is (0, 1, 2)
536  // and for the midside nodes (3, 4, 5)
537 
538  // Corner nodes:
539 
540  dof_type x0 = xdofs[0];
541  dof_type x1 = xdofs[2];
542  dof_type x2 = xdofs[4];
543 
544  dof_type y0 = xdofs[1];
545  dof_type y1 = xdofs[3];
546  dof_type y2 = xdofs[5];
547 
548  // Midside nodes:
549 
552 
553  // dof_type x3 = xdofs[6];
554  // dof_type x4 = xdofs[8];
555  // dof_type x5 = xdofs[10];
556 
557  // dof_type y3 = xdofs[7];
558  // dof_type y4 = xdofs[9];
559  // dof_type y5 = xdofs[11];
560 
561 
562  dof_type x_global = xglobal_coords[0];
563  dof_type y_global = xglobal_coords[1];
564 
566 
567  double a0 = x1*y2 - x2*y1;
568  double a1 = x2*y0 - x0*y2;
569  double a2 = x0*y1 - x1*y0;
570 
571  double b0 = y1 - y2;
572  double b1 = y2 - y0;
573  //double b2 = y0 - y1;
574 
575  double c0 = x2 - x1;
576  double c1 = x0 - x2;
577  //double c2 = x1 - x0;
578 
579  double area_x_2 = a0 + a1 + a2;
580 
581  double shape0 = (a0 + b0*x_global + c0*y_global) / area_x_2;
582  double shape1 = (a1 + b1*x_global + c1*y_global) / area_x_2;
583  //double shape2 = (a2 + b2*x_global + c2*y_global) / area_x_2;
584 
585  //double shape2 = 1.0 - (shape0 + shape1);
586 
587  cout << "shape0 = " << shape0 << endl;
588  cout << "shape1 = " << shape1 << endl;
589  cout << "shape2 = " << 1.0 - (shape0 + shape1) << endl;
590 
591  // Return 2 local (area) coordinates and later generate the third
592  // from the fact that they sum to 1 (ie: shape0 + shape1 + shape2 = 1).
593 
594  xlocal_coords[0] = shape0;
595  xlocal_coords[1] = shape1;
596 
597  // Return non null only if the search point is inside the element
598  // or on the element boundary.
599 
600  //if((shape0 >= 0.0) && (shape1 >= 0.0) && (shape2 >= 0.0))
601  // result = xlocal_coords;
602 
603  // Postconditions:
604 
605  ensure(invariant());
606 
607  //ensure(result != 0 ? result == xlocal_coords : true);
608 
610 
611  // ensure(unexecutable(result != 0
612  // ? value_at_coord_ua(xdofs, xdofs_ub, xcoords, xcoords_ub) == xvalue
613  // : true));
614 
615  //return result;
616 
617 }
618 
619 // ===========================================================
620 // ANY FACET
621 // ===========================================================
622 
626 clone() const
627 {
628  quadratic_2d* result;
629 
630  // Preconditions:
631 
632  // Body:
633 
634  result = new quadratic_2d();
635 
636  // Postconditions:
637 
638  ensure(result != 0);
639  ensure(is_same_type(result));
640  //ensure(invariant());
641  ensure(result->invariant());
642 
643  return result;
644 }
645 
650 {
651  // Preconditions:
652 
653  require(is_ancestor_of(&xother));
654 
655  // Body:
656 
657  not_implemented();
658 
659  // Postconditions:
660 
661  ensure(invariant());
662 
663  return *this;
664 }
665 
669 operator=(const quadratic_2d& xother)
670 {
671 
672  // Preconditions:
673 
674  require(is_ancestor_of(&xother));
675 
676  // Body:
677 
678  not_implemented();
679 
680  // Postconditions:
681 
682  ensure(invariant());
683 
684  // Exit:
685 
686  return *this;
687 }
688 
690 bool
692 invariant() const
693 {
694  bool result = true;
695 
696  // Preconditions:
697 
698  // Body:
699 
700  // Must satisfy base class invariant.
701 
702  result = result && linear_fcn_space::invariant();
703 
704  if(invariant_check())
705  {
706  // Prevent recursive calls to invariant.
707 
708  disable_invariant_check();
709 
710  invariance(basis_values() != 0);
711 
712  // Finished, turn invariant checking back on.
713 
714  enable_invariant_check();
715  }
716 
717  // Postconditions:
718 
719  return result;
720 }
721 
723 bool
725 is_ancestor_of(const any* xother) const
726 {
727 
728  // Preconditions:
729 
730  require(xother != 0);
731 
732  // Body:
733 
734  // True if other conforms to this
735 
736  bool result = dynamic_cast<const quadratic_2d*>(xother) != 0;
737 
738  // Postconditions:
739 
740  return result;
741 
742 }
743 
744 
745 // ===========================================================
746 // PRIVATE MEMBERS
747 // ===========================================================
748 
virtual void basis_derivs_at_coord(const dof_type xlocal_coords[], size_type xlocal_coords_ub)
Computes the value of the derivatives of each basis function at local coordinates xlocal_coords...
virtual void coord_at_value(const dof_type xdofs[], size_type xdofs_ub, const dof_type xglobal_coords[], size_type xglobal_coord_ub, dof_type xlocal_coords[], size_type xlocal_coords_ub) const
The local coordinates of a point at which the field has the value xvalue. The dofs are assumed to be ...
virtual value_type volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
Volume for specified coordinate dofs xcoord_dofs and fiber space dimension xdf.
virtual void gauss_point(pod_index_type xindex, coord_type xresult[], size_type xresult_ub)
The local coordinates of the gauss point with index xindex.
virtual ~quadratic_2d()
Destructor.
Definition: quadratic_2d.cc:74
STL namespace.
virtual int dl() const
The dimension of this function space.
Definition: quadratic_2d.cc:94
sec_vd_dof_type dof_type
The type of degree of freedom.
virtual quadratic_2d * clone() const
Virtual constructor, creates a new instance of the same type as this.
virtual bool in_standard_domain(const dof_type xlocal_coords[], size_type xlocal_coords_ub) const
Return true if the specified local coordinates are in the "standard" domain; otherwise return false...
virtual void local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const
The local coordinates of the dof with local index xindex.
quadratic_2d()
Default constructor.
Definition: quadratic_2d.cc:35
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual void basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
Computes the value of each basis function at local coordinates xlocal_coord.
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
virtual value_type jacobian_determinant(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const coord_type xlocal_coords[], size_type xlocal_coords_ub)
Computes the the determinant of the jacobian matrix at local coordinates xlocal_coords with coordinat...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual void jacobian(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const dof_type xlocal_coords[], size_type xlocal_coords_ub)
Computes the the jacobian matrix at local coordinates xlocal_coords with coordinate dofs xcoord_dofs...
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
vd_value_type value_type
The type of component in the value; the scalar type in the range vector space.
A section evaluator using quadratic interpolation over a triangular 2D domain.
Definition: quadratic_2d.h:37
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual void dxi_local(size_type xlocal_coord_index, const dof_type xsource_dofs[], size_type xsource_dofs_ub, dof_type xresult_dofs[], size_type xresult_dofs_ub) const
First partial derivative of this with respect to local coordinate xlocal_coord_index.
virtual bool invariant() const
Class invariant.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual void integrate(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const dof_type xintegrands[], size_type xintegrands_ub, value_type xresult_integrals[], size_type xresult_integrals_ub)
Computes the value of the integral of the integrand array...
Namespace for the fiber_bundles component of the sheaf system.
virtual quadratic_2d & operator=(const section_evaluator &xother)
Assignment operator.