23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 27 #ifndef ASSERT_CONTRACT_H 28 #include "SheafSystem/assert_contract.h" 32 #include "SheafSystem/sec_tp.h" 45 template <
typename V0,
typename VR>
48 operator()(
const V0& x0, VR& xresult)
52 require(precondition_of(
alt(x0, xresult)));
60 ensure(postcondition_of(
alt(x0, xresult)));
68 template <
typename V0,
typename VR>
71 operator()(
const V0& x0, VR& xresult)
75 require(precondition_of(
sym(x0, xresult)));
83 ensure(postcondition_of(
sym(x0, xresult)));
91 template <
typename V0,
typename V1,
typename VR>
93 tensor_functor<V0, V1, VR>::
94 operator()(
const V0& x0,
const V1& x1, VR& xresult)
98 require(precondition_of(
tensor(x0, x1, xresult)));
106 ensure(postcondition_of(
tensor(x0, x1, xresult)));
114 template <
typename V0,
typename VR>
116 contract_functor<V0, VR>::
117 operator()(
const V0& x0, VR& xresult)
121 require(precondition_of(
contract(x0, _p, _q, xresult)));
129 ensure(postcondition_of(
contract(x0, _p, _q, xresult)));
139 template <
typename GT,
typename AT>
140 void alt(
const GT& x0, AT& xresult,
bool xauto_access)
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());
153 x0.get_read_access();
154 xresult.get_read_write_access(
true);
157 typedef typename GT::fiber_type::volatile_type V0;
158 typedef typename AT::fiber_type::volatile_type VR;
159 alt_functor<V0, VR> f;
164 xresult.put_variance(x0.variance(
false),
false);
169 xresult.release_access();
174 ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
175 ensure(unexecutable(
"xresult is equal to the antisymmetric part of x0"));
183 template <
typename GT,
typename ST>
184 void sym(
const GT& x0, ST& xresult,
bool xauto_access)
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());
197 x0.get_read_access();
198 xresult.get_read_write_access(
true);
201 typedef typename GT::fiber_type::volatile_type V0;
202 typedef typename ST::fiber_type::volatile_type VR;
203 sym_functor<V0, VR> f;
208 xresult.put_variance(x0.variance(
false),
false);
213 xresult.release_access();
218 ensure(xresult.variance(xauto_access) == x0.variance(xauto_access));
219 ensure(unexecutable(
"xresult is equal to the symmetric part of x0"));
227 template <
typename S0,
typename S1,
typename SR>
228 void tensor(
const S0& x0,
const S1& x1, SR& xresult,
bool xauto_access)
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));
243 x0.get_read_access();
244 x1.get_read_access();
245 xresult.get_read_write_access(
true);
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);
256 xresult.put_variance(
264 xresult.release_access();
269 ensure(xresult.variance(xauto_access) == \
270 tensor_product(x0.variance(xauto_access), x1.variance(xauto_access)));
278 template <
typename S0,
typename SR>
279 void contract(
const S0& x0,
int xp,
int xq, SR& xresult,
bool xauto_access)
283 require(x0.state_is_auto_read_accessible(xauto_access));
284 require(xresult.state_is_auto_read_accessible(xauto_access));
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));
296 x0.get_read_access();
297 xresult.get_read_write_access(
true);
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);
307 xresult.put_variance(
contract(x0.variance(
false), xp, xq),
false);
312 xresult.release_access();
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"));
335 require(xp >= 0 && xp < x0.
p(xauto_access));
336 require(xq >= 0 && xq < x0.
p(xauto_access));
338 x0.is_contravariant(xq, xauto_access));
350 contract_functor<V0, VR> f(xp, xq);
351 unary_op(x0, xresult, f, xauto_access);
362 ensure(unexecutable(
"xresult is the contraction of x0 on indices xp and xq"));
379 require(xp >= 0 && xp < x0.
p(xauto_access));
380 require(xq >= 0 && xq < x0.
p(xauto_access));
382 x0.is_contravariant(xq, xauto_access));
394 contract_functor<V0, VR> f(xp, xq);
395 unary_op(x0, xresult, f, xauto_access);
406 ensure(unexecutable(
"xresult is the contraction of x0 on indices xp and xq"));
416 #endif // ifndef SEC_TP_IMPL_H void alt(const GT &x0, AT &xresult, bool xauto_access)
void sym(const GT &x0, ST &xresult, bool xauto_access)
void unary_op(const S0 &x0, SR &xresult, F xfunctor, bool xauto_access)
Unary operator.
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.
A tensor of degree 2 over an abstract vector space (volatile version).
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.
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Antisymetric tensor of degree 0 (volatile version).
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.
A section of a bundle with fiber type t2_e3.
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...
void tensor(const S0 &x0, const S1 &x1, SR &xresult, bool xauto_access)