SheafSystem  0.0.0.0
uniform_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 uniform_2d
19 
20 #include "SheafSystem/uniform_2d.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_2D 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_2d(const uniform_2d& 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 
73 {
74  // Preconditions:
75 
76  // Body:
77 
78  // Postconditions:
79 
80  ensure(invariant());
81 
82  return;
83 }
84 
85 // ===========================================================
86 // LINEAR_FCN_SPACE FACET
87 // ===========================================================
88 
90 int
92 dl() const
93 {
94  int result;
95 
96  // Preconditions:
97 
98 
99  // Body:
100 
101  result = DL;
102 
103  // Postconditions:
104 
105  ensure(result == 4);
106 
107  // Exit:
108 
109  return result;
110 }
111 
112 // BILINEAR_2D INTERFACE
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 
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 
131  _basis_values[0] = 0.25*(1.0 - u)*(1.0 - v);
132  _basis_values[1] = 0.25*(1.0 + u)*(1.0 - v);
133  _basis_values[2] = 0.25*(1.0 + u)*(1.0 + v);
134  _basis_values[3] = 0.25*(1.0 - u)*(1.0 + v);
135 
136  // Postconditions:
137 
138  ensure(invariant());
139 
140 }
141 
143 void
145 basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
146 {
147  // Preconditions:
148 
149  require(xlocal_coord != 0);
150  require(xlocal_coord_ub >= db());
151  require(basis_deriv_values() != 0);
152 
153  // Body:
154 
155  double r = xlocal_coord[0];
156  double s = xlocal_coord[1];
157 
158  double quartr = 0.25 * r;
159  double quarts = 0.25 * s;
160 
161  double rp = 0.25 + quartr;
162  double rm = 0.25 - quartr;
163  double sp = 0.25 + quarts;
164  double sm = 0.25 - quarts;
165 
166  // Derivative with respect to r.
167 
168  _basis_deriv_value_buffer[0] = -sm;
169  _basis_deriv_value_buffer[2] = sm;
170  _basis_deriv_value_buffer[4] = sp;
171  _basis_deriv_value_buffer[6] = -sp;
172 
173  // Derivative with respect to s.
174 
175  _basis_deriv_value_buffer[1] = -rm;
176  _basis_deriv_value_buffer[3] = -rp;
177  _basis_deriv_value_buffer[5] = rp;
178  _basis_deriv_value_buffer[7] = rm;
179 
180  // Postconditions:
181 
182  ensure(invariant());
183 
184  // Exit:
185 
186  return;
187 }
188 
189 // ===========================================================
190 // INTEGRABLE_SECTION_EVALUATOR FACET
191 // ===========================================================
192 
196 jacobian_determinant(const dof_type xcoord_dofs[],
197  size_type xcoord_dofs_ub,
198  size_type xdf,
199  const coord_type xlocal_coords[],
200  size_type xlocal_coords_ub)
201 {
202  // Preconditions:
203 
204  require(xcoord_dofs != 0);
205  require(xcoord_dofs_ub >= db()*dl());
206  require(xlocal_coords != 0);
207  require(xlocal_coords_ub >= db());
208  //require(jacobian_values() != 0);
209 
210  // Body:
211 
212  not_implemented();
213 
215 
216  value_type result = 0.0;
217 
218  // Postconditions:
219 
220  ensure(invariant());
221 
222  // Exit:
223 
224  return result;
225 }
226 
230 volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
231 {
232  // Preconditions:
233 
234  require(xcoord_dofs != 0);
235  require(xcoord_dofs_ub >= dl()*db());
236  require(xdf == 2 || xdf == 2 || xdf == 3);
237 
238  // Body:
239 
241 
242  not_implemented();
243 
244  value_type result = 0.0;
245 
246  // Postconditions:
247 
248  ensure(invariant());
249 
250  // Exit:
251 
252  return result;
253 }
254 
256 void
258 integrate(const dof_type xcoord_dofs[],
259  size_type xcoord_dofs_ub,
260  size_type xdf,
261  const dof_type xintegrands[],
262  size_type xintegrands_ub,
263  value_type xresult_integrals[],
264  size_type xresult_integrals_ub)
265 {
267 
268  // Preconditions:
269 
270  require(xcoord_dofs != 0);
271  require(xcoord_dofs_ub >= dl()*db());
272  require(xintegrands != 0);
273  require(xintegrands_ub >= dl());
274  require(xresult_integrals != 0);
275  require(xresult_integrals_ub > 0);
276 
277  // Body:
278 
279  not_implemented();
280 
282 
283  // Postconditions:
284 
285  ensure(invariant());
286 
287  // Exit:
288 
289  return;
290 }
291 
293 void
295 integrate(const dof_type xcoord_dofs[],
296  size_type xcoord_dofs_ub,
297  size_type xdf,
298  const dof_type xintegrand,
299  value_type xresult_integrals[],
300  size_type xresult_integrals_ub)
301 {
303 
304  // Preconditions:
305 
306  require(xcoord_dofs != 0);
307  require(xcoord_dofs_ub >= dl()*db());
308  require(xresult_integrals != 0);
309  require(xresult_integrals_ub >= dl());
310 
311  // Body:
312 
313  not_implemented();
314 
316 
317  // Postconditions:
318 
319  ensure(invariant());
320 
321  // Exit:
322 
323  return;
324 }
325 
327 void
330  coord_type xresult[],
331  size_type xresult_ub)
332 {
333  // Preconditions:
334 
335  require((0 <= xindex) && (xindex < dof_ct()));
336  require(xresult_ub >= db());
337 
338  // Body:
339 
340  not_implemented();
341 
343 
344  // Postconditions:
345 
346  ensure(in_standard_domain(xresult, xresult_ub));
347  ensure(invariant());
348 
349  // Exit:
350 
351  return;
352 }
353 
354 // ===========================================================
355 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
356 // ===========================================================
357 
359 void
361 dxi_local(size_type xlocal_coord_index,
362  const dof_type xsource_dofs[],
363  size_type xsource_dofs_ub,
364  dof_type xresult_dofs[],
365  size_type xresult_dofs_ub) const
366 {
367  // Preconditions:
368 
369  require(xlocal_coord_index < db());
370  require(xsource_dofs != 0);
371  //require(xsource_dofs_ub >= dof_ct());
372  require(xresult_dofs != 0);
373  //require(xresult_dofs_ub >= dof_ct());
374 
375  // Body:
376 
377  if(xlocal_coord_index == 0)
378  {
379  dof_type d_minus = 0.5 * (xsource_dofs[1] - xsource_dofs[0]);
380  dof_type d_plus = 0.5 * (xsource_dofs[2] - xsource_dofs[3]);
381 
382  xresult_dofs[0] = d_minus;
383  xresult_dofs[1] = d_minus;
384 
385  xresult_dofs[2] = d_plus;
386  xresult_dofs[3] = d_plus;
387  }
388  else
389  {
390  dof_type d_minus = 0.5 * (xsource_dofs[3] - xsource_dofs[0]);
391  dof_type d_plus = 0.5 * (xsource_dofs[2] - xsource_dofs[1]);
392 
393  xresult_dofs[0] = d_minus;
394  xresult_dofs[3] = d_minus;
395 
396  xresult_dofs[1] = d_plus;
397  xresult_dofs[2] = d_plus;
398  }
399 
400  // Postconditions:
401 
402  // Exit:
403 
404  return;
405 }
406 
408 void
410 jacobian(const dof_type xcoord_dofs[],
411  size_type xcoord_dofs_ub,
412  size_type xdf,
413  const dof_type xlocal_coords[],
414  size_type xlocal_coords_ub)
415 {
416  // Preconditions:
417 
418  require(xcoord_dofs != 0);
419  require(xcoord_dofs_ub >= db()*dl());
420  require(xlocal_coords != 0);
421  require(xlocal_coords_ub >= db());
422  require(jacobian_values() != 0);
423 
424  // Body:
425 
426  not_implemented();
427 
429 
430  // Postconditions:
431 
432  ensure(invariant());
433 
434  // Exit:
435 
436  return;
437 }
438 
439 // ===========================================================
440 // DOMAIN FACET
441 // ===========================================================
442 
444 int
446 db() const
447 {
448  int result;
449 
450  // Preconditions:
451 
452 
453  // Body:
454 
455  result = 2;
456 
457  // Postconditions:
458 
459  ensure(result == 2);
460 
461  // Exit:
462 
463  return result;
464 }
465 
466 
468 void
471  coord_type xresult[],
472  size_type xresult_ub) const
473 {
474  // Preconditions:
475 
476  require((0 <= xindex) && (xindex < dof_ct()));
477  require(xresult_ub >= db());
478 
479  // Body:
480 
481  static const coord_type lcoords[4][2] =
482  {
483  {
484  -1, -1
485  }
486  , {1, -1}, {1, 1}, {-1, 1}
487  } ;
488 
489  xresult[0] = lcoords[xindex][0];
490  xresult[1] = lcoords[xindex][1];
491 
492  // Postconditions:
493 
494  ensure(in_standard_domain(xresult, xresult_ub));
495 
496  // Exit:
497 
498  return;
499 }
500 
501 
503 bool
505 in_standard_domain(const dof_type xlocal_coords[],
506  size_type xlocal_coords_ub) const
507 {
508  // Preconditions:
509 
510  require(xlocal_coords != 0);
511  require(xlocal_coords_ub >= 2);
512 
513  // Body:
514 
515  dof_type u = xlocal_coords[0];
516  dof_type v = xlocal_coords[1];
517 
518  // "Extend" the bounds by the dof type epsilon (attempting
519  // to ensure that the boundary is included in the domain).
520 
521  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
522 
523  bool result = (u >= -one) && (u <= one) && (v >= -one) && (v <= one);
524 
525  // Postconditions:
526 
527  // Exit:
528 
529  return result;
530 
531 }
532 
533 // ===========================================================
534 // EVALUATION FACET
535 // ===========================================================
536 
538 void
540 coord_at_value(const dof_type xdofs[],
541  size_type xdofs_ub,
542  const dof_type xglobal_coords[],
543  size_type xglobal_coord_ub,
544  dof_type xlocal_coords[],
545  size_type xlocal_coords_ub) const
546 {
547  // Preconditions:
548 
549  require(xdofs != 0);
550  require(xdofs_ub >= 8);
551  require(xglobal_coords != 0);
552  require(xglobal_coord_ub >= 2);
553  require(xlocal_coords != 0);
554  require(xlocal_coords_ub >= 2);
555 
556  // Body:
557 
558  //cout << "uniform_2d::coord_at_value()" << endl;
559 
560  // The dofs are assumed to be interleaved (x0, y0, x1, y1, ...).
561 
562  dof_type x0 = xdofs[0];
563  //dof_type x1 = xdofs[2];
564  dof_type x2 = xdofs[4];
565  //dof_type x3 = xdofs[6];
566 
567  dof_type y0 = xdofs[1];
568  //dof_type y1 = xdofs[3];
569  dof_type y2 = xdofs[5];
570  //dof_type y3 = xdofs[7];
571 
572  dof_type x_global = xglobal_coords[0];
573  dof_type y_global = xglobal_coords[1];
574 
575  // Solve for u.
576 
577  double xlength = x2 - x0;
578 
579  xlocal_coords[0] = (2.0*x_global - (x0 + x2)) / xlength;
580 
581  // Solve for v.
582 
583  double ylength = y2 - y0;
584 
585  xlocal_coords[1] = (2.0*y_global - (y0 + y2)) / ylength;
586 
587  // Postconditions:
588 
589  ensure(invariant());
590 
591 }
592 
593 // ===========================================================
594 // ANY FACET
595 // ===========================================================
596 
600 clone() const
601 {
602  uniform_2d* result;
603 
604  // Preconditions:
605 
606  // Body:
607 
608  result = new uniform_2d();
609 
610  // Postconditions:
611 
612  ensure(result != 0);
613  ensure(is_same_type(result));
614  //ensure(invariant());
615  ensure(result->invariant());
616 
617  return result;
618 }
619 
620 
625 {
626  // Preconditions:
627 
628  require(is_ancestor_of(&xother));
629 
630  // Body:
631 
632  not_implemented();
633 
634  // Postconditions:
635 
636  ensure(invariant());
637 
638  return *this;
639 }
640 
644 operator=(const uniform_2d& xother)
645 {
646 
647  // Preconditions:
648 
649  require(is_ancestor_of(&xother));
650 
651  // Body:
652 
653  not_implemented();
654 
655  // Postconditions:
656 
657  ensure(invariant());
658 
659  // Exit:
660 
661  return *this;
662 }
663 
664 
666 bool
668 invariant() const
669 {
670  bool result = true;
671 
672  // Preconditions:
673 
674  // Body:
675 
676  // Must satisfy base class invariant.
677 
678  result = result && linear_fcn_space::invariant();
679 
680  if(invariant_check())
681  {
682  // Prevent recursive calls to invariant.
683 
684  disable_invariant_check();
685 
686  // Finished, turn invariant checking back on.
687 
688  enable_invariant_check();
689  }
690 
691  // Postconditions:
692 
693  return result;
694 }
695 
697 bool
699 is_ancestor_of(const any* xother) const
700 {
701 
702  // Preconditions:
703 
704  require(xother != 0);
705 
706  // Body:
707 
708  // True if other conforms to this
709 
710  bool result = dynamic_cast<const uniform_2d*>(xother) != 0;
711 
712  // Postconditions:
713 
714  return result;
715 
716 }
717 
718 // ===========================================================
719 // PRIVATE MEMBERS
720 // ===========================================================
721 
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Definition: uniform_2d.cc:699
virtual ~uniform_2d()
Destructor.
Definition: uniform_2d.cc:72
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_2d.cc:361
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_2d.cc:470
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_2d.cc:196
virtual uniform_2d & operator=(const section_evaluator &xother)
Assignment operator.
Definition: uniform_2d.cc:624
STL namespace.
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_2d.cc:410
sec_vd_dof_type dof_type
The type of degree of freedom.
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_2d.cc:540
virtual int dl() const
The dimension of this function space.
Definition: uniform_2d.cc:92
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_2d.cc:329
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual uniform_2d * clone() const
Virtual constructor, creates a new instance of the same type as this.
Definition: uniform_2d.cc:600
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_2d.cc:230
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
uniform_2d()
Default constructor.
Definition: uniform_2d.cc:33
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
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_2d.cc:117
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 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_2d.cc:505
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_2d.cc:145
A section evaluator using bilinear interpolation over a square 2D domain. Intended for use with unifo...
Definition: uniform_2d.h:39
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool invariant() const
Class invariant.
Definition: uniform_2d.cc:668
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 int db() const
The base dimension; the dimension of the local coordinates (independent variable).
Definition: uniform_2d.cc:446