SheafSystem  0.0.0.0
average_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/average_push_action.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/block.h"
25 #include "SheafSystem/error_message.h"
26 #include "SheafSystem/sec_vd.h"
27 
28 using namespace std;
29 using namespace fields; // Workaround for MS C++ bug.
30 
31 // =============================================================================
32 // AVERAGE_PUSH_ACTION FACET
33 // =============================================================================
34 
35 // PUBLIC MEMBER FUNCTIONS
36 
37 fields::average_push_action::
38 average_push_action(int xdst_df)
40 {
41 
42  // Preconditions:
43 
44  require(xdst_df >= 0);
45 
46  // Body:
47 
49 
52 
53 
54 
55  // Postconditions:
56 
57  ensure(invariant());
58  ensure(dst_df() == xdst_df);
59 
60  // Exit:
61 
62  return;
63 }
64 
65 
66 
67 
70 {
71  // Preconditions:
72 
73 
74  // Body:
75 
76  // Nothing to do;
77 
78  // Postconditions:
79 
80  // Exit:
81 
82  return;
83 }
84 
85 
86 // =============================================================================
87 // SECTION_PUSHER_PUSH_ACTION FACET
88 // =============================================================================
89 
90 // PUBLIC MEMBER FUNCTIONS
91 
92 void
94 operator()(pullback_map::iterator& xitr,
95  sec_vd& xdst,
96  block<sec_vd_dof_type>& xdst_dofs)
97 {
98 #ifdef DIAGNOSTIC_OUTPUT
99  post_information_message("Entering average_push_action::operator()");
100 #endif
101 
102  // Preconditions:
103 
104  require(xdst.state_is_read_accessible());
105  require(xdst.schema().df() == dst_df());
106  require(xdst_dofs.ub() >= dst_df());
107  require(unexecutable("xdst_dofs initialized to source value"));
108  require(xdst_dofs.ct() == dst_df()); // Partial statement of above
109 
110  // Body:
111 
112  xdst.get_fiber(xitr->disc_id, _dst_dofs.base(),
113  _dst_dofs.ct()*sizeof(sec_vd_dof_type), false);
114 
115 #ifdef DIAGNOSTIC_OUTPUT
116 
117  cout << "disc id: " << setw(4) << xitr->disc_id
118  << " _dst_dofs: " << _dst_dofs;
119 #endif
120 
121  for(int i=0; i<_dst_df; ++i)
122  {
123  xdst_dofs[i] += _dst_dofs[i];
124  }
125 
126  pod_index_type lclient_id = _disc_seq_id_space->pod(xitr->disc_id);
127 
128  ++_branch_cts[lclient_id];
129 
130 #ifdef DIAGNOSTIC_OUTPUT
131 
132  cout << " xdst_dofs: " << xdst_dofs
133  << " ct: " << _branch_cts[lclient_id]
134  << endl;
135 #endif
136 
137  // Postconditions:
138 
139  ensure(unexecutable("xdst_dofs += xdst dofs"));
140 
141  // Exit:
142 
143 #ifdef DIAGNOSTIC_OUTPUT
144 
145  post_information_message("Leaving average_push_action::operator()");
146 #endif
147 
148  return;
149 }
150 
151 
152 void
155 {
156  // Preconditions:
157 
158  require(xdst.state_is_read_write_accessible());
159 
160  // Body:
161 
162  _dst_dofs.assign(0.0);
163 
164  _disc_ct = xdst.schema().discretization_ct();
167 
168  for(int i= 0; i<_disc_ct; ++i)
169  {
170  xdst.put_fiber(i, _dst_dofs.base(), _dst_dofs.ct()*sizeof(sec_vd_dof_type));
171 
172  _branch_cts[i] = 0;
173  }
174 
176 
177  // Postconditions:
178 
179 
180  // Exit:
181 
182  return;
183 }
184 
185 void
188 {
189  // Preconditions:
190 
191  require(xdst.state_is_read_write_accessible());
192 
193  // Body:
194 
195  // Normalize the accumulated values.
196 
197  for(int i= 0; i<_disc_ct; ++i)
198  {
199  xdst.get_fiber(i, _dst_dofs.base(), _dst_dofs.ct()*sizeof(sec_vd_dof_type));
200 
201  int lbranch_ct = _branch_cts[i];
202  if(lbranch_ct != 0)
203  {
204  for(int j=0; j<_dst_df; ++j)
205  {
206  _dst_dofs[j] /= lbranch_ct;
207  }
208  }
209  xdst.put_fiber(i, _dst_dofs.base(), _dst_dofs.ct()*sizeof(sec_vd_dof_type));
210  }
211 
212  // Postconditions:
213 
214 
215  // Exit:
216 
217  return;
218 }
219 
220 
221 // =============================================================================
222 // ANY FACET
223 // =============================================================================
224 
225 // PUBLIC MEMBER FUNCTIONS
226 
227 bool
229 is_ancestor_of(const any* xother) const
230 {
231 
232  // Preconditions:
233 
234  require(xother != 0);
235 
236  // Body:
237 
238  // True if other conforms to this
239 
240  bool result = dynamic_cast<const average_push_action*>(xother) != 0;
241 
242  // Postconditions:
243 
244  return result;
245 }
246 
249 clone() const
250 {
251  average_push_action* result;
252 
253  // Preconditions:
254 
255  // Body:
256 
257  result = new average_push_action(*this);
258 
259  // Postconditions:
260 
261  ensure(result != 0);
262  ensure(is_same_type(result));
263 
264  // Exit:
265 
266  return result;
267 }
268 
273 {
274 
275  // Preconditions:
276 
277  require(is_ancestor_of(&xother));
278 
279  // Body:
280 
281  not_implemented();
282 
283  // Postconditions:
284 
285  ensure(invariant());
286 
287  // Exit:
288 
289  return *this;
290 }
291 
292 
296 {
297 
298  // Preconditions:
299 
300 
301  // Body:
302 
303  _dst_df = xother._dst_df;
304 
305  // Postconditions:
306 
307  ensure(invariant());
308 
309  // Exit
310 
311  return *this;
312 }
313 
314 bool
316 invariant() const
317 {
318  bool result = true;
319 
320  if(invariant_check())
321  {
322  // Prevent recursive calls to invariant
323 
325 
326  // Must satisfy base class invariant
327 
329 
330  // Invariances for this class:
331 
332  // Finished, turn invariant checking back on.
333 
335  }
336 
337  // Exit
338 
339  return result;
340 }
341 
342 
343 // =============================================================================
344 // NON-MEMBER FUNCTIONS
345 // =============================================================================
346 
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.
Abstract functor to compute the dofs at a destination discretization point.
Namespace for fields component of sheaf system.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void get_fiber(pod_index_type xdisc_id, vd_lite &xfiber) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
Definition: sec_vd.cc:1087
virtual bool invariant() const
Class invariant.
block< int > _branch_cts
Number of branches accumulated for each discretization member.
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.
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
block< sec_vd_dof_type > _dst_dofs
Buffer for destination dofs.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual ~average_push_action()
Destructor.
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
pointer_type base() const
The underlying storage array.
void set_ct(size_type xct)
Sets ct() == xct.
int discretization_ct() const
The number of members in the intersection of the discretization subposet and the down set of the base...
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 pod_type pod(pod_type xid) const =0
The pod index in this space equivalent to xid in the hub id space.
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
virtual void initialize(sec_vd &xdst)
Initializes xdst as needed.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
void put_fiber(pod_index_type xdisc_id, const vd_lite &xfiber)
Sets the fiber referred to by discretization id xdisc_id to xfiber.
Definition: sec_vd.cc:1144
const index_space_handle & discretization_id_space() const
The id space for the discretization members in the down set of the base space of this (const version)...
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual void finalize(sec_vd &xdst)
Finalizes xdst as needed.
int df() const
The dimension of the fiber space component.
index_space_handle * _disc_seq_id_space
Discretization sequence id space for destination section.
int _disc_ct
Discretization count of destination.
Functor to compute the dofs at a destination discretization point by averaging the source values form...
double sec_vd_dof_type
The type of degree of freedom in the section space.
Definition: fiber_bundle.h:78
virtual average_push_action * clone() const
Virtual constructor, makes a new instance of the same type as this.
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
virtual average_push_action & operator=(const section_pusher_push_action &xother)
Assignment operator.