SheafSystem  0.0.0.0
barycentric_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/barycentric_triangle_refiner.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/error_message.h"
25 #include "SheafSystem/wsv_block.h"
26 
27 using namespace std;
28 using namespace fields; // Workaround for MS C++ bug.
29 
30 // ===========================================================
31 // BARYCENTRIC_TRIANGLE_REFINER FACET
32 // ===========================================================
33 
34 // PUBLIC MEMBER FUNCTIONS
35 
39 {
40  // Preconditions:
41 
42  // Body:
43 
44  // Postconditions:
45 
46  ensure(invariant());
47  ensure(&policy() == &xpolicy);
48 
49  return;
50 }
51 
52 
56 {
57  // Preconditions:
58 
59  // Body:
60 
61  not_implemented();
62 
63  // Postconditions:
64 
65  ensure(invariant());
66 
67  return;
68 }
69 
70 // ===========================================================
71 // PROTECTED MEMBERS FACET
72 // ===========================================================
73 
74 
77 {
78  // Preconditions:
79 
80  // Body:
81 
82  not_implemented();
83 
84  // Postconditions:
85 
86  ensure(invariant());
87 
88  return;
89 }
90 
94 {
95 
96  // Preconditions:
97 
98 
99  // Body:
100 
101  static size_type result = 3;
102 
103  // Postconditions:
104 
105 
106  // Exit:
107 
108  return result;
109 }
110 
114 {
115  size_type result;
116 
117  // Preconditions:
118 
119 
120  // Body:
121 
122  result = REFINED_ZONE_CT;
123 
124  // Postconditions:
125 
126  ensure(result > 1);
127 
128  // Exit:
129 
130  return result;
131 }
132 
133 bool
136 {
137  bool result;
138 
139  // Preconditions:
140 
141 
142  // Body:
143 
144  result = true;
145 
146  // Postconditions:
147 
148 
149  // Exit:
150 
151  return result;
152 }
153 
157 {
158 
159  // Preconditions:
160 
161 
162  // Body:
163 
164  // The vertices of the barycentric subdivision are the barycenters
165  // of all the simplices in the original triangle, i.e. the "center"
166  // of each original vertex (local ids 0, 2, 4), the centers of each
167  // edge (local ids 1, 3, 5) and the center of the triangle itself.
168  // The indexing is arbitrary but convenient.
169  // The barycentric subdivision contains 6 new triangles:
170  //
171  // 4
172  // *+*
173  // * + *
174  // * + *
175  // 5+++C+++3
176  // * + + + *
177  // * + + + *
178  // *+ + +*
179  // 0*******1*******2
180  //
181  // There is one triangle for each vertex in the boundary, and if we
182  // traverse the boundary in the CCW direction, the connectivity
183  // of each triangle is given by 2 consecutive vertices followed by the
184  // center vertex. If the boundary contains additional vertices from
185  // adjacent, more highly refined triangles, these appear between the
186  // desired vertices and should appear in the lower cover of the new
187  // triangle which contains them.
188 
189  // Last entry duplicates first entry.
190 
191  static const wsv_block<size_type> result("0 1 2 3 4 5 0");
192 
193  // Postconditions:
194 
195  ensure(result.ct() > 1);
196 
197  // Exit:
198 
199  return result;
200 }
201 
202 
203 // PRIVATE MEMBERS
204 
205 //const sheaf::size_type
206 //fields::barycentric_triangle_refiner::
207 //REFINED_ZONE_CT;
208 
209 
210 // ===========================================================
211 // LOCAL_FIELD_REFINER FACET
212 // ===========================================================
213 
214 // PUBLIC MEMBER FUNCTIONS
215 
216 const std::string&
219 {
220  // Preconditions:
221 
222 
223  // Body:
224 
225  static const string result("triangle_nodes");
226 
227  // Postconditions:
228 
229  ensure(!result.empty());
230 
231  // Exit:
232 
233  return result;
234 }
235 
239 {
240  // Preconditions:
241 
242  require(xi < refined_zone_ct());
243 
244  // Body:
245 
246  // Affine transformation u'[i] = T[i][j]*u[j] + T[i][db];
247  // with sum convention over 0 <= j < db.
248 
249  // Specifically:
250  //
251  // u' = a*u +b*v + c;
252  // v' = d*u _e*v + f.
253  //
254  // map = {a, b, c, d, e, f}
255  // One such map for each refined zone.
256 
257  // 6 = db*(db+1)
258 
259  static const chart_point_coord_type lmap[REFINED_ZONE_CT][6] =
260  {
261  {
262  2.0/3.0, 1.0/6.0, 1.0/3.0, -1.0/3.0, 1.0/6.0, 1.0/3.0
263  },
264  { 1.0/6.0, -1.0/3.0, 1.0/3.0, -1.0/3.0, 2.0/3.0, 1.0/3.0},
265  {-1.0/3.0, -1.0/3.0, 1.0/3.0, 2.0/3.0, 1.0/6.0, 1.0/3.0},
266  {-1.0/3.0, -1.0/3.0, 1.0/3.0, 1.0/6.0, -1.0/3.0, 1.0/3.0},
267  {-1.0/3.0, 1.0/6.0, 1.0/3.0, -1.0/3.0, -1.0/3.0, 1.0/3.0},
268  { 1.0/6.0, 2.0/3.0, 1.0/3.0, -1.0/3.0, -1.0/3.0, 1.0/3.0}
269  };
270 
271 
272  const chart_point_coord_type* result = lmap[xi];
273 
274  // Postconditions:
275 
276  // Exit:
277 
278  return result;
279 }
280 
281 
282 // ===========================================================
283 // ANY FACET
284 // ===========================================================
285 
286 // PUBLIC MEMBER FUNCTIONS
287 
290 clone() const
291 {
293 
294  // Preconditions:
295 
296  // Body:
297 
298  result = new barycentric_triangle_refiner();
299 
300  // Postconditions:
301 
302  ensure(result != 0);
303  // ensure(invariant());
304  ensure(result->invariant());
305  ensure(is_same_type(result));
306 
307  return result;
308 }
309 
310 
314 {
315  // Preconditions:
316 
317  require(is_ancestor_of(&xother));
318 
319  // Body:
320 
321  not_implemented();
322 
323  // Postconditions:
324 
325  ensure(invariant());
326 
327  return *this;
328 }
329 
334 {
335 
336  // Preconditions:
337 
338  require(is_ancestor_of(&xother));
339 
340  // Body:
341 
342  not_implemented();
343 
344  // Postconditions:
345 
346  ensure(invariant());
347 
348  // Exit:
349 
350  return *this;
351 }
352 
353 
356 {
357  // Preconditions:
358 
359  // Body:
360 
361  // Postconditions:
362 
363  ensure(invariant());
364 
365  return;
366 }
367 
368 
369 bool
371 invariant() const
372 {
373  bool result = true;
374 
375  // Preconditions:
376 
377  // Body:
378 
379  // Must satisfy base class invariant.
380 
381  result = result && edge_centered_polygon_refiner::invariant();
382 
383  if(invariant_check())
384  {
385  // Prevent recursive calls to invariant.
386 
388 
389  // Finished, turn invariant checking back on.
390 
392  }
393 
394  // Postconditions:
395 
396  return result;
397 }
398 
399 bool
401 is_ancestor_of(const any* xother) const
402 {
403 
404  // Preconditions:
405 
406  require(xother != 0);
407 
408  // Body:
409 
410  // True if other conforms to this
411 
412  bool result = dynamic_cast<const barycentric_triangle_refiner*>(xother) != 0;
413 
414  // Postconditions:
415 
416  return result;
417 
418 }
419 
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 const std::string & zone_type_name() const
The name of the type of zone this creates during refinement.
size_type ct() const
The number of items currently in use.
Namespace for fields component of sheaf system.
An abstract field refiner that subdivides a polygon by introducing new vertices into the centers of t...
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
STL namespace.
virtual barycentric_triangle_refiner & operator=(const local_field_refiner &xother)
Assignment operator.
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
virtual bool is_zone_centered_refiner() const
True if this adds a vertex at the center of the zone.
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 disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
Definition: any.h:97
const chart_point_coord_type * local_coordinates_map(size_type xi) const
The map from the local coordinates of refined zone xi t0 the local coordinates of the parent zone...
virtual bool invariant() const
Class invariant.
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...
barycentric_triangle_refiner()
Default constructor; disabled.
An abstract refiner for a field over a local region (primitive cell) in the base space.
virtual size_type unrefined_vertex_ct() const
The number of vertices with refinement depth <= unrefined zone depth.
bool invariant_check() const
True if invariant checking is enabled.
Definition: any.h:79
virtual size_type refined_zone_ct() const
The number of refined zones created by this.
A field refiner that subdivides a triangle into 6 triangles by introducing a new vertex in the center...
virtual barycentric_triangle_refiner * clone() const
Virtual constructor, creates a new instance of the same type as this.
virtual bool invariant() const
Class invariant.
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
Whitespace-separated-value block; A block of objects of type T that can be conveniently initialized b...
Definition: tuple.h:62