25 #include "grins_config.h"
27 #ifdef GRINS_HAVE_CPPUNIT
29 #include <libmesh/ignore_warnings.h>
30 #include <cppunit/extensions/HelperMacros.h>
31 #include <cppunit/TestCase.h>
32 #include <libmesh/restore_warnings.h>
35 #include "grins_test_paths.h"
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"
52 #include <libmesh/ignore_warnings.h>
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);
86 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh =
new libMesh::SerialMesh(*
TestCommWorld);
88 mesh->set_mesh_dimension(2);
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 );
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);
99 mesh->prepare_for_use();
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);
115 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh =
new libMesh::SerialMesh(*
TestCommWorld);
117 mesh->set_mesh_dimension(2);
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 );
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);
133 mesh->prepare_for_use();
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);
149 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh =
new libMesh::SerialMesh(*
TestCommWorld);
151 mesh->set_mesh_dimension(2);
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 );
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);
162 mesh->prepare_for_use();
171 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh =
new libMesh::SerialMesh(*
TestCommWorld);
173 mesh->set_mesh_dimension(2);
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 );
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);
184 mesh->prepare_for_use();
186 libMesh::Point start_point(0.3,0.0);
187 libMesh::Point end_point(0.3,1.0);
196 libMesh::Point origin = libMesh::Point(0,0.5);
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);
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);
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);
210 libMesh::Point origin = libMesh::Point(0,0.5);
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);
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);
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);
224 libMesh::Point origin = libMesh::Point(0.0,1.5);
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);
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);
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);
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);
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);
244 libMesh::Point origin = libMesh::Point(0.0,1.5);
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);
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);
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);
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);
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);
264 libMesh::Point origin = libMesh::Point(0.0,0.0);
266 libMesh::Node calc_end_node_straight = libMesh::Node(3.0,3.0);
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);
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);
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)
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);
295 CPPUNIT_ASSERT_EQUAL(n_elem,mesh->n_elem());
303 for(
unsigned int i=0; i<pts.size(); i++)
305 libMesh::Point start_point = pts[i];
308 for(
unsigned int j=0; j<pts.size(); j++)
313 libMesh::Point end_point = pts[j];
315 libMesh::Real theta =
calc_theta(start_point,end_point);
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)
328 rayfire->init(*mesh);
330 const libMesh::Elem* original_elem = mesh->elem_ptr(exit_elem);
332 const libMesh::Elem* rayfire_elem = rayfire->map_to_rayfire_elem(original_elem->id());
335 libmesh_error_msg(
"Attempted to map an element that is not in the Rayfire");
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);
341 GRINS::SharedPtr<libMesh::UnstructuredMesh>
build_mesh(
const GetPot& input )
347 libMesh::Real
calc_theta(libMesh::Point& start, libMesh::Point end)
349 return std::atan2( (end(1)-start(1)), (end(0)-start(0)) );
358 #endif // GRINS_HAVE_CPPUNIT
void fire_through_vertex()
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
libMesh::Real calc_theta(libMesh::Point &start, libMesh::Point end)
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)
void origin_between_elems()
libMesh::Parallel::Communicator * TestCommWorld
CPPUNIT_TEST(quad4_all_sides)
void run_test_on_all_point_combinations(std::vector< libMesh::Point > pts, GRINS::SharedPtr< libMesh::UnstructuredMesh > mesh)
void test_vertical_fire()
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.
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)
GRINS::SharedPtr< libMesh::UnstructuredMesh > build_mesh(const GetPot &input)
void test_slanted_quad4()
CPPUNIT_TEST_SUITE(RayfireTest)