SheafSystem  0.0.0.0
constant_push_action.cc
Go to the documentation of this file.
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 
20 
21 #include "SheafSystem/constant_push_action.h"
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/error_message.h"
24 #include "SheafSystem/sec_vd.h"
25 
26 using namespace std;
27 using namespace fields; // Workaround for MS C++ bug.
28 
29 // =============================================================================
30 // CONSTANT_PUSH_ACTION FACET
31 // =============================================================================
32 
33 // PUBLIC MEMBER FUNCTIONS
34 
35 fields::constant_push_action::
36 constant_push_action(int xdst_df, const block<sec_vd_dof_type>& xdst_dofs)
37  : section_pusher_push_action(xdst_df),
38  _dst_dofs(xdst_dofs)
39 {
40 
41  // Preconditions:
42 
43  require(xdst_df >= 0);
44  require(xdst_dofs.ct() == xdst_df);
45 
46  // Body:
47 
48  // Nothing to do.
49 
50  // Postconditions:
51 
52  ensure(invariant());
53  ensure(dst_df() == xdst_df);
54  ensure(dst_dofs().ct() == xdst_df);
55  ensure_for_all(i, 0, dst_df(), dst_dofs()[i] == xdst_dofs[i]);
56 
57  // Exit:
58 
59  return;
60 }
61 
62 fields::constant_push_action::
63 constant_push_action(int xdst_df, sec_vd_dof_type xdst_dof)
65 {
66 
67  // Preconditions:
68 
69  require(xdst_df >= 0);
70 
71  // Body:
72 
75  _dst_dofs.assign(xdst_dof);
76 
77  // Postconditions:
78 
79  ensure(invariant());
80  ensure(dst_df() == xdst_df);
81  ensure(dst_dofs().ct() == xdst_df);
82  ensure_for_all(i, 0, dst_df(), dst_dofs()[i] == xdst_dof);
83 
84  // Exit:
85 
86  return;
87 }
88 
91 {
92  // Preconditions:
93 
94 
95  // Body:
96 
97  // Nothing to do;
98 
99  // Postconditions:
100 
101  // Exit:
102 
103  return;
104 }
105 
109 {
110  return _dst_dofs;
111 }
112 
113 
114 // =============================================================================
115 // SECTION_PUSHER_PUSH_ACTION FACET
116 // =============================================================================
117 
118 // PUBLIC MEMBER FUNCTIONS
119 
120 void
122 operator()(pullback_map::iterator& xitr,
123  sec_vd& xdst,
124  block<sec_vd_dof_type>& xdst_dofs)
125 {
126  // Preconditions:
127 
128  require(xdst.state_is_read_accessible());
129  require(xdst.schema().df() == dst_df());
130  require(xdst_dofs.ub() >= dst_df());
131 
132  // Body:
133 
134  xdst_dofs = _dst_dofs;
135 
136  // Postconditions:
137 
138  ensure_for_all(i, 0, dst_df(), dst_dofs()[i] == xdst_dofs[i]);
139 
140  // Exit:
141 
142  return;
143 }
144 
145 
146 // =============================================================================
147 // ANY FACET
148 // =============================================================================
149 
150 // PUBLIC MEMBER FUNCTIONS
151 
152 bool
154 is_ancestor_of(const any* xother) const
155 {
156 
157  // Preconditions:
158 
159  require(xother != 0);
160 
161  // Body:
162 
163  // True if xother conforms to this
164 
165  bool result = dynamic_cast<const constant_push_action*>(xother) != 0;
166 
167  // Postconditions:
168 
169  return result;
170 }
171 
174 clone() const
175 {
176  constant_push_action* result;
177 
178  // Preconditions:
179 
180  // Body:
181 
182  result = new constant_push_action(*this);
183 
184  // Postconditions:
185 
186  ensure(result != 0);
187  ensure(is_same_type(result));
188 
189  // Exit:
190 
191  return result;
192 }
193 
198 {
199 
200  // Preconditions:
201 
202  require(is_ancestor_of(&xother));
203 
204  // Body:
205 
206  not_implemented();
207 
208  // Postconditions:
209 
210  ensure(invariant());
211 
212  // Exit:
213 
214  return *this;
215 }
216 
217 
221 {
222 
223  // Preconditions:
224 
225 
226  // Body:
227 
228  _dst_df = xother._dst_df;
229  _dst_dofs = xother._dst_dofs;
230 
231  // Postconditions:
232 
233  ensure(invariant());
234 
235  // Exit
236 
237  return *this;
238 }
239 
240 bool
242 invariant() const
243 {
244  bool result = true;
245 
246  if(invariant_check())
247  {
248  // Prevent recursive calls to invariant
249 
251 
252  // Must satisfy base class invariant
253 
255 
256  // Invariances for this class:
257 
258  // Finished, turn invariant checking back on.
259 
261  }
262 
263  // Exit
264 
265  return result;
266 }
267 
268 // =============================================================================
269 // NON-MEMBER FUNCTIONS
270 // =============================================================================
271 
block< sec_vd_dof_type > _dst_dofs
Constant value for destination dofs.
virtual constant_push_action * clone() const
Virtual constructor, makes a new instance of the same type as this.
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual constant_push_action & operator=(const section_pusher_push_action &xother)
Assignment operator.
Abstract functor to compute the dofs at a destination discretization point.
block< sec_vd_dof_type > & dst_dofs()
Constant value for destination dofs.
Namespace for fields component of sheaf system.
virtual bool invariant() const
Class invariant.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
virtual ~constant_push_action()
Destructor.
void set_ct(size_type xct)
Sets ct() == xct.
int _dst_df
The fiber dimension of the destination.
int dst_df()
The fiber dimension of the destination.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual void operator()(pullback_map::iterator &xitr, sec_vd &xdst, block< sec_vd_dof_type > &xdst_dofs)
Computes xdst_dofs using xitr and the dofs already in xdst, as needed.
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
Abstract functor to compute the dofs at a destination discretization point.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
int df() const
The dimension of the fiber space component.
double sec_vd_dof_type
The type of degree of freedom in the section space.
Definition: fiber_bundle.h:78
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87