SheafSystem  0.0.0.0
property_disc_iterator_1_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_1_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_1_3 FACET
49 // ===========================================================
50 
51 // PUBLIC MEMBER FUNCTIONS
52 
53 fields::property_disc_iterator_1_3::
54 property_disc_iterator_1_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  require(xfield.property().schema().evaluation().is_same_state(&xfield.coordinates().schema().evaluation()));
62  require(!xfield.property().schema().rep().eval_is_above_disc());
63 
64  // Body:
65 
66  initialize_iteration(xfield, BIORDER);
67 
68  // Postconditions:
69 
70  ensure(invariant());
71  ensure(is_initialized());
72  ensure(coordinates_schema().is_same_state(&xfield.coordinates().schema()));
73  ensure(coordinates_schema().is_same_type(&xfield.coordinates().schema()));
74  ensure(coordinates_schema().version() == xfield.coordinates().schema().version());
75  ensure(property_schema().is_same_state(&xfield.property().schema()));
76  ensure(property_schema().is_same_type(&xfield.property().schema()));
77  ensure(property_schema().version() == xfield.property().schema().version());
78  ensure(descending());
79  ensure(!strict());
80  ensure(unexecutable(!is_done() implies this is first member));
81 
82  return;
83 }
84 
85 fields::property_disc_iterator_1_3::
86 property_disc_iterator_1_3(
87  const section_space_schema_member& xcoordinates_schema,
88  const section_space_schema_member& xproperty_schema)
89 {
90 
91  // Preconditions:
92 
93  require(xcoordinates_schema.state_is_read_accessible());
94  require(xcoordinates_schema.base_space().schema().conforms_to(base_space_member::standard_schema_path()));
95  require(xproperty_schema.state_is_read_accessible());
96  require(xproperty_schema.evaluation().is_same_state(&xcoordinates_schema.evaluation()));
97  require(!xproperty_schema.rep().eval_is_above_disc());
98 
99  // Body:
100 
101  initialize_iteration(xcoordinates_schema, xproperty_schema, BIORDER);
102 
103  // Postconditions:
104 
105  ensure(invariant());
106  ensure(is_initialized());
107  ensure(coordinates_schema().is_same_state(&xcoordinates_schema));
108  ensure(coordinates_schema().is_same_type(&xcoordinates_schema));
109  ensure(coordinates_schema().version() == xcoordinates_schema.version());
110  ensure(property_schema().is_same_state(&xproperty_schema));
111  ensure(property_schema().is_same_type(&xproperty_schema));
112  ensure(property_schema().version() == xproperty_schema.version());
113  ensure(descending());
114  ensure(!strict());
115  ensure(unexecutable(!is_done() implies this is first member));
116 
117  return;
118 }
119 
122 {
123  // Preconditions:
124 
125  // Body:
126 
127  // Postconditions:
128 
129 }
130 
131 
132 
133 void
136 {
137  // Preconditions:
138 
139  require(xsec.state_is_read_accessible());
140  require(xsec.schema().is_same_state(&coordinates_schema()));
141 
142  // Implementation of evaluate below only correct for binary schema.
144 
145  require(dynamic_cast<const binary_section_space_schema_member*>
146  (&xsec.schema()) != 0);
147 
149 
150  require(xsec.schema().df() <= 3);
151 
152  // Since the prop disc at or above the prop eval, there should only
153  // be a single disc member.
154 
155  require(property_discretization_members().ct() == 1);
156 
157  // Body:
158 
159  _coord_state.gather_dofs(xsec);
160 
161  int ldf = _coord_state.df;
162  block<sec_vd_dof_type>& lcoord_dofs = _coord_state.dofs;
163  section_evaluator* lcoord_eval = _coord_state.eval;
164  size_type lcoord_local_id = 0;
165 
166  section_evaluator* lprop_eval = _prop_state.eval;
167  block<discretization_context>& ldisc_mbrs = _prop_state.discretization_members;
168  size_type ldisc_ct = ldisc_mbrs.ct();
169 
170  discretization_context& ldisc_mbr = ldisc_mbrs[0];
171 
172  // Have to evaluate the coords at the prop disc point.
173  // Get the local coordinates of the disc point.
174 
175  const int MAX_DB = 3;
176  chart_point_coord_type local_coords[MAX_DB];
177 
178  lprop_eval->local_coordinates(ldisc_mbr.local_id, local_coords, MAX_DB);
179 
180  // Evaluate the global coordinate section.
181 
182  lcoord_eval->value_at_coord(lcoord_dofs.base(),
183  lcoord_dofs.ct(),
184  local_coords,
185  MAX_DB,
186  ldisc_mbr.values,
187  ldf);
188 
189  // Postconditions:
190 
191 
192  // Exit:
193 
194  return;
195 }
196 
197 
198 // PRIVATE MEMBER FUNCTIONS
199 
200 void
201 fields::property_disc_iterator_1_3::
202 coord_eval_previsit_action()
203 {
204  // Preconditions:
205 
206  require(_at.coord_eval);
207 
208  // Body:
209 
210  _above.coord_eval = false;
211 
212  _coord_state.set_evaluation_member(_index);
213  _coord_state.initialize_order_correction();
214  _coord_state.discretization_members.set_ct(0);
215  _coord_state.down_set.set_ct(0);
216 
217  _prop_state.set_evaluation_member(_index);
218 
219  // Postconditions:
220 
221 
222  // Exit:
223 
224  return;
225 }
226 
227 void
228 fields::property_disc_iterator_1_3::
229 prop_disc_previsit_action()
230 {
231  // Preconditions:
232 
233  require(_at.prop_disc);
234 
235  // Body:
236 
237  _above.prop_disc = false;
238 
239  _prop_state.discretization_members.set_ct(0);
240  _prop_state.gather_discretization_member(_index);
241 
242  // Postconditions:
243 
244 
245  // Exit:
246 
247  return;
248 }
249 
250 void
251 fields::property_disc_iterator_1_3::
252 coord_disc_previsit_action()
253 {
254  // Preconditions:
255 
256  require(_at.coord_disc);
257 
258  // Body:
259 
260  _above.coord_disc = false;
261 
262  _coord_state.gather_discretization_member(_index, greater_index());
263  _coord_state.local_id++;
264 
265  // Postconditions:
266 
267 
268  // Exit:
269 
270  return;
271 }
272 
273 void
274 fields::property_disc_iterator_1_3::
275 coord_eval_postvisit_action()
276 {
277  // Preconditions:
278 
279  require(_at.coord_eval);
280 
281  // Body:
282 
283  block<scoped_index>& ldown_set = _coord_state.down_set;
284  size_type lct = ldown_set.ct();
285  for(size_type i=0; i<lct; ++i)
286  {
287  put_has_visited(ldown_set[i], false);
288  }
289  ldown_set.set_ct(0);
290 
291  _above.coord_eval = true;
292 
293  // Postconditions:
294 
295 
296  // Exit:
297 
298  return;
299 }
300 
301 
302 // ===========================================================
303 // DEPTH_FIRST_ITERATOR FACET
304 // ===========================================================
305 
306 // PUBLIC MEMBER FUNCTIONS
307 
308 void
310 next(bool xtruncate)
311 {
312  // Preconditions:
313 
314  require(!is_done());
315 
316  // Body:
317 
318  bool ltruncate = xtruncate;
319 
320  // Traverse the graph gathering coord and prop disc members until
321  // we have enough context to evaluate the coordinates at the
322  // the property disc points or until the trversal is done.
323 
324  property_disc_iterator::next(ltruncate);
325 
326  while(!is_done())
327  {
328  if(action() == PREVISIT_ACTION)
329  {
330  if(!_above.coord_eval)
331  {
332  _coord_state.down_set.push_back(_index);
333  }
334 
335  // The coord and prop eval are both the element subposet and
336  // the coord disc is the vertices. The prop disc is strictly above
337  // the elements.
338 
339  _at.coord_eval = _coord_state.eval_sp.contains_member(_index);
340  _at.coord_disc = _coord_state.disc_sp.contains_member(_index);
341  _at.prop_disc = _prop_state.disc_sp.contains_member(_index);
342 
343  if(_at.coord_eval)
344  {
345  coord_eval_previsit_action();
346  }
347 
348  if(_at.prop_disc)
349  {
350  prop_disc_previsit_action();
351  }
352 
353  if(_at.coord_disc)
354  {
355  coord_disc_previsit_action();
356  ltruncate = true;
357  }
358  }
359  else if(action() == POSTVISIT_ACTION)
360  {
361  _at.coord_eval = _coord_state.eval_sp.contains_member(_index);
362 
363  if(_at.coord_eval)
364  {
365  coord_eval_postvisit_action();
366  break;
367  }
368 
369  // If we invoke property_disc_iterator::next() from the postvisit action,
370  // the truncation flag will be ignored, since you can only truncate
371  // in the previsit action. But just to be specific, we'll set it false no
372  // matter what we've done here.
373 
374  ltruncate = false;
375  }
376  else
377  {
378  post_fatal_error_message("unrecognized action");
379  }
380 
381  property_disc_iterator::next(ltruncate);
382  } // end while(!is_done())
383 
384  // Postconditions:
385 
386  ensure(invariant());
387  ensure(!is_done() ? action() == POSTVISIT_ACTION : true);
388 
389  // Exit
390 
391  return;
392 }
393 
394 
395 // ===========================================================
396 // ANY FACET
397 // ===========================================================
398 
399 // PUBLIC MEMBER FUNCTIONS
400 
401 bool
403 is_ancestor_of(const any* xother) const
404 {
405  // Preconditions:
406 
407  // Body:
408 
409  bool result = dynamic_cast<const property_disc_iterator_1_3*>(xother) != 0;
410 
411  // Postconditions:
412 
413  // Exit
414 
415  return result;
416 }
417 
420 clone() const
421 {
422  // Preconditions:
423 
424  // Body:
425 
427  new property_disc_iterator_1_3(coordinates_schema(), property_schema());
428 
429  // Postconditions:
430 
431  // ensure(invariant());
432  ensure(result != 0);
433 
434  // Exit
435 
436  return result;
437 }
438 
439 bool
441 invariant() const
442 {
443  bool result = true;
444 
445  // Preconditions:
446 
447  // Body:
448 
449 
450  if(invariant_check())
451  {
452  invariance(property_disc_iterator::invariant());
453 
454  disable_invariant_check();
455 
456  invariance(order() == BIORDER);
457  invariance(property_schema().evaluation().is_same_state(&coordinates_schema().evaluation()));
458  invariance(!property_schema().rep().eval_is_above_disc());
459 
460  // Since the prop eval is at or below the prop disc, there should
461  // be at most a single disc member for each eval.
462 
463  require(!is_done() ? property_discretization_members().ct() <= 1 : true);
464 
465  // Finished, turn invariant checking back on.
466 
467  enable_invariant_check();
468  }
469 
470  // Postconditions:
471 
472  // Exit
473 
474  return result;
475 }
476 
477 
double chart_point_coord_type
The type of local coordinate in the base space; the scalar type for the local coordinate vector space...
Definition: fiber_bundle.h:57
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.
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...
subposet & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
virtual void get_prop_disc_values(const sec_vd &xsec)
The gets the values of xsec at the property discretization points.
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.
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 invariant() const
The class invariant.
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.
void set_ct(size_type xct)
Sets ct() == xct.
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.
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...
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
A property discretization iterator for a property section with the same evaluation subposet as the co...
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 property_disc_iterator_1_3 * clone() const
Make a new instance of the same type as this.