GRINS-0.8.0
rayfire_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/serial_mesh.h"
50 
51 // Ignore warnings from auto_ptr in CPPUNIT_TEST_SUITE_END()
52 #include <libmesh/ignore_warnings.h>
53 
54 namespace GRINSTesting
55 {
56  class RayfireTest : public CppUnit::TestCase
57  {
58  public:
60 
71 
73 
74  public:
75 
77  {
78  // vector of intersection points
79  std::vector<libMesh::Point> pts(4);
80  pts[0] = libMesh::Point(0.0,0.5);
81  pts[1] = libMesh::Point(0.915243860856226,0.0);
82  pts[2] = libMesh::Point(1.0,0.25);
83  pts[3] = libMesh::Point(0.321046307967165,1.0);
84 
85  // create the mesh (single square QUAD4 element)
86  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
87 
88  mesh->set_mesh_dimension(2);
89 
90  mesh->add_point( libMesh::Point(0.0,0.0),0 );
91  mesh->add_point( libMesh::Point(1.0,0.0),1 );
92  mesh->add_point( libMesh::Point(1.0,1.0),2 );
93  mesh->add_point( libMesh::Point(0.0,1.0),3 );
94 
95  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad4 );
96  for (unsigned int n=0; n<4; n++)
97  elem->set_node(n) = mesh->node_ptr(n);
98 
99  mesh->prepare_for_use();
100 
102 
103  }
104 
106  {
107  // vector of intersection points
108  std::vector<libMesh::Point> pts(4);
109  pts[0] = libMesh::Point(0.0,0.5);
110  pts[1] = libMesh::Point(0.915243860856226,0.0);
111  pts[2] = libMesh::Point(1.375,0.25);
112  pts[3] = libMesh::Point(0.321046307967165,1.0);
113 
114  // create a non-rectangular QUAD9
115  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
116 
117  mesh->set_mesh_dimension(2);
118 
119  mesh->add_point( libMesh::Point(0.0,0.0),0 );
120  mesh->add_point( libMesh::Point(1.0,0.0),1 );
121  mesh->add_point( libMesh::Point(1.0,1.0),2 );
122  mesh->add_point( libMesh::Point(0.0,1.0),3 );
123  mesh->add_point( libMesh::Point(0.5,0.0),4 );
124  mesh->add_point( libMesh::Point(1.5,0.5),5 );
125  mesh->add_point( libMesh::Point(0.5,1.0),6 );
126  mesh->add_point( libMesh::Point(0.0,0.5),7 );
127  mesh->add_point( libMesh::Point(0.5,0.5),8 );
128 
129  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad9 );
130  for (unsigned int n=0; n<9; n++)
131  elem->set_node(n) = mesh->node_ptr(n);
132 
133  mesh->prepare_for_use();
134 
136 
137  }
138 
140  {
141  // vector of intersection points
142  std::vector<libMesh::Point> pts(4);
143  pts[0] = libMesh::Point(0.5,0.0);
144  pts[1] = libMesh::Point(1.75,0.75);
145  pts[2] = libMesh::Point(1.5,0.9);
146  pts[3] = libMesh::Point(-0.1,0.1);
147 
148  // create the mesh (single trapezoidal QUAD4 element)
149  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
150 
151  mesh->set_mesh_dimension(2);
152 
153  mesh->add_point( libMesh::Point(0.0,0.0),0 );
154  mesh->add_point( libMesh::Point(1.0,0.0),1 );
155  mesh->add_point( libMesh::Point(2.0,1.0),2 );
156  mesh->add_point( libMesh::Point(-0.5,0.5),3 );
157 
158  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad4 );
159  for (unsigned int n=0; n<4; n++)
160  elem->set_node(n) = mesh->node_ptr(n);
161 
162  mesh->prepare_for_use();
163 
165 
166  }
167 
169  {
170  // create the mesh (single square QUAD4 element)
171  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = new libMesh::SerialMesh(*TestCommWorld);
172 
173  mesh->set_mesh_dimension(2);
174 
175  mesh->add_point( libMesh::Point(0.0,0.0),0 );
176  mesh->add_point( libMesh::Point(1.0,0.0),1 );
177  mesh->add_point( libMesh::Point(1.0,1.0),2 );
178  mesh->add_point( libMesh::Point(0.0,1.0),3 );
179 
180  libMesh::Elem* elem = mesh->add_elem( new libMesh::Quad4 );
181  for (unsigned int n=0; n<4; n++)
182  elem->set_node(n) = mesh->node_ptr(n);
183 
184  mesh->prepare_for_use();
185 
186  libMesh::Point start_point(0.3,0.0);
187  libMesh::Point end_point(0.3,1.0);
188 
189  libMesh::Real theta = GRINS::Constants::pi/2.0;
190 
191  this->run_test_with_mesh(mesh,start_point,theta,end_point,0);
192  }
193 
195  {
196  libMesh::Point origin = libMesh::Point(0,0.5);
197 
198  libMesh::Node calc_end_node_straight = libMesh::Node(5.0,0.5);
199  this->run_test(origin,0.0,calc_end_node_straight,5,4,"quad4",1);
200 
201  libMesh::Node calc_end_node_angle = libMesh::Node(0.5/std::tan(0.15),1.0);
202  this->run_test(origin,0.15,calc_end_node_angle,5,3,"quad4",1);
203 
204  libMesh::Node calc_end_node_neg_angle = libMesh::Node(0.5/std::tan(0.15),0.0);
205  this->run_test(origin,-0.15,calc_end_node_neg_angle,5,3,"quad4",1);
206  }
207 
209  {
210  libMesh::Point origin = libMesh::Point(0,0.5);
211 
212  libMesh::Node calc_end_node_straight = libMesh::Node(5.0,0.5);
213  this->run_test(origin,0.0,calc_end_node_straight,5,4,"quad9",1);
214 
215  libMesh::Node calc_end_node_angle = libMesh::Node(0.5/std::tan(0.15),1.0);
216  this->run_test(origin,0.15,calc_end_node_angle,5,3,"quad9",1);
217 
218  libMesh::Node calc_end_node_neg_angle = libMesh::Node(0.5/std::tan(0.15),0.0);
219  this->run_test(origin,-0.15,calc_end_node_neg_angle,5,3,"quad9",1);
220  }
221 
223  {
224  libMesh::Point origin = libMesh::Point(0.0,1.5);
225 
226  libMesh::Node calc_end_node_straight = libMesh::Node(3.0,1.5);
227  this->run_test(origin,0.0,calc_end_node_straight,9,5,"quad4",2);
228 
229  libMesh::Node calc_end_node_small_angle = libMesh::Node(3.0,1.5+3.0*std::tan(0.15));
230  this->run_test(origin,0.15,calc_end_node_small_angle,9,5,"quad4",2);
231 
232  libMesh::Node calc_end_node_small_neg_angle = libMesh::Node(3.0,1.5+3.0*std::tan(-0.15));
233  this->run_test(origin,-0.15,calc_end_node_small_neg_angle,9,5,"quad4",2);
234 
235  libMesh::Node calc_end_node_large_angle = libMesh::Node( (3.0-1.5)/std::tan(1.0), 3.0);
236  this->run_test(origin,1.0,calc_end_node_large_angle,9,6,"quad4",2);
237 
238  libMesh::Node calc_end_node_large_neg_angle = libMesh::Node( (0.0-1.5)/std::tan(-1.0), 0.0);
239  this->run_test(origin,-1.0,calc_end_node_large_neg_angle,9,0,"quad4",2);
240  }
241 
243  {
244  libMesh::Point origin = libMesh::Point(0.0,1.5);
245 
246  libMesh::Node calc_end_node_straight = libMesh::Node(3.0,1.5);
247  this->run_test(origin,0.0,calc_end_node_straight,9,5,"quad9",2);
248 
249  libMesh::Node calc_end_node_small_angle = libMesh::Node(3.0,1.5+3.0*std::tan(0.15));
250  this->run_test(origin,0.15,calc_end_node_small_angle,9,5,"quad9",2);
251 
252  libMesh::Node calc_end_node_small_neg_angle = libMesh::Node(3.0,1.5+3.0*std::tan(-0.15));
253  this->run_test(origin,-0.15,calc_end_node_small_neg_angle,9,5,"quad9",2);
254 
255  libMesh::Node calc_end_node_large_angle = libMesh::Node( (3.0-1.5)/std::tan(1.0), 3.0);
256  this->run_test(origin,1.0,calc_end_node_large_angle,9,6,"quad9",2);
257 
258  libMesh::Node calc_end_node_large_neg_angle = libMesh::Node( (0.0-1.5)/std::tan(-1.0), 0.0);
259  this->run_test(origin,-1.0,calc_end_node_large_neg_angle,9,0,"quad9",2);
260  }
261 
263  {
264  libMesh::Point origin = libMesh::Point(0.0,0.0);
265 
266  libMesh::Node calc_end_node_straight = libMesh::Node(3.0,3.0);
267 
268  // 3x3 QUAD4 mesh
269  this->run_test(origin,45.0*GRINS::Constants::pi/180.0,calc_end_node_straight,9,8,"quad4",2);
270 
271  // 3x3 QUAD9 mesh
272  this->run_test(origin,45.0*GRINS::Constants::pi/180.0,calc_end_node_straight,9,8,"quad9",2);
273  }
274 
276  {
277  libMesh::Point origin = libMesh::Point(0.0,1.0);
278  libMesh::Node calc_end_node = libMesh::Node(3.0,3.0);
279  libMesh::Real theta = calc_theta(origin,calc_end_node);
280 
281  this->run_test(origin,theta,calc_end_node,9,8,"quad4",2);
282  this->run_test(origin,theta,calc_end_node,9,8,"quad9",2);
283  }
284 
285 
286  private:
287 
288  void run_test(libMesh::Point& origin, libMesh::Real theta, libMesh::Node& calc_end_node, unsigned int n_elem, unsigned int exit_elem, std::string elem_type, unsigned int dim)
289  {
290  std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+"/mesh_"+elem_type+"_"+std::to_string(n_elem)+"elem_"+std::to_string(dim)+"D.in";
291  GetPot input(filename);
292  GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = this->build_mesh(input);
293 
294  // ensure the mesh has the desired number of elements
295  CPPUNIT_ASSERT_EQUAL(n_elem,mesh->n_elem());
296 
297  run_test_with_mesh(mesh,origin,theta,calc_end_node,exit_elem);
298  }
299 
300  void run_test_on_all_point_combinations(std::vector<libMesh::Point> pts, GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh)
301  {
302  // iterate over the starting points
303  for(unsigned int i=0; i<pts.size(); i++)
304  {
305  libMesh::Point start_point = pts[i];
306 
307  // iterate over all the intersection points
308  for(unsigned int j=0; j<pts.size(); j++)
309  {
310  if(j==i)
311  continue;
312 
313  libMesh::Point end_point = pts[j];
314 
315  libMesh::Real theta = calc_theta(start_point,end_point);
316 
317  // run the test
318  this->run_test_with_mesh(mesh,start_point,theta,end_point,0);
319  }
320 
321  }
322 
323  }
324 
325  void run_test_with_mesh(GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh, libMesh::Point& origin, libMesh::Real theta, libMesh::Point& calc_end_point, unsigned int exit_elem)
326  {
327  GRINS::SharedPtr<GRINS::RayfireMesh> rayfire = new GRINS::RayfireMesh(origin,theta);
328  rayfire->init(*mesh);
329 
330  const libMesh::Elem* original_elem = mesh->elem_ptr(exit_elem);
331 
332  const libMesh::Elem* rayfire_elem = rayfire->map_to_rayfire_elem(original_elem->id());
333 
334  if (!rayfire_elem)
335  libmesh_error_msg("Attempted to map an element that is not in the Rayfire");
336 
337  CPPUNIT_ASSERT_DOUBLES_EQUAL(calc_end_point(0), (*(rayfire_elem->node_ptr(1)))(0),libMesh::TOLERANCE);
338  CPPUNIT_ASSERT_DOUBLES_EQUAL(calc_end_point(1), (*(rayfire_elem->node_ptr(1)))(1),libMesh::TOLERANCE);
339  }
340 
341  GRINS::SharedPtr<libMesh::UnstructuredMesh> build_mesh( const GetPot& input )
342  {
343  GRINS::MeshBuilder mesh_builder;
344  return mesh_builder.build( input, *TestCommWorld );
345  }
346 
347  libMesh::Real calc_theta(libMesh::Point& start, libMesh::Point end)
348  {
349  return std::atan2( (end(1)-start(1)), (end(0)-start(0)) );
350  }
351 
352  };
353 
354  CPPUNIT_TEST_SUITE_REGISTRATION( RayfireTest );
355 
356 } // end namespace GRINSTesting
357 
358 #endif // GRINS_HAVE_CPPUNIT
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
libMesh::Real calc_theta(libMesh::Point &start, libMesh::Point end)
Definition: rayfire_test.C:347
void run_test_with_mesh(GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh, libMesh::Point &origin, libMesh::Real theta, libMesh::Point &calc_end_point, unsigned int exit_elem)
Definition: rayfire_test.C:325
RayfireMesh.
Definition: rayfire_mesh.h:65
const libMesh::Real pi
libMesh::Parallel::Communicator * TestCommWorld
Definition: unit_driver.C:70
CPPUNIT_TEST(quad4_all_sides)
void run_test_on_all_point_combinations(std::vector< libMesh::Point > pts, GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
Definition: rayfire_test.C:300
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 run_test(libMesh::Point &origin, libMesh::Real theta, libMesh::Node &calc_end_node, unsigned int n_elem, unsigned int exit_elem, std::string elem_type, unsigned int dim)
Definition: rayfire_test.C:288
GRINS::SharedPtr< libMesh::UnstructuredMesh > build_mesh(const GetPot &input)
Definition: rayfire_test.C:341
CPPUNIT_TEST_SUITE(RayfireTest)

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