GRINS-0.8.0
rayfireAMR_test.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include "grins_config.h"
26 
27 #ifdef GRINS_HAVE_CPPUNIT
28 
29 #include <libmesh/ignore_warnings.h>
30 #include <cppunit/extensions/HelperMacros.h>
31 #include <cppunit/TestCase.h>
32 #include <libmesh/restore_warnings.h>
33 
34 #include "test_comm.h"
35 #include "grins_test_paths.h"
36 
37 // GRINS
38 #include "grins/grins_enums.h"
39 #include "grins/mesh_builder.h"
40 #include "grins/rayfire_mesh.h"
41 #include "grins/math_constants.h"
42 
43 // libMesh
44 #include "libmesh/elem.h"
45 #include "libmesh/getpot.h"
46 #include "libmesh/face_quad4.h"
47 #include "libmesh/face_quad9.h"
48 #include "libmesh/fe_interface.h"
49 #include "libmesh/mesh_refinement.h"
50 #include "libmesh/serial_mesh.h"
51 
52 // Ignore warnings from auto_ptr in CPPUNIT_TEST_SUITE_END()
53 #include <libmesh/ignore_warnings.h>
54 
55 namespace GRINSTesting
56 {
57  class RayfireTestAMR : public CppUnit::TestCase
58  {
59  public:
61 
76 
78 
79  public:
80 
82  void single_elems()
83  {
84  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
85  test_single_elem(mesh);
86 
87  mesh = build_quad9_elem();
88  test_single_elem(mesh);
89  }
90 
93  {
94  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
95  test_through_vertex(mesh);
96 
97  mesh = build_quad9_elem();
98  test_through_vertex(mesh);
99  }
100 
103  {
104  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
105  test_near_vertex(mesh);
106 
107  mesh = build_quad9_elem();
108  test_near_vertex(mesh);
109  }
110 
113  {
114  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad4_100elem_2D.in";
115  GetPot input_quad4(filename);
116  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input_quad4);
117  test_large_mesh(mesh);
118 
119  filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad9_100elem_2D.in";
120  GetPot input_quad9(filename);
121  mesh = this->build_mesh(input_quad9);
122  test_large_mesh(mesh);
123  }
124 
127  {
128  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad4_100elem_2D.in";
129  GetPot input(filename);
130  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input);
131 
132  libMesh::Point origin(0.0,6.5);
133  libMesh::Point end_point(10.0,0.25);
134  libMesh::Real theta = calc_theta(origin,end_point);
135 
136  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
137  rayfire->init(*mesh);
138 
139  // elem 0 is not along the rayfire
140  mesh->elem_ptr(0)->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
141 
142  libMesh::MeshRefinement mr(*mesh);
143  mr.refine_elements();
144 
145  rayfire->reinit(*mesh);
146 
147  // elem 0 should not be in the rayfire
148  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->id()) ) );
149 
150  // no children of elem 0 should be in the rayfire
151  for (unsigned int i=0; i<4; i++)
152  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem( mesh->elem_ptr(0)->child_ptr(i)->id() ) ) );
153  }
154 
157  {
158  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
160 
161  mesh = build_quad9_elem();
163  }
164 
167  {
168  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad4_100elem_2D.in";
169  GetPot input_quad4(filename);
170  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input_quad4);
171  test_coarsen(mesh);
172 
173  filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad9_100elem_2D.in";
174  GetPot input_quad9(filename);
175  mesh = this->build_mesh(input_quad9);
176  test_coarsen(mesh);
177  }
178 
181  {
182  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
183 
184  libMesh::Point origin(0.0,0.1);
185  libMesh::Point end_point(1.0,0.1);
186  libMesh::Real theta = calc_theta(origin,end_point);
187 
188  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
189  rayfire->init(*mesh);
190 
191  libMesh::MeshRefinement mr(*mesh);
192  mr.uniformly_refine();
193  rayfire->reinit(*mesh);
194  mr.uniformly_refine();
195  rayfire->reinit(*mesh);
196 
197  // refine elem(0)->child_ptr(1)->child_ptr(1)
198  mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
199  // coarsen elem(0)->child_ptr(0)
200  for (unsigned int c=0; c<mesh->elem_ptr(0)->child_ptr(0)->n_children(); c++)
201  mesh->elem_ptr(0)->child_ptr(0)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
202 
203  mr.refine_and_coarsen_elements();
204  rayfire->reinit(*mesh);
205 
206  CPPUNIT_ASSERT( mesh->elem_ptr(0)->child_ptr(0)->active() );
207 
208  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->id()) );
209  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(0)->id()) );
210  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->child_ptr(0)->id()) );
211  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->child_ptr(1)->id()) );
212 
213 
214  }
215 
218  {
219  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mixed_quad_tri.in";
220  GetPot input(filename);
221  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input);
222 
223  libMesh::Point origin(0.0,0.25);
224  libMesh::Point end_point(1.0,0.25);
225  libMesh::Real theta = calc_theta(origin,end_point);
226 
227  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
228  rayfire->init(*mesh);
229 
230  // check that the rayfire is through the right elems
231  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(0) );
232  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(6) );
233  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(9) );
234  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(8) );
235 
236  // and not through others
237  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(2)) );
238  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(3)) );
239  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(4)) );
240  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(5)) );
241  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(1)) );
242  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(7)) );
243 
244  // now do a uniform refinement
245  libMesh::MeshRefinement mr(*mesh);
246  mr.uniformly_refine();
247 
248  rayfire->reinit(*mesh);
249 
250  // check post-refinement
251  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->id()) );
252  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->id()) );
253  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(6)->child_ptr(0)->id()) );
254  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(9)->child_ptr(1)->id()) );
255  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(8)->child_ptr(2)->id()) );
256 
257  // coarsen two of the TRIs
258  for (unsigned int c=0; c<mesh->elem_ptr(6)->n_children(); c++)
259  {
260  mesh->elem_ptr(6)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
261  mesh->elem_ptr(9)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
262  }
263 
264  mr.coarsen_elements();
265  rayfire->reinit(*mesh);
266 
267  CPPUNIT_ASSERT( mesh->elem_ptr(6)->active() );
268  CPPUNIT_ASSERT( mesh->elem_ptr(9)->active() );
269 
270  // check post-coarsen
271  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->id()) );
272  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->id()) );
273  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(8)->child_ptr(2)->id()) );
274  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(6) );
275  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(9) );
276 
277  for (unsigned int c=0; c<mesh->elem_ptr(6)->n_children(); c++)
278  {
279  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(6)->child_ptr(c)->id())) );
280  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(9)->child_ptr(c)->id())) );
281  }
282  }
283 
286  {
287  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = build_quad4_elem();
288 
289  // uniform refinement
290  libMesh::MeshRefinement mr(*mesh);
291  mr.uniformly_refine();
292 
293  // now init the rayfire
294  libMesh::Point origin(0.0,0.1);
295  libMesh::Point end_point(1.0,0.1);
296  libMesh::Real theta = calc_theta(origin,end_point);
297 
298  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
299  rayfire->init(*mesh);
300 
301  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->id()) );
302  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->id()) );
303 
304  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(2)->id())) );
305  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(3)->id())) );
306 
307  // refine again
308  mr.uniformly_refine();
309  rayfire->reinit(*mesh);
310 
311  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(0)->id()) );
312  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(1)->id()) );
313  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(0)->id()) );
314  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->id()) );
315 
316  // uniformly coarsen twice to get back to a single elem
317  mr.uniformly_coarsen();
318  rayfire->reinit(*mesh);
319  mr.uniformly_coarsen();
320  rayfire->reinit(*mesh);
321 
322  // ensure the original elem is active
323  CPPUNIT_ASSERT( mesh->elem_ptr(0)->active() );
324 
325  // the original elem should be in the rayfire
326  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(0) );
327 
328  // and no other elem
329  for (unsigned int e=1; e<mesh->n_elem(); e++)
330  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(e)) );
331  }
332 
335  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
336 
337  mesh->set_mesh_dimension(2);
338 
339  mesh->add_point( libMesh::Point(0.0,0.0),0 );
340  mesh->add_point( libMesh::Point(1.0,0.0),1 );
341  mesh->add_point( libMesh::Point(1.0,1.0),2 );
342  mesh->add_point( libMesh::Point(0.0,1.0),3 );
343  mesh->add_point( libMesh::Point(1.0,2.0),4 );
344  mesh->add_point( libMesh::Point(0.0,2.0),5 );
345 
346  libMesh::Elem* elem0 = mesh->add_elem( new libMesh::Quad4 );
347  elem0->set_node(0) = mesh->node_ptr(0);
348  elem0->set_node(1) = mesh->node_ptr(1);
349  elem0->set_node(2) = mesh->node_ptr(2);
350  elem0->set_node(3) = mesh->node_ptr(3);
351 
352  libMesh::Elem* elem1 = mesh->add_elem( new libMesh::Quad4 );
353  elem1->set_node(0) = mesh->node_ptr(3);
354  elem1->set_node(1) = mesh->node_ptr(2);
355  elem1->set_node(2) = mesh->node_ptr(4);
356  elem1->set_node(3) = mesh->node_ptr(5);
357 
358  mesh->prepare_for_use();
359 
360  libMesh::Point origin(0.0,1.0);
361  libMesh::Real theta = 0.0;
362 
363  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
364  rayfire->init(*mesh);
365 
366  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(elem0->id()) );
367  CPPUNIT_ASSERT( !rayfire->map_to_rayfire_elem(elem1->id()) );
368 
369  elem0->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
370 
371  libMesh::MeshRefinement mr(*mesh);
372  mr.refine_elements();
373 
374  rayfire->reinit(*mesh);
375 
376  CPPUNIT_ASSERT( !rayfire->map_to_rayfire_elem(elem1->id()) );
377 
378  CPPUNIT_ASSERT( !rayfire->map_to_rayfire_elem(elem0->child_ptr(0)->id()) );
379  CPPUNIT_ASSERT( !rayfire->map_to_rayfire_elem(elem0->child_ptr(1)->id()) );
380  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(elem0->child_ptr(2)->id()) );
381  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(elem0->child_ptr(3)->id()) );
382  }
383 
386  {
387  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
388 
389  mesh->set_mesh_dimension(2);
390 
391  mesh->add_point( libMesh::Point(0.0,0.0),0 );
392  mesh->add_point( libMesh::Point(1.0,0.0),1 );
393  mesh->add_point( libMesh::Point(1.1,1.1),2 );
394  mesh->add_point( libMesh::Point(0.2,1.0),3 );
395 
396  libMesh::Elem* e = mesh->add_elem( new libMesh::Quad4 );
397  for (unsigned int n=0; n<4; n++)
398  e->set_node(n) = mesh->node_ptr(n);
399 
400  mesh->prepare_for_use();
401 
402  CPPUNIT_ASSERT_EQUAL( mesh->n_elem(), (libMesh::dof_id_type)1 );
403 
404  libMesh::Real y = 0.5250005;
405  libMesh::Real x = y/5.0;
406 
407  libMesh::Point origin(x,y); // within libMesh::TOLERANCE of node 8
408  libMesh::Real theta = 0.0;
409 
410  std::vector<unsigned int> children_in_rayfire;
411  children_in_rayfire.push_back(1);
412  children_in_rayfire.push_back(2);
413  children_in_rayfire.push_back(3);
414 
415  std::vector<unsigned int> children_not_in_rayfire;
416  children_not_in_rayfire.push_back(0);
417 
418  this->test_deformed_elem(mesh,origin,theta,children_in_rayfire,children_not_in_rayfire);
419  }
420 
425  {
426  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
427 
428  mesh->set_mesh_dimension(2);
429 
430  mesh->add_point( libMesh::Point(0.26591876082146976,0.016285303166482301),2 );
431  mesh->add_point( libMesh::Point(0.26539426622418877,0.016285726631637167),3 );
432  mesh->add_point( libMesh::Point(0.26538091506882988,0.015714299294800886),0 );
433  mesh->add_point( libMesh::Point(0.26590538328042834,0.015713833483130532),1 );
434 
435  libMesh::Elem* e = mesh->add_elem( new libMesh::Quad4 );
436  for (unsigned int n=0; n<4; n++)
437  e->set_node(n) = mesh->node_ptr(n);
438 
439  mesh->prepare_for_use();
440 
441  CPPUNIT_ASSERT_EQUAL( mesh->n_elem(), (libMesh::dof_id_type)1 );
442 
443  libMesh::Real x = 0.26538759034362924;
444  libMesh::Real y = 0.01600000000000000;
445 
446  libMesh::Point origin(x,y);
447  libMesh::Real theta = 0.0;
448 
449  std::vector<unsigned int> children_in_rayfire;
450  children_in_rayfire.push_back(0);
451  children_in_rayfire.push_back(2);
452  children_in_rayfire.push_back(3);
453 
454  std::vector<unsigned int> children_not_in_rayfire;
455  children_not_in_rayfire.push_back(1);
456 
457  this->test_deformed_elem(mesh,origin,theta,children_in_rayfire,children_not_in_rayfire);
458  }
459 
464  {
465  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_quad4_9elem_2D.in";
466  GetPot input_quad4(filename);
467  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input_quad4);
468 
469  // refine elem 1 before rayfire init
470  libMesh::MeshRefinement mr(*mesh);
471  mesh->elem_ptr(1)->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
472  mr.refine_elements();
473 
474  CPPUNIT_ASSERT( !(mesh->elem_ptr(1)->active()) );
475  CPPUNIT_ASSERT( mesh->elem_ptr(1)->has_children() );
476 
477  libMesh::Point origin(0.0,0.1);
478  libMesh::Real theta = 0.0;
479 
480  // initialize the rayfire
481  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
482  rayfire->init(*mesh);
483 
484  // make sure we pick up the 2 unrefined elements
485  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(0) );
486  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(2) );
487 
488  // rayfire should not include elem 1 since it's INACTIVE
489  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(1)) );
490 
491  // rayfire should contain children 0,1 of elem 1
492  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ref(1).child_ptr(0)->id()) );
493  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ref(1).child_ptr(1)->id()) );
494  }
495 
496  private:
497 
498  libMesh::Real calc_theta(libMesh::Point& start, libMesh::Point end)
499  {
500  return std::atan2( (end(1)-start(1)), (end(0)-start(0)) );
501  }
502 
503  GRINS::SharedPtr<libMesh::UnstructuredMesh> build_mesh( const GetPot& input )
504  {
505  GRINS::MeshBuilder mesh_builder;
506  return mesh_builder.build( input, *TestCommWorld );
507  }
508 
510  GRINS::SharedPtr<libMesh::UnstructuredMesh> build_quad4_elem()
511  {
512  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
513 
514  mesh->set_mesh_dimension(2);
515 
516  mesh->add_point( libMesh::Point(0.0,0.0),0 );
517  mesh->add_point( libMesh::Point(1.0,0.0),1 );
518  mesh->add_point( libMesh::Point(1.0,1.0),2 );
519  mesh->add_point( libMesh::Point(0.0,1.0),3 );
520 
521  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad4 );
522  for (unsigned int n=0; n<4; n++)
523  elem->set_node(n) = mesh->node_ptr(n);
524 
525  mesh->prepare_for_use();
526 
527  return mesh;
528  }
529 
531  GRINS::SharedPtr<libMesh::UnstructuredMesh> build_quad9_elem()
532  {
533  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
534 
535  mesh->set_mesh_dimension(2);
536 
537  mesh->add_point( libMesh::Point(0.0,0.0),0 );
538  mesh->add_point( libMesh::Point(1.0,0.0),1 );
539  mesh->add_point( libMesh::Point(1.0,1.0),2 );
540  mesh->add_point( libMesh::Point(0.0,1.0),3 );
541  mesh->add_point( libMesh::Point(0.5,0.0),4 );
542  mesh->add_point( libMesh::Point(1.0,0.5),5 );
543  mesh->add_point( libMesh::Point(0.5,1.0),6 );
544  mesh->add_point( libMesh::Point(0.0,0.5),7 );
545  mesh->add_point( libMesh::Point(0.5,0.5),8 );
546 
547  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad9 );
548  for (unsigned int n=0; n<9; n++)
549  elem->set_node(n) = mesh->node_ptr(n);
550 
551  mesh->prepare_for_use();
552 
553  return mesh;
554  }
555 
557  void test_single_elem(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
558  {
559  CPPUNIT_ASSERT_EQUAL( mesh->n_elem(), (libMesh::dof_id_type)1 );
560 
561  libMesh::Point origin(0.0,0.1);
562  libMesh::Point end_point(1.0,0.2);
563  libMesh::Real theta = calc_theta(origin,end_point);
564 
565  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
566  rayfire->init(*mesh);
567 
568  libMesh::Elem* elem = mesh->elem_ptr(0);
569  CPPUNIT_ASSERT(elem);
570 
571  elem->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
572 
573  libMesh::MeshRefinement mr(*mesh);
574  mr.refine_elements();
575 
576  rayfire->reinit(*mesh);
577 
578  const libMesh::Elem* rayfire_elem0 = rayfire->map_to_rayfire_elem( elem->child_ptr(0)->id() );
579  CPPUNIT_ASSERT(rayfire_elem0);
580 
581  const libMesh::Elem* rayfire_elem1 = rayfire->map_to_rayfire_elem( elem->child_ptr(1)->id() );
582  CPPUNIT_ASSERT(rayfire_elem1);
583 
584  CPPUNIT_ASSERT( (rayfire_elem0->node_ptr(0))->absolute_fuzzy_equals(origin) );
585  CPPUNIT_ASSERT( (rayfire_elem0->node_ptr(1))->absolute_fuzzy_equals(libMesh::Point(0.5,0.15)) );
586  CPPUNIT_ASSERT( (rayfire_elem1->node_ptr(0))->absolute_fuzzy_equals(libMesh::Point(0.5,0.15)) );
587  CPPUNIT_ASSERT( (rayfire_elem1->node_ptr(1))->absolute_fuzzy_equals(end_point) );
588  }
589 
590  void test_through_vertex(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
591  {
592  libMesh::Point origin(0.0,0.0);
593  libMesh::Point end_point(1.0,1.0);
594  libMesh::Real theta = calc_theta(origin,end_point);
595 
596  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
597  rayfire->init(*mesh);
598 
599  libMesh::Elem* elem = mesh->elem_ptr(0);
600  CPPUNIT_ASSERT(elem);
601 
602  elem->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
603 
604  libMesh::MeshRefinement mr(*mesh);
605  mr.refine_elements();
606 
607  rayfire->reinit(*mesh);
608 
609  const libMesh::Elem* rayfire_elem0 = rayfire->map_to_rayfire_elem( elem->child_ptr(0)->id() );
610  CPPUNIT_ASSERT(rayfire_elem0);
611 
612  const libMesh::Elem* rayfire_elem1 = rayfire->map_to_rayfire_elem( elem->child_ptr(3)->id() );
613  CPPUNIT_ASSERT(rayfire_elem1);
614 
615  CPPUNIT_ASSERT( (rayfire_elem0->node_ptr(0))->absolute_fuzzy_equals(origin) );
616  CPPUNIT_ASSERT( (rayfire_elem0->node_ptr(1))->absolute_fuzzy_equals(libMesh::Point(0.5,0.5)) );
617  CPPUNIT_ASSERT( (rayfire_elem1->node_ptr(0))->absolute_fuzzy_equals(libMesh::Point(0.5,0.5)) );
618  CPPUNIT_ASSERT( (rayfire_elem1->node_ptr(1))->absolute_fuzzy_equals(end_point) );
619  }
620 
621  void test_near_vertex(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
622  {
623  libMesh::Point origin(0.4999,0.0);
624  libMesh::Point end_point(1.0,1.0);
625  libMesh::Real theta = calc_theta(origin,end_point);
626 
627  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
628  rayfire->init(*mesh);
629 
630  libMesh::Elem* elem = mesh->elem_ptr(0);
631  CPPUNIT_ASSERT(elem);
632 
633  elem->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
634 
635  libMesh::MeshRefinement mr(*mesh);
636  mr.refine_elements();
637 
638  rayfire->reinit(*mesh);
639 
640  const libMesh::Elem* rayfire_elem0 = rayfire->map_to_rayfire_elem( elem->child_ptr(0)->id() );
641  CPPUNIT_ASSERT(rayfire_elem0);
642 
643  const libMesh::Elem* rayfire_elem1 = rayfire->map_to_rayfire_elem( elem->child_ptr(1)->id() );
644  CPPUNIT_ASSERT(rayfire_elem1);
645 
646  const libMesh::Elem* rayfire_elem2 = rayfire->map_to_rayfire_elem( elem->child_ptr(3)->id() );
647  CPPUNIT_ASSERT(rayfire_elem2);
648 
649  // not in rayfire
650  const libMesh::Elem* non_rayfire_elem = rayfire->map_to_rayfire_elem( elem->child_ptr(2)->id() );
651  CPPUNIT_ASSERT(!non_rayfire_elem);
652  }
653 
655  void test_large_mesh(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
656  {
657  libMesh::Point origin(0.0,6.5);
658  libMesh::Point end_point(10.0,0.25);
659  libMesh::Real theta = calc_theta(origin,end_point);
660 
661  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
662  rayfire->init(*mesh);
663 
664  // manually refine specific elements
665  // map index 0: main_elem id to refine
666  // map index 1: children that should be in the rayfire post-refinement
667  std::map<unsigned int,std::vector<unsigned int> > refine_elems;
668  refine_elems[60] = std::vector<unsigned int>();
669  refine_elems[60].push_back(0);
670  refine_elems[60].push_back(1);
671 
672  refine_elems[52] = std::vector<unsigned int>();
673  refine_elems[52].push_back(0);
674 
675  refine_elems[34] = std::vector<unsigned int>();
676  refine_elems[34].push_back(1);
677  refine_elems[34].push_back(2);
678  refine_elems[34].push_back(3);
679 
680  refine_elems[25] = std::vector<unsigned int>();
681  refine_elems[25].push_back(3);
682 
683  refine_elems[26] = std::vector<unsigned int>();
684  refine_elems[26].push_back(0);
685  refine_elems[26].push_back(1);
686  refine_elems[26].push_back(2);
687 
688  refine_elems[17] = std::vector<unsigned int>();
689  refine_elems[17].push_back(2);
690  refine_elems[17].push_back(3);
691 
692  refine_elems[9] = std::vector<unsigned int>();
693  refine_elems[9].push_back(1);
694  refine_elems[9].push_back(2);
695  refine_elems[9].push_back(3);
696 
697  // check to make sure those elements are along the rayfire
698  // and then set their refinement flags
699  std::map<unsigned int,std::vector<unsigned int> >::iterator it = refine_elems.begin();
700  for(; it != refine_elems.end(); it++)
701  {
702  libMesh::Elem* elem = mesh->elem_ptr( it->first );
703  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(elem->id()) );
704  elem->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
705  }
706 
707  // refine the elements
708  libMesh::MeshRefinement mr(*mesh);
709  mr.refine_elements();
710 
711  // reinitialize the rayfire
712  rayfire->reinit(*mesh);
713 
714  // check the refined elements and their children
715  it = refine_elems.begin();
716  for(; it != refine_elems.end(); it++)
717  {
718  libMesh::Elem* elem = mesh->elem_ptr( it->first );
719 
720  // make sure it was refined
721  CPPUNIT_ASSERT_EQUAL( elem->refinement_flag(), libMesh::Elem::RefinementState::INACTIVE );
722 
723  // make sure it was deleted from the rayfire
724  CPPUNIT_ASSERT( !( rayfire->map_to_rayfire_elem(elem->id()) ) );
725 
726  // check that the computed children are in the rayfire
727  // and that the rest are not
728  std::vector<unsigned int> children = it->second;
729  unsigned int index = 0;
730  for(unsigned int c=0; c<elem->n_children(); c++)
731  {
732  if (index<children.size())
733  {
734  if (c==children[index])
735  {
736  index++;
737  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem( elem->child_ptr(c)->id() ) );
738  }
739  }
740  else
741  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem( elem->child_ptr(c)->id() )) );
742  }
743  }
744  }
745 
747  void test_multiple_refinements(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
748  {
749  libMesh::Point origin(0.0,0.0);
750  libMesh::Point end_point(1.0,0.25);
751  libMesh::Real theta = calc_theta(origin,end_point);
752 
753  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
754  rayfire->init(*mesh);
755 
756  libMesh::MeshRefinement mr(*mesh);
757 
758  // do 3 successive uniform refinements
759  for (unsigned int i=0; i<3; i++)
760  {
761  mr.uniformly_refine();
762  rayfire->reinit(*mesh);
763  }
764 
765  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(0)->child_ptr(0)->id()) );
766  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(0)->child_ptr(1)->id()) );
767  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(1)->child_ptr(0)->id()) );
768  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(0)->child_ptr(1)->child_ptr(1)->id()) );
769 
770  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(0)->child_ptr(2)->id()) );
771  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(0)->child_ptr(3)->id()) );
772  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->child_ptr(2)->id()) );
773  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(1)->child_ptr(1)->child_ptr(3)->id()) );
774 
775  }
776 
778  void test_coarsen(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
779  {
780  libMesh::Point origin(0.0,6.5);
781  libMesh::Point end_point(10.0,0.25);
782  libMesh::Real theta = calc_theta(origin,end_point);
783 
784  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
785  rayfire->init(*mesh);
786 
787  // unifromly refine the elements
788  libMesh::MeshRefinement mr(*mesh);
789  mr.uniformly_refine();
790  rayfire->reinit(*mesh);
791 
792  // coarsen specific elements along the rayfire
793  for(unsigned int c=0; c<4; c++)
794  {
795  mesh->elem_ptr(60)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
796  mesh->elem_ptr(25)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
797  mesh->elem_ptr(26)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
798  mesh->elem_ptr(9)->child_ptr(c)->set_refinement_flag(libMesh::Elem::RefinementState::COARSEN);
799  }
800 
801  mr.coarsen_elements();
802  rayfire->reinit(*mesh);
803 
804  // check that the coarsened elems are in the rayfire
805  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(60) );
806  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(25) );
807  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(26) );
808  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(9) );
809 
810  // and that their children are not
811  for(unsigned int c=0; c<4; c++)
812  {
813  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(60)->child_ptr(c)->id())) );
814  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(25)->child_ptr(c)->id())) );
815  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(26)->child_ptr(c)->id())) );
816  CPPUNIT_ASSERT( !(rayfire->map_to_rayfire_elem(mesh->elem_ptr(9)->child_ptr(c)->id())) );
817  }
818  }
819 
820  void test_deformed_elem( GRINS::SharedPtr<libMesh::UnstructuredMesh> & mesh,
821  libMesh::Point & origin, libMesh::Real theta,
822  std::vector<unsigned int> & children_in_rayfire,
823  std::vector<unsigned int> & children_not_in_rayfire )
824  {
825  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
826  rayfire->init(*mesh);
827 
828  libMesh::Elem* elem = mesh->elem_ptr(0);
829  CPPUNIT_ASSERT(elem);
830 
831  elem->set_refinement_flag(libMesh::Elem::RefinementState::REFINE);
832 
833  libMesh::MeshRefinement mr(*mesh);
834  mr.refine_elements();
835 
836  rayfire->reinit(*mesh);
837 
838  for (unsigned int c=0; c<children_in_rayfire.size(); c++)
839  CPPUNIT_ASSERT( rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(children_in_rayfire[c])->id()) );
840 
841  for (unsigned int c=0; c<children_not_in_rayfire.size(); c++)
842  CPPUNIT_ASSERT( !rayfire->map_to_rayfire_elem(mesh->elem_ptr(0)->child_ptr(children_not_in_rayfire[c])->id()) );
843 
844  }
845 
846  };
847 
848  CPPUNIT_TEST_SUITE_REGISTRATION( RayfireTestAMR );
849 
850 } // end namespace GRINSTesting
851 
852 #endif // GRINS_HAVE_CPPUNIT
void test_coarsen(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
Test coarsening specific elements on a large mesh.
void single_elems()
Refine a single element.
void test_large_mesh(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
Refine specific elements on a large mesh.
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
void refine_and_coarsen()
Refine and coarsen before calling reinit()
void through_vertex_postrefinment()
After refinement, the rayfire will travel through a vertex.
GRINS::SharedPtr< libMesh::UnstructuredMesh > build_quad9_elem()
Build a single square QUAD9.
void mixed_type_mesh()
Mesh contains 2 QUAD4 and 2 TRI3.
RayfireMesh.
Definition: rayfire_mesh.h:65
libMesh::Parallel::Communicator * TestCommWorld
Definition: unit_driver.C:70
void refine_elem_not_on_rayfire()
Make sure refined elements not on the rayfire do not get added.
GRINS::SharedPtr< libMesh::UnstructuredMesh > build_quad4_elem()
Build a single square QUAD4.
CPPUNIT_TEST_SUITE(RayfireTestAMR)
void large_2D_mesh()
A 10x10 mesh with selectively refined elements.
void refined_above_unrefined()
2 QUAD4 elems, one is refined, one if not, rayfire travels boundary between them
void test_multiple_refinements(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
Refine the mesh 3 times.
void test_deformed_elem(GRINS::SharedPtr< libMesh::UnstructuredMesh > &mesh, libMesh::Point &origin, libMesh::Real theta, std::vector< unsigned int > &children_in_rayfire, std::vector< unsigned int > &children_not_in_rayfire)
SharedPtr< libMesh::UnstructuredMesh > build(const GetPot &input, const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Builds the libMesh::Mesh according to input options.
Definition: mesh_builder.C:46
void multiple_refinements()
Test for multiple successive refinements.
GRINS::SharedPtr< libMesh::UnstructuredMesh > build_mesh(const GetPot &input)
libMesh::Real calc_theta(libMesh::Point &start, libMesh::Point end)
void near_vertex_postrefinement()
After refinement, the rayfire will travel very near (but not through) a vertex.
void test_near_vertex(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
void test_single_elem(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
Runs the test on single square QUADs of unit length and width.
void coarsen_elements()
Test of the coarsening functionality.
void test_through_vertex(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
void start_with_refined_mesh()
Mesh given to init() is already refined.
void refine_deformed_elem()
QUAD4 elem is deformed, rayfire goes within libMesh::TOLERANCE central node.

Generated on Tue Dec 19 2017 12:47:29 for GRINS-0.8.0 by  doxygen 1.8.9.1