SheafSystem  0.0.0.0
uniform_3d.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 uniform_3d
19 
20 #include "SheafSystem/uniform_3d.h"
21 #include "SheafSystem/assert_contract.h"
22 #include "SheafSystem/std_limits.h"
23 
24 using namespace std;
25 using namespace fiber_bundle; // Workaround for MS C++ bug.
26 
27 // ===========================================================
28 // UNIFORM_3D FACET
29 // ===========================================================
30 
34 {
35  // Preconditions:
36 
37  // Body:
38 
39  _basis_values = _basis_value_buffer;
40  _basis_deriv_values = _basis_deriv_value_buffer;
41  _jacobian_values = _jacobian_value_buffer;
42 
43  // Postconditions:
44 
45  ensure(invariant());
46 
47  return;
48 }
49 
50 
53 uniform_3d(const uniform_3d& xother)
54 {
55  // Preconditions:
56 
57  // Body:
58 
59  _basis_values = _basis_value_buffer;
60  _basis_deriv_values = _basis_deriv_value_buffer;
61  _jacobian_values = _jacobian_value_buffer;
62 
63  // Postconditions:
64 
65  ensure(invariant());
66 
67  return;
68 }
69 
70 
74 {
75  // Preconditions:
76 
77  // Body:
78 
79  // Postconditions:
80 
81  ensure(invariant());
82 
83  return;
84 }
85 
86 // ===========================================================
87 // LINEAR_FCN_SPACE FACET
88 // ===========================================================
89 
91 int
93 dl() const
94 {
95  int result;
96 
97  // Preconditions:
98 
99 
100  // Body:
101 
102  result = DL;
103 
104  // Postconditions:
105 
106  ensure(result == 8);
107 
108  // Exit:
109 
110  return result;
111 }
112 
114 void
116 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
117 {
118 
119  // Preconditions:
120 
121  require(xlocal_coord != 0);
122  require(xlocal_coord_ub >= 3);
123 
124  // Body:
125 
126  // Interpolate the field value at the global coordinates.
127 
128  dof_type u = xlocal_coord[0];
129  dof_type v = xlocal_coord[1];
130  dof_type w = xlocal_coord[2];
131 
132  _basis_values[0] = 0.125*(1.0 - u)*(1.0 - v)*(1.0 - w);
133  _basis_values[1] = 0.125*(1.0 + u)*(1.0 - v)*(1.0 - w);
134  _basis_values[2] = 0.125*(1.0 + u)*(1.0 + v)*(1.0 - w);
135  _basis_values[3] = 0.125*(1.0 - u)*(1.0 + v)*(1.0 - w);
136 
137  _basis_values[4] = 0.125*(1.0 - u)*(1.0 - v)*(1.0 + w);
138  _basis_values[5] = 0.125*(1.0 + u)*(1.0 - v)*(1.0 + w);
139  _basis_values[6] = 0.125*(1.0 + u)*(1.0 + v)*(1.0 + w);
140  _basis_values[7] = 0.125*(1.0 - u)*(1.0 + v)*(1.0 + w);
141 
142  // Postconditions:
143 
144  ensure(invariant());
145 
146 }
147 
149 void
151 basis_derivs_at_coord(const dof_type xlocal_coords[],
152  size_type xlocal_coords_ub)
153 {
154  // Preconditions:
155 
156  require(xlocal_coords != 0);
157  require(xlocal_coords_ub >= db());
158  require(basis_deriv_values() != 0);
159 
160  // Body:
161 
162  // Evaluate the derivatives of the interpolation functions.
163  // The derivatives are interleaved (N,r[0], N,s[0], N,t[0],
164  // N,r[1], N,s[1], N,t[1], ...).
165 
166  double r = xlocal_coords[0];
167  double s = xlocal_coords[1];
168  double t = xlocal_coords[2];
169 
170  double rp = 1.0 + r;
171  double rm = 1.0 - r;
172  double sp = 1.0 + s;
173  double sm = 1.0 - s;
174  double tp = 1.0 + t;
175  double tm = 1.0 - t;
176 
177  double rmxsm = rm * sm;
178  double rpxsm = rp * sm;
179  double rpxsp = rp * sp;
180  double rmxsp = rm * sp;
181 
182  double rmxtm = rm * tm;
183  double rpxtm = rp * tm;
184  double rpxtp = rp * tp;
185  double rmxtp = rm * tp;
186 
187  double smxtm = sm * tm;
188  double spxtm = sp * tm;
189  double spxtp = sp * tp;
190  double smxtp = sm * tp;
191 
192  // Derivative with respect to r.
193 
194  _basis_deriv_value_buffer[ 0] = -smxtm;
195  _basis_deriv_value_buffer[ 3] = smxtm;
196  _basis_deriv_value_buffer[ 6] = spxtm;
197  _basis_deriv_value_buffer[ 9] = -spxtm;
198  _basis_deriv_value_buffer[12] = -smxtp;
199  _basis_deriv_value_buffer[15] = smxtp;
200  _basis_deriv_value_buffer[18] = spxtp;
201  _basis_deriv_value_buffer[21] = -spxtp;
202 
203  // Derivative with respect to s.
204 
205  _basis_deriv_value_buffer[ 1] = -rmxtm;
206  _basis_deriv_value_buffer[ 4] = -rpxtm;
207  _basis_deriv_value_buffer[ 7] = rpxtm;
208  _basis_deriv_value_buffer[10] = rmxtm;
209  _basis_deriv_value_buffer[13] = -rmxtp;
210  _basis_deriv_value_buffer[16] = -rpxtp;
211  _basis_deriv_value_buffer[19] = rpxtp;
212  _basis_deriv_value_buffer[22] = rmxtp;
213 
214  // Derivative with respect to t.
215 
216  _basis_deriv_value_buffer[ 2] = -rmxsm;
217  _basis_deriv_value_buffer[ 5] = -rpxsm;
218  _basis_deriv_value_buffer[ 8] = -rpxsp;
219  _basis_deriv_value_buffer[11] = -rmxsp;
220  _basis_deriv_value_buffer[14] = rmxsm;
221  _basis_deriv_value_buffer[17] = rpxsm;
222  _basis_deriv_value_buffer[20] = rpxsp;
223  _basis_deriv_value_buffer[23] = rmxsp;
224 
225  for(int i=0; i<24; i++)
226  {
227  _basis_deriv_value_buffer[i] *= 0.125;
228  }
229 
230  // Postconditions:
231 
232  ensure(invariant());
233 
234  // Exit:
235 
236  return;
237 }
238 
239 // ===========================================================
240 // INTEGRABLE_SECTION_EVALUATOR FACET
241 // ===========================================================
242 
246 jacobian_determinant(const dof_type xcoord_dofs[],
247  size_type xcoord_dofs_ub,
248  size_type xdf,
249  const coord_type xlocal_coords[],
250  size_type xlocal_coords_ub)
251 {
252  // Preconditions:
253 
254  require(xcoord_dofs != 0);
255  require(xcoord_dofs_ub >= db()*dl());
256  require(xlocal_coords != 0);
257  require(xlocal_coords_ub >= db());
258  //require(jacobian_values() != 0);
259 
260  // Body:
261 
262  not_implemented();
263 
265 
266  value_type result = 0.0;
267 
268  // Postconditions:
269 
270  ensure(invariant());
271 
272  // Exit:
273 
274  return result;
275 }
276 
280 volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
281 {
282  // Preconditions:
283 
284  require(xcoord_dofs != 0);
285  require(xcoord_dofs_ub >= dl()*db());
286  require(xdf == 2 || xdf == 2 || xdf == 3);
287 
288  // Body:
289 
291 
292  not_implemented();
293 
294  value_type result = 0.0;
295 
296  // Postconditions:
297 
298  ensure(invariant());
299 
300  // Exit:
301 
302  return result;
303 }
304 
305 
307 void
309 integrate(const dof_type xcoord_dofs[],
310  size_type xcoord_dofs_ub,
311  size_type xdf,
312  const dof_type xintegrands[],
313  size_type xintegrands_ub,
314  value_type xresult_integrals[],
315  size_type xresult_integrals_ub)
316 {
318 
319  // Preconditions:
320 
321  require(xcoord_dofs != 0);
322  require(xcoord_dofs_ub >= dl()*db());
323  require(xintegrands != 0);
324  require(xintegrands_ub >= dl());
325  require(xresult_integrals != 0);
326  require(xresult_integrals_ub > 0);
327 
328  // Body:
329 
330  not_implemented();
331 
333 
334  // Postconditions:
335 
336  ensure(invariant());
337 
338  // Exit:
339 
340  return;
341 }
342 
344 void
346 integrate(const dof_type xcoord_dofs[],
347  size_type xcoord_dofs_ub,
348  size_type xdf,
349  const dof_type xintegrand,
350  value_type xresult_integrals[],
351  size_type xresult_integrals_ub)
352 {
354 
355  // Preconditions:
356 
357  require(xcoord_dofs != 0);
358  require(xcoord_dofs_ub >= dl()*db());
359  require(xresult_integrals != 0);
360  require(xresult_integrals_ub >= dl());
361 
362  // Body:
363 
364  not_implemented();
365 
367 
368  // Postconditions:
369 
370  ensure(invariant());
371 
372  // Exit:
373 
374  return;
375 }
376 
378 void
381  coord_type xresult[],
382  size_type xresult_ub)
383 {
384  // Preconditions:
385 
386  require((0 <= xindex) && (xindex < dof_ct()));
387  require(xresult_ub >= db());
388 
389  // Body:
390 
391  not_implemented();
392 
394 
395  // Postconditions:
396 
397  ensure(in_standard_domain(xresult, xresult_ub));
398  ensure(invariant());
399 
400  // Exit:
401 
402  return;
403 }
404 
405 // ===========================================================
406 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
407 // ===========================================================
408 
410 void
412 dxi_local(size_type xlocal_coord_index,
413  const dof_type xsource_dofs[],
414  size_type xsource_dofs_ub,
415  dof_type xresult_dofs[],
416  size_type xresult_dofs_ub) const
417 {
418  // Preconditions:
419 
420  require(xlocal_coord_index < db());
421  require(xsource_dofs != 0);
422  require(xsource_dofs_ub >= 24);
423  require(xresult_dofs != 0);
424  //require(xresult_dofs_ub >= dof_ct());
425 
426  // Body:
427 
429 
430  not_implemented();
431 
432  // if(xlocal_coord_index == 0)
433  // {
434  // dof_type d_minus = 0.5 * (xsource_dofs[1] - xsource_dofs[0]);
435  // dof_type d_plus = 0.5 * (xsource_dofs[2] - xsource_dofs[3]);
436 
437  // xresult_dofs[0] = d_minus;
438  // xresult_dofs[1] = d_minus;
439 
440  // xresult_dofs[2] = d_plus;
441  // xresult_dofs[3] = d_plus;
442  // }
443  // else if(xlocal_coord_index == 1)
444  // {
445  // dof_type d_minus = 0.5 * (xsource_dofs[3] - xsource_dofs[0]);
446  // dof_type d_plus = 0.5 * (xsource_dofs[2] - xsource_dofs[1]);
447 
448  // xresult_dofs[0] = d_minus;
449  // xresult_dofs[3] = d_minus;
450 
451  // xresult_dofs[1] = d_plus;
452  // xresult_dofs[2] = d_plus;
453  // }
454  // else
455  // {
456  // dof_type d_minus = 0.5 * (xsource_dofs[3] - xsource_dofs[0]);
457  // dof_type d_plus = 0.5 * (xsource_dofs[2] - xsource_dofs[1]);
458 
459  // xresult_dofs[0] = d_minus;
460  // xresult_dofs[3] = d_minus;
461 
462  // xresult_dofs[1] = d_plus;
463  // xresult_dofs[2] = d_plus;
464  // }
465 
466 
467  // Postconditions:
468 
469  // Exit:
470 
471  return;
472 }
473 
475 void
477 jacobian(const dof_type xcoord_dofs[],
478  size_type xcoord_dofs_ub,
479  size_type xdf,
480  const dof_type xlocal_coords[],
481  size_type xlocal_coords_ub)
482 {
483  // Preconditions:
484 
485  require(xcoord_dofs != 0);
486  require(xcoord_dofs_ub >= db()*dl());
487  require(xlocal_coords != 0);
488  require(xlocal_coords_ub >= db());
489  require(jacobian_values() != 0);
490 
491  // Body:
492 
493  not_implemented();
494 
496 
497  // Postconditions:
498 
499  ensure(invariant());
500 
501  // Exit:
502 
503  return;
504 }
505 
506 // ===========================================================
507 // DOMAIN FACET
508 // ===========================================================
509 
511 int
513 db() const
514 {
515  int result;
516 
517  // Preconditions:
518 
519 
520  // Body:
521 
522  result = 3;
523 
524  // Postconditions:
525 
526  ensure(result == 3);
527 
528  // Exit:
529 
530  return result;
531 }
532 
533 
535 void
538  coord_type xresult[],
539  size_type xresult_ub) const
540 {
541  // Preconditions:
542 
543  require((0 <= xindex) && (xindex < dof_ct()));
544  require(xresult_ub >= db());
545 
546  // Body:
547 
548  static const coord_type lcoords[8][3] =
549  {
550  {
551  -1.0, -1.0, -1.0
552  },
553  { 1.0, -1.0, -1.0},
554  { 1.0, 1.0, -1.0},
555  {-1.0, 1.0, -1.0},
556  {-1.0, -1.0, 1.0},
557  { 1.0, -1.0, 1.0},
558  { 1.0, 1.0, 1.0},
559  {-1.0, 1.0, 1.0}
560  } ;
561 
562  xresult[0] = lcoords[xindex][0];
563  xresult[1] = lcoords[xindex][1];
564  xresult[2] = lcoords[xindex][2];
565 
566  // Postconditions:
567 
568  ensure(in_standard_domain(xresult, xresult_ub));
569 
570  // Exit:
571 
572  return;
573 }
574 
576 bool
578 in_standard_domain(const dof_type xlocal_coords[],
579  size_type xlocal_coords_ub) const
580 {
581  // Preconditions:
582 
583  require(xlocal_coords != 0);
584  require(xlocal_coords_ub >= 3);
585 
586  // Body:
587 
588  dof_type u = xlocal_coords[0];
589  dof_type v = xlocal_coords[1];
590  dof_type w = xlocal_coords[2];
591 
592  // "Extend" the bounds by the dof type epsilon (attempting
593  // to ensure that the boundary is included in the domain).
594 
595  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
596 
597  bool result =
598  (u >= -one) && (u <= one) &&
599  (v >= -one) && (v <= one) &&
600  (w >= -one) && (w <= one);
601 
602  // Postconditions:
603 
604  // Exit:
605 
606  return result;
607 
608 }
609 
610 // ===========================================================
611 // EVALUATION FACET
612 // ===========================================================
613 
615 void
617 coord_at_value(const dof_type xdofs[],
618  size_type xdofs_ub,
619  const dof_type xglobal_coords[],
620  size_type xglobal_coord_ub,
621  dof_type xlocal_coords[],
622  size_type xlocal_coords_ub) const
623 {
624  // Preconditions:
625 
626  require(xdofs != 0);
627  require(xdofs_ub >= 24);
628  require(xglobal_coords != 0);
629  require(xglobal_coord_ub >= 3);
630  require(xlocal_coords != 0);
631  require(xlocal_coords_ub >= 3);
632 
633  // Body:
634 
635  // The dofs are assumed to be interleaved (x0, y0, z0, x1, y1, z0, ...).
636 
637  dof_type x0 = xdofs[0];
638  dof_type y0 = xdofs[1];
639  dof_type z0 = xdofs[2];
640 
641  // dof_type x1 = xdofs[3];
642  // dof_type y1 = xdofs[4];
643  // dof_type z1 = xdofs[5];
644 
645  // dof_type x2 = xdofs[6];
646  // dof_type y2 = xdofs[7];
647  // dof_type z2 = xdofs[8];
648 
649  // dof_type x3 = xdofs[9];
650  // dof_type y3 = xdofs[10];
651  // dof_type z3 = xdofs[11];
652 
653  // dof_type x4 = xdofs[12];
654  // dof_type y4 = xdofs[13];
655  // dof_type z4 = xdofs[14];
656 
657  // dof_type x5 = xdofs[15];
658  // dof_type y5 = xdofs[16];
659  // dof_type z5 = xdofs[17];
660 
661  dof_type x6 = xdofs[18];
662  dof_type y6 = xdofs[19];
663  dof_type z6 = xdofs[20];
664 
665  // dof_type x7 = xdofs[21];
666  // dof_type y7 = xdofs[22];
667  // dof_type z7 = xdofs[23];
668 
669  dof_type x_global = xglobal_coords[0];
670  dof_type y_global = xglobal_coords[1];
671  dof_type z_global = xglobal_coords[2];
672 
673  // Solve for u.
674 
675  double xlength = x6 - x0;
676 
677  xlocal_coords[0] = (2.0*x_global - (x0 + x6)) / xlength;
678 
679  // Solve for v.
680 
681  double ylength = y6 - y0;
682 
683  xlocal_coords[1] = (2.0*y_global - (y0 + y6)) / ylength;
684 
685  // Solve for v.
686 
687  double zlength = z6 - z0;
688 
689  xlocal_coords[2] = (2.0*z_global - (z0 + z6)) / zlength;
690 
691  // Postconditions:
692 
693  ensure(invariant());
694 
695 }
696 
697 // ===========================================================
698 // ANY FACET
699 // ===========================================================
700 
704 clone() const
705 {
706  uniform_3d* result;
707 
708  // Preconditions:
709 
710  // Body:
711 
712  result = new uniform_3d();
713 
714  // Postconditions:
715 
716  ensure(result != 0);
717  ensure(is_same_type(result));
718  //ensure(invariant());
719  ensure(result->invariant());
720 
721  return result;
722 }
723 
724 
729 {
730  // Preconditions:
731 
732  require(is_ancestor_of(&xother));
733 
734  // Body:
735 
736  not_implemented();
737 
738  // Postconditions:
739 
740  ensure(invariant());
741 
742  return *this;
743 }
744 
748 operator=(const uniform_3d& xother)
749 {
750 
751  // Preconditions:
752 
753  require(is_ancestor_of(&xother));
754 
755  // Body:
756 
757  not_implemented();
758 
759  // Postconditions:
760 
761  ensure(invariant());
762 
763  // Exit:
764 
765  return *this;
766 }
767 
769 bool
771 invariant() const
772 {
773  bool result = true;
774 
775  // Preconditions:
776 
777  // Body:
778 
779  // Must satisfy base class invariant.
780 
781  result = result && linear_fcn_space::invariant();
782 
783  if(invariant_check())
784  {
785  // Prevent recursive calls to invariant.
786 
787  disable_invariant_check();
788 
789  invariance(basis_values() != 0);
790 
791  // Finished, turn invariant checking back on.
792 
793  enable_invariant_check();
794  }
795 
796  // Postconditions:
797 
798  return result;
799 }
800 
802 bool
804 is_ancestor_of(const any* xother) const
805 {
806 
807  // Preconditions:
808 
809  require(xother != 0);
810 
811  // Body:
812 
813  // True if other conforms to this
814 
815  bool result = dynamic_cast<const uniform_3d*>(xother) != 0;
816 
817  // Postconditions:
818 
819  return result;
820 
821 }
822 
823 // ===========================================================
824 // PRIVATE MEMBERS
825 // ===========================================================
826 
827 
828 
829 
uniform_3d()
Default constructor.
Definition: uniform_3d.cc:33
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.
Definition: uniform_3d.cc:537
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.
Definition: uniform_3d.cc:116
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...
Definition: uniform_3d.cc:477
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...
Definition: uniform_3d.cc:246
STL namespace.
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
Definition: uniform_3d.cc:513
A section evaluator using trilinear interpolation over a cubic 3D domain. Intended for use with unifo...
Definition: uniform_3d.h:39
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...
sec_vd_dof_type dof_type
The type of degree of freedom.
A general tensor of "degree" p and given "variance" over an abstract vector space.
Definition: tp.h:253
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...
Definition: uniform_3d.cc:151
Abstract base class with useful features for all objects.
Definition: any.h:39
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.
Definition: uniform_3d.cc:380
virtual uniform_3d * clone() const
Virtual constructor, creates a new instance of the same type as this.
Definition: uniform_3d.cc:704
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...
Definition: uniform_3d.cc:578
virtual uniform_3d & operator=(const section_evaluator &xother)
Assignment operator.
Definition: uniform_3d.cc:728
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual ~uniform_3d()
Destructor.
Definition: uniform_3d.cc:73
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
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.
Definition: uniform_3d.cc:280
vd_value_type value_type
The type of component in the value; the scalar type in the range vector space.
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.
Definition: uniform_3d.cc:804
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool invariant() const
Class invariant.
Definition: uniform_3d.cc:771
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.
Definition: uniform_3d.cc:412
virtual int dl() const
The dimension of this function space.
Definition: uniform_3d.cc:93
Namespace for the fiber_bundles component of the sheaf system.
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 ...
Definition: uniform_3d.cc:617