SheafSystem  0.0.0.0
constant_triangle.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_triangle
19 
20 #include "SheafSystem/constant_triangle.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/error_message.h"
24 #include "SheafSystem/std_limits.h"
25 
26 using namespace std;
27 using namespace fiber_bundle; // Workaround for MS C++ bug.
28 
29 // ===========================================================
30 // CONSTANT_TRIANGLE FACET
31 // ===========================================================
32 
36 {
37  // Preconditions:
38 
39  // Body:
40 
41  _basis_deriv_values = _basis_deriv_value_buffer;
42 
43  // Postconditions:
44 
45  ensure(invariant());
46 
47  // Exit:
48 
49  return;
50 }
51 
52 
56  : constant_fcn_space(xother)
57 {
58  // Preconditions:
59 
60  // Body:
61 
63 
64  // Postconditions:
65 
66  ensure(invariant());
67 
68  // Exit:
69 
70  return;
71 }
72 
73 
74 // ===========================================================
75 // CONSTANT_FCN_SPACE FACET
76 // ===========================================================
77 
78 // ===========================================================
79 // LINEAR_FCN_SPACE FACET
80 // ===========================================================
81 
82 // ===========================================================
83 // INTEGRABLE_SECTION_EVALUATOR FACET
84 // ===========================================================
85 
89 volume(const dof_type xcoord_dofs[],
90  size_type xcoord_dofs_ub,
91  size_type xdf)
92 {
93  // Preconditions:
94 
95  require(xcoord_dofs != 0);
96  require(xcoord_dofs_ub >= 0);
97 
98  // Body:
99 
101 
102  not_implemented();
103 
104  value_type result = 0.0;
105 
106  // Postconditions:
107 
108  ensure(invariant());
109 
110  // Exit:
111 
112  return result;
113 }
114 
115 // ===========================================================
116 // DIFFERENTIABLE_SECTION_EVALUATOR FACET
117 // ===========================================================
118 
119 // ===========================================================
120 // DOMAIN FACET
121 // ===========================================================
122 
124 int
126 db() const
127 {
128  int result;
129 
130  // Preconditions:
131 
132 
133  // Body:
134 
135  result = 2;
136 
137  // Postconditions:
138 
139  ensure(result == 2);
140 
141  // Exit:
142 
143  return result;
144 }
145 
146 
148 void
151  coord_type xresult[],
152  size_type xresult_ub) const
153 {
154  // Preconditions:
155 
156  require((0 <= xindex) && (xindex < dof_ct()));
157  require(xresult_ub >= db());
158 
159  // Body:
160 
161  center(xresult, xresult_ub);
162 
163  // Postconditions:
164 
165  ensure(in_standard_domain(xresult, xresult_ub));
166 
167  // Exit:
168 
169  return;
170 }
171 
173 void
175 center(coord_type xresult[], size_type xresult_ub) const
176 {
177  // Preconditions:
178 
179  require(xresult != 0);
180  require(xresult_ub >= db());
181 
182  // Body:
183 
184  static coord_type one_third =
185  static_cast<coord_type>(1.0)/static_cast<coord_type>(3.0);
186 
187  xresult[0] = one_third;
188  xresult[1] = one_third;
189 
190  // Postconditions:
191 
192 
193  // Exit:
194 
195  return;
196 }
197 
198 
200 bool
202 in_standard_domain(const dof_type xlocal_coords[],
203  size_type xlocal_coords_ub) const
204 {
205  // Preconditions:
206 
207  require(xlocal_coords != 0);
208  require(xlocal_coords_ub >= db());
209 
210  // Body:
211 
212  dof_type u = xlocal_coords[0];
213  dof_type v = xlocal_coords[1];
214 
215  // "Extend" the bounds by the dof type epsilon (attempting
216  // to ensure that the boundary is included in the domain).
217 
218  dof_type zero = 0.0 - 1000.0*numeric_limits<dof_type>::epsilon();
219  dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
220 
221  // bool result = (u >= zero) && (u <= one) && (v >= zero) && (v <= one);
222  bool result = (u >= zero) && (u <= one) && (v >= zero) && (v <= one - u);
223 
224  // Postconditions:
225 
226  // Exit:
227 
228  return result;
229 
230 }
231 
232 // ===========================================================
233 // EVALUATION FACET
234 // ===========================================================
235 
236 // ===========================================================
237 // ANY FACET
238 // ===========================================================
239 
243 clone() const
244 {
245  constant_triangle* result;
246 
247  // Preconditions:
248 
249  // Body:
250 
251  result = new constant_triangle();
252 
253  // Postconditions:
254 
255  ensure(result != 0);
256  //ensure(invariant());
257  ensure(result->invariant());
258  ensure(is_same_type(result));
259 
260  return result;
261 }
262 
263 
268 {
269  // Preconditions:
270 
271  require(is_ancestor_of(&xother));
272 
273  // Body:
274 
276 
277  not_implemented();
278 
279  // Postconditions:
280 
281  ensure(invariant());
282 
283  return *this;
284 }
285 
290 {
291 
292  // Preconditions:
293 
294  require(is_ancestor_of(&xother));
295 
296  // Body:
297 
298  not_implemented();
299 
300  // Postconditions:
301 
302  ensure(invariant());
303 
304  // Exit:
305 
306  return *this;
307 }
308 
312 {
313  // Preconditions:
314 
315  // Body:
316 
317  // Postconditions:
318 
319  return;
320 }
321 
323 bool
325 invariant() const
326 {
327  bool result = true;
328 
329  // Preconditions:
330 
331  // Body:
332 
333  // Must satisfy base class invariant.
334 
335  result = result && constant_fcn_space::invariant();
336 
337  if(invariant_check())
338  {
339  // Prevent recursive calls to invariant.
340 
342 
343  invariance(basis_values() != 0);
344 
345  // Finished, turn invariant checking back on.
346 
348  }
349 
350  // Postconditions:
351 
352  return result;
353 }
354 
356 bool
358 is_ancestor_of(const any* xother) const
359 {
360 
361  // Preconditions:
362 
363  require(xother != 0);
364 
365  // Body:
366 
367  // True if other conforms to this
368 
369  bool result = dynamic_cast<const constant_triangle*>(xother) != 0;
370 
371  // Postconditions:
372 
373  return result;
374 
375 }
376 
377 // ===========================================================
378 // PRIVATE MEMBERS
379 // ===========================================================
380 
virtual ~constant_triangle()
Destructor.
constant_triangle()
Default constructor.
virtual void center(coord_type xresult[], size_type xresult_ub) const
The local coordinates at the center of the evaluator.
virtual bool invariant() const
Class invariant.
STL namespace.
A section evaluator with a constant value over a triangular 2D domain.
value_type * _basis_deriv_values
The result of the preceding call to basis_derivs_at_coord.
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 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.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual constant_triangle * clone() const
Virtual constructor, creates a new instance of the same type as this.
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.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual constant_triangle & operator=(const section_evaluator &xother)
Assignment operator.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
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.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
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...
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
virtual bool invariant() const
Class invariant.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
const value_type * basis_values() const
The result of the preceding call to basis_at_coord.
value_type _basis_deriv_value_buffer[int(DB) *int(DL)]
Storage for the result of the preceeding call to basis_derivs_at_coord.
An section evaluator with a constant value over an abstract domain.
Namespace for the fiber_bundles component of the sheaf system.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87