SheafSystem  0.0.0.0
property_disc_iterator_4_3.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_3.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_3 FACET
49 // ===========================================================
50 
51 // PUBLIC MEMBER FUNCTIONS
52 
53 fields::property_disc_iterator_4_3::
54 property_disc_iterator_4_3(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_3::
93 property_disc_iterator_4_3(
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 coord eval and disc are the same,
168  // there should only be a single coord disc member.
169 
170  require(coordinate_discretization_members().ct() == 1);
171 
172  // Since the prop disc at or above the prop eval,
173  // there should only be a single prop disc member.
174 
175  require(property_discretization_members().ct() == 1);
176 
177  // Body:
178 
179  if(_coord_state.dofs.ct() == 0)
180  {
181  // The dofs have not been gathered for thiscoord eval member.
182 
183  _coord_state.gather_dofs(xsec);
184  }
185 
186  int ldf = _coord_state.df;
187  block<sec_vd_dof_type>& lcoord_dofs = _coord_state.dofs;
188  section_evaluator* lcoord_eval = _coord_state.eval;
189  size_type lcoord_local_id = 0;
190 
191  section_evaluator* lprop_eval = _prop_state.eval;
192  block<discretization_context>& ldisc_mbrs = _prop_state.discretization_members;
193  size_type ldisc_ct = ldisc_mbrs.ct();
194 
195  discretization_context& ldisc_mbr = ldisc_mbrs[0];
196 
197  // Get the local coordinates of the disc point.
198 
199  chart_point_3d ldisc_pt;
200  ldisc_pt.put_chart_id(ldisc_mbr.eval_id);
201 
202  lprop_eval->local_coordinates(ldisc_mbr.local_id, ldisc_pt.local_coords(), 3);
203 
204  // Unrefine from the prop eval to the coord eval.
205 
208 
209  _coord_state.eval_mbr->unrefine_point_pa(ldisc_pt, ldisc_pt);
210 
211  // Evaluate the global coordinate section.
212 
213  lcoord_eval->value_at_coord(lcoord_dofs.base(),
214  lcoord_dofs.ct(),
215  ldisc_pt.local_coords(),
216  3,
217  ldisc_mbr.values,
218  ldf);
219 
220  // Postconditions:
221 
222 
223  // Exit:
224 
225  return;
226 }
227 
228 
229 // ===========================================================
230 // DEPTH_FIRST_ITERATOR FACET
231 // ===========================================================
232 
233 // PUBLIC MEMBER FUNCTIONS
234 
235 void
237 next(bool xtruncate)
238 {
239  // Preconditions:
240 
241  require(!is_done());
242 
243  // Body:
244 
245  bool ltruncate = xtruncate;
246 
247  // Traverse the graph gathering coord and prop disc members until
248  // we have enough context to evaluate the coordinates at the
249  // the property disc points or until the trversal is done.
250 
251  property_disc_iterator::next(ltruncate);
252 
253  while(!is_done())
254  {
255  if(action() == PREVISIT_ACTION)
256  {
257  // The coord eval and disc are both __blocks.
258  // The prop eval is at or below the prop disc.
259 
260  if(_coord_state.eval_sp.contains_member(_index))
261  {
262  _coord_state.set_and_attach_evaluation_member(_index);
263  _coord_state.discretization_members.set_ct(0);
264  _coord_state.gather_discretization_member(_index, greater_index());
265  _coord_state.dofs.set_ct(0);
266  }
267 
268  if(_prop_state.eval_sp.contains_member(_index))
269  {
270  _prop_state.set_evaluation_member(_index);
271  ltruncate = true;
272  }
273 
274  if(_prop_state.disc_sp.contains_member(_index))
275  {
276  _prop_state.discretization_members.set_ct(0);
277  _prop_state.gather_discretization_member(_index);
278  }
279 
280  }
281  else if(action() == POSTVISIT_ACTION)
282  {
283  if(_prop_state.eval_sp.contains_member(_index))
284  {
285  break;
286  }
287 
288  // If we invoke property_disc_iterator::next() from the postvisit action,
289  // the truncation flag will be ignored, since you can only truncate
290  // in the previsit action. But just to be specific, we'll set it false no
291  // matter what we've done here.
292 
293  ltruncate = false;
294  }
295  else
296  {
297  post_fatal_error_message("unrecognized action");
298  }
299 
300  property_disc_iterator::next(ltruncate);
301  } // end while(!is_done())
302 
303  // Postconditions:
304 
305  ensure(invariant());
306  ensure(!is_done() ? action() == POSTVISIT_ACTION : true);
307 
308  // Exit
309 
310  return;
311 }
312 
313 
314 // ===========================================================
315 // ANY FACET
316 // ===========================================================
317 
318 // PUBLIC MEMBER FUNCTIONS
319 
320 bool
322 is_ancestor_of(const any* xother) const
323 {
324  // Preconditions:
325 
326  // Body:
327 
328  bool result = dynamic_cast<const property_disc_iterator_4_3*>(xother) != 0;
329 
330  // Postconditions:
331 
332  // Exit
333 
334  return result;
335 }
336 
339 clone() const
340 {
341  // Preconditions:
342 
343  // Body:
344 
346  new property_disc_iterator_4_3(coordinates_schema(), property_schema());
347 
348  // Postconditions:
349 
350  // ensure(invariant());
351  ensure(result != 0);
352 
353  // Exit
354 
355  return result;
356 }
357 
358 bool
360 invariant() const
361 {
362  bool result = true;
363 
364  // Preconditions:
365 
366  // Body:
367 
368 
369  if(invariant_check())
370  {
371  invariance(property_disc_iterator::invariant());
372 
373  disable_invariant_check();
374 
375  invariance(order() == BIORDER);
376 
377  invariance(coordinates_schema().evaluator_family_name() == "uniform");
378 
381 
382  invariance(property_schema().base_space().is_same_state(&coordinates_schema().base_space()));
383 
384  invariance(!property_schema().rep().eval_is_above_disc());
385 
386  // Since the coord disc is the same as the coord eval, there should
387  // be at most a single disc member.
388 
389  require(!is_done() ? coordinate_discretization_members().ct() <= 1 : true);
390 
391  // Finished, turn invariant checking back on.
392 
393  enable_invariant_check();
394  }
395 
396  // Postconditions:
397 
398  // Exit
399 
400  return result;
401 }
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.
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_3 * 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.
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
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
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).
A property discretization iterator for a field with uniform coordinates section and a property sectio...
virtual void get_prop_disc_values(const sec_vd &xsec)
The gets the values of xsec at the property discretization points.