SheafSystem  0.0.0.0
sec_atp.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 // Implementation for sec_atp facet function templates.
18 
19 #ifndef SEC_ATP_IMPL_H
20 #define SEC_ATP_IMPL_H
21 
22 #ifndef SHEAF_DLL_SPEC_H
23 #include "SheafSystem/sheaf_dll_spec.h"
24 #endif
25 
26 #ifndef ASSERT_CONTRACT_H
27 #include "SheafSystem/assert_contract.h"
28 #endif
29 
30 #ifndef SEC_ATP_H
31 #include "SheafSystem/sec_atp.h"
32 #endif
33 
34 namespace fiber_bundle
35 {
36 
37 //==============================================================================
38 // NON-MEMBER FUNCTIONS
39 //==============================================================================
40 
41 //==============================================================================
42 
44 template <typename V0, typename V1, typename VR>
45 void
46 hook_functor<V0, V1, VR>::
47 operator()(const V0& x0, const V1& x1, VR& xresult)
48 {
49  // Preconditions:
50 
51  require(precondition_of(hook(x0, x1, xresult)));
52 
53  // Body:
54 
55  hook(x0, x1, xresult);
56 
57  // Postconditions:
58 
59  ensure(postcondition_of(hook(x0, x1, xresult)));
60 
61  // Exit:
62 
63  return;
64 }
65 
67 template <typename V0, typename VR>
68 void
69 star_functor<V0, VR>::
70 operator()(const V0& x0, VR& xresult)
71 {
72  // Preconditions:
73 
74  require(precondition_of(star(x0, xresult)));
75 
76  // Body:
77 
78  star(x0, xresult);
79 
80  // Postconditions:
81 
82  ensure(postcondition_of(star(x0, xresult)));
83 
84  // Exit:
85 
86  return;
87 }
88 
90 template <typename V0, typename V1, typename VR>
91 void
92 wedge_functor<V0, V1, VR>::
93 operator()(const V0& x0, const V1& x1, VR& xresult)
94 {
95  // Preconditions:
96 
97  require(precondition_of(wedge(x0, x1, xresult)));
98 
99  // Body:
100 
101  wedge(x0, x1, xresult);
102 
103  // Postconditions:
104 
105  ensure(postcondition_of(wedge(x0, x1, xresult)));
106 
107  // Exit:
108 
109  return;
110 }
111 
112 //==============================================================================
113 
115 template <typename S0, typename S1, typename SR>
116 void hook(const S0& x0, const S1& x1, SR& xresult, bool xauto_access)
117 {
118  // Preconditions:
119 
120  require(x0.state_is_auto_read_accessible(xauto_access));
121  require(x1.state_is_auto_read_accessible(xauto_access));
122  require(xresult.state_is_auto_read_accessible(xauto_access));
123  require(x1.dd(xauto_access) == x0.dd(xauto_access));
124  require(x0.is_p_form(xauto_access) == x1.is_p_form(xauto_access));
125  require(xresult.p(xauto_access) == x0.p(xauto_access) - 1);
126 
127  // Body:
128 
129  if(xauto_access)
130  {
131  x0.get_read_access();
132  x1.get_read_access();
133  xresult.get_read_write_access(true);
134  }
135 
136  typedef typename S0::fiber_type::volatile_type V0;
137  typedef typename S1::fiber_type::volatile_type V1;
138  typedef typename SR::fiber_type::volatile_type VR;
139  hook_functor<V0, V1, VR> f;
140  binary_op(x0, x1, xresult, f, false);
141 
142  // Set the variance of the result.
143 
144  //x0.is_p_form(false) ? xresult.put_is_p_form(false)
145  // : xresult.put_is_p_vector(false);
146  xresult.put_variance(hook(x0.variance(false)), false);
147 
148 
149  if(xauto_access)
150  {
151  x0.release_access();
152  x1.release_access();
153  xresult.release_access();
154  }
155 
156  // Postconditions:
157 
158  //ensure(xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access));
159  ensure(xresult.variance(xauto_access) == hook(x0.variance(xauto_access)));
160 
161 
162  // Exit:
163 
164  return;
165 }
166 
168 template <typename S0, typename SR>
169 void star(const S0& x0, SR& xresult, bool xauto_access)
170 {
171  // Preconditions:
172 
173  require(x0.state_is_auto_read_accessible(xauto_access));
174  require(xresult.state_is_auto_read_write_accessible(xauto_access));
175 
176  // Body:
177 
178  if(xauto_access)
179  {
180  x0.get_read_access();
181  xresult.get_read_write_access(true);
182  }
183 
184  typedef typename S0::fiber_type::volatile_type V0;
185  typedef typename SR::fiber_type::volatile_type VR;
186  star_functor<V0, VR> f;
187  unary_op(x0, xresult, f, false);
188 
189  // Set the variance of the result.
190 
191  // If the x0.p() == 0 then x0 is a sec_at0 which is both a p_form
192  // and a p_vector. In that case we do no need to set the variance
193  // of the result because it does not change.
194 
195  define_old_variable(bool old_xresult_is_p_form = xresult.is_p_form(false));
196 
197  if(x0.p() > 0)
198  {
199  xresult.put_variance( star(x0.variance(false), x0.dd()), false );
200  }
201 
202  if(xauto_access)
203  {
204  x0.release_access();
205  xresult.release_access();
206  }
207 
208  // Postconditions:
209 
210  ensure((x0.p(xauto_access)>0) \
211  ? (xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access)) : true);
212  ensure((x0.p(xauto_access)==0) \
213  ? (xresult.is_p_form(xauto_access) == old_xresult_is_p_form): true );
214 
215  // Exit:
216 
217  return;
218 }
219 
221 template <typename S0, typename S1, typename SR>
222 void wedge(const S0& x0, const S1& x1, SR& xresult, bool xauto_access)
223 {
224  // Preconditions:
225 
226  require(x0.state_is_auto_read_accessible(xauto_access));
227  require(x1.state_is_auto_read_accessible(xauto_access));
228  require(xresult.state_is_auto_read_write_accessible(xauto_access));
229  require(x0.dd(xauto_access) >= xresult.dd(xauto_access));
230  require(x1.dd(xauto_access) >= xresult.dd(xauto_access));
231  require(xresult.p(xauto_access) == x0.p(xauto_access) + x1.p(xauto_access));
232  require(x0.is_p_form(xauto_access) == x1.is_p_form(xauto_access));
233 
234  // Body:
235 
236  if(xauto_access)
237  {
238  x0.get_read_access();
239  x1.get_read_access();
240  xresult.get_read_write_access(true);
241  }
242 
243  typedef typename S0::fiber_type::volatile_type V0;
244  typedef typename S1::fiber_type::volatile_type V1;
245  typedef typename SR::fiber_type::volatile_type VR;
246  wedge_functor<V0, V1, VR> f;
247  binary_op(x0, x1, xresult, f, false);
248 
249  // Set the variance of the result.
250 
251  xresult.put_variance(wedge(x0.variance(false), x1.variance(false)), false);
252 
253  if(xauto_access)
254  {
255  x0.release_access();
256  x1.release_access();
257  xresult.release_access();
258  }
259 
260  // Postconditions:
261 
262  ensure(xresult.variance(xauto_access) == \
263  wedge(x0.variance(xauto_access), x1.variance(xauto_access)));
264 
265  // Exit:
266 
267  return;
268 }
269 
270 
271 } // namespace fiber_bundle
272 
273 #endif // ifndef SEC_ATP_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
SHEAF_DLL_SPEC tensor_variance hook(const tensor_variance &x0)
The variance of the hook of a tensor with variance x0.
SHEAF_DLL_SPEC tensor_variance wedge(const tensor_variance &x0, const tensor_variance &x1)
The variance of the wedge of a tensor with variance x0 with a tnesor with variance x1...
SHEAF_DLL_SPEC tensor_variance star(const tensor_variance &x0, int xdd)
The variance of the Hodge star of a tensor with variance x0 over a vector space of dimension xdd...
Namespace for the fiber_bundles component of the sheaf system.