SheafSystem  0.0.0.0
local_field_refiner.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/local_field_refiner.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_poset.h"
25 #include "SheafSystem/block.impl.h"
26 #include "SheafSystem/depth_bound_refinement_policy.h"
27 #include "SheafSystem/field_refinement_buffer.h"
28 #include "SheafSystem/field_refinement_policy.h"
29 #include "SheafSystem/section_evaluator.h"
30 #include "SheafSystem/sec_vd.h"
31 #include "SheafSystem/field_vd.h"
32 
33 using namespace std;
34 using namespace fields; // Workaround for MS C++ bug.
35 
36 // ===========================================================
37 // LOCAL_FIELD_REFINER FACET
38 // ===========================================================
39 
40 // PUBLIC MEMBER FUNCTIONS
41 
44 {
45  // Preconditions:
46 
47  // Body:
48 
49  // Postconditions:
50 
51  ensure(invariant());
52 
53  return;
54 }
55 
56 int
58 db() const
59 {
60  int result = -1;
61 
62  // Preconditions:
63 
64 
65  // Body:
66 
67  is_abstract();
68 
69  // Postconditions:
70 
71  ensure(result >= -1);
72 
73  // Exit:
74 
75  return result;
76 }
77 
78 const std::string&
81 {
82  // Preconditions:
83 
84 
85  // Body:
86 
87  is_abstract();
88 
89  static const string result("NOT_A_TYPE_NAME"); // Just to keep compiler happy
90 
91  // Postconditions:
92 
93  ensure(!result.empty());
94 
95  // Exit:
96 
97  return result;
98 }
99 
100 
101 const std::string&
104 {
105  // Preconditions:
106 
107 
108  // Body:
109 
110  static const string result("point");
111 
112  // Postconditions:
113 
114  ensure(!result.empty());
115 
116  // Exit:
117 
118  return result;
119 }
120 
121 
124 policy() const
125 {
126  return _policy;
127 }
128 
129 
130 void
133 {
134  // Preconditions:
135 
136  require(unexecutable("coordinate dofs have been gathered"));
137  require(unexecutable("property dofs have been gathered"));
138 
139  // Body:
140 
141  refine_base_space(xbuffer);
142  refine_coordinates(xbuffer);
143 
144  // Postconditions:
145 
146  // Exit:
147 
148  return;
149 }
150 
154 {
155  size_type result = 0;
156 
157  // Preconditions:
158 
159 
160  // Body:
161 
162  is_abstract();
163 
164  // Postconditions:
165 
166  ensure(result > 1);
167 
168  // Exit:
169 
170  return result;
171 }
172 
176 {
177  return _refined_zone_ids;
178 }
179 
183 {
184  // Preconditions:
185 
186  require(xi < refined_zone_ids().ct());
187 
188  // Body:
189 
190  is_abstract();
191 
192  // Just to keep compiler happy:
193 
194  chart_point_coord_type* result = 0;
195 
196  // Postconditions:
197 
198  // Exit:
199 
200  return result;
201 }
202 
203 
204 // PROTECTED MEMBER FUNCTIONS
205 
208  : _policy(*(new depth_bound_refinement_policy(0))) // Just to keep compiler happy.
209 {
210  // Preconditions:
211 
212  // Body:
213 
214  not_implemented();
215 
217 
218  // Postconditions:
219 
220  ensure(invariant());
221 
222  return;
223 }
224 
227  : _policy(xother._policy),
231 {
232  // Preconditions:
233 
234  // Body:
235 
236  // Postconditions:
237 
238  ensure(invariant());
239 
240  return;
241 }
242 
245  : _policy(xpolicy)
246 {
247  // Preconditions:
248 
249  // Body:
250 
252 
253  // Postconditions:
254 
255  ensure(invariant());
256  ensure(&policy() == &xpolicy);
257 
258  return;
259 }
260 
261 void
264 {
265  // Preconditions:
266 
267 
268  // Body:
269 
270  // Reserve some arbitrary amount of space
271  // to avoid many small auto-allocations.
272 
276 
277  // Initialize the dof tuple ids to invalid;
278  // they will be created as needed.
279 
281 
283 
285 
287 
288  // Postconditions:
289 
290 
291  // Exit:
292 
293  return;
294 }
295 
298 create_vertex(base_space_poset& xbase, int xdepth)
299 {
300  // Preconditions:
301 
302  require(xbase.in_jim_edit_mode());
303  require(xdepth >= 0);
304 
305  // Body:
306 
307  // Find or create the right dof tuple.
308 
309  scoped_index ltuple_id;
310 
311  if(xdepth < _point_dof_tuple_ids.ub())
312  {
313  ltuple_id = _point_dof_tuple_ids[xdepth];
314  }
315 
316  if(!ltuple_id.is_valid())
317  {
318  ltuple_id = xbase.prototype_dof_tuple_id(vertex_type_name(), xdepth, true, false);
319  _point_dof_tuple_ids.force_item(xdepth, ltuple_id);
320  }
321 
322  // Create the vertex and link it to the bottom.
323 
324  pod_index_type result = xbase.new_member(true, ltuple_id.hub_pod());
325 
326  xbase.new_link(result, BOTTOM_INDEX);
327 
328  // Postconditions:
329 
330  ensure(xbase.contains_member(result));
331  ensure(xbase.type_name(result) == "point");
332  ensure(xbase.refinement_depth(result) == xdepth);
333 
334  // The following is made unexecutable because it is expensive,
335  // have to search the upper cover of bottom, which is O(#vertices).
336 
337  ensure(unexecutable(xbase.contains_cover_link(result, BOTTOM_INDEX)));
338 
339  // Exit:
340 
341  return result;
342 }
343 
346 create_zone(base_space_poset& xbase, int xdepth)
347 {
348  // Preconditions:
349 
350  require(xbase.in_jim_edit_mode());
351 
352  // Body:
353 
354  // Find or create the right dof tuple.
355 
356  scoped_index ltuple_id;
357 
358  if(xdepth < _zone_dof_tuple_ids.ub())
359  {
360  ltuple_id = _zone_dof_tuple_ids[xdepth];
361  }
362 
363  if(!ltuple_id.is_valid())
364  {
365  ltuple_id = xbase.prototype_dof_tuple_id(zone_type_name(), xdepth, true, false);
366  _zone_dof_tuple_ids.force_item(xdepth, ltuple_id);
367  }
368 
369  // Create the triangle.
370 
371  pod_index_type result = xbase.new_member(true, ltuple_id.hub_pod());
372 
373  // Postconditions:
374 
375  ensure(xbase.contains_member(result));
376 
377  // Exit:
378 
379  return result;
380 }
381 
382 
383 // ===========================================================
384 // ANY FACET
385 // ===========================================================
386 
387 // PUBLIC MEMBER FUNCTIONS
388 
391 clone() const
392 {
393  local_field_refiner* result = 0;
394 
395  // Preconditions:
396 
397  // Body:
398 
399  is_abstract();
400 
401  // Postconditions:
402 
403  ensure(result != 0);
404  ensure(is_same_type(result));
405 
406  // Exit:
407 
408  return result;
409 }
410 
414 {
415  // Preconditions:
416 
417  require(is_ancestor_of(&xother));
418 
419  // Body:
420 
421  not_implemented();
422 
423  // Postconditions:
424 
425  ensure(invariant());
426 
427  // Exit
428 
429  return *this;
430 }
431 
432 bool
434 invariant() const
435 {
436  bool result = true;
437 
438  // Preconditions:
439 
440  // Body:
441 
442  // Must satisfy base class invariant.
443 
444  result = result && any::invariant();
445 
446  if(invariant_check())
447  {
448  // Prevent recursive calls to invariant.
449 
451 
452  // Finished, turn invariant checking back on.
453 
455  }
456 
457  // Postconditions:
458 
459  return result;
460 }
461 
462 bool
464 is_ancestor_of(const any* xother) const
465 {
466 
467  // Preconditions:
468 
469  require(xother != 0);
470 
471  // Body:
472 
473  // True if other conforms to this
474 
475  bool result = dynamic_cast<const local_field_refiner*>(xother) != 0;
476 
477  // Postconditions:
478 
479  return result;
480 
481 }
482 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
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
virtual ~local_field_refiner()
Destructor.
virtual bool invariant() const
Class invariant.
virtual int db() const =0
The base dimension; the dimension of the local coordinates (independent variable).
bool is_valid() const
True if this is a valid id.
Definition: scoped_index.h:832
virtual void new_link(pod_index_type xgreater, pod_index_type xlesser)
Insert a cover link from greater to lesser (that is, hub id xgreater covers hub id xlesser)...
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
virtual const chart_point_coord_type * local_coordinates_map(size_type xi) const =0
The affine map from the local coordinates of refined zone xi the the local coordinates of the parent ...
A buffer for data which is used by both a local_field_refiner object and its associated field_refinem...
std::string type_name(pod_index_type xmbr_hub_id) const
The type id of the member with hub id xmbr_hub_id.
Namespace for fields component of sheaf system.
int refinement_depth(pod_index_type xmbr_hub_id) const
The refinement depth of the member with hub id xmbr_hub_id.
virtual size_type refined_zone_ct() const =0
The number of refined zones created by this.
pod_index_type create_vertex(base_space_poset &xbase, int xdepth)
Creates a new vertex at depth xdepth.
void force_item(index_type xindex, const_reference_type xitem)
Puts the item xitem at index xindex, resizing if necessary; any other new storage allocated is uninit...
STL namespace.
void reserve(index_type xub)
Makes ub() at least xub; if new storage is allocated, it is uninitialized.
scoped_index prototype_dof_tuple_id(const std::string &xname, int xdepth, bool xcreate, bool xauto_access) const
The dof tuple id in this of the base space member prototype with name xname and refinememnt_depth xde...
void refine(field_refinement_buffer &xbuffer)
Refines the zone specified by xbuffer.zone_id one level and evaluates the coordinates section on the ...
const field_refinement_policy & policy() const
The refinement policy for this refiner.
Abstract base class with useful features for all objects.
Definition: any.h:39
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
local_field_refiner()
Default constructor; disabled.
A policy that determines a zone should be refined if the refinement depth is less than a given upper ...
void assign(const_reference_type xitem)
Sets the values of all items to xitem.
void set_ct(size_type xct)
Sets ct() == xct.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
An abstract policy that determines the conditions under which a zone should be refined.
void initialize_buffers()
Initializes the dof tuple and refined zone buffers.
virtual bool contains_member(pod_index_type xmbr_hub_id, bool xauto_access=true) const
True if some version of this poset contains poset member with hub id xmbr_hub_id. ...
virtual const std::string & zone_type_name() const =0
The name of the type of zone this creates during refinement.
static const scoped_index & INVALID()
The invalid id.
Definition: scoped_index.h:871
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
pod_index_type new_member(const std::string &xprototype_name, bool xcopy_dof_map)
Creates a disconnected jim using the prototype with name xprototype_name. If xcopy_dof_map or if xhos...
virtual local_field_refiner & operator=(const local_field_refiner &xother)
Assignment operator.
const field_refinement_policy & _policy
The refinement policy.
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
virtual const std::string & vertex_type_name() const
The name of the type of vertex this creates during refinement.
block< scoped_index > _zone_dof_tuple_ids
The dof tuple index for quadrangle cells at various depths.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
pod_index_type create_zone(base_space_poset &xbase, int xdepth)
Creates a new quadrangle in base space xbase, with refinement depth xdepth.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
void enable_invariant_check() const
Enable invariant checking.
Definition: any.h:87
virtual local_field_refiner * clone() const =0
Virtual constructor, makes a new instance of the same type as this.
const block< scoped_index > & refined_zone_ids() const
The member ids of the zones created by the most recent execution of refine().
block< scoped_index > _refined_zone_ids
The member ids of the zones created by the most recent execution of refine().
block< scoped_index > _point_dof_tuple_ids
The dof tuple index for point cells at various depths.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710