SheafSystem  0.0.0.0
uniform_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 // Implementation for class uniform_1d
18 
19 #include "SheafSystem/uniform_1d.h"
20 #include "SheafSystem/assert_contract.h"
21 #include "SheafSystem/std_limits.h"
22 
23 using namespace std;
24 using namespace fiber_bundle; // Workaround for MS C++ bug.
25 
26 // ===========================================================
27 // UNIFORM_1D FACET
28 // ===========================================================
29 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  _basis_values = _basis_value_buffer;
39  _basis_deriv_values = _basis_deriv_value_buffer;
40  _jacobian_values = _jacobian_value_buffer;
41 
42  // Postconditions:
43 
44  ensure(invariant());
45 
46  return;
47 }
48 
51 uniform_1d(const uniform_1d& xother)
52 {
53  // Preconditions:
54 
55  // Body:
56 
57  _basis_values = _basis_value_buffer;
58  _basis_deriv_values = _basis_deriv_value_buffer;
59  _jacobian_values = _jacobian_value_buffer;
60 
61  // Postconditions:
62 
63  ensure(invariant());
64 
65  return;
66 }
67 
71 {
72  // Preconditions:
73 
74  // Body:
75 
76  // Postconditions:
77 
78  ensure(invariant());
79 
80  return;
81 }
82 
83 // ===========================================================
84 // LINEAR_FCN_SPACE FACET
85 // ===========================================================
86 
88 int
90 dl() const
91 {
92  int result;
93 
94  // Preconditions:
95 
96 
97  // Body:
98 
99  result = DL;
100 
101  // Postconditions:
102 
103  ensure(result == 2);
104 
105  // Exit:
106 
107  return result;
108 }
109 
111 void
113 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
114 {
115  // cout << "uniform_1d::basis_at_coord()" << endl;
116 
117  // Preconditions:
118 
119  require(xlocal_coord != 0);
120  require(xlocal_coord_ub >= db());
121  require(basis_values() != 0);
122 
123  // Body:
124 
125  // Interpolate the field value at the global coordinates.
126 
127  dof_type u = xlocal_coord[0];
128 
129  _basis_values[0] = 0.5*(1.0 - u);
130  _basis_values[1] = 0.5*(1.0 + u);
131 
132  // Postconditions:
133 
134  ensure(invariant());
135 
136 }
137 
139 void
141 basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
142 {
143  // Preconditions:
144 
145  require(xlocal_coord != 0);
146  require(xlocal_coord_ub >= db());
147  require(basis_deriv_values() != 0);
148 
149  // Body:
150 
151  _basis_deriv_values[0] = -0.5;
152  _basis_deriv_values[1] = 0.5;
153 
154  // Postconditions:
155 
156  ensure(invariant());
157 
158  // Exit:
159 
160  return;
161 }
162 
163 // ===========================================================
164 // INTEGRABLE_SECTION_EVALUATOR FACET
165 // ===========================================================
166 
170 jacobian_determinant(const dof_type xcoord_dofs[],
171  size_type xcoord_dofs_ub,
172  size_type xdf,
173  const coord_type xlocal_coords[],
174  size_type xlocal_coords_ub)
175 {
176  // Preconditions:
177 
178  require(xcoord_dofs != 0);
179  require(xcoord_dofs_ub >= db()*dl());
180  require(xlocal_coords != 0);
181  require(xlocal_coords_ub >= db());
182  //require(jacobian_values() != 0);
183 
184  // Body:
185 
186  not_implemented();
187 
189 
190  value_type result = 0.0;
191 
192  // Postconditions:
193 
194  ensure(invariant());
195 
196  // Exit:
197 
198  return result;
199 }
200 
204 volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
205 {
206  // Preconditions:
207 
208  require(xcoord_dofs != 0);
209  require(xcoord_dofs_ub >= dl()*db());
210  require(xdf == 2 || xdf == 2 || xdf == 3);
211 
212  // Body:
213 
215 
216  not_implemented();
217 
218  value_type result = 0.0;
219 
220  // Postconditions:
221 
222  ensure(invariant());
223 
224  // Exit:
225 
226  return result;
227 }
228 
230 void
232 integrate(const dof_type xcoord_dofs[],
233  size_type xcoord_dofs_ub,
234  size_type xdf,
235  const dof_type xintegrands[],
236  size_type xintegrands_ub,
237  value_type xresult_integrals[],
238  size_type xresult_integrals_ub)
239 {
241 
242  // Preconditions:
243 
244  require(xcoord_dofs != 0);
245  require(xcoord_dofs_ub >= dl()*db());
246  require(xintegrands != 0);
247  require(xintegrands_ub >= dl());
248  require(xresult_integrals != 0);
249  require(xresult_integrals_ub > 0);
250 
251  // Body:
252 
253  not_implemented();
254 
256 
257  // Postconditions:
258 
259  ensure(invariant());
260 
261  // Exit:
262 
263  return;
264 }
265 
267 void
269 integrate(const dof_type xcoord_dofs[],
270  size_type xcoord_dofs_ub,
271  size_type xdf,
272  const dof_type xintegrand,
273  value_type xresult_integrals[],
274  size_type xresult_integrals_ub)
275 {
277 
278  // Preconditions:
279 
280  require(xcoord_dofs != 0);
281  require(xcoord_dofs_ub >= dl()*db());
282  require(xresult_integrals != 0);
283  require(xresult_integrals_ub >= dl());
284 
285  // Body:
286 
287  not_implemented();
288 
290 
291  // Postconditions:
292 
293  ensure(invariant());
294 
295  // Exit:
296 
297  return;
298 }
299 
301 void
304  coord_type xresult[],
305  size_type xresult_ub)
306 {
307  // Preconditions:
308 
309  require((0 <= xindex) && (xindex < dof_ct()));
310  require(xresult_ub >= db());
311 
312  // Body:
313 
314  not_implemented();
315 
317 
318  // Postconditions:
319 
320  ensure(in_standard_domain(xresult, xresult_ub));
321  ensure(invariant());
322 
323  // Exit:
324 
325  return;
326 }
327 
328 // ===========================================================
329 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
330 // ===========================================================
331 
333 void
335 dxi_local(size_type xlocal_coord_index,
336  const dof_type xsource_dofs[],
337  size_type xsource_dofs_ub,
338  dof_type xresult_dofs[],
339  size_type xresult_dofs_ub) const
340 {
341  // Preconditions:
342 
343  require(xlocal_coord_index < db());
344  require(xsource_dofs != 0);
345  //require(xsource_dofs_ub >= dof_ct());
346  require(xresult_dofs != 0);
347  //require(xresult_dofs_ub >= dof_ct());
348 
349  // Body:
350 
351 
352  xresult_dofs[0] = 0.5 * (xsource_dofs[1] - xsource_dofs[0]);
353 
354  // Postconditions:
355 
356  // Exit:
357 
358  return;
359 }
360 
362 void
364 jacobian(const dof_type xcoord_dofs[],
365  size_type xcoord_dofs_ub,
366  size_type xdf,
367  const dof_type xlocal_coords[],
368  size_type xlocal_coords_ub)
369 {
370  // Preconditions:
371 
372  require(xcoord_dofs != 0);
373  require(xcoord_dofs_ub >= db()*dl());
374  require(xlocal_coords != 0);
375  require(xlocal_coords_ub >= db());
376  require(jacobian_values() != 0);
377 
378  // Body:
379 
380  not_implemented();
381 
383 
384  // Postconditions:
385 
386  ensure(invariant());
387 
388  // Exit:
389 
390  return;
391 }
392 
393 // ===========================================================
394 // DOMAIN FACET
395 // ===========================================================
396 
398 int
400 db() const
401 {
402  int result;
403 
404  // Preconditions:
405 
406 
407  // Body:
408 
409  result = 1;
410 
411  // Postconditions:
412 
413  ensure(result == 1);
414 
415  // Exit:
416 
417  return result;
418 }
419 
420 
422 void
425  coord_type xresult[],
426  size_type xresult_ub) const
427 {
428  // Preconditions:
429 
430  require((0 <= xindex) && (xindex < dof_ct()));
431  require(xresult_ub >= db());
432 
433  // Body:
434 
435  static const coord_type lcoords[2] =
436  {
437  -1.0, 1.0
438  } ;
439 
440  xresult[0] = lcoords[xindex];
441 
442  // Postconditions:
443 
444  ensure(in_standard_domain(xresult, xresult_ub));
445 
446  // Exit:
447 
448  return;
449 }
450 
452 bool
454 in_standard_domain(const dof_type xlocal_coords[],
455  size_type xlocal_coords_ub) const
456 {
457  // Preconditions:
458 
459  require(xlocal_coords != 0);
460  require(xlocal_coords_ub >= 1);
461 
462  // Body:
463 
464  dof_type u = xlocal_coords[0];
465 
466  // "Extend" the bounds by the dof type epsilon (attempting
467  // to ensure that the boundary is included in the domain).
468 
469  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
470 
471  bool result = (u >= -one) && (u <= one);
472 
473  // Postconditions:
474 
475  // Exit:
476 
477  return result;
478 
479 }
480 
481 // ===========================================================
482 // EVALUATION FACET
483 // ===========================================================
484 
486 void
488 coord_at_value(const dof_type xdofs[],
489  size_type xdofs_ub,
490  const dof_type xglobal_coords[],
491  size_type xglobal_coord_ub,
492  dof_type xlocal_coords[],
493  size_type xlocal_coords_ub) const
494 {
495  // Preconditions:
496 
497  require(xdofs != 0);
498  require(xdofs_ub >= 2);
499  require(xglobal_coords != 0);
500  require(xglobal_coord_ub >= 1);
501  require(xlocal_coords != 0);
502  require(xlocal_coords_ub >= 1);
503 
504  // Body:
505 
506  // cout << "uniform_1d::coord_at_value()" << endl;
507 
508 
509  dof_type x0 = xdofs[0];
510  dof_type x1 = xdofs[1];
511 
512  dof_type x_global = xglobal_coords[0];
513 
514  // Solve for u.
515 
516  double xlength = x1 - x0;
517 
518  xlocal_coords[0] = (2.0*x_global - (x0 + x1)) / xlength;
519 
520  // Postconditions:
521 
522  ensure(invariant());
523 
524 }
525 
526 // ===========================================================
527 // ANY FACET
528 // ===========================================================
529 
530 
534 clone() const
535 {
536  uniform_1d* result;
537 
538  // Preconditions:
539 
540  // Body:
541 
542  result = new uniform_1d();
543 
544  // Postconditions:
545 
546  ensure(result != 0);
547  ensure(is_same_type(result));
548  //ensure(invariant());
549  ensure(result->invariant());
550 
551  return result;
552 }
553 
554 
559 {
560  // Preconditions:
561 
562  require(is_ancestor_of(&xother));
563 
564  // Body:
565 
566  not_implemented();
567 
568  // Postconditions:
569 
570  ensure(invariant());
571 
572  return *this;
573 }
574 
578 operator=(const uniform_1d& xother)
579 {
580 
581  // Preconditions:
582 
583  require(is_ancestor_of(&xother));
584 
585  // Body:
586 
587  not_implemented();
588 
589  // Postconditions:
590 
591  ensure(invariant());
592 
593  // Exit:
594 
595  return *this;
596 }
597 
599 bool
601 invariant() const
602 {
603  bool result = true;
604 
605  // Preconditions:
606 
607  // Body:
608 
609  // Must satisfy base class invariant.
610 
611  result = result && linear_fcn_space::invariant();
612 
613  if(invariant_check())
614  {
615  // Prevent recursive calls to invariant.
616 
617  disable_invariant_check();
618 
619  // Finished, turn invariant checking back on.
620 
621  enable_invariant_check();
622  }
623 
624  // Postconditions:
625 
626  return result;
627 }
628 
630 bool
632 is_ancestor_of(const any* xother) const
633 {
634 
635  // Preconditions:
636 
637  require(xother != 0);
638 
639  // Body:
640 
641  // True if other conforms to this
642 
643  bool result = dynamic_cast<const uniform_1d*>(xother) != 0;
644 
645  // Postconditions:
646 
647  return result;
648 
649 }
650 
651 // ===========================================================
652 // PRIVATE MEMBERS
653 // ===========================================================
654 
655 
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_1d.cc:364
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_1d.cc:204
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_1d.cc:335
STL namespace.
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_1d.cc:141
virtual int dl() const
The dimension of this function space.
Definition: uniform_1d.cc:90
sec_vd_dof_type dof_type
The type of degree of freedom.
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_1d.cc:303
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual uniform_1d * clone() const
Virtual constructor, creates a new instance of the same type as this.
Definition: uniform_1d.cc:534
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_1d.cc:170
uniform_1d()
Default constructor.
Definition: uniform_1d.cc:32
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
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_1d.cc:424
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.
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_1d.cc:113
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
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.
Definition: uniform_1d.cc:488
A section evaluator using linear interpolation over a 1D domain which is refined into a uniform mesh...
Definition: uniform_1d.h:39
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...
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_1d.cc:454
virtual uniform_1d & operator=(const section_evaluator &xother)
Assignment operator.
Definition: uniform_1d.cc:558
Namespace for the fiber_bundles component of the sheaf system.
virtual ~uniform_1d()
Destructor.
Definition: uniform_1d.cc:70
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
Definition: uniform_1d.cc:400
virtual bool invariant() const
Class invariant.
Definition: uniform_1d.cc:601
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
Definition: uniform_1d.cc:632