SheafSystem  0.0.0.0
average_base_space_map_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_base_space_map_push_action.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/block.h"
25 #include "SheafSystem/error_message.h"
26 #include "SheafSystem/index_space_iterator.h"
27 #include "SheafSystem/preorder_iterator.h"
28 #include "SheafSystem/sec_vd.h"
29 #include "SheafSystem/section_space_schema_poset.h"
30 
31 using namespace std;
32 using namespace fields; // Workaround for MS C++ bug.
33 
34 
35 // =============================================================================
36 // AVERAGE_BASE_SPACE_MAP_PUSH_ACTION FACET
37 // =============================================================================
38 
39 // PUBLIC MEMBER FUNCTIONS
40 
43 {
44 
45  // Preconditions:
46 
47  // Body:
48 
49  // Postconditions:
50 
51  ensure(invariant());
52 
53  // Exit:
54 
55  return;
56 }
57 
58 
59 
60 
63 {
64  // Preconditions:
65 
66 
67  // Body:
68 
69  // Nothing to do;
70 
71  // Postconditions:
72 
73  // Exit:
74 
75  return;
76 }
77 
78 
79 // =============================================================================
80 // BASE_SPACE_MAP_PUSH_ACTION FACET
81 // =============================================================================
82 
83 // PUBLIC MEMBER FUNCTIONS
84 
85 void
87 operator()(pullback_map::iterator& xitr,
88  block<sec_vd*>& xoutputs,
89  block< block<sec_vd_dof_type>* >& xout_dofs)
90 {
91 #ifdef DIAGNOSTIC_OUTPUT
92  post_information_message("Entering average_base_space_map_push_action::operator()");
93 #endif
94 
95  // Preconditions:
96 
97  require(xoutputs.ct() > 0);
98  require(xout_dofs.ct() >= xoutputs.ct());
99  require_for_all(i, 0, xoutputs.ct(), xoutputs[i]->state_is_read_accessible());
100  require_for_all(i, 0, xoutputs.ct(), xout_dofs[i]->ub() >= xoutputs[i]->schema().df());
101 
102  // Body:
103 
104  for(int lout_id = 0; lout_id<xoutputs.ct(); ++lout_id)
105  {
106  sec_vd& loutput = *xoutputs[lout_id];
107 
108  sec_vd_dof_type* lout_dofs_base = _out_dofs[lout_id].base();
109  int lout_dofs_ct = _out_dofs[lout_id].ct();
110 
111  sec_vd_dof_type* xout_dofs_base = xout_dofs[lout_id]->base();
112  int xout_dofs_ct = xout_dofs[lout_id]->ct();
113 
114  loutput.get_fiber(xitr->disc_id, lout_dofs_base,
115  lout_dofs_ct*sizeof(sec_vd_dof_type), false);
116 
117 #ifdef DIAGNOSTIC_OUTPUT
118 
119  cout << "disc id: " << setw(4) << xitr->disc_id
120  << " _out_dofs: " << _out_dofs[lout_id];
121 #endif
122 
123  for(int i=0; i<xout_dofs_ct; ++i)
124  {
125  xout_dofs_base[i] += lout_dofs_base[i];
126  }
127 
128  ++_branch_cts[xitr->disc_id.pod()];
129 
130 #ifdef DIAGNOSTIC_OUTPUT
131 
132  cout << " xout_dofs: " << *xout_dofs[lout_id]
133  << " ct: " << _branch_cts[xitr->disc_id]
134  << endl;
135 #endif
136 
137  }
138 
139  // Postconditions:
140 
141  ensure(unexecutable("xdst_dofs += xdst dofs"));
142 
143  // Exit:
144 
145 #ifdef DIAGNOSTIC_OUTPUT
146 
147  post_information_message("Leaving average_base_space_map_push_action::operator()");
148 #endif
149 
150  return;
151 }
152 
153 
154 void
157 {
158  // Preconditions:
159 
160  require_for_all(i, 0, xoutputs.ct(), xoutputs[i]->state_is_read_write_accessible());
161 
162  // Body:
163 
164 
165  section_space_schema_member& lschema0 = xoutputs[0]->schema();
166 
167  _disc_id_space = &lschema0.discretization().id_space();
168 
169  int lid_ub = lschema0.host()->base_space().member_index_ub().pod();
170 
171  _branch_cts.reserve(lid_ub);
172  _branch_cts.set_ct(lid_ub);
173  _branch_cts.assign(0);
174 
175  int lct = xoutputs.ct();
176 
177  _out_dofs.reserve(lct);
178  _out_dofs.set_ct(lct);
179 
180  for(int i=0; i<lct; ++i)
181  {
182  sec_vd& loutput = *xoutputs[i];
183  section_space_schema_member& lschema = loutput.schema();
184 
185  block<sec_vd_dof_type>& lout_dofs = _out_dofs[i];
186  lout_dofs.reserve(lschema.df());
187  lout_dofs.set_ct(lschema.df());
188  lout_dofs.assign(0.0);
189 
190  // Initialize the output section to zero.
191 
192  //loutput.zero_sa();
193  assign(loutput, 0.0, false);
194  }
195 
196  // Postconditions:
197 
198 
199  // Exit:
200 
201  return;
202 }
203 
204 void
207 {
208  // Preconditions:
209 
210  require_for_all(i, 0, xoutputs.ct(), xoutputs[i]->state_is_read_write_accessible());
211 
212  // Body:
213 
214  // Normalize the accumulated dofs for each output.
215 
216  for(int lout_id=0; lout_id<xoutputs.ct(); ++lout_id)
217  {
218  sec_vd& loutput = *xoutputs[lout_id];
219 
220  sec_vd_dof_type* lout_dofs_base = _out_dofs[lout_id].base();
221  int lout_dofs_ct = _out_dofs[lout_id].ct();
222 
223  // Normalize the accumulated dofs for this output.
224 
225  pod_index_type lindex;
226 
227  index_space_iterator& litr =
229  while(!litr.is_done())
230  {
231  lindex = litr.pod();
232 
233  loutput.get_fiber(lindex, lout_dofs_base,
234  lout_dofs_ct*sizeof(sec_vd_dof_type));
235 
236  int lbranch_ct = _branch_cts[_disc_id_space->hub_pod(lindex)];
237 
238  if(lbranch_ct != 0)
239  {
240  for(int k=0; k<lout_dofs_ct; ++k)
241  {
242  lout_dofs_base[k] /= lbranch_ct;
243  }
244  }
245 
246  loutput.put_fiber(lindex, lout_dofs_base,
247  lout_dofs_ct*sizeof(sec_vd_dof_type));
248  }
249 
251  }
252 
253  // Postconditions:
254 
255 
256  // Exit:
257 
258  return;
259 }
260 
261 
262 // =============================================================================
263 // ANY FACET
264 // =============================================================================
265 
266 // PUBLIC MEMBER FUNCTIONS
267 
268 bool
270 is_ancestor_of(const any* xother) const
271 {
272 
273  // Preconditions:
274 
275  require(xother != 0);
276 
277  // Body:
278 
279  // True if other conforms to this
280 
281  bool result = dynamic_cast<const average_base_space_map_push_action*>(xother) != 0;
282 
283  // Postconditions:
284 
285  return result;
286 }
287 
290 clone() const
291 {
293 
294  // Preconditions:
295 
296  // Body:
297 
298  result = new average_base_space_map_push_action(*this);
299 
300  // Postconditions:
301 
302  ensure(result != 0);
303  ensure(is_same_type(result));
304 
305  // Exit:
306 
307  return result;
308 }
309 
314 {
315 
316  // Preconditions:
317 
318  require(is_ancestor_of(&xother));
319 
320  // Body:
321 
322  not_implemented();
323 
324  // Postconditions:
325 
326  ensure(invariant());
327 
328  // Exit:
329 
330  return *this;
331 }
332 
336 {
337 
338  // Preconditions:
339 
340 
341  // Body:
342 
343  not_implemented();
344 
345  // Postconditions:
346 
347  ensure(invariant());
348 
349  // Exit
350 
351  return *this;
352 }
353 
354 bool
356 invariant() const
357 {
358  bool result = true;
359 
360  if(invariant_check())
361  {
362  // Prevent recursive calls to invariant
363 
364  disable_invariant_check();
365 
366  // Must satisfy base class invariant
367 
368  invariance(base_space_map_push_action::invariant());
369 
370  // Invariances for this class:
371 
372  // Finished, turn invariant checking back on.
373 
374  enable_invariant_check();
375  }
376 
377  // Exit
378 
379  return result;
380 }
381 
382 
383 // =============================================================================
384 // NON-MEMBER FUNCTIONS
385 // =============================================================================
386 
size_type ct() const
The number of items currently in use.
An abstract iterator over the ids of an id space.
pod_type pod() const
The current id in the iteration.
Namespace for fields component of sheaf system.
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 void operator()(pullback_map::iterator &xitr, block< sec_vd *> &xoutputs, block< block< sec_vd_dof_type > * > &xout_dofs)
Computes xout_dofs using xitr and the dofs already in xoutputs, as needed.
abstract_poset_member & base()
The restricted base of this section space member (mutable version)
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
virtual average_base_space_map_push_action * clone() const
Virtual constructor, makes a new instance of the same type as this.
Functor to compute the dofs at a output discretization point by averaging the input values from all b...
SHEAF_DLL_SPEC void assign(sec_vd &x0, const sec_vd &x1, bool xauto_access)
Assignment to another section; makes x0 have the same value as x1 on the meet of their bases...
Definition: sec_vd.cc:2235
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual void initialize(block< sec_vd *> &xoutputs)
Initializes outputs as needed.
bool is_done() const
True if iteration is finished.
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
pointer_type base() const
The underlying storage array.
virtual void release_iterator(index_space_iterator &xitr) const =0
Returns the id space iterator xitr to the iterator pool.
void set_ct(size_type xct)
Sets ct() == xct.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual index_space_iterator & get_iterator() const =0
Allocates an id space iterator from the iterator pool.
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
virtual void finalize(block< sec_vd *> &xoutputs)
Finalizes outputs as needed.
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).
Abstract functor to compute the dofs at a destination discretization point.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
A client handle for a poset member which has been prepared for use as a schema for a section space...
virtual average_base_space_map_push_action & operator=(const base_space_map_push_action &xother)
Assignment operator.
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
An auto_block with a no-initialization initialization policy.