SheafSystem  0.0.0.0
sec_met.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_met facet function templates.
19 
20 #ifndef SEC_MET_IMPL_H
21 #define SEC_MET_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_MET_H
32 #include "SheafSystem/sec_met.h"
33 #endif
34 
35 namespace fiber_bundle
36 {
37 
38 //==============================================================================
39 // NON-MEMBER FUNCTIONS
40 //==============================================================================
41 
42 //==============================================================================
43 
45 template <typename VMET, typename VVECTOR, typename VR>
46 void
47 lower_functor<VMET, VVECTOR, VR>::
48 operator()(const VMET& xmet, const VVECTOR& xvector, VR& xresult)
49 {
50  // Preconditions:
51 
52  require(precondition_of(lower(xmet, xvector, xresult)));
53 
54  // Body:
55 
56  lower(xmet, xvector, xresult);
57 
58  // Postconditions:
59 
60  ensure(postcondition_of(lower(xmet, xvector, xresult)));
61 
62  // Exit:
63 
64  return;
65 }
66 
68 template <typename VMET, typename VCOVECTOR, typename VR>
69 void
70 raise_functor<VMET, VCOVECTOR, VR>::
71 operator()(const VMET& xmet, const VCOVECTOR& xcovector, VR& xresult)
72 {
73  // Preconditions:
74 
75  require(precondition_of( raise(xmet, xcovector, xresult)));
76 
77  // Body:
78 
79  raise(xmet, xcovector, xresult);
80 
81  // Postconditions:
82 
83  ensure(postcondition_of( raise(xmet, xcovector, xresult)));
84 
85  // Exit:
86 
87  return;
88 }
89 
90 
91 //==============================================================================
92 
94 template <typename SMET, typename SVECTOR, typename SR>
95 void lower(const SMET& xmetric, const SVECTOR& xvector, SR& xresult,
96  bool xauto_access)
97 {
98  // Preconditions:
99 
100  require(xmetric.state_is_auto_read_accessible(xauto_access));
101  require(xvector.state_is_auto_read_accessible(xauto_access));
102  require(xresult.state_is_auto_read_write_accessible(xauto_access));
103  require(xmetric.is_covariant(0, xauto_access));
104  require(xvector.is_contravariant(0, xauto_access)); // !is_dual;
105 
106  // Body:
107 
108  if(xauto_access)
109  {
110  xmetric.get_read_access();
111  xvector.get_read_access();
112  xresult.get_read_write_access(true);
113  }
114 
115  typedef typename SMET::fiber_type::volatile_type VMET;
116  typedef typename SVECTOR::fiber_type::volatile_type VVECTOR;
117  typedef typename SR::fiber_type::volatile_type VR;
118  lower_functor<VMET, VVECTOR, VR> f;
119  binary_op(xmetric, xvector, xresult, f, xauto_access);
120 
121 
122  // Make sure the result is covariant/p_form.
123 
124  xresult.put_is_p_form(false);
125 
126  if(xauto_access)
127  {
128  xmetric.release_access();
129  xvector.release_access();
130  xresult.release_access();
131  }
132 
133  // Postconditions:
134 
135  ensure(xresult.is_covariant(0, xauto_access)); // is_dual
136 
137  // Exit:
138 
139  return;
140 
141 }
142 
144 template <typename SMET, typename SCOVECTOR, typename SR>
145 void raise(const SMET& xmetric, const SCOVECTOR& xcovector, SR& xresult,
146  bool xauto_access)
147 {
148  // Preconditions:
149 
150  require(xmetric.state_is_auto_read_accessible(xauto_access));
151  require(xcovector.state_is_auto_read_accessible(xauto_access));
152  require(xresult.state_is_auto_read_write_accessible(xauto_access));
153  require(xmetric.is_contravariant(0, xauto_access));
154  require(xcovector.is_covariant(0, xauto_access)); // is_dual;
155 
156  // Body:
157 
158  if(xauto_access)
159  {
160  xmetric.get_read_access();
161  xcovector.get_read_access();
162  xresult.get_read_write_access(true);
163  }
164 
165  typedef typename SMET::fiber_type::volatile_type VMET;
166  typedef typename SCOVECTOR::fiber_type::volatile_type VCOVECTOR;
167  typedef typename SR::fiber_type::volatile_type VR;
168  raise_functor<VMET, VCOVECTOR, VR> f;
169  binary_op(xmetric, xcovector, xresult, f, xauto_access);
170 
171  // Make sure the result is contravariant/p_vector.
172 
173  xresult.put_is_p_vector(false);
174 
175  if(xauto_access)
176  {
177  xmetric.release_access();
178  xcovector.release_access();
179  xresult.release_access();
180  }
181 
182  // Postconditions:
183 
184  ensure(xresult.is_contravariant(0, xauto_access)); // !is_dual
185 
186  // Exit:
187 
188  return;
189 }
190 
191 } // namespace fiber_bundle
192 
193 
194 #endif // ifndef SEC_MET_IMPL_H
SHEAF_DLL_SPEC tensor_variance lower(const tensor_variance &x0, int xi)
The variance of the lower of a tensor with variance x0 on index xi.
void binary_op(const S0 &x0, const S1 &x1, SR &xresult, F xfunctor, bool xauto_access)
Binary operator.
Definition: sec_vd.impl.h:48
Namespace for the fiber_bundles component of the sheaf system.