SheafSystem  0.0.0.0
quadratic_1d.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_1d
19 
20 #include "SheafSystem/quadratic_1d.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_1D 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_1d(const quadratic_1d& 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 
72 
73 
74 
78 {
79  // Preconditions:
80 
81  // Body:
82 
83  // Postconditions:
84 
85  ensure(invariant());
86 
87  return;
88 }
89 
90 // ===========================================================
91 // LINEAR_FCN_SPACE FACET
92 // ===========================================================
93 
95 int
97 dl() const
98 {
99  int result;
100 
101  // Preconditions:
102 
103 
104  // Body:
105 
106  result = DL;
107 
108  // Postconditions:
109 
110  ensure(result == 3);
111 
112  // Exit:
113 
114  return result;
115 }
116 
118 void
120 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
121 {
122  // Preconditions:
123 
124  require(xlocal_coord != 0);
125  require(xlocal_coord_ub >= db());
126 
127  // Body:
128 
129  // Evaluate the interpolation functions.
130 
131  dof_type r = xlocal_coord[0];
132 
133  _basis_values[0] = 0.5*r*(r - 1.0);
134  _basis_values[1] = 1.0 - r*r;
135  _basis_values[2] = 0.5*r*(r + 1.0);
136 
137  // Postconditions:
138 
139  ensure(invariant());
140 
141 }
142 
144 void
146 basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
147 {
148  // Preconditions:
149 
150  require(xlocal_coord != 0);
151  require(xlocal_coord_ub >= db());
152  require(basis_deriv_values() != 0);
153 
154  // Body:
155 
156  dof_type r = xlocal_coord[0];
157 
158  _basis_deriv_values[0] = r - 0.5;
159  _basis_deriv_values[1] = -2.0*r;
160  _basis_deriv_values[2] = r + 0.5;
161 
162  // Postconditions:
163 
164  ensure(invariant());
165 
166  // Exit:
167 
168  return;
169 }
170 
171 // ===========================================================
172 // INTEGRABLE_SECTION_EVALUATOR FACET
173 // ===========================================================
174 
178 jacobian_determinant(const dof_type xcoord_dofs[],
179  size_type xcoord_dofs_ub,
180  size_type xdf,
181  const coord_type xlocal_coords[],
182  size_type xlocal_coords_ub)
183 {
184  // Preconditions:
185 
186  require(xcoord_dofs != 0);
187  require(xcoord_dofs_ub >= db()*dl());
188  require(xlocal_coords != 0);
189  require(xlocal_coords_ub >= db());
190  //require(jacobian_values() != 0);
191 
192  // Body:
193 
194  not_implemented();
195 
197 
198  value_type result = 0.0;
199 
200  // Postconditions:
201 
202  ensure(invariant());
203 
204  // Exit:
205 
206  return result;
207 }
208 
212 volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
213 {
214  // Preconditions:
215 
217 
218  require(xcoord_dofs != 0);
219  require(xcoord_dofs_ub >= dl()*db());
220  require(xdf == 1 || xdf == 2 || xdf == 3);
221 
222  // Body:
223 
228 
229  // Sum the squares for the coordinate component differences.
230 
233 
234  double sum = 0.0;
235  int index = 0;
236  for(int i=0; i<xdf; ++i)
237  {
238  // The coordinate dofs are interlaced (x0, y0, z0, x1,...).
239 
240  double c0 = xcoord_dofs[index];
241  double c1 = xcoord_dofs[index+xdf];
242  double c10 = c1 - c0;
243  sum += c10*c10;
244 
245  index++;
246  }
247 
248  // Length is the square root of sum.
249 
250  value_type result = sqrt(sum);
251 
252  // Postconditions:
253 
254  ensure(invariant());
255  ensure(result >= 0.0);
256 
257  // Exit:
258 
259  return result;
260 }
261 
263 void
265 integrate(const dof_type xcoord_dofs[],
266  size_type xcoord_dofs_ub,
267  size_type xdf,
268  const dof_type xintegrands[],
269  size_type xintegrands_ub,
270  value_type xresult_integrals[],
271  size_type xresult_integrals_ub)
272 {
274 
275  // Preconditions:
276 
277  require(xcoord_dofs != 0);
278  require(xcoord_dofs_ub >= dl()*db());
279  require(xintegrands != 0);
280  require(xintegrands_ub >= dl());
281  require(xresult_integrals != 0);
282  require(xresult_integrals_ub > 0);
283 
284  // Body:
285 
286  not_implemented();
287 
289 
290  // Postconditions:
291 
292  ensure(invariant());
293 
294  // Exit:
295 
296  return;
297 }
298 
300 void
302 integrate(const dof_type xcoord_dofs[],
303  size_type xcoord_dofs_ub,
304  size_type xdf,
305  const dof_type xintegrand,
306  value_type xresult_integrals[],
307  size_type xresult_integrals_ub)
308 {
310 
311  // Preconditions:
312 
313  require(xcoord_dofs != 0);
314  require(xcoord_dofs_ub >= dl()*db());
315  require(xresult_integrals != 0);
316  require(xresult_integrals_ub >= dl());
317 
318  // Body:
319 
320  not_implemented();
321 
323 
324  // Postconditions:
325 
326  ensure(invariant());
327 
328  // Exit:
329 
330  return;
331 }
332 
334 void
337  coord_type xresult[],
338  size_type xresult_ub)
339 {
340  // Preconditions:
341 
342  require((0 <= xindex) && (xindex < dof_ct()));
343  require(xresult_ub >= db());
344 
345  // Body:
346 
347  not_implemented();
348 
350 
351  // Postconditions:
352 
353  ensure(in_standard_domain(xresult, xresult_ub));
354  ensure(invariant());
355 
356  // Exit:
357 
358  return;
359 }
360 
361 // ===========================================================
362 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
363 // ===========================================================
364 
366 void
368 dxi_local(size_type xlocal_coord_index,
369  const dof_type xsource_dofs[],
370  size_type xsource_dofs_ub,
371  dof_type xresult_dofs[],
372  size_type xresult_dofs_ub) const
373 {
374  // Preconditions:
375 
376  require(xlocal_coord_index < db());
377  require(xsource_dofs != 0);
378  require(xsource_dofs_ub >= 3);
379  require(xresult_dofs != 0);
380  require(xresult_dofs_ub >= 3);
381 
382  // Body:
383 
384  // The first derivative is linear for quadratic 1d.
385 
386  double u0 = xsource_dofs[0];
387  double u1 = xsource_dofs[1];
388  double u2 = xsource_dofs[2];
389 
390  xresult_dofs[0] = -1.5*u0 + 2.0*u1 - 0.5*u2;
391  xresult_dofs[1] = 0.5*(u2 - u0);
392  xresult_dofs[2] = 0.5*u0 - 2.0*u1 + 1.5*u2;
393 
394  // Postconditions:
395 
396  ensure(invariant());
397 
398  return;
399 }
400 
402 void
404 jacobian(const dof_type xcoord_dofs[],
405  size_type xcoord_dofs_ub,
406  size_type xdf,
407  const dof_type xlocal_coords[],
408  size_type xlocal_coords_ub)
409 {
410  // Preconditions:
411 
412  require(xcoord_dofs != 0);
413  require(xcoord_dofs_ub >= db()*dl());
414  require(xlocal_coords != 0);
415  require(xlocal_coords_ub >= db());
416  require(jacobian_values() != 0);
417 
418  // Body:
419 
420  not_implemented();
421 
423 
424  // Postconditions:
425 
426  ensure(invariant());
427 
428  // Exit:
429 
430  return;
431 }
432 
433 // ===========================================================
434 // DOMAIN FACET
435 // ===========================================================
436 
438 int
440 db() const
441 {
442  int result;
443 
444  // Preconditions:
445 
446 
447  // Body:
448 
449  result = 1;
450 
451  // Postconditions:
452 
453  ensure(result == 1);
454 
455  // Exit:
456 
457  return result;
458 }
459 
460 
462 void
464 local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const
465 {
466  // Preconditions:
467 
468  require((0 <= xindex) && (xindex < dof_ct()));
469  require(xresult_ub >= db());
470 
471  // Body:
472 
473  static const coord_type lcoords[3] =
474  {
475  -1.0 , 0.0, 1.0
476  } ;
477 
478  xresult[0] = lcoords[xindex];
479 
480  // Postconditions:
481 
482  ensure(in_standard_domain(xresult, xresult_ub));
483 
484  // Exit:
485 
486  return;
487 }
488 
490 bool
492 in_standard_domain(const dof_type xlocal_coords[],
493  size_type xlocal_coords_ub) const
494 {
495  // Preconditions:
496 
497  require(xlocal_coords != 0);
498  require(xlocal_coords_ub >= 1);
499 
500  // Body:
501 
502  dof_type u = xlocal_coords[0];
503 
504  // "Extend" the bounds by the dof type epsilon (attempting
505  // to ensure that the boundary is included in the domain).
506 
507  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
508 
509  bool result = (u >= -one) && (u <= one);
510 
511  // Postconditions:
512 
513  // Exit:
514 
515  return result;
516 
517 }
518 
519 // ===========================================================
520 // EVALUATION FACET
521 // ===========================================================
522 
524 void
526 coord_at_value(const dof_type xdofs[],
527  size_type xdofs_ub,
528  const dof_type xglobal_coords[],
529  size_type xglobal_coord_ub,
530  dof_type xlocal_coords[],
531  size_type xlocal_coords_ub) const
532 {
533  // Preconditions:
534 
535  require(xdofs != 0);
536  require(xdofs_ub >= 3);
537  require(xglobal_coords != 0);
538  require(xglobal_coord_ub >= 1);
539  require(xlocal_coords != 0);
540  require(xlocal_coords_ub >= 1);
541 
542  // Body:
543 
544  cout << "quadratic_1d::coord_at_value()" << endl;
545 
546  dof_type x0 = xdofs[0];
547  dof_type x1 = xdofs[1];
548  dof_type x2 = xdofs[2];
549 
550  dof_type x_global = xglobal_coords[0];
551 
552  cout << "##### x0 = " << x0 << endl;
553  cout << "##### x1 = " << x1 << endl;
554  cout << "##### x2 = " << x2 << endl;
555  cout << "##### x_global = " << x_global << endl;
556 
557 
558  // NOTE: a is always 0 for this element (2*x1 == x0 + x2).
559 
560  double a = x0 - 2.0*x1 + x2;
561  double b = x2 - x0;
562  double c = 2.0*(x1 - x_global);
563 
564  cout << "#### a = " << a << endl;
565  cout << "#### b = " << b << endl;
566  cout << "#### c = " << c << endl;
567 
568  //double local_coord = (-b + sqrt(b*b - 4.0*a*c))/(2.0*a);
569 
570  double local_coord = -c/b;
571 
572  cout << "#### local_coord = " << local_coord << endl;
573 
574  xlocal_coords[0] = local_coord;
575 
576  // Return non null only if the search point is inside the element
577  // or on the element boundary.
578 
579  // Postconditions:
580 
581  ensure(invariant());
582 
583  //ensure(result != 0 ? result == xlocal_coords : true);
584 
586 
587  // ensure(unexecutable(result != 0
588  // ? value_at_coord_ua(xdofs, xdofs_ub, xcoords, xcoords_ub) == xvalue
589  // : true));
590 
591  //return result;
592 
593 }
594 
595 // ===========================================================
596 // ANY FACET
597 // ===========================================================
598 
602 clone() const
603 {
604  quadratic_1d* result;
605 
606  // Preconditions:
607 
608  // Body:
609 
610  result = new quadratic_1d();
611 
612  // Postconditions:
613 
614  ensure(result != 0);
615  ensure(is_same_type(result));
616  //ensure(invariant());
617  ensure(result->invariant());
618 
619  return result;
620 }
621 
622 
627 {
628  // Preconditions:
629 
630  require(is_ancestor_of(&xother));
631 
632  // Body:
633 
634  not_implemented();
635 
636  // Postconditions:
637 
638  ensure(invariant());
639 
640  return *this;
641 }
642 
646 operator=(const quadratic_1d& xother)
647 {
648 
649  // Preconditions:
650 
651  require(is_ancestor_of(&xother));
652 
653  // Body:
654 
655  not_implemented();
656 
657  // Postconditions:
658 
659  ensure(invariant());
660 
661  // Exit:
662 
663  return *this;
664 }
665 
667 bool
669 invariant() const
670 {
671  bool result = true;
672 
673  // Preconditions:
674 
675  // Body:
676 
677  // Must satisfy base class invariant.
678 
679  result = result && linear_fcn_space::invariant();
680 
681  if(invariant_check())
682  {
683  // Prevent recursive calls to invariant.
684 
685  disable_invariant_check();
686 
687  invariance(basis_values() != 0);
688 
689  // Finished, turn invariant checking back on.
690 
691  enable_invariant_check();
692  }
693 
694  // Postconditions:
695 
696  return result;
697 }
698 
700 bool
702 is_ancestor_of(const any* xother) const
703 {
704 
705  // Preconditions:
706 
707  require(xother != 0);
708 
709  // Body:
710 
711  // True if other conforms to this
712 
713  bool result = dynamic_cast<const quadratic_1d*>(xother) != 0;
714 
715  // Postconditions:
716 
717  return result;
718 
719 }
720 
721 // ===========================================================
722 // PRIVATE MEMBERS
723 // ===========================================================
SHEAF_DLL_SPEC void sqrt(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute sqrt of x0 (sqrt(x0)) (pre-allocated version).
Definition: sec_at0.cc:1556
virtual quadratic_1d & operator=(const section_evaluator &xother)
Assignment operator.
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
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 ~quadratic_1d()
Destructor.
Definition: quadratic_1d.cc:77
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...
STL namespace.
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...
sec_vd_dof_type dof_type
The type of degree of freedom.
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 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 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...
Abstract base class with useful features for all objects.
Definition: any.h:39
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.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
quadratic_1d()
Default constructor.
Definition: quadratic_1d.cc:35
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
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 1D domain.
Definition: quadratic_1d.h:38
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
virtual int dl() const
The dimension of this function space.
Definition: quadratic_1d.cc:97
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
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.
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 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_1d * clone() const
Virtual constructor, creates a new instance of the same type as this.
Namespace for the fiber_bundles component of the sheaf system.
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 bool invariant() const
Class invariant.