SheafSystem  0.0.0.0
sec_ed.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_ed facet function templates.
19 
20 #ifndef SEC_ED_IMPL_H
21 #define SEC_ED_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_ED_H
32 #include "SheafSystem/sec_ed.h"
33 #endif
34 
35 namespace fiber_bundle
36 {
37 
38 //==============================================================================
39 // NON-MEMBER FUNCTIONS
40 //==============================================================================
41 
42 //==============================================================================
43 
44 // template <typename T, typename R>
45 // void
46 // dot_functor<T, R>::
47 // operator()(const T& x0, const T& x1, R& xresult)
48 // {
49 // // Preconditions:
50 
51 // require(precondition_of(xresult = dot(x0, x1)));
52 
53 // // Body:
54 
55 // //@issue Do we want to add a new preallocated "dot" function to ed
56 // // which takes an at0 return type?
57 
58 // xresult = dot(x0, x1);
59 
60 // // Postconditions:
61 
62 // ensure(postcondition_of(xresult = dot(x0, x1)));
63 
64 // // Exit:
65 
66 // return;
67 // }
68 
69 
70 // template <typename T, typename R>
71 // void
72 // length_functor<T, R>::
73 // operator()(const T& x0, R& xresult)
74 // {
75 // // Preconditions:
76 
77 // require(precondition_of(xresult = length(x0)));
78 
79 // // Body:
80 
81 // //@issue Do we want to add a new preallocated "length" function to ed
82 // // which takes an at0 return type?
83 
84 // xresult = length(x0);
85 
86 // // Postconditions:
87 
88 // ensure(postcondition_of(xresult = length(x0)));
89 
90 // // Exit:
91 
92 // return;
93 // }
94 
95 
96 // template <typename T>
97 // void
98 // put_length_functor<T>::
99 // operator()(T& x0, const vd_value_type& xlength)
100 // {
101 // // Preconditions:
102 
103 // require(precondition_of(put_length(x0, xlength)));
104 
105 // // Body:
106 
107 // put_length(x0, xlength);
108 
109 // // Postconditions:
110 
111 // ensure(postcondition_of(put_length(x0, xlength)));
112 
113 // // Exit:
114 
115 // return;
116 // }
117 
118 // template <typename T>
119 // void
120 // normalize_functor<T>::
121 // operator()(const T& x0, T& xresult)
122 // {
123 // // Preconditions:
124 
125 // require(precondition_of(normalize(x0, xresult)));
126 
127 // // Body:
128 
129 // normalize(x0, xresult);
130 
131 // // Postconditions:
132 
133 // ensure(postcondition_of(normalize(x0, xresult)));
134 
135 // // Exit:
136 
137 // return;
138 // }
139 
140 //==============================================================================
141 
143 template <typename S, typename SR>
144 void dot(const S& x0, const S& x1, SR& xresult, bool xauto_access)
145 {
146  // Preconditions:
147 
148  require(x0.state_is_auto_read_accessible(xauto_access));
149  require(x1.state_is_auto_read_accessible(xauto_access));
150  require(x0.is_same_type(&x1));
151  require(x0.is_p_form(xauto_access) == x1.is_p_form(xauto_access));
152 
153  // Body:
154 
155  if(xauto_access)
156  {
157  x0.get_read_access();
158  x1.get_read_access();
159  }
160 
161  typedef typename S::fiber_type::volatile_type V;
162  typedef typename SR::fiber_type::volatile_type VR;
163  dot_functor<V, VR> f;
164  binary_op(x0, x1, xresult, f, xauto_access);
165 
166  if(xauto_access)
167  {
168  x0.release_access();
169  x1.release_access();
170  }
171 
172  // Postconditions:
173 
174  // Exit:
175 
176  return;
177 }
178 
180 template <typename S, typename SR>
181 void length(const S& x0, SR& xresult, bool xauto_access)
182 {
183  // Preconditions:
184 
185  require(x0.state_is_auto_read_accessible(xauto_access));
186 
187  // Body:
188 
189  if(xauto_access)
190  {
191  x0.get_read_access();
192  }
193 
194  typedef typename S::fiber_type::volatile_type V;
195  typedef typename SR::fiber_type::volatile_type VR;
196  length_functor<V, VR> f;
197  unary_op(x0, xresult, f, xauto_access);
198 
199  if(xauto_access)
200  {
201  x0.release_access();
202  }
203 
204  // Postconditions:
205 
206  // Exit:
207 
208  return;
209 }
210 
212 template <typename S>
213 void put_length(S& x0, const vd_value_type& xlength, bool xauto_access)
214 {
215  // Preconditions:
216 
217  require(x0.state_is_auto_read_write_accessible(xauto_access));
218  ensure(xlength >= 0.0);
219 
220  // Body:
221 
222  if(xauto_access)
223  {
224  x0.get_read_write_access(true);
225  }
226 
227  put_length_functor<typename S::fiber_type::volatile_type> f;
228  unary_op(x0, xlength, f, xauto_access);
229 
230  if(xauto_access)
231  {
232  x0.release_access();
233  }
234 
235  // Postconditions:
236 
237  ensure(unexecutable("length(x0, xauto_access) == xlength"));
238 
239  // Exit:
240 
241  return;
242 }
243 
245 template <typename S, typename SR>
246 void normalize(const S& x0, SR& xresult, bool xauto_access)
247 {
248  // Preconditions:
249 
250  require(x0.state_is_auto_read_accessible(xauto_access));
251  require(xresult.state_is_auto_read_write_accessible(xauto_access));
252  require(x0.is_same_type(&xresult));
253  require(x0.is_p_form(xauto_access) == xresult.is_p_form(xauto_access));
254 
255  // Body:
256 
257  if(xauto_access)
258  {
259  x0.get_read_access();
260  xresult.get_read_write_access(true);
261  }
262 
263  normalize_functor<typename S::fiber_type::volatile_type> f;
264  unary_op(x0, xresult, f, xauto_access);
265 
266  if(xauto_access)
267  {
268  x0.release_access();
269  xresult.release_access();
270  }
271 
272  // Postconditions:
273 
274  ensure(xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access));
275  ensure(unexecutable("length(xresult, xauto_access) == 1.0"));
276 
277  // Exit:
278 
279  return;
280 }
281 
283 template <typename T>
284 void normalize(T& x0, bool xauto_access)
285 {
286  // Preconditions:
287 
288  require(precondition_of(normalize(x0, x0, xauto_access)));
289 
290  // Body:
291 
292  normalize(x0, x0, xauto_access);
293 
294  // Postconditions:
295 
296  ensure(postcondition_of(normalize(x0, x0, xauto_access)));
297 
298  // Exit:
299 }
300 
301 } // namespace fiber_bundle
302 
303 #endif // ifndef SEC_ED_IMPL_H
void length(const S &x0, SR &xresult, bool xauto_access)
Definition: sec_ed.impl.h:181
void unary_op(const S0 &x0, SR &xresult, F xfunctor, bool xauto_access)
Unary operator.
Definition: sec_vd.impl.h:224
void normalize(const S &x0, SR &xresult, bool xauto_access)
Definition: sec_ed.impl.h:246
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Definition: sec_vd.impl.h:48
void dot(const S &x0, const S &x1, SR &xresult, bool xauto_access)
Definition: sec_ed.impl.h:144
void put_length(S &x0, const vd_value_type &xlength, bool xauto_access)
Definition: sec_ed.impl.h:213
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