SheafSystem  0.0.0.0
sec_tp.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_tp facet function templates.
19 
20 #ifndef SEC_TP_IMPL_H
21 #define SEC_TP_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_TP_H
32 #include "SheafSystem/sec_tp.h"
33 #endif
34 
35 namespace fiber_bundle
36 {
37 
38 //==============================================================================
39 // NON-MEMBER FUNCTIONS
40 //==============================================================================
41 
42 //==============================================================================
43 
45 template <typename V0, typename VR>
46 void
47 alt_functor<V0, VR>::
48 operator()(const V0& x0, VR& xresult)
49 {
50  // Preconditions:
51 
52  require(precondition_of(alt(x0, xresult)));
53 
54  // Body:
55 
56  alt(x0, xresult);
57 
58  // Postconditions:
59 
60  ensure(postcondition_of(alt(x0, xresult)));
61 
62  // Exit:
63 
64  return;
65 }
66 
68 template <typename V0, typename VR>
69 void
70 sym_functor<V0, VR>::
71 operator()(const V0& x0, VR& xresult)
72 {
73  // Preconditions:
74 
75  require(precondition_of(sym(x0, xresult)));
76 
77  // Body:
78 
79  sym(x0, xresult);
80 
81  // Postconditions:
82 
83  ensure(postcondition_of(sym(x0, xresult)));
84 
85  // Exit:
86 
87  return;
88 }
89 
91 template <typename V0, typename V1, typename VR>
92 void
93 tensor_functor<V0, V1, VR>::
94 operator()(const V0& x0, const V1& x1, VR& xresult)
95 {
96  // Preconditions:
97 
98  require(precondition_of(tensor(x0, x1, xresult)));
99 
100  // Body:
101 
102  tensor(x0, x1, xresult);
103 
104  // Postconditions:
105 
106  ensure(postcondition_of( tensor(x0, x1, xresult)));
107 
108  // Exit:
109 
110  return;
111 }
112 
114 template <typename V0, typename VR>
115 void
116 contract_functor<V0, VR>::
117 operator()(const V0& x0, VR& xresult)
118 {
119  // Preconditions:
120 
121  require(precondition_of(contract(x0, _p, _q, xresult)));
122 
123  // Body:
124 
125  contract(x0, _p, _q, xresult);
126 
127  // Postconditions:
128 
129  ensure(postcondition_of(contract(x0, _p, _q, xresult)));
130 
131  // Exit:
132 
133  return;
134 }
135 
136 //==============================================================================
137 
139 template <typename GT, typename AT>
140 void alt(const GT& x0, AT& xresult, bool xauto_access)
141 {
142  // Preconditions:
143 
144  require(x0.state_is_auto_read_accessible(xauto_access));
145  require(xresult.state_is_auto_read_accessible(xauto_access));
146  require(x0.dd(xauto_access) == xresult.dd(xauto_access));
147  require(!x0.variance(xauto_access).is_mixed());
148 
149  // Body:
150 
151  if(xauto_access)
152  {
153  x0.get_read_access();
154  xresult.get_read_write_access(true);
155  }
156 
157  typedef typename GT::fiber_type::volatile_type V0;
158  typedef typename AT::fiber_type::volatile_type VR;
159  alt_functor<V0, VR> f;
160  unary_op(x0, xresult, f, false);
161 
162  // Set the variance of the result.
163 
164  xresult.put_variance(x0.variance(false), false);
165 
166  if(xauto_access)
167  {
168  x0.release_access();
169  xresult.release_access();
170  }
171 
172  // Postconditions:
173 
174  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
175  ensure(unexecutable("xresult is equal to the antisymmetric part of x0"));
176 
177  // Exit:
178 
179  return;
180 }
181 
183 template <typename GT, typename ST>
184 void sym(const GT& x0, ST& xresult, bool xauto_access)
185 {
186  // Preconditions:
187 
188  require(x0.state_is_auto_read_accessible(xauto_access));
189  require(xresult.state_is_auto_read_accessible(xauto_access));
190  require(x0.dd(xauto_access) == xresult.dd(xauto_access));
191  require(!x0.variance(xauto_access).is_mixed());
192 
193  // Body:
194 
195  if(xauto_access)
196  {
197  x0.get_read_access();
198  xresult.get_read_write_access(true);
199  }
200 
201  typedef typename GT::fiber_type::volatile_type V0;
202  typedef typename ST::fiber_type::volatile_type VR;
203  sym_functor<V0, VR> f;
204  unary_op(x0, xresult, f, false);
205 
206  // Set the variance of the result.
207 
208  xresult.put_variance(x0.variance(false), false);
209 
210  if(xauto_access)
211  {
212  x0.release_access();
213  xresult.release_access();
214  }
215 
216  // Postconditions:
217 
218  ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
219  ensure(unexecutable("xresult is equal to the symmetric part of x0"));
220 
221  // Exit:
222 
223  return;
224 }
225 
227 template <typename S0, typename S1, typename SR>
228 void tensor(const S0& x0, const S1& x1, SR& xresult, bool xauto_access)
229 {
230 
231  // Preconditions:
232 
233  require(x0.state_is_auto_read_accessible(xauto_access));
234  require(x1.state_is_auto_read_accessible(xauto_access));
235  require(xresult.state_is_auto_read_accessible(xauto_access));
236  require(x1.dd(xauto_access) == x0.dd(xauto_access));
237  require(xresult.dd(xauto_access) == x0.dd(xauto_access));
238 
239  // Body:
240 
241  if(xauto_access)
242  {
243  x0.get_read_access();
244  x1.get_read_access();
245  xresult.get_read_write_access(true);
246  }
247 
248  typedef typename S0::fiber_type::volatile_type V0;
249  typedef typename S1::fiber_type::volatile_type V1;
250  typedef typename SR::fiber_type::volatile_type VR;
251  tensor_functor<V0, V1, VR> f;
252  binary_op(x0, x1, xresult, f, xauto_access);
253 
254  // Set the variance of the result.
255 
256  xresult.put_variance(
257  tensor_product(x0.variance(false), x1.variance(false)), false);
258 
259 
260  if(xauto_access)
261  {
262  x0.release_access();
263  x1.release_access();
264  xresult.release_access();
265  }
266 
267  // Postconditions:
268 
269  ensure(xresult.variance(xauto_access) == \
270  tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
271 
272  // Exit:
273 
274  return;
275 }
276 
278 template <typename S0, typename SR>
279 void contract(const S0& x0, int xp, int xq, SR& xresult, bool xauto_access)
280 {
281  // Preconditions:
282 
283  require(x0.state_is_auto_read_accessible(xauto_access));
284  require(xresult.state_is_auto_read_accessible(xauto_access));
285  require(xp != xq);
286  require(xp >= 0 && xp < x0.p(xauto_access));
287  require(xq >= 0 && xq < x0.p(xauto_access));
288  require(xresult.p(xauto_access) == x0.p(xauto_access) - 2);
289  require(x0.is_contravariant(xp, xauto_access) != \
290  x0.is_contravariant(xq, xauto_access));
291 
292  // Body:
293 
294  if(xauto_access)
295  {
296  x0.get_read_access();
297  xresult.get_read_write_access(true);
298  }
299 
300  typedef typename S0::fiber_type::volatile_type V0;
301  typedef typename SR::fiber_type::volatile_type VR;
302  contract_functor<V0, VR> f(xp, xq);
303  unary_op(x0, xresult, f, xauto_access);
304 
305  // Set the variance of the result.
306 
307  xresult.put_variance(contract(x0.variance(false), xp, xq), false);
308 
309  if(xauto_access)
310  {
311  x0.release_access();
312  xresult.release_access();
313  }
314 
315  // Postconditions:
316 
317  ensure(xresult.variance(xauto_access) == \
318  contract(x0.variance(xauto_access), xp, xq));
319  ensure(unexecutable("xresult is the contraction of x0 on indices xp and xq"));
320 
321  // Exit:
322 
323  return;
324 }
325 
326 template<>
327 void contract(const sec_t2_e2& x0, int xp, int xq, sec_at0& xresult,
328  bool xauto_access)
329 {
330  // Preconditions:
331 
332  require(x0.state_is_auto_read_accessible(xauto_access));
333  require(xresult.state_is_auto_read_accessible(xauto_access));
334  require(xp != xq);
335  require(xp >= 0 && xp < x0.p(xauto_access));
336  require(xq >= 0 && xq < x0.p(xauto_access));
337  require(x0.is_contravariant(xp, xauto_access) != \
338  x0.is_contravariant(xq, xauto_access));
339 
340  // Body:
341 
342  if(xauto_access)
343  {
344  x0.get_read_access();
345  xresult.get_read_write_access(true);
346  }
347 
350  contract_functor<V0, VR> f(xp, xq);
351  unary_op(x0, xresult, f, xauto_access);
352 
353 
354  if(xauto_access)
355  {
356  x0.release_access();
357  xresult.release_access();
358  }
359 
360  // Postconditions:
361 
362  ensure(unexecutable("xresult is the contraction of x0 on indices xp and xq"));
363  //ensure(xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access));
364 
365  // Exit:
366 
367  return;
368 }
369 
370 template<>
371 void contract(const sec_t2_e3& x0, int xp, int xq, sec_at0& xresult,
372  bool xauto_access)
373 {
374  // Preconditions:
375 
376  require(x0.state_is_auto_read_accessible(xauto_access));
377  require(xresult.state_is_auto_read_accessible(xauto_access));
378  require(xp != xq);
379  require(xp >= 0 && xp < x0.p(xauto_access));
380  require(xq >= 0 && xq < x0.p(xauto_access));
381  require(x0.is_contravariant(xp, xauto_access) != \
382  x0.is_contravariant(xq, xauto_access));
383 
384  // Body:
385 
386  if(xauto_access)
387  {
388  x0.get_read_access();
389  xresult.get_read_write_access(true);
390  }
391 
394  contract_functor<V0, VR> f(xp, xq);
395  unary_op(x0, xresult, f, xauto_access);
396 
397 
398  if(xauto_access)
399  {
400  x0.release_access();
401  xresult.release_access();
402  }
403 
404  // Postconditions:
405 
406  ensure(unexecutable("xresult is the contraction of x0 on indices xp and xq"));
407  //ensure(xresult.is_p_form(xauto_access) == x0.is_p_form(xauto_access));
408 
409  // Exit:
410 
411  return;
412 }
413 
414 } // namespace fiber_bundle
415 
416 #endif // ifndef SEC_TP_IMPL_H
void alt(const GT &x0, AT &xresult, bool xauto_access)
Definition: sec_tp.impl.h:140
void sym(const GT &x0, ST &xresult, bool xauto_access)
Definition: sec_tp.impl.h:184
void unary_op(const S0 &x0, SR &xresult, F xfunctor, bool xauto_access)
Unary operator.
Definition: sec_vd.impl.h:224
bool state_is_auto_read_accessible(bool xauto_access) const
True if the state is auto accessible for read, that is, if the state is already accessible for read o...
virtual void get_read_access() const
Get read access to the state associated with this.
SHEAF_DLL_SPEC tensor_variance tensor_product(const tensor_variance &x0, const tensor_variance &x1)
The variance of the tensor product of tensors with variance x0 and x1.
virtual int p() const
The degree of the tensors in host(); the sum of the contravariant and covariant degrees.
Definition: sec_tp.cc:391
A tensor of degree 2 over an abstract vector space (volatile version).
Definition: t2.h:43
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
virtual bool is_contravariant(bool xauto_access) const
True if and only if all tensor index positions are contravariant.
Definition: sec_tp.cc:748
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Definition: sec_vd.impl.h:48
Antisymetric tensor of degree 0 (volatile version).
Definition: at0.h:127
SHEAF_DLL_SPEC tensor_variance contract(const tensor_variance &x0, int xp, int xq)
The variance of the contration of a tensor with variance x0 on indices xp and xq. ...
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
A section of a bundle with fiber type t2_e2.
Definition: sec_t2_e2.h:48
A section of a bundle with fiber type t2_e3.
Definition: sec_t2_e3.h:48
Namespace for the fiber_bundles component of the sheaf system.
Antisymetric tensor of degree 0. As the degree is 0 there is nothing to be symmetric or antisymmetric...
Definition: sec_at0.h:51
void tensor(const S0 &x0, const S1 &x1, SR &xresult, bool xauto_access)
Definition: sec_tp.impl.h:228