SheafSystem  0.0.0.0
linear_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 linear_fcn_space
19 
20 #include "SheafSystem/linear_fcn_space.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/std_cmath.h"
24 
25 using namespace fiber_bundle; // Workaround for MS C++ bug.
26 
27 //#define DIAGNOSTIC_OUTPUT
28 
29 // ===========================================================
30 // LINEAR_FCN_SPACE FACET
31 // ===========================================================
32 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  // Initialize _basis_values to 0 here just to
42  // make precondition in basis_at_coord meaningful.
43  // Will be reinitialized in descendants to point to
44  // an auto allocated data member. This allows us to
45  // avoid newing the basis values buffer within
46  // deeply nested loops without using a virtual function.
47 
48  _basis_values = 0;
49 
50  // Postconditions:
51 
52  ensure(invariant());
53 
54  return;
55 }
56 
57 // Destructor.
61 {
62  // Preconditions:
63 
64  // Body:
65 
66  // Postconditions:
67 
68  ensure(invariant());
69 
70  return;
71 }
72 
74 int
76 dl() const
77 {
78  int result = 0;
79 
80  // Preconditions:
81 
82 
83  // Body:
84 
85  is_abstract();
86 
87  // Postconditions:
88 
89  ensure(result >= 0);
90 
91  // Exit:
92 
93  return result;
94 }
95 
97 void
99 basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
100 {
101  // Preconditions:
102 
103  require(xlocal_coord != 0);
104  require(xlocal_coord_ub >= db());
105  require(basis_values() != 0);
106 
107  // Body:
108 
109  is_abstract();
110 
111  // Postconditions:
112 
113  ensure(invariant());
114 
115  // Exit:
116 
117  return;
118 }
119 
121 void
123 basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
124 {
125  // Preconditions:
126 
127  require(xlocal_coord != 0);
128  require(xlocal_coord_ub >= db());
129  require(basis_deriv_values() != 0);
130 
131  // Body:
132 
133  is_abstract();
134 
135  // Postconditions:
136 
137  ensure(invariant());
138 
139  // Exit:
140 
141  return;
142 }
143 
148 {
149 
150  // Preconditions:
151 
152 
153  // Body:
154 
155  const value_type* result = _basis_values;
156 
157  // Postconditions:
158 
159 
160  // Exit:
161 
162  return result;
163 }
164 
169 {
170 
171  // Preconditions:
172 
173 
174  // Body:
175 
176  const value_type* result = _basis_deriv_values;
177 
178  // Postconditions:
179 
180 
181  // Exit:
182 
183  return result;
184 }
185 
189 {
190  // Preconditions:
191 
192  // Body:
193 
194  // Initialize _basis_values to 0 here just to
195  // make precondition in basis_at_coord meaningful.
196  // Will be reinitialized in descendants to point to
197  // an auto allocated data member. This allows us to
198  // avoid newing the basis values buffer within
199  // deeply nested loops without using a virtual function.
200 
201  _basis_values = 0;
202 
203  // Postconditions:
204 
205  ensure(invariant());
206 
207  return;
208 }
209 
210 
211 // ===========================================================
212 // EVALUATION FACET
213 // ===========================================================
214 
218 dof_ct() const
219 {
220  int result;
221 
222  // Preconditions:
223 
224 
225  // Body:
226 
227  result = dl();
228 
229  // Postconditions:
230 
231  ensure(result >= 0);
232 
233  // Exit:
234 
235  return result;
236 }
237 
239 void
241 value_at_coord(const dof_type xdofs[],
242  size_type xdofs_ub,
243  const dof_type xlocal_coords[],
244  size_type xlocal_coords_ub,
245  dof_type xresult[],
246  size_type xresult_ub) const
247 {
248  // Preconditions:
249 
250  require(xdofs != 0);
251  require(xdofs_ub >= dl()*xresult_ub);
252  require(unexecutable(xdofs must be interleaved));
253  require(xlocal_coords != 0);
254  require(xlocal_coords_ub >= db());
255  require(xresult != 0);
256  require(xresult_ub > 0);
257  require(basis_values() != 0);
258 
259 
260  // Body:
261 
262  int ldl = dl();
263 
264  linear_fcn_space* cthis = const_cast<linear_fcn_space*>(this);
265  cthis->basis_at_coord(xlocal_coords, xlocal_coords_ub);
266 
267  for(size_type i=0; i<xresult_ub; ++i)
268  {
269  dof_type value = 0.0;
270  size_type dof_index = i;
271 
272  for(size_type j=0; j<ldl; ++j)
273  {
274  value += _basis_values[j]*xdofs[dof_index];
275  dof_index += xresult_ub;
276  }
277 
278  xresult[i] = value;
279  }
280 
281  // Postconditions:
282 
283  ensure(invariant());
284 
285 }
286 
287 // ===========================================================
288 // ANY FACET
289 // ===========================================================
290 
294 clone() const
295 {
296  linear_fcn_space* result = 0;
297 
298  // Preconditions:
299 
300  is_abstract();
301 
302  // Body:
303 
304  // Postconditions:
305 
306  ensure(result != 0);
307  ensure(is_same_type(result));
308 
309  return result;
310 }
311 
312 
313 // Assignment operator.
318 {
319  // Preconditions:
320 
321  require(is_ancestor_of(&xother));
322 
323  // Body:
324 
325  not_implemented();
326 
327  // Postconditions:
328 
329  ensure(invariant());
330 
331  return *this;
332 }
333 
338 {
339 
340  // Preconditions:
341 
342  require(is_ancestor_of(&xother));
343 
344  // Body:
345 
346  not_implemented();
347 
348  // Postconditions:
349 
350  ensure(invariant());
351 
352  // Exit:
353 
354  return *this;
355 }
356 
357 // Class invariant.
359 bool
361 invariant() const
362 {
363  bool result = true;
364 
365  // Preconditions:
366 
367  // Body:
368 
369  // Must satisfy base class invariant.
370 
371  result = result && section_evaluator::invariant();
372 
373  if(invariant_check())
374  {
375  // Prevent recursive calls to invariant.
376 
377  disable_invariant_check();
378 
379  // Finished, turn invariant checking back on.
380 
381  enable_invariant_check();
382  }
383 
384  // Postconditions:
385 
386  return result;
387 }
388 
389 // Conformance test.
391 bool
393 is_ancestor_of(const any* xother) const
394 {
395 
396  // Preconditions:
397 
398  require(xother != 0);
399 
400  // Body:
401 
402  // True if other conforms to this
403 
404  bool result = dynamic_cast<const linear_fcn_space*>(xother) != 0;
405 
406  // Postconditions:
407 
408  return result;
409 
410 }
411 
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual void basis_derivs_at_coord(const dof_type xlocal_coords[], size_type xlocal_coords_ub)=0
Computes the value of the derivatives of each basis function at local coordinates xlocal_coords...
virtual linear_fcn_space & operator=(const section_evaluator &xother)
Assignment operator.
sec_vd_dof_type dof_type
The type of degree of freedom.
virtual size_type dof_ct() const
The number of dofs required for each component of the dependent variable.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
An abstract integrable section evaluator which is a member of a linear function space.
const value_type * basis_deriv_values() const
The result of the preceding call to basis_derivs_at_coord.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
vd_value_type value_type
The type of component in the value; the scalar type in the range vector space.
virtual bool invariant() const
Class invariant.
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
virtual linear_fcn_space * clone() const =0
Virtual constructor, creates a new instance of the same type as this.
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 basis_at_coord(const dof_type xlocal_coords[], size_type xlocal_coords_ub)=0
Computes the value of each basis function at local coordinates xlocal_coords.
linear_fcn_space()
Default constructor.
virtual int dl() const =0
The dimension of this function space.
const value_type * basis_values() const
The result of the preceding call to basis_at_coord.
Namespace for the fiber_bundles component of the sheaf system.
virtual ~linear_fcn_space()
Destructor.