SheafSystem  0.0.0.0
refining_section_pusher.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 
21 
22 #include "SheafSystem/refining_section_pusher.h"
23 
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/base_space_member.h"
26 #include "SheafSystem/base_space_poset.h"
27 #include "SheafSystem/depth_bound_refinement_policy.h"
28 #include "SheafSystem/error_message.h"
29 #include "SheafSystem/factory.h"
30 #include "SheafSystem/field_eval_iterator.h"
31 #include "SheafSystem/field_refinement_buffer.h"
32 #include "SheafSystem/field_refinement_policy.h"
33 #include "SheafSystem/local_field_refiner.h"
34 #include "SheafSystem/field_refiner_family.h"
35 #include "SheafSystem/section_evaluator.h"
36 #include "SheafSystem/sec_ed_invertible.h"
37 #include "SheafSystem/sec_vd.h"
38 #include "SheafSystem/variance_bound_refinement_policy.h"
39 #include "SheafSystem/field_vd.h"
40 #include "SheafSystem/zone_centered_error_bound_refinement_policy.h"
41 
42 using namespace std;
43 using namespace fields; // Workaround for MS C++ bug.
44 
45 // #define DIAGNOSTIC_OUTPUT 1
46 
47 // =============================================================================
48 // REFINING_SECTION_PUSHER FACET
49 // =============================================================================
50 
51 // PUBLIC MEMBER FUNCTIONS
52 
54 refining_section_pusher(const poset& xbase_space,
55  const std::string& xrefiner_family_name,
56  const std::string& xrefinement_policy_name,
57  bool xauto_access)
58 {
59  // Preconditions:
60 
61  require(xauto_access || xbase_space.state_is_read_accessible());
62  require(field_refiner_family::family_factory().contains_prototype(xrefiner_family_name));
63  require(field_refinement_policy::policy_factory().contains_prototype(xrefinement_policy_name));
64 
65  // Body:
66 
67  if(xauto_access)
68  {
69  xbase_space.get_read_access();
70  }
71 
72 
73  _refiners = field_refiner_family::new_family(xrefiner_family_name);
74 
75  field_refinement_policy* lpolicy =
76  field_refinement_policy::new_policy(xrefinement_policy_name);
77 
80 
81  _refiners->initialize(dynamic_cast<const base_space_poset&>(xbase_space),
82  *lpolicy);
83 
84  if(xauto_access)
85  {
86  xbase_space.release_access();
87  }
88 
89  // Postconditions:
90 
91  ensure(invariant());
92  ensure(refiners().is_initialized());
93  ensure(refiners().class_name() == xrefiner_family_name);
94 
95  // Exit:
96 
97  return;
98 }
99 
103 {
104  return *_refiners;
105 }
106 
109 policy() const
110 {
111 
112  // Preconditions:
113 
114 
115  // Body:
116 
117  field_refinement_policy& result = _refiners->policy();
118 
119  // Postconditions:
120 
121 
122  // Exit:
123 
124  return result;
125 }
126 
127 void
129 push(const field_vd& xsource, field_vd& xtarget, bool xauto_access)
130 {
131 
132 #ifdef DIAGNOSTIC_OUTPUT
133  post_information_message("Entering push_pa:");
134 #endif
135 
136  // Preconditions:
137 
138  require(xauto_access || xsource.state_is_read_accessible());
139  require(xauto_access || xtarget.base_space().state_is_read_write_accessible());
140  require(xauto_access || xtarget.state_is_read_write_accessible());
141 
142  define_old_variable(int old_xsource_access_request_depth =
143  xsource.access_request_depth());
144  define_old_variable(int old_xtarget_access_request_depth =
145  xtarget.access_request_depth());
146 
147 
148  if(xauto_access)
149  {
150  xsource.get_read_access();
151  xtarget.get_read_write_access(true, true);
152  }
153 
154  require(xtarget.same_evaluation());
155 
156  // Body:
157 
158  // Initialize inversion for the source coordinates.
159 
160  if(!xsource.coordinates().is_invertible())
161  {
162  xsource.coordinates().initialize_point_locator(false);
163  }
164 
165  // Put target base space in jim edit mode.
166 
170 
171  xtarget.base_space().host()->begin_jim_edit_mode(false);
172 
173  // Create an evaluation iterator for the target.
174 
175  field_eval_iterator litr(xtarget);
176 
177  // Initialize the buffer shared by this, the refiner and the refinement policy;
178  // uses discretization buffers from iterator.
179 
180  field_refinement_buffer lbuffer(xsource,
181  xtarget,
184  policy().refinement_depth_ub());
185 
186  // Traverse the target; pushing and refining as needed.
187 
188  while(!litr.is_done())
189  {
190  lbuffer.zone_id = litr.index();
191  lbuffer.coord_evaluator = &litr.coordinate_evaluator();
192  lbuffer.prop_evaluator = &litr.property_evaluator();
193 
194  // Gather the coordinate dofs for this zone.
195 
196  lbuffer.gather_coordinate_dofs();
197 
198  // Push any property dofs that have not been pushed.
199 
200  lbuffer.push_prop_dofs();
201 
202  // Gather the property dofs for this zone.
204 
205  lbuffer.gather_property_dofs();
206 
207  // Get the refiner to match the cell type.
208 
209  local_field_refiner* lrefiner = _refiners->member(litr.type_id());
210 
211  assertion(lrefiner != 0);
212 
213  // Test the refinement policy.
214 
215  if(lrefiner->policy().should_refine(lbuffer, litr.refinement_depth()))
216  {
217  // Policy says refine; do it.
218 
219  lrefiner->refine(lbuffer);
220 
221  // Repeat the traversal of the down set of the current
222  // zone in case we need to further refine the zones we
223  // just added. Arg == true tells iterator we've just
224  // refined this zone.
225 
226  litr.repeat(true);
227  }
228  else
229  {
230  // Just continue to the next zone.
231 
232  litr.next();
233  }
234  }
235 
236  // Finished with jim edit mode.
237 
238  xtarget.base_space().host()->end_jim_edit_mode(true, false);
239 
240  xtarget.coordinates().schema().force_cache_update();
241  xtarget.property().schema().force_cache_update();
242 
243  if(xauto_access)
244  {
245  xtarget.release_access();
246  xsource.release_access();
247  }
248 
249  // Postconditions:
250 
251  ensure(xsource.access_request_depth() == old_xsource_access_request_depth);
252  ensure(xtarget.access_request_depth() == old_xtarget_access_request_depth);
253 
254  // Exit
255 
256  return;
257 }
258 
259 
260 bool
262 same_fiber(const sec_vd& x1, const sec_vd& x2) const
263 {
264  bool result;
265 
266  // Preconditions:
267 
268  require(x1.state_is_read_accessible());
269  require(x2.state_is_read_accessible());
270 
271  // Body:
272 
273  result =
275  (x1.schema().df() == x2.schema().df());
276 
277  // Postconditions:
278 
279  ensure(result ==
281  (x1.schema().df() == x2.schema().df())));
282 
283  // Exit:
284 
285  return result;
286 }
287 
288 
289 // PROTECTED MEMBER FUNCTIONS
290 
293  : _refiners(0)
294 {
295  // Preconditions:
296 
297  // Body:
298 
299  not_implemented();
300 
301  // Postconditions:
302 
303  // Exit:
304 
305  return;
306 }
307 
308 // =============================================================================
309 // ANY FACET
310 // =============================================================================
311 
312 // PUBLIC MEMBER FUNCTIONS
313 
316 {
317  // Preconditions:
318 
319  // Body:
320 
321  not_implemented();
322 
323  // Postconditions:
324 
325  ensure(invariant());
326 
327  // Exit:
328 }
329 
332 {
333  // Preconditions:
334 
335  // Body:
336 
337  // Postconditions:
338 
339  // Exit:
340 }
341 
342 bool
344 invariant() const
345 {
346  bool result = true;
347 
348  // Preconditions:
349 
350  // Body:
351 
352  invariance(any::invariant());
353 
354  if(invariant_check())
355  {
357 
358  // Finished, turn invariant checking back on.
359 
361  }
362 
363  // Postconditions:
364 
365  // Exit
366 
367  return result;
368 }
369 
370 // ===========================================================
371 // NONMEMBER FUNCTIONS
372 // ===========================================================
373 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
virtual void get_read_write_access(bool xbase_access, bool xrelease_read_only_access)
Get read write access to the coordinates and property sections, which implies read access to the base...
Definition: field_vd.cc:1550
void repeat(bool xwas_eval_member)
Repeats the iteration over the down set of index(). If index() refers to a zone that has just been re...
void next()
Makes this the next member of the subset.
section_evaluator & property_evaluator() const
The property field evaluator associated with the current evaluation member.
A family of compatible local_field_refiners, one for each member of some family of cell types; a map ...
bool state_is_read_write_accessible(bool xbase_access=false) const
True if this is attached and if coordinates(), property() and (if xbase access) base_space() are acce...
Definition: field_vd.cc:1428
schema_poset_member & fiber_schema()
The fiber schema component of this (mutable version).
A buffer for data which is used by both a local_field_refiner object and its associated field_refinem...
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...
virtual ~refining_section_pusher()
Destructor.
pod_index_type type_id() const
The type id of the current member.
virtual void get_read_access() const
Get read access to the state associated with this.
Definition: field_vd.cc:1516
An iterator which concurrently traverses the schema of both the coordinates and property sections of ...
virtual void initialize_point_locator(bool xauto_access)
Initializes point locater search structure using default values.
bool is_invertible() const
True if this can be inverted.
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 bool invariant() const
Class invariant.
size_type refinement_depth() const
The refinement depth; the number of evaluation members the current evaluation member is contained in...
void refine(field_refinement_buffer &xbuffer)
Refines the zone specified by xbuffer.zone_id one level and evaluates the coordinates section on the ...
bool same_fiber(const sec_vd &x1, const sec_vd &x2) const
True if and only if x1 and x2 have the same fiber type and dimension.
const block< scoped_index > & property_discretization_members() const
The property discretization members in the downset of the current evaluation member.
const field_refinement_policy & policy() const
The refinement policy for this refiner.
field_refinement_policy & policy() const
The refinement policy of the refiners.
scoped_index zone_id
The id of the current zone.
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...
A client handle for a mutable partially ordered set.
Definition: poset.h:40
poset * host() const
The poset which this is a handle to a member of.
virtual bool should_refine(field_refinement_buffer &xbuffer, size_type xrefinement_depth) const =0
True if the zone specified by xzone_id should be refined.
int access_request_depth() const
The number of times access has been requested and granted without being released. ...
Definition: field_vd.cc:1489
section_evaluator & coordinate_evaluator() const
The coordinate field evaluator associated with the current evaluation member.
An abstract policy that determines the conditions under which a zone should be refined.
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 void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
Definition: field_vd.cc:1594
const block< scoped_index > & coordinate_discretization_members() const
The coordinate discretization members in the downset of the current evaluation member.
void push(const field_vd &xsource, field_vd &xtarget, bool xauto_access)
Pushes field xsource to field xtarget, pre-allocated.
refining_section_pusher()
Default constructor; disabled.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
base_space_member & base_space() const
The base space of this field.
Definition: field_vd.cc:373
void force_cache_update()
Forces update of the attribute cache.
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
bool is_done() const
True if iteration finished.
bool same_evaluation() const
True if the coordinates and property sections both use the same evaluation subposet.
Definition: field_vd.cc:822
An abstract refiner for a field over a local region (primitive cell) in the base space.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
A refining section push-forward operator. Moves sections from one sec_rep_space to another using exte...
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
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
virtual void end_jim_edit_mode(bool xensure_lattice_invariant=true, bool xauto_access=true)
Prevent editing of jims and jim order relation.
Definition: poset.cc:253
int df() const
The dimension of the fiber space component.
virtual void get_read_access() const
Get read access to the state associated with this.
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
field_refiner_family & refiners()
The family of refiners for the range.
const scoped_index & index() const
The index of the current member of the iteration.
virtual void begin_jim_edit_mode(bool xauto_access=true)
Allow editing of jims and jim order relation.
Definition: poset.cc:230