SheafSystem  0.0.0.0
constant_fcn_space.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 constant_fcn_space
19 
20 #include "SheafSystem/constant_fcn_space.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/error_message.h"
24 #include "SheafSystem/std_limits.h"
25 
26 using namespace fiber_bundle; // Workaround for MS C++ bug.
27 
28 // ===========================================================
29 // CONSTANT_FCN_SPACE FACET
30 // ===========================================================
31 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  _basis_values = _basis_value_buffer;
41 
42  // Postconditions:
43 
44  ensure(invariant());
45 
46  return;
47 }
48 
49 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  _basis_values = _basis_value_buffer;
59 
60  // Postconditions:
61 
62  ensure(invariant());
63 
64  return;
65 }
66 
67 
68 
69 // ===========================================================
70 // LINEAR_FCN_SPACE FACET
71 // ===========================================================
72 
74 int
76 dl() const
77 {
78  int result;
79 
80  // Preconditions:
81 
82 
83  // Body:
84 
85  result = DL;
86 
87  // Postconditions:
88 
89  ensure(result == 1);
90 
91  // Exit:
92 
93  return result;
94 }
95 
96 void
98 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
99 {
100  // Preconditions:
101 
102  require(xlocal_coord != 0);
103  require(xlocal_coord_ub >= db());
104 
105  // Body:
106 
107  // Basis is 1, independent of the local coordinate.
108 
109  _basis_values[0] = 1.0;
110 
111  // Postconditions:
112 
113  ensure(invariant());
114 }
115 
117 void
119 basis_derivs_at_coord(const dof_type xlocal_coords[],
120  size_type xlocal_coords_ub)
121 {
122  // Preconditions:
123 
124  require(xlocal_coords != 0);
125  require(xlocal_coords_ub >= db());
126 
127  // Body:
128 
129  int ldb = db();
130 
131  if(ldb == 0)
132  {
136 
137  ldb = 1;
138  }
139 
140  int lct = ldb*dl();
141 
142  for(int i=0; i< lct; i++)
143  {
144  _basis_deriv_values[i] = 0.0;
145  }
146 
147  // Postconditions:
148 
149  ensure(invariant());
150 
151  // Exit:
152 
153  return;
154 }
155 
156 // ===========================================================
157 // INTEGRABLE_SECTION_EVALUATOR FACET
158 // ===========================================================
159 
161 void
163 integrate(const dof_type xcoord_dofs[],
164  size_type xcoord_dofs_ub,
165  size_type xdf,
166  const dof_type xintegrands[],
167  size_type xintegrands_ub,
168  value_type xresult_integrals[],
169  size_type xresult_integrals_ub)
170 {
172 
173  // Preconditions:
174 
175  require(xcoord_dofs != 0);
176  require(xcoord_dofs_ub >= 0);
177  require(xintegrands != 0);
178  require(xintegrands_ub >= 0);
179  require(xresult_integrals != 0);
180  require(xresult_integrals_ub > 0);
181 
182  // Body:
183 
184  value_type lvolume = volume(xcoord_dofs, xcoord_dofs_ub, xdf);
185 
186  for(size_type i=0; i<xintegrands_ub; ++i)
187  {
188  xresult_integrals[i] = xintegrands[i]*lvolume;
189  }
190 
191  // Postconditions:
192 
193  ensure(invariant());
194 
195  // Exit:
196 
197  return;
198 }
199 
201 void
204  coord_type xresult[],
205  size_type xresult_ub)
206 {
207  // Preconditions:
208 
209  require((0 <= xindex) && (xindex < dof_ct()));
210  require(xresult_ub >= db());
211 
212  // Body:
213 
214  int ldb = db();
215  for(size_type i=0; i<ldb; ++i)
216  {
217  xresult[i] = 0.0;
218  }
219 
220  // Postconditions:
221 
222  ensure(in_standard_domain(xresult, xresult_ub));
223  ensure(invariant());
224 
225  // Exit:
226 
227  return;
228 }
229 
230 // ===========================================================
231 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
232 // ===========================================================
233 
235 void
237 dxi_local(size_type xlocal_coord_index,
238  const dof_type xsource_dofs[],
239  size_type xsource_dofs_ub,
240  dof_type xresult_dofs[],
241  size_type xresult_dofs_ub) const
242 {
243  // Preconditions:
244 
245  require(xlocal_coord_index < db());
246  require(xsource_dofs != 0);
247  require(xsource_dofs_ub >= dl());
248  require((xsource_dofs_ub % dl()) == 0);
249  require(xresult_dofs != 0);
250  require(xresult_dofs_ub >= xsource_dofs_ub);
251 
252  // Body:
253 
254  // The 1st derivative is 0.
255 
256  for(size_type l=0; l<xsource_dofs_ub; ++l)
257  {
258  xresult_dofs[l] = 0.0;
259  }
260 
261  // Postconditions:
262 
263  // Exit:
264 
265  return;
266 }
267 
269 void
271 jacobian(const dof_type xcoord_dofs[],
272  size_type xcoord_dofs_ub,
273  size_type xdf,
274  const dof_type xlocal_coords[],
275  size_type xlocal_coords_ub)
276 {
277  // Preconditions:
278 
279  require(xcoord_dofs != 0);
280  require(xcoord_dofs_ub >= 0);
281  require(xlocal_coords != 0);
282  require(xlocal_coords_ub >= db());
283  require(jacobian_values() != 0);
284 
285  // Body:
286 
287  int ldj = xdf*db();
288  for(int i=0; i<ldj; ++i)
289  {
290  _jacobian_values[i] = 0.0;
291  }
292 
293  // Postconditions:
294 
295  ensure(invariant());
296 
297  // Exit:
298 
299  return;
300 }
301 
305 jacobian_determinant(const dof_type xcoord_dofs[],
306  size_type xcoord_dofs_ub,
307  size_type xdf,
308  const coord_type xlocal_coords[],
309  size_type xlocal_coords_ub)
310 {
311  // Preconditions:
312 
313  require(xcoord_dofs != 0);
314  require(xcoord_dofs_ub >= 0);
315  require(xlocal_coords != 0);
316  require(xlocal_coords_ub >= db());
317  require(jacobian_values() != 0);
318 
319  // Body:
320 
321  value_type result = 0.0;
322 
323  // Postconditions:
324 
325  ensure(invariant());
326 
327  // Exit:
328 
329  return result;
330 }
331 
332 // ===========================================================
333 // DOMAIN FACET
334 // ===========================================================
335 
336 // ===========================================================
337 // EVALUATION FACET
338 // ===========================================================
339 
341 void
343 value_at_coord(const dof_type xdofs[],
344  size_type xdofs_ub,
345  const dof_type xlocal_coords[],
346  size_type xlocal_coords_ub,
347  dof_type xresult[],
348  size_type xresult_ub) const
349 {
350  // Preconditions:
351 
352  require(xdofs != 0);
353  require(xdofs_ub >= dl()*xresult_ub);
354  require(unexecutable(xdofs must be interleaved));
355  require(xlocal_coords != 0);
356  require(xlocal_coords_ub >= db());
357  require(xresult != 0);
358  require(xresult_ub > 0);
359  require(basis_values() != 0);
360 
361 
362  // Body:
363 
364  for(size_type i=0; i<xresult_ub; ++i)
365  {
366  xresult[i] = xdofs[i];
367  }
368 
369  // Postconditions:
370 
371  ensure(invariant());
372 
373 }
374 
376 void
378 coord_at_value(const dof_type xdofs[],
379  size_type xdofs_ub,
380  const dof_type xglobal_coords[],
381  size_type xglobal_coord_ub,
382  dof_type xlocal_coords[],
383  size_type xlocal_coords_ub) const
384 {
385  // Preconditions:
386 
387  require(xdofs != 0);
388  require(xdofs_ub >= dl()*db());
389  require(xglobal_coords != 0);
390  require(xglobal_coord_ub >= db());
391  require(xlocal_coords != 0);
392  require(xlocal_coords_ub >= db());
393 
394  // Body:
395 
396 
397  // The inverse of the constant function is not unique;
398  // define it to be the center of the evaluator.
399 
400  center(xlocal_coords, xlocal_coords_ub);
401 
402  // Postconditions:
403 
404  ensure(invariant());
405 
406  // Exit:
407 
408  return;
409 
410 }
411 
412 // ===========================================================
413 // ANY FACET
414 // ===========================================================
415 
419 clone() const
420 {
421  constant_fcn_space* result = 0;
422 
423  // Preconditions:
424 
425  // Body:
426 
427  is_abstract();
428 
429  // Postconditions:
430 
431  ensure(result != 0);
432  //ensure(invariant());
433  ensure(result->invariant());
434  ensure(is_same_type(result));
435 
436  return result;
437 }
438 
439 
444 {
445  // Preconditions:
446 
447  require(is_ancestor_of(&xother));
448 
449  // Body:
450 
451  // Postconditions:
452 
453  ensure(invariant());
454 
455  return *this;
456 }
457 
462 {
463 
464  // Preconditions:
465 
466  require(is_ancestor_of(&xother));
467 
468  // Body:
469 
470  not_implemented();
471 
472  // Postconditions:
473 
474  ensure(invariant());
475 
476  // Exit:
477 
478  return *this;
479 }
480 
481 
485 {
486  // Preconditions:
487 
488  // Body:
489 
490  // Postconditions:
491 
492  ensure(invariant());
493 
494  return;
495 }
496 
497 
499 bool
501 invariant() const
502 {
503  bool result = true;
504 
505  // Preconditions:
506 
507  // Body:
508 
509  // Must satisfy base class invariant.
510 
511  result = result && linear_fcn_space::invariant();
512 
513  if(invariant_check())
514  {
515  // Prevent recursive calls to invariant.
516 
517  disable_invariant_check();
518 
519  invariance(basis_values() != 0);
520 
521  // Finished, turn invariant checking back on.
522 
523  enable_invariant_check();
524  }
525 
526  // Postconditions:
527 
528  return result;
529 }
530 
532 bool
534 is_ancestor_of(const any* xother) const
535 {
536 
537  // Preconditions:
538 
539  require(xother != 0);
540 
541  // Body:
542 
543  // True if other conforms to this
544 
545  bool result = dynamic_cast<const constant_fcn_space*>(xother) != 0;
546 
547  // Postconditions:
548 
549  return result;
550 
551 }
552 
553 // ===========================================================
554 // PRIVATE MEMBERS
555 // ===========================================================
556 
virtual void value_at_coord(const dof_type xdofs[], size_type xdofs_ub, const dof_type xlocal_coords[], size_type xlocal_coords_ub, dof_type xresult[], size_type xresult_ub) const
Computes the value of the function at local coordinates xlocal_coords using the degrees of freedom xd...
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 constant_fcn_space * clone() const =0
Virtual constructor, creates a new instance of the same type as this.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual ~constant_fcn_space()
Destructor.
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 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.
sec_vd_dof_type dof_type
The type of degree of freedom.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
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.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual constant_fcn_space & operator=(const section_evaluator &xother)
Assignment operator.
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 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...
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
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...
virtual int dl() const
The dimension of this function space.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
constant_fcn_space()
Default constructor.
An section evaluator with a constant value over an abstract domain.
Namespace for the fiber_bundles component of the sheaf system.
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...