SheafSystem  0.0.0.0
property_disc_iterator_4_2.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 
22 #include "SheafSystem/property_disc_iterator_4_2.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/base_space_member.h"
26 #include "SheafSystem/binary_section_space_schema_member.h"
27 #include "SheafSystem/eval_family.h"
28 #include "SheafSystem/sec_rep_descriptor.h"
29 #include "SheafSystem/section_evaluator.h"
30 #include "SheafSystem/section_space_schema_member.h"
31 #include "SheafSystem/sec_ed_invertible.h"
32 #include "SheafSystem/sec_vd.h"
33 #include "SheafSystem/std_limits.h"
34 #include "SheafSystem/structured_block_1d.h"
35 #include "SheafSystem/structured_block_2d.h"
36 #include "SheafSystem/structured_block_3d.h"
37 #include "SheafSystem/subposet_member_iterator.h"
38 #include "SheafSystem/uniform_eval_family.h"
39 #include "SheafSystem/field_vd.h"
40 
41 using namespace std;
42 using namespace fields; // Workaround for MS C++ bug.
43 
44 //#define DIAGNOSTIC_OUTPUT 1
45 
46 
47 // ===========================================================
48 // PROPERTY_DISC_ITERATOR_4_2 FACET
49 // ===========================================================
50 
51 // PUBLIC MEMBER FUNCTIONS
52 
53 fields::property_disc_iterator_4_2::
54 property_disc_iterator_4_2(const field_vd& xfield)
55 {
56 
57  // Preconditions:
58 
59  require(xfield.state_is_read_accessible());
60  require(xfield.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
61 
62  require(xfield.coordinates().schema().evaluator_family_name() == "uniform");
63 
66 
67  require(xfield.property().schema().base_space().is_same_state(&xfield.coordinates().schema().base_space()));
68  require(xfield.property().schema().rep().eval_is_above_disc());
69 
70  // Body:
71 
72  initialize_iteration(xfield, BIORDER);
73 
74  // Postconditions:
75 
76  ensure(invariant());
77  ensure(is_initialized());
78  ensure(coordinates_schema().is_same_state(&xfield.coordinates().schema()));
79  ensure(coordinates_schema().is_same_type(&xfield.coordinates().schema()));
80  ensure(coordinates_schema().version() == xfield.coordinates().schema().version());
81  ensure(property_schema().is_same_state(&xfield.property().schema()));
82  ensure(property_schema().is_same_type(&xfield.property().schema()));
83  ensure(property_schema().version() == xfield.property().schema().version());
84  ensure(descending());
85  ensure(!strict());
86  ensure(unexecutable(!is_done() implies this is first member));
87 
88  return;
89 }
90 
91 
92 fields::property_disc_iterator_4_2::
93 property_disc_iterator_4_2(
94  const section_space_schema_member& xcoordinates_schema,
95  const section_space_schema_member& xproperty_schema)
96 {
97 
98  // Preconditions:
99 
100  require(xcoordinates_schema.state_is_read_accessible());
101  require(xcoordinates_schema.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
102 
103  require(xcoordinates_schema.evaluator_family_name() == "uniform");
104 
105  require(xproperty_schema.state_is_read_accessible());
106 
109 
110  require(xproperty_schema.base_space().is_same_state(&xcoordinates_schema.base_space()));
111  require(xproperty_schema.rep().eval_is_above_disc());
112 
113  // Body:
114 
115  initialize_iteration(xcoordinates_schema, xproperty_schema, BIORDER);
116 
117  // Postconditions:
118 
119  ensure(invariant());
120  ensure(is_initialized());
121  ensure(coordinates_schema().is_same_state(&xcoordinates_schema));
122  ensure(coordinates_schema().is_same_type(&xcoordinates_schema));
123  ensure(coordinates_schema().version() == xcoordinates_schema.version());
124  ensure(property_schema().is_same_state(&xproperty_schema));
125  ensure(property_schema().is_same_type(&xproperty_schema));
126  ensure(property_schema().version() == xproperty_schema.version());
127  ensure(descending());
128  ensure(!strict());
129  ensure(unexecutable(!is_done() implies this is first member));
130 
131  return;
132 }
133 
134 
137 {
138  // Preconditions:
139 
140  // Body:
141 
142  // Postconditions:
143 
144 }
145 
146 
147 
148 void
151 {
152  // Preconditions:
153 
154  require(xsec.state_is_read_accessible());
155  require(xsec.schema().is_same_state(&coordinates_schema()));
156 
157  // Implementation of evaluate below only correct for binary schema.
159 
160  require(dynamic_cast<const binary_section_space_schema_member*>
161  (&xsec.schema()) != 0);
162 
164 
165  require(xsec.schema().df() <= 3);
166 
167  // Since the prop disc at or above the prop eval, there should only
168  // be a single disc member.
169 
170  require(coordinate_discretization_members().ct() == 1);
171 
172  // Body:
173 
174  if(_coord_state.dofs.ct() == 0)
175  {
176  // The dofs have not been gathered for thiscoord eval member.
177 
178  _coord_state.gather_dofs(xsec);
179  }
180 
181  int ldf = _coord_state.df;
182  block<sec_vd_dof_type>& lcoord_dofs = _coord_state.dofs;
183  section_evaluator* lcoord_eval = _coord_state.eval;
184  size_type lcoord_local_id = 0;
185 
186  section_evaluator* lprop_eval = _prop_state.eval;
187  block<discretization_context>& ldisc_mbrs = _prop_state.discretization_members;
188  size_type ldisc_ct = ldisc_mbrs.ct();
189 
190  for(size_type i=0; i<ldisc_ct; ++i)
191  {
192  discretization_context& ldisc_mbr = ldisc_mbrs[i];
193 
194  // Get the local coordinates of the disc point.
195 
196  chart_point_3d ldisc_pt;
197  ldisc_pt.put_chart_id(ldisc_mbr.eval_id);
198 
199  lprop_eval->local_coordinates(ldisc_mbr.local_id, ldisc_pt.local_coords(), 3);
200 
201  // Unrefine from the prop eval to the coord eval.
202 
205 
206  _coord_state.eval_mbr->unrefine_point_pa(ldisc_pt, ldisc_pt);
207 
208  // Evaluate the global coordinate section.
209 
210  lcoord_eval->value_at_coord(lcoord_dofs.base(),
211  lcoord_dofs.ct(),
212  ldisc_pt.local_coords(),
213  3,
214  ldisc_mbr.values,
215  ldf);
216  }
217 
218  // Postconditions:
219 
220 
221  // Exit:
222 
223  return;
224 }
225 
226 
227 // ===========================================================
228 // DEPTH_FIRST_ITERATOR FACET
229 // ===========================================================
230 
231 // PUBLIC MEMBER FUNCTIONS
232 
233 void
235 next(bool xtruncate)
236 {
237  // Preconditions:
238 
239  require(!is_done());
240 
241  // Body:
242 
243  bool ltruncate = xtruncate;
244 
245  // Traverse the graph gathering coord and prop disc members until
246  // we have enough context to evaluate the coordinates at the
247  // the property disc points or until the traversal is done.
248 
249  property_disc_iterator::next(ltruncate);
250 
251  while(!is_done())
252  {
253  if(action() == PREVISIT_ACTION)
254  {
255  // The coord eval and disc are both __blocks.
256  // The prop eval is strictly above the prop disc.
257 
258  if(_coord_state.eval_sp.contains_member(_index))
259  {
260  _coord_state.set_and_attach_evaluation_member(_index);
261  _coord_state.discretization_members.set_ct(0);
262  _coord_state.gather_discretization_member(_index, greater_index());
263  _coord_state.local_id++;
264  _coord_state.dofs.set_ct(0);
265  }
266 
267  if(_prop_state.eval_sp.contains_member(_index))
268  {
269  _above.prop_eval = false;
270  put_visit_once(false);
271 
272  _prop_state.set_evaluation_member(_index);
273  _prop_state.initialize_order_correction();
274  _prop_state.discretization_members.set_ct(0);
275  }
276 
277  if(_prop_state.disc_sp.contains_member(_index))
278  {
279  // We only gather a prop disc member when we're below a
280  // prop eval member and we haven't gathered it before.
281 
282  if(!(_above.prop_eval || _prop_state.visited[_index.pod()]))
283  {
284  _prop_state.gather_discretization_member(_index);
285 
286  _prop_state.visited.put(_index.pod(), true);
287  }
288  _prop_state.local_id++;
289  ltruncate = true;
290  }
291 
292  }
293  else if(action() == POSTVISIT_ACTION)
294  {
295  if(_prop_state.eval_sp.contains_member(_index))
296  {
297  put_visit_once(true);
298  _above.prop_eval = true;
299 
300  break;
301  }
302 
303  // If we invoke property_disc_iterator::next() from the postvisit action,
304  // the truncation flag will be ignored, since you can only truncate
305  // in the previsit action. But just to be specific, we'll set it false no
306  // matter what we've done here.
307 
308  ltruncate = false;
309  }
310  else
311  {
312  post_fatal_error_message("unrecognized action");
313  }
314 
315  property_disc_iterator::next(ltruncate);
316  } // end while(!is_done())
317 
318  // Postconditions:
319 
320  ensure(invariant());
321  ensure(!is_done() ? action() == POSTVISIT_ACTION : true);
322 
323  // Exit
324 
325  return;
326 }
327 
328 void
330 reset(bool xreset_markers)
331 {
332  // Preconditions:
333 
334 
335  // Body:
336 
337  if(xreset_markers)
338  {
339  _prop_state.visited.make_false();
340  }
341 
342  // Gather buffers and control flags reset in force_is_done
343  // called from property_disc_iterator::reset
344 
345  property_disc_iterator::reset(xreset_markers);
346 
347  // Postconditions:
348 
349 
350  // Exit:
351 
352  return;
353 }
354 
355 
356 // ===========================================================
357 // ANY FACET
358 // ===========================================================
359 
360 // PUBLIC MEMBER FUNCTIONS
361 
362 bool
364 is_ancestor_of(const any* xother) const
365 {
366  // Preconditions:
367 
368  // Body:
369 
370  bool result = dynamic_cast<const property_disc_iterator_4_2*>(xother) != 0;
371 
372  // Postconditions:
373 
374  // Exit
375 
376  return result;
377 }
378 
381 clone() const
382 {
383  // Preconditions:
384 
385  // Body:
386 
388  new property_disc_iterator_4_2(coordinates_schema(), property_schema());
389 
390  // Postconditions:
391 
392  // ensure(invariant());
393  ensure(result != 0);
394 
395  // Exit
396 
397  return result;
398 }
399 
400 bool
402 invariant() const
403 {
404  bool result = true;
405 
406  // Preconditions:
407 
408  // Body:
409 
410 
411  if(invariant_check())
412  {
413  invariance(property_disc_iterator::invariant());
414 
415  disable_invariant_check();
416 
417  invariance(order() == BIORDER);
418 
419  invariance(coordinates_schema().evaluator_family_name() == "uniform");
420 
423 
424  invariance(property_schema().base_space().is_same_state(&coordinates_schema().base_space()));
425 
426  invariance(property_schema().rep().eval_is_above_disc());
427 
428  // Since the coord disc is the same as the coord eval, there should
429  // be at most a single disc member.
430 
431  require(!is_done() ? coordinate_discretization_members().ct() <= 1 : true);
432 
433  // Finished, turn invariant checking back on.
434 
435  enable_invariant_check();
436  }
437 
438  // Postconditions:
439 
440  // Exit
441 
442  return result;
443 }
scoped_index eval_id
The eval member the disc member is contained in.
A context for discretization members. Intended for implementing various iterators, especially concurrent iterations over multiple sections.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
size_type ct() const
The number of items currently in use.
bool invariant() const
The class invariant.
A point in a 3D chart space.
A property discretization iterator for a field with uniform coordinates section and a property sectio...
Namespace for fields component of sheaf system.
bool conforms_to(const schema_poset_member &xother) const
True if the dofs defined by this agree in type and in order with the dofs defined by xother...
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual property_disc_iterator_4_2 * clone() const
Make a new instance of the same type as this.
STL namespace.
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
void put_chart_id(pod_index_type xchart)
Sets chart_id() to xchart_id.
Definition: chart_point.cc:103
virtual dof_type value_at_coord(const dof_type xdofs[], size_type xdofs_ub, const dof_type xlocal_coords[], size_type xlocal_coords_ub) const
Value at a specified local_coordinate. Single component version.
Abstract base class with useful features for all objects.
Definition: any.h:39
bool eval_is_above_disc() const
True is the evaluation subposet is strictly above the discretization subposet.
int local_id
The local index of the disc member with respect to the eval member.
pointer_type base() const
The underlying storage array.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
A vd-valued property as a function of global coordinates.
Definition: field_vd.h:69
sec_vd & property() const
The dependent variable of this field.
Definition: field_vd.cc:357
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
virtual void reset(bool xreset_markers=true)
Restarts the iteration.
void next()
Makes this the next member of the subset.
std::string evaluator_family_name() const
The name of the evaluator family for section spaces on schemae hosted by this.
sec_vd_value_type values[values_ub]
The values of another section (typically the global coordinates) at this disc point.
base_space_member & base_space() const
The base space of this field.
Definition: field_vd.cc:373
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
coord_type * local_coords()
The array of local coordinates.
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
total_poset_member & base_space()
The base space component of this (mutable version).
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
A client handle for a poset member which has been prepared for use as a schema for a section space...
sec_ed_invertible & coordinates() const
The independent variable of this field.
Definition: field_vd.cc:339
bool state_is_read_accessible() const
True if this is attached and if the coordinates and property are accessible for read or access contro...
Definition: field_vd.cc:1380
int df() const
The dimension of the fiber space component.
virtual void local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const =0
The local coordinates of the dof with local index xindex.
sec_rep_descriptor & rep()
The representation for section spaces on this schema (mutable version).
virtual schema_poset_member & schema()
The schema for this member (mutable version).
virtual void get_prop_disc_values(const sec_vd &xsec)
The gets the values of xsec at the property discretization points.