SheafSystem  0.0.0.0
vd.impl.h
Go to the documentation of this file.
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 
20 
21 #ifndef VD_IMPL_H
22 #define VD_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef ASSERT_CONTRACT_H
29 #include "SheafSystem/assert_contract.h"
30 #endif
31 
32 #ifndef VD_H
33 #include "SheafSystem/vd.h"
34 #endif
35 
36 namespace fiber_bundle
37 {
38 
39 //==============================================================================
40 // CLASS VD_ROW_DOFS_TYPE
41 //==============================================================================
42 
43 // PUBLIC MEMBER FUNCTIONS
44 
45 template <typename T>
46 const std::string&
49 {
50  // Preconditions:
51 
52  // Body:
53 
54  static const std::string result("vd_row_dofs_type");
55 
56  // Postconditions:
57 
58  ensure(!result.empty());
59 
60  // Exit:
61 
62  return result;
63 }
64 
65 template <typename T>
66 T&
68 operator[] (int xindex)
69 {
70  // Preconditions:
71 
72  require(xindex >= 0);
73 
74  // Body:
75 
76  T& result = reinterpret_cast<T*>(this)[xindex];
77 
78  // Postconditions:
79 
80  // Exit:
81 
82  return result;
83 }
84 
85 template <typename T>
86 const T&
88 operator[] (int xindex) const
89 {
90  // Preconditions:
91 
92  require(xindex >= 0);
93 
94  // Body:
95 
96  const T& result = reinterpret_cast<const T*>(this)[xindex];
97 
98  // Postconditions:
99 
100  // Exit:
101 
102  return result;
103 }
104 
105 template <typename T>
108 {
109  // Preconditions:
110 
111  // Body:
112 
114 
115  // Postconditions:
116 
117  ensure(result != 0);
118 
119  // Exit:
120 
121  return result;
122 }
123 
124 
125 //==============================================================================
126 // NON-MEMBER FUNCTIONS
127 //==============================================================================
128 
129 // ===========================================================
130 // VECTOR ALGEBRA
131 // ===========================================================
132 
133 namespace vd_algebra
134 {
135 
136 // ===========================================================
137 // VECTOR ALGEBRA: ADDITION
138 // ===========================================================
139 
140 // Instantiates for persisent and volatile types.
141 
142 template <typename T>
143 T* add(const T& x0, const T& x1)
144 {
145  // Preconditions:
146 
147  require(precondition_of(x0.clone()));
148  require(precondition_of(add(x0, x1, *result)));
149 
150  // Body:
151 
152  T* result = x0.clone();
153 
154  add(x0, x1, *result);
155 
156  // Postconditions:
157 
158  ensure(result != 0);
159  ensure(postcondition_of(x0.clone()));
160  ensure(postcondition_of(add(x0, x1, *result)));
161 
162  // Exit:
163 
164  return result;
165 }
166 
167 template <typename T>
168 void add_equal(T& xresult, const T& xother)
169 {
170  // Preconditions:
171 
172  require(precondition_of(add(xresult, xother, xresult)));
173 
174  // Body:
175 
176  add(xresult, xother, xresult);
177 
178  // Postconditions:
179 
180  ensure(postcondition_of(add(xresult, xother, xresult)));
181 
182  // Exit:
183 
184  return;
185 }
186 
187 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
188 
189 template <typename T>
190 T* operator+(const T& x0, const T& x1)
191 {
192  // Preconditions:
193 
194  require(precondition_of(result = add(x0, x1)));
195 
196  // Body:
197 
198  T* result = add(x0, x1);
199 
200  // Postconditions:
201 
202  ensure(postcondition_of(result = add(x0, x1)));
203 
204  // Exit:
205 
206  return result;
207 }
208 
209 template <typename T>
210 T& operator+=(T& xresult, const T& xother)
211 {
212  // Preconditions:
213 
214  require(precondition_of(add_equal(xresult, xother)));
215 
216  // Body:
217 
218  add_equal(xresult, xother);
219 
220  // Postconditions:
221 
222  ensure(postcondition_of(add_equal(xresult, xother)));
223 
224  // Exit:
225 
226  return xresult;
227 }
228 
229 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
230 
231 // ===========================================================
232 // VECTOR ALGEBRA: SUBTRACTION
233 // ===========================================================
234 
235 // Instantiates for any volatile type.
236 
237 template <typename T>
238 T* subtract(const T& x0, const T& x1)
239 {
240  // Preconditions:
241 
242  require(precondition_of(x0.clone()));
243  require(precondition_of(subtract(x0, x1, *result)));
244 
245  // Body:
246 
247  T* result = x0.clone();
248 
249  subtract(x0, x1, *result);
250 
251  // Postconditions:
252 
253  ensure(result != 0);
254  ensure(postcondition_of(x0.clone()));
255  ensure(postcondition_of(subtract(x0, x1, *result)));
256 
257  // Exit:
258 
259  return result;
260 }
261 
262 template <typename T>
263 void subtract_equal(T& xresult, const T& xother)
264 {
265  // Preconditions:
266 
267  require(precondition_of(subtract(xresult, xother, xresult)));
268 
269  // Body:
270 
271  subtract(xresult, xother, xresult);
272 
273  // Postconditions:
274 
275  ensure(postcondition_of(subtract(xresult, xother, xresult)));
276 
277  // Exit:
278 
279  return;
280 }
281 
282 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
283 
284 template <typename T>
285 T* operator-(const T& x0, const T& x1)
286 {
287  // Preconditions:
288 
289  require(precondition_of(result = subtract(x0, x1)));
290 
291  // Body:
292 
293  T* result = subtract(x0, x1);
294 
295  // Postconditions:
296 
297  ensure(postcondition_of(result = subtract(x0, x1)));
298 
299  // Exit:
300 
301  return result;
302 }
303 
304 template <typename T>
305 T& operator-=(T& xresult, const T& xother)
306 {
307  // Preconditions:
308 
309  require(precondition_of(subtract_equal(xresult, xother)));
310 
311  // Body:
312 
313  subtract_equal(xresult, xother);
314 
315  // Postconditions:
316 
317  ensure(postcondition_of(subtract_equal(xresult, xother)));
318 
319  // Exit:
320 
321  return xresult;
322 }
323 
324 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
325 
326 
327 // ===========================================================
328 // VECTOR ALGEBRA: SCALAR MULTIPLICATION
329 // ===========================================================
330 
331 // $$SCRIBBLE kabuch: This makes no sense. doxygen does not complain about
332 // divide() and it has the same template structure and
333 // arguments.
334 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
335 
336 template <typename T>
337 T* multiply(const T& x0, const vd_value_type& x1)
338 {
339  // Preconditions:
340 
341  require(precondition_of(multiply(x0, x1, result)));
342 
343  // Body:
344 
345  T* result = x0.clone();
346 
347  multiply(x0, x1, *result);
348 
349  // Postconditions:
350 
351  ensure(postcondition_of(multiply(x0, x1, *result)));
352 
353  // Exit:
354 
355  return result;
356 }
357 
358 template <typename T>
359 void multiply_equal(T& xresult, const vd_value_type& x1)
360 {
361  // Preconditions:
362 
363  require(precondition_of(multiply(xresult, x1, xresult)));
364 
365  // Body:
366 
367  multiply(xresult, x1, xresult);
368 
369  // Postconditions:
370 
371  ensure(postcondition_of(multiply(xresult, x1, xresult)));
372 
373  // Exit:
374 
375  return;
376 }
377 
378 template <typename T>
379 T* operator*(const T& x0, const vd_value_type& x1)
380 {
381  // Preconditions:
382 
383  // Body:
384 
385  T* result = multiply(x0, x1);
386 
387  // Postconditions:
388 
389  // Exit:
390 
391  return result;
392 }
393 
394 template <typename T>
395 T& operator*=(T& x0, const vd_value_type& x1)
396 {
397  // Preconditions:
398 
399  // Body:
400 
401  multiply_equal(x0, x1);
402 
403  // Postconditions:
404 
405  // Exit:
406 
407  return x0;
408 }
409 
410 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS
411 
412 
413 // ===========================================================
414 // VECTOR ALGEBRA: SCALAR DIVISION
415 // ===========================================================
416 
417 template <typename T>
418 T* divide(const T& x0, const vd_value_type& x1)
419 {
420  // Preconditions:
421 
422  require(precondition_of(divide(x0, x1, result)));
423 
424  // Body:
425 
426  T* result = x0.clone();
427 
428  divide(x0, x1, *result);
429 
430  // Postconditions:
431 
432  ensure(postcondition_of(divide(x0, x1, *result)));
433 
434  // Exit:
435 
436  return result;
437 }
438 
439 template <typename T>
440 void divide_equal(T& xresult, const vd_value_type& x1)
441 {
442  // Preconditions:
443 
444  require(precondition_of(divide(xresult, x1, xresult)));
445 
446  // Body:
447 
448  divide(xresult, x1, xresult);
449 
450  // Postconditions:
451 
452  ensure(postcondition_of(divide(xresult, x1, xresult)));
453 
454  // Exit:
455 
456  return;
457 }
458 
459 template <typename T>
460 T* operator/(const T& x0, const vd_value_type& x1)
461 {
462  // Preconditions:
463 
464  // Body:
465 
466  T* result = divide(x0, x1);
467 
468  // Postconditions:
469 
470  // Exit:
471 
472  return result;
473 }
474 
475 template <typename T>
476 T& operator/=(T& x0, const vd_value_type& x1)
477 {
478  // Preconditions:
479 
480  // Body:
481 
482  divide_equal(x0, x1);
483 
484  // Postconditions:
485 
486  // Exit:
487 
488  return x0;
489 }
490 
491 } // namespace vd_algebra
492 
493 } // namespace fiber_bundle
494 
495 #endif // ifndef VD_IMPL_H
T & operator*=(T &xresult, const vd_value_type &x1)
Vector x0 *= scalar x1 (self-allocated for volatile types); synonym for multiply_equal(x0, x1).
Definition: vd.impl.h:395
SHEAF_DLL_SPEC void add(const e3_lite &x0, const e3_lite &x1, vd_value_type xt, e3_lite &xresult)
Weighted sum x0*(1-xt) + x1*xt (pre-allocated version for volatile types).
Definition: e3.cc:2381
row_dofs_type * clone() const
Creates a new instance of the same type as this.
Definition: vd.impl.h:107
T & operator-=(T &xresult, const T &xother)
x0 -= x1 (self-allocated for volatile types); synonym for subtract_equal(x0, x1). ...
Definition: vd.impl.h:305
static const std::string & static_class_name()
The name of this class.
Definition: vd.impl.h:48
T * operator/(const T &x0, const vd_value_type &x1)
Vector x0 / scalar x1 (auto-allocated for volatile types); synonym for divide(x0, x1)...
Definition: vd.impl.h:460
T & operator+=(T &xresult, const T &xother)
x0 += x1 (self-allocated for volatile types); synonym for add_equal(x0, x1).
Definition: vd.impl.h:210
SHEAF_DLL_SPEC void subtract(const vd &x0, const vd &x1, vd &xresult, bool xauto_access)
x0 subtract x1 (pre-allocated version for persistent types).
Definition: vd.cc:1789
SHEAF_DLL_SPEC void divide_equal(vd &xresult, const vd_value_type &xother, bool xauto_access)
Vector x0 divided by scalar x1 (self-allocated version for persistent types); synonym for divide(xres...
Definition: vd.cc:2072
T * operator+(const T &x0, const T &x1)
x0 + x1 (auto-allocated for volatile types); synonym for add(x0, x1).
Definition: vd.impl.h:190
T & operator/=(T &xresult, const vd_value_type &x1)
Vector x0 /= scalar x1 (self-allocated for volatile types); synonym for divide_equal(x0, x1).
Definition: vd.impl.h:476
SHEAF_DLL_SPEC void multiply_equal(vd &xresult, const vd_value_type &xother, bool xauto_access)
Vector x0 multiplied by scalar x1 (self-allocated version for persistent types); synonym for multiply...
Definition: vd.cc:1971
SHEAF_DLL_SPEC void divide(const vd &x0, const vd_value_type &x1, vd &xresult, bool xauto_access)
Vector x0 divided by scalar x1 (pre-allocated version for persistent types).
Definition: vd.cc:2024
T * operator-(const T &x0, const T &x1)
x0 - x1 (auto-allocated for volatile types); synonym for subtract(x0, x1).
Definition: vd.impl.h:285
T * operator*(const T &x0, const vd_value_type &x1)
Vector x0 * scalar x1 (auto-allocated for volatile types); synonym for multiply(x0, x1).
Definition: vd.impl.h:379
T & operator[](int xindex)
Value of xindex-th component (row dof) (non const version).
Definition: vd.impl.h:68
SHEAF_DLL_SPEC void add_equal(vd &xresult, const vd &xother, bool xauto_access)
x0 add x1 (self-allocated version for persistent types); synonym for add(xresult, xother...
Definition: vd.cc:1764
SHEAF_DLL_SPEC void multiply(const vd &x0, const vd_value_type &x1, vd &xresult, bool xauto_access)
Vector x0 multiplied by scalar x1 (pre-allocated version for persistent types).
Definition: vd.cc:1924
SHEAF_DLL_SPEC void subtract_equal(vd &xresult, const vd &xother, bool xauto_access)
x0 subtract_equal x1 (self-allocated version for persistent types); synonym for subtract(xresult, xother, xresult, xauto_access).
Definition: vd.cc:1871
Namespace for the fiber_bundles component of the sheaf system.
Row dofs type for class vd.
Definition: vd.h:61
double vd_value_type
The type of component in the fiber; the scalar type in the fiber vector space.
Definition: fiber_bundle.h:63