SheafSystem  0.0.0.0
edge_centered_triangle_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/edge_centered_triangle_refiner.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_poset.h"
25 #include "SheafSystem/error_message.h"
26 #include "SheafSystem/field_refinement_buffer.h"
27 #include "SheafSystem/wsv_block.h"
28 
29 using namespace std;
30 using namespace fields; // Workaround for MS C++ bug.
31 
32 // #define DIAGNOSTIC_OUTPUT 1
33 
34 // ===========================================================
35 // EDGE_CENTERED_TRIANGLE_REFINER FACET
36 // ===========================================================
37 
38 // PUBLIC MEMBER FUNCTIONS
39 
43 {
44  // Preconditions:
45 
46  // Body:
47 
48  // Postconditions:
49 
50  ensure(invariant());
51  ensure(&policy() == &xpolicy);
52 
53  return;
54 }
55 
56 
60 {
61  // Preconditions:
62 
63  // Body:
64 
65  not_implemented();
66 
67  // Postconditions:
68 
69  ensure(invariant());
70 
71  return;
72 }
73 
74 
75 // PROTECTED MEMBERS FUNCTIONS
76 
79 {
80  // Preconditions:
81 
82  // Body:
83 
84  not_implemented();
85 
86  // Postconditions:
87 
88  ensure(invariant());
89 
90  return;
91 }
92 
93 void
96 {
97  // Preconditions:
98 
99  require(xbuffer.base_space != 0);
100  require(xbuffer.base_space->in_jim_edit_mode());
101 
102  // Body:
103 
104  // The vertices of the edge-centered subdivision are original vertices
105  // and the center of each edge:
106  //
107  // 4
108  // * *
109  // * *
110  // * *
111  // 5+++++++3
112  // * + + *
113  // * + + *
114  // * + + *
115  // 0*******1*******2
116  //
117  // There is one triangle for in the center plus one for each edge center.
118  // If we start with and edge center and traverse the boundary in the
119  // CCW direction, the connectivity of each edge-centered triangle is
120  // given by 3 consecutive vertices at this refinement depth. If the boundary
121  // contains additional vertices from adjacent, more highly refined triangles,
122  // these appear between the desired vertices and should appear in the lower
123  // cover of the new triangle which contains them.
124 
125  make_new_vertices(xbuffer);
126 
127  make_new_zones(xbuffer);
128 
129  // Create the new triangle in the center of the original.
130 
131  base_space_poset* lbase = xbuffer.base_space;
132  scoped_index lzone_id = xbuffer.zone_id;
133  int lzone_depth = lbase->refinement_depth(lzone_id);
134  int lnew_depth = lzone_depth + 1;
135 
136  scoped_index lnew_tri = lbase->member_id(create_zone(*lbase, lnew_depth), false);
137  _refined_zone_ids.push_back(lnew_tri);
138 
139  // Create the upper cover of the new triangle.
140 
141  lbase->new_link(lzone_id, lnew_tri);
142 
143  // Create the lower cover.
144 
145  lbase->new_link(lnew_tri, _vertex_ids[1]);
146  lbase->new_link(lnew_tri, _vertex_ids[3]);
147  lbase->new_link(lnew_tri, _vertex_ids[5]);
148 
149 #ifdef DIAGNOSTIC_OUTPUT
150 
151  cout << "triangle: " << setw(6) << lnew_tri;
152  cout << " lower cover: ";
153  cover_set_state& lnew_tri_cvr = lbase->lower_cover(lnew_tri);
154  copy(lnew_tri_cvr.begin(),
155  lnew_tri_cvr.end(),
156  ostream_iterator<scoped_index>(cout, " "));
157  cout << endl << endl;
158 #endif
159 
160  // Postconditions:
161 
162  ensure(_refined_zone_ids.ct() == refined_zone_ct());
163 
164  // Exit:
165 
166  return;
167 }
168 
172 {
173 
174  // Preconditions:
175 
176 
177  // Body:
178 
179  static size_type result = 3;
180 
181  // Postconditions:
182 
183 
184  // Exit:
185 
186  return result;
187 }
188 
192 {
193  size_type result;
194 
195  // Preconditions:
196 
197 
198  // Body:
199 
200  result = REFINED_ZONE_CT;
201 
202  // Postconditions:
203 
204  ensure(result > 1);
205 
206  // Exit:
207 
208  return result;
209 }
210 
211 bool
214 {
215  bool result;
216 
217  // Preconditions:
218 
219 
220  // Body:
221 
222  result = false;
223 
224  // Postconditions:
225 
226 
227  // Exit:
228 
229  return result;
230 }
231 
235 {
236 
237  // Preconditions:
238 
239 
240  // Body:
241 
242  // The vertices of the edge-centered subdivision are original vertices
243  // and the center of each edge:
244  //
245  // 4
246  // * *
247  // * *
248  // * *
249  // 5+++++++3
250  // * + + *
251  // * + + *
252  // * + + *
253  // 0*******1*******2
254  //
255  // There is one triangle for in the center plus one for each edge center.
256  // The edge centers are the first vertex of each refined zone,
257  // and the first entry is duplicated at the end
258 
259  static const wsv_block<size_type> result("1 3 5 1");
260 
261  // Postconditions:
262 
263  ensure(result.ct() > 1);
264 
265  // Exit:
266 
267  return result;
268 }
269 
270 
271 // PRIVATE MEMBERS
272 
273 //const sheaf::size_type
274 //fields::edge_centered_triangle_refiner::
275 //REFINED_ZONE_CT;
276 
277 
278 // ===========================================================
279 // LOCAL_FIELD_REFINER FACET
280 // ===========================================================
281 
282 // PUBLIC MEMBER FUNCTIONS
283 
284 const std::string&
287 {
288  // Preconditions:
289 
290 
291  // Body:
292 
293  static const string result("triangle_nodes");
294 
295  // Postconditions:
296 
297  ensure(!result.empty());
298 
299  // Exit:
300 
301  return result;
302 }
303 
307 {
308  // Preconditions:
309 
310  require(xi < refined_zone_ct());
311 
312  // Body:
313 
314  // Affine transformation u'[i] = T[i][j]*u[j] + T[i][db];
315  // with sum convention over 0 <= j < db.
316 
317  // Specifically:
318  //
319  // u' = a*u +b*v + c;
320  // v' = d*u _e*v + f.
321  //
322  // map = {a, b, c, d, e, f}
323  // One such map for each refined zone.
324 
325  // 6 = db*(db+1)
326 
327  static const chart_point_coord_type lmap[REFINED_ZONE_CT][6] =
328  {
329  {
330  0.5, 0.0, 0.0, 0.0, 0.5, 0.5
331  },
332  {-0.5, -0.5, 0.5, 0.5, 0.0, 0.0},
333  { 0.0, 0.5, 0.5, -0.5, -0.5, 0.5},
334  { 0.0, -0.5, 0.5, 0.5, 0.5, 0.0}
335  };
336 
337 
338  const chart_point_coord_type* result = lmap[xi];
339 
340  // Postconditions:
341 
342  // Exit:
343 
344  return result;
345 }
346 
347 
348 // ===========================================================
349 // ANY FACET
350 // ===========================================================
351 
352 // PUBLIC MEMBER FUNCTIONS
353 
356 clone() const
357 {
359 
360  // Preconditions:
361 
362  // Body:
363 
364  result = new edge_centered_triangle_refiner();
365 
366  // Postconditions:
367 
368  ensure(result != 0);
369  ensure(invariant());
370 
371  ensure(result->invariant());
372  ensure(is_same_type(result));
373 
374  return result;
375 }
376 
380 {
381  // Preconditions:
382 
383  require(is_ancestor_of(&xother));
384 
385  // Body:
386 
387  not_implemented();
388 
389  // Postconditions:
390 
391  ensure(invariant());
392 
393  return *this;
394 }
395 
400 {
401 
402  // Preconditions:
403 
404  require(is_ancestor_of(&xother));
405 
406  // Body:
407 
408  not_implemented();
409 
410  // Postconditions:
411 
412  ensure(invariant());
413 
414  // Exit:
415 
416  return *this;
417 }
418 
421 {
422  // Preconditions:
423 
424  // Body:
425 
426  // Postconditions:
427 
428  ensure(invariant());
429 
430  return;
431 }
432 
433 
434 bool
436 invariant() const
437 {
438  bool result = true;
439 
440  // Preconditions:
441 
442  // Body:
443 
444  // Must satisfy base class invariant.
445 
446  result = result && local_field_refiner::invariant();
447 
448  if(invariant_check())
449  {
450  // Prevent recursive calls to invariant.
451 
453 
454  // Finished, turn invariant checking back on.
455 
457  }
458 
459  // Postconditions:
460 
461  return result;
462 }
463 
464 bool
466 is_ancestor_of(const any* xother) const
467 {
468 
469  // Preconditions:
470 
471  require(xother != 0);
472 
473  // Body:
474 
475  // True if other conforms to this
476 
477  bool result = dynamic_cast<const edge_centered_triangle_refiner*>(xother) != 0;
478 
479  // Postconditions:
480 
481  return result;
482 
483 }
484 
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 field refiner that subdivides a triangle into 4 triangles by introducing a new vertex in the center...
virtual bool invariant() const
Class invariant.
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)...
size_type ct() const
The number of items currently in use.
virtual void modify_crg(field_refinement_buffer &xbuffer)
Modifies the cover relation graph of the base space.
virtual bool is_zone_centered_refiner() const
True if this adds a vertex at the center of the zone.
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.
int refinement_depth(pod_index_type xmbr_hub_id) const
The refinement depth of the member with hub id xmbr_hub_id.
const chart_point_coord_type * local_coordinates_map(size_type xi) const
The map from the local coordinates of refined zone xi the the local coordinates of the parent zone...
An abstract field refiner that subdivides a polygon by introducing new vertices into the centers of t...
virtual size_type unrefined_vertex_ct() const
The number of vertices with refinement depth <= unrefined zone depth.
virtual const std::string & zone_type_name() const
The name of the type of zone this creates during refinement.
STL namespace.
void make_new_zones(field_refinement_buffer &xbuffer)
Make the new zones in the refinement.
block< scoped_index > _vertex_ids
The ids of the vertices in boundary <= new refinement depth.
virtual size_type refined_zone_ct() const
The number of refined zones created by this.
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...
virtual edge_centered_triangle_refiner * clone() const
Virtual constructor, creates a new instance of the same type as this.
virtual const block< size_type > & first_vertex_index() const
The index in _vertex_pos of the first vertex of each new zone; contains number of zones + 1 because f...
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
scoped_index zone_id
The id of the current zone.
edge_centered_triangle_refiner()
Default constructor; disabled.
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.
virtual bool invariant() const
Class invariant.
virtual edge_centered_triangle_refiner & operator=(const local_field_refiner &xother)
Assignment operator.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
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
pod_index_type create_zone(base_space_poset &xbase, int xdepth)
Creates a new quadrangle in base space xbase, with refinement depth xdepth.
void make_new_vertices(field_refinement_buffer &xbuffer)
Makes new vertices in edge centers as needed and builds the list of vertices in the boundary of the z...
base_space_poset * base_space
The current base space.
bool in_jim_edit_mode() const
True if editing jims and jim order relation is allowed.
An auto_block with a no-initialization initialization policy.
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
block< scoped_index > _refined_zone_ids
The member ids of the zones created by the most recent execution of refine().
Whitespace-separated-value block; A block of objects of type T that can be conveniently initialized b...
Definition: tuple.h:62
virtual const scoped_index & member_id(bool xauto_access) const
An id in the member hub id space; intended for copying to initialize ids to the member id space...