7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Tests mesh interpolation"
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/list_of.hpp>
12 #include <boost/assign/std/vector.hpp>
44 using namespace boost;
58 m_argc = boost::unit_test::framework::master_test_suite().argc;
59 m_argv = boost::unit_test::framework::master_test_suite().argv;
82 Core::instance().initiate(m_argc,m_argv);
83 PE::Comm::instance().init(m_argc,m_argv);
84 Core::instance().environment().options().set(
"log_level",(
Uint)
DEBUG);
85 Core::instance().environment().options().set(
"exception_backtrace",
true);
86 Core::instance().environment().options().set(
"regist_signal_handlers",
true);
96 boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>(
"cf3.mesh.neu.Reader",
"meshreader");
100 Mesh& source = *Core::instance().
root().create_component<
Mesh>(
"box");
103 boost::shared_ptr<MeshGenerator> mesh_gen = allocate_component<SimpleMeshGenerator>(
"meshgen");
104 mesh_gen->
options().
set(
"nb_cells",std::vector<Uint>(3,5));
105 mesh_gen->options().set(
"lengths",std::vector<Real>(3,10.));
106 mesh_gen->options().set(
"mesh",source.
uri());
112 Mesh& target = *Core::instance().
root().create_component<
Mesh>(
"quadtriag");
113 meshreader->read_mesh_into(
"../../resources/quadtriag.neu",target);
125 boost::shared_ptr< Interpolator >
interpolator = allocate_component<Interpolator>(
"interpolator");
126 interpolator->options().set(
"store",
false);
129 std::string nvars =
"rho_n[1] , V_n[3] , p_n[1]";
134 nvars_2 =
"rho_n_2[1] , V_n_2[3] , p_n_2[1]";
135 evars =
"rho_e[1] , V_e[3] , p_e[1]";
136 evars_2 =
"rho_e_2[1] , V_e_2[3] , p_e_2[1]";
144 Field& s_nodebased = source_node_fields.
create_field(
"nodebased",
"rho_n[1], V_n[3], p_n[1]" );
145 Field& s_elembased = source_elem_fields.
create_field(
"elementbased",
"rho_e[1], V_e[3], p_e[1]" );
147 Field& t_nodebased = target_node_fields.
create_field(
"nodebased",
"rho_n[1], V_n[3], p_n[1]" );
148 Field& t_nodebased_2 = target_node_fields.
create_field(
"nodebased_2",
"rho_n_2[1], V_n_2[3], p_n_2[1]" );
149 Field& t_elembased = target_elem_fields.
create_field(
"elementbased",
"rho_e[1], V_e[3], p_e[1]" );
157 Field::Row data = s_nodebased[
idx];
159 data[0]=coords[
XX]+2.*coords[
YY]+2.*coords[
ZZ];
169 const Space& space = s_elembased.
space(*s_elements);
171 for (
Uint elem_idx = 0; elem_idx<s_elements->
size(); ++elem_idx)
175 s_elembased[pt][0]=coordinates[pt][
XX]+2.*coordinates[pt][
YY]+2.*coordinates[pt][
ZZ];
176 s_elembased[pt][1]=coordinates[pt][
XX];
177 s_elembased[pt][2]=coordinates[pt][
YY];
178 s_elembased[pt][3]=7.0;
179 s_elembased[pt][4]=coordinates[pt][
XX];
188 BOOST_CHECK_NO_THROW(interpolator->interpolate(s_nodebased,s_elembased));
189 BOOST_CHECK_NO_THROW(interpolator->interpolate(s_nodebased,t_nodebased));
190 BOOST_CHECK_NO_THROW(interpolator->interpolate(s_elembased,t_nodebased_2));
191 BOOST_CHECK_NO_THROW(interpolator->interpolate(s_elembased,t_elembased));
196 boost::shared_ptr< MeshWriter > meshwriter = build_component_abstract_type<MeshWriter>(
"cf3.mesh.gmsh.Writer",
"meshwriter");
200 std::vector<URI> s_fields;
202 s_fields.push_back(field.
uri());
204 meshwriter->options().set(
"fields",s_fields);
205 meshwriter->options().set(
"file",
URI(
"source.msh"));
206 meshwriter->options().set(
"mesh",source.
handle<
Mesh>());
207 meshwriter->execute();
209 std::vector<URI> t_fields;
211 t_fields.push_back(field.
uri());
213 meshwriter->options().set(
"fields",t_fields);
214 meshwriter->options().set(
"file",
URI(
"interpolated.msh"));
215 meshwriter->options().set(
"mesh",target.
handle<
Mesh>());
216 meshwriter->execute();
228 boost::shared_ptr< MeshReader > meshreader = build_component_abstract_type<MeshReader>(
"cf3.mesh.neu.Reader",
"meshreader");
231 boost::shared_ptr<MeshGenerator> mesh_gen = allocate_component<SimpleMeshGenerator>(
"meshgen");
232 mesh_gen->
options().
set(
"nb_cells",std::vector<Uint>(3,5));
233 mesh_gen->options().set(
"lengths",std::vector<Real>(3,10.));
234 mesh_gen->options().set(
"mesh",source_mesh->uri());
239 boost::shared_ptr< PointInterpolator > point_interpolator = allocate_component<PointInterpolator>(
"interpolator");
245 point_interpolator->options().set(
"dict",source_mesh->geometry_fields().handle<
Dictionary>());
248 std::vector<Real> interpolated_value;
250 point_interpolator->interpolate(source_field,coord,interpolated_value);
256 Dictionary& target_dict = source_mesh->create_continuous_space(
"target",
"cf3.mesh.LagrangeP1");
259 boost::shared_ptr< AInterpolator >
interpolator = allocate_component<Interpolator>(
"interpolator");
260 interpolator->options().set(
"store",
true);
264 BOOST_CHECK_NO_THROW(interpolator->interpolate(source_mesh->geometry_fields().coordinates(),target_field));
268 BOOST_CHECK_NO_THROW(interpolator->interpolate(source_mesh->geometry_fields().coordinates(),target_field));
272 interpolator->options().set(
"store",
false);
273 BOOST_CHECK_NO_THROW(interpolator->interpolate(source_mesh->geometry_fields().coordinates(),target_field));
277 Handle<Mesh> source_mesh_2 = Core::instance().root().create_component<
Mesh>(
"quadtriag_new");
278 meshreader->read_mesh_into(
"../../resources/quadtriag.neu",*source_mesh_2);
294 interpolator->options().set(
"store",
false);
299 std::vector<Uint> source_vars = boost::assign::list_of(0)(1);
300 std::vector<Uint> target_vars = boost::assign::list_of(1)(0);
301 BOOST_CHECK_NO_THROW(interpolator->interpolate_vars(source_mesh_2->
geometry_fields().
coordinates(),target_field_2,source_vars,target_vars));
312 PE::Comm::instance().finalize();
314 Core::instance().terminate();
318 Core::instance().event_handler().raise_event(
"ping", frame);
324 BOOST_AUTO_TEST_SUITE_END()
#define CFinfo
these are always defined
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
Field & coordinates() const
Safe pointer to an object. This is the supported method for referring to components.
Dictionary & create_discontinuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
external boost library namespace
MeshInterpolation_Fixture()
common setup for each test case
Dictionary & create_continuous_space(const std::string &space_name, const std::string &space_lib_name, const std::vector< Handle< Entities > > &entities)
~MeshInterpolation_Fixture()
common tear-down for each test case
URI uri() const
Construct the full path.
#define boost_foreach
lowercase version of BOOST_FOREACH
const Field & coordinates() const
const std::vector< Handle< Entities > > & entities_range() const
Common_API std::string to_str(const T &v)
Converts to std::string.
Handle< Component const > root() const
Uint size() const
return the number of elements
int m_argc
possibly common functions used on the tests below
Basic Classes for Mesh applications used by COOLFluiD.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
BOOST_AUTO_TEST_CASE(init_mpi)
const Handle< Space const > & space(const Handle< Entities const > &entities) const
Top-level namespace for coolfluid.
Uint row_size(Uint i=0) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
unsigned int Uint
typedef for unsigned int
Handle< Component > handle()
Get a handle to the component.
Dictionary & geometry_fields() const
void set(const std::string &pname, const boost::any &val)
Most basic kernel library.
Connectivity & connectivity()
connectivity table to dictionary entries