SheafSystem  0.0.0.0
sec_vd.impl.h
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 sec_vd facet function templates.
19 
20 #ifndef SEC_VD_IMPL_H
21 #define SEC_VD_IMPL_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef ASSERT_CONTRACT_H
28 #include "SheafSystem/assert_contract.h"
29 #endif
30 
31 #ifndef SEC_VD_H
32 #include "SheafSystem/sec_vd.h"
33 #endif
34 
35 #ifndef SEC_SECTION_EVALUATOR_H
36 #include "SheafSystem/section_evaluator.h"
37 #endif
38 
39 namespace fiber_bundle
40 {
41 
42 namespace sec_vd_algebra
43 {
44 
46 template <typename S0, typename S1, typename SR, typename F>
47 void
48 binary_op(const S0& x0, const S1& x1, SR& xresult, F xfunctor,
49  bool xauto_access)
50 {
51  // Preconditions:
52 
53  require(x0.state_is_auto_read_accessible(xauto_access));
54  require(x1.state_is_auto_read_accessible(xauto_access));
55  require(xresult.state_is_auto_read_write_accessible(xauto_access));
56  require((const_cast<S0&>(x0)).discretization_ct(xauto_access) == \
57  (const_cast<S1&>(x1)).discretization_ct(xauto_access));
58  require((const_cast<S0&>(x0)).discretization_ct(xauto_access) == \
59  xresult.discretization_ct(xauto_access));
60 
61  // Body:
62 
63  if(xauto_access)
64  {
65  x0.get_read_access();
66  x1.get_read_access();
67  xresult.get_read_write_access(true);
68  }
69 
70  // Create temporary volatile fiber type instances.
71 
72  typedef typename S0::fiber_type::volatile_type volatile_type_0;
73  typedef typename S1::fiber_type::volatile_type volatile_type_1;
74  typedef typename SR::fiber_type::volatile_type volatile_type_r;
75 
76  volatile_type_0* lx0_fiber = x0.fiber_prototype().lite_prototype().clone();
77  volatile_type_1* lx1_fiber = x1.fiber_prototype().lite_prototype().clone();
78  volatile_type_r* lxresult_fiber =
79  xresult.fiber_prototype().lite_prototype().clone();
80 
81  // Get pointers to the volatile fiber row_dofs.
82 
83  //$$SCRIBBLE:
84  // It would be nice if we didn't have to explicitly create these
85  // pointers. We could create additional get/put_discretization_dofs
86  // functions to simplify things; but, at the cost of some efficiency.
87 
90 
91  typedef sec_vd::dof_type dof_type;
92 
93  // Iterate over the discretization performing the specified operation
94  // (via the functor argument) on the dofs.
95 
98 
99  S0& lx0 = const_cast<S0&>(x0);
100  S1& lx1 = const_cast<S1&>(x1);
101 
102  size_type ldisc_ct = lx0.discretization_ct();
103 
104  for(size_type i=0; i<ldisc_ct; ++i)
105  {
106  // Gather all the fiber dofs of this at the same base point as result.
107 
108  lx0.get_fiber(i, *lx0_fiber);
109  lx1.get_fiber(i, *lx1_fiber);
110 
111  // Compute the result.
112 
113  xfunctor(*lx0_fiber, *lx1_fiber, *lxresult_fiber);
114 
115  // Store the dofs in the result field.
116 
117  xresult.put_fiber(i, *lxresult_fiber);
118  }
119 
120  if(xauto_access)
121  {
122  x0.release_access();
123  x1.release_access();
124  xresult.release_access();
125  }
126 
127  delete lx0_fiber;
128  delete lx1_fiber;
129  delete lxresult_fiber;
130 
131  // Postconditions:
132 
133  // Exit:
134 
135  return;
136 }
137 
139 template <typename S0, typename SR, typename F>
140 void
141 binary_op(const S0& x0, const vd_value_type& xvalue, SR& xresult, F xfunctor,
142  bool xauto_access)
143 {
144  // Preconditions:
145 
146  require(x0.state_is_auto_read_accessible(xauto_access));
147  require(xresult.state_is_auto_read_write_accessible(xauto_access));
148  require((const_cast<S0&>(x0)).discretization_ct(xauto_access) == \
149  xresult.discretization_ct(xauto_access));
150 
151  // Body:
152 
153  if(xauto_access)
154  {
155  x0.get_read_access();
156  xresult.get_read_write_access(true);
157  }
158 
159  // Create temporary volatile fiber type instances.
160 
161  typedef typename S0::fiber_type::volatile_type volatile_type_0;
162  typedef typename SR::fiber_type::volatile_type volatile_type_r;
163 
164  volatile_type_0* lx0_fiber = x0.fiber_prototype().lite_prototype().clone();
165  volatile_type_r* lxresult_fiber =
166  xresult.fiber_prototype().lite_prototype().clone();
167 
168  // Get pointers to the volatile fiber row_dofs.
169 
170  //$$SCRIBBLE:
171  // It would be nice if we didn't have to explicitly create these
172  // pointers. We could create additional get/put_discretization_dofs
173  // functions to simplify things; but, at the cost of some efficiency.
174 
177 
178  typedef sec_vd::dof_type dof_type;
179 
180  // Iterate over the discretization performing the specified operation
181  // (via the functor argument) on the dofs.
182 
185 
186  S0& lx0 = const_cast<S0&>(x0);
187 
188  size_type ldisc_ct = lx0.discretization_ct();
189 
190  for(size_type i=0; i<ldisc_ct; ++i)
191  {
192  // Gather all the fiber dofs of this at the same base point as result.
193 
194  lx0.get_fiber(i, *lx0_fiber);
195 
196  // Compute the result.
197 
198  xfunctor(*lx0_fiber, xvalue, *lxresult_fiber);
199 
200  // Store the dofs in the result field.
201 
202  xresult.put_fiber(i, *lxresult_fiber);
203  }
204 
205  if(xauto_access)
206  {
207  x0.release_access();
208  xresult.release_access();
209  }
210 
211  delete lx0_fiber;
212  delete lxresult_fiber;
213 
214  // Postconditions:
215 
216  // Exit:
217 
218  return;
219 }
220 
222 template <typename S0, typename SR, typename F>
223 void
224 unary_op(const S0& x0, SR& xresult, F xfunctor, bool xauto_access)
225 
226 {
227  // Preconditions:
228 
229  require(x0.state_is_auto_read_accessible(xauto_access));
230  require(xresult.state_is_auto_read_write_accessible(xauto_access));
231  require((const_cast<S0&>(x0)).discretization_ct(xauto_access) == \
232  xresult.discretization_ct(xauto_access));
233 
234  // Body:
235 
236  if(xauto_access)
237  {
238  x0.get_read_access();
239  xresult.get_read_write_access(true);
240  }
241 
242  // Create temporary volatile fiber type instances.
243 
244  typedef typename S0::fiber_type::volatile_type volatile_type_0;
245  typedef typename SR::fiber_type::volatile_type volatile_type_r;
246 
247  volatile_type_0* lx0_fiber = x0.fiber_prototype().lite_prototype().clone();
248  volatile_type_r* lxresult_fiber =
249  xresult.fiber_prototype().lite_prototype().clone();
250 
251  // Get pointers to the volatile fiber row_dofs.
252 
253  typedef sec_vd::dof_type dof_type;
254 
255  // Iterate over the discretization performing the specified
256  // (via the functor argument) on the dofs.
257 
258  S0& lx0 = const_cast<S0&>(x0);
259  size_type ldisc_ct = lx0.discretization_ct();
260 
261  for(size_type i=0; i<ldisc_ct; ++i)
262  {
263  // Gather all the fiber dofs of this at the same base point as result.
264 
265  lx0.get_fiber(i, *lx0_fiber);
266 
267  // Compute the result.
268 
269  xfunctor(*lx0_fiber, *lxresult_fiber);
270 
271  // Store the dofs in the result field.
272 
273  xresult.put_fiber(i, *lxresult_fiber);
274  }
275 
276  if(xauto_access)
277  {
278  x0.release_access();
279  xresult.release_access();
280  }
281 
282  delete lx0_fiber;
283  delete lxresult_fiber;
284 
285  // Postconditions:
286 
287  // Exit:
288 
289  return;
290 }
291 
293 template <typename S0, typename F>
294 void
295 unary_op(S0& x0, const vd_value_type& x1, F xfunctor, bool xauto_access)
296 
297 {
298  // Preconditions:
299 
300  require(x0.state_is_auto_read_write_accessible(xauto_access));
301 
302  // Body:
303 
304  if(xauto_access)
305  {
306  x0.get_read_write_access(true);
307  }
308 
309  // Create a temporary volatile fiber type instance.
310 
311  typedef typename S0::fiber_type::volatile_type volatile_type_0;
312 
313  volatile_type_0* lx0_fiber = x0.fiber_prototype().lite_prototype().clone();
314 
315  // Get ap pointer to the volatile fiber row_dofs.
316 
317  typedef sec_vd::dof_type dof_type;
318 
319  // Iterate over the discretization performing the specified
320  // (via the functor argument) on the dofs.
321 
322  S0& lx0 = const_cast<S0&>(x0);
323  size_type ldisc_ct = lx0.discretization_ct();
324 
325  for(size_type i=0; i<ldisc_ct; ++i)
326  {
327  // Gather all the fiber dofs of this at the same base point as result.
328 
329  lx0.get_fiber(i, *lx0_fiber);
330 
331  // Compute the result.
332 
333  xfunctor(*lx0_fiber, x1);
334 
335  // Store the dofs in the result field.
336 
337  x0.put_fiber(i, *lx0_fiber);
338  }
339 
340  if(xauto_access)
341  {
342  x0.release_access();
343  }
344 
345  delete lx0_fiber;
346 
347  // Postconditions:
348 
349  // Exit:
350 
351  return;
352 }
353 
355 template <typename S0, typename SR, typename F>
356 void
357 unary_op(const S0& x0, SR& xresult1, SR& xresult2, F xfunctor,
358  bool xauto_access)
359 {
360  // Preconditions:
361 
362  require(x0.state_is_auto_read_accessible(xauto_access));
363  require(xresult1.state_is_auto_read_write_accessible(xauto_access));
364  require(xresult2.state_is_auto_read_write_accessible(xauto_access));
365  require((const_cast<S0&>(x0)).discretization_ct(xauto_access) == \
366  xresult1.discretization_ct(xauto_access));
367 
368  // Body:
369 
370  if(xauto_access)
371  {
372  x0.get_read_access();
373  xresult1.get_read_write_access(true);
374  xresult2.get_read_write_access(true);
375  }
376 
377  // Create temporary volatile fiber type instances.
378 
379  typedef typename S0::fiber_type::volatile_type volatile_type_0;
380  typedef typename SR::fiber_type::volatile_type volatile_type_r;
381 
382  volatile_type_0 lx0_fiber;
383  volatile_type_r lxresult1_fiber;
384  volatile_type_r lxresult2_fiber;
385 
386  // Get pointers to the volatile fiber row_dofs.
387 
388  typedef sec_vd::dof_type dof_type;
389 
390  S0& lx0 = const_cast<S0&>(x0);
391  size_type ldisc_ct = lx0.discretization_ct();
392 
393  // Iterate over the discretization performing the specified
394  // (via the functor argument) on the dofs.
395 
396  for(size_type i=0; i<ldisc_ct; ++i)
397  {
398  // Gather all the fiber dofs of this at the same base point as result.
399 
400  lx0.get_fiber(i, lx0_fiber);
401 
402  // Compute the result.
403 
404  xfunctor(lx0_fiber, lxresult1_fiber, lxresult2_fiber);
405 
406  // Store the dofs in the result fields.
407 
408  xresult1.put_fiber(i, lxresult1_fiber);
409  xresult2.put_fiber(i, lxresult2_fiber);
410  }
411 
412  if(xauto_access)
413  {
414  x0.release_access();
415  xresult1.release_access();
416  xresult2.release_access();
417  }
418 
419  // Postconditions:
420 
421  // Exit:
422 
423  return;
424 }
425 
426 } // namespace sec_vd_algebra
427 
428 } // namespace fiber_bundle
429 
430 #endif // ifndef SEC_VD_IMPL_H
void unary_op(const S0 &x0, SR &xresult, F xfunctor, bool xauto_access)
Unary operator.
Definition: sec_vd.impl.h:224
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Definition: sec_vd.impl.h:48
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
sec_vd_dof_type dof_type
The type of degree of freedom.
Definition: sec_vd.h:91
Namespace for the fiber_bundles component of the sheaf system.
double vd_value_type
The type of component in the fiber; the scalar type in the fiber vector space.
Definition: fiber_bundle.h:63