7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Some benchmarkings for vector operations"
10 #include <boost/test/unit_test.hpp>
11 #include <boost/numeric/ublas/vector.hpp>
14 #include <Eigen/Dense>
41 template<
typename VectorType>
44 const Uint nb_elem = connectivity.
size();
54 c0[
XX] = crow0[
XX]; c0[
YY] = crow0[
YY];
57 c1[
XX] = crow1[
XX]; c1[
YY] = crow1[
YY];
60 c2[
XX] = crow2[
XX]; c2[
YY] = crow2[
YY];
63 c3[
XX] = crow3[
XX]; c3[
YY] = crow3[
YY];
65 result += 0.25*(c0 + c1 + c2 + c3);
72 template<
typename VectorType>
84 const Uint nb_elem = connectivity.
size();
95 c0[
XX] = crow0[
XX]; c0[
YY] = crow0[
YY]; c0[
ZZ] = crow0[
ZZ];
98 c1[
XX] = crow1[
XX]; c1[
YY] = crow1[
YY]; c1[
ZZ] = crow1[
ZZ];
101 c2[
XX] = crow2[
XX]; c2[
YY] = crow2[
YY]; c2[
ZZ] = crow2[
ZZ];
104 c3[
XX] = crow3[
XX]; c3[
YY] = crow3[
YY]; c3[
ZZ] = crow3[
ZZ];
107 c4[
XX] = crow4[
XX]; c4[
YY] = crow4[
YY]; c4[
ZZ] = crow4[
ZZ];
110 c5[
XX] = crow5[
XX]; c5[
YY] = crow5[
YY]; c5[
ZZ] = crow5[
ZZ];
113 c6[
XX] = crow6[
XX]; c6[
YY] = crow6[
YY]; c6[
ZZ] = crow6[
ZZ];
116 c7[
XX] = crow7[
XX]; c7[
YY] = crow7[
YY]; c7[
ZZ] = crow7[
ZZ];
118 result += 0.125*(c0 + c1 + c2 + c3 + c4 + c5 + c6 + c7);
124 BOOST_AUTO_TEST_SUITE( VectorBenchmarkSuite )
129 grid_2d = allocate_component<Mesh>(
"grid_2d");
131 channel_3d = allocate_component<Mesh>(
"channel_3d");
132 boost::shared_ptr<Component>
root = boost::static_pointer_cast<
Component>(allocate_component<Group>(
"root"));
133 BlockData& block_data = *root->create_component<BlockData>(
"block_data");
146 centroid_2d( find_component_recursively_with_filter<Elements>( *grid_2d,
IsElementsVolume() ).geometry_space().connectivity().array(), grid_2d->geometry_fields().coordinates().array(),
c0,
c1, c2, c3, result);
148 BOOST_CHECK_CLOSE(result[
XX], 0.5, 1
e-6);
149 BOOST_CHECK_CLOSE(result[
YY], 0.5, 1
e-6);
154 boost::numeric::ublas::c_vector<Real, 2>
c0(2);
155 boost::numeric::ublas::c_vector<Real, 2>
c1(2);
156 boost::numeric::ublas::c_vector<Real, 2> c2(2);
157 boost::numeric::ublas::c_vector<Real, 2> c3(2);
158 boost::numeric::ublas::c_vector<Real, 2> result(2);
160 centroid_2d( find_component_recursively_with_filter<Elements>( *grid_2d,
IsElementsVolume() ).geometry_space().connectivity().array(), grid_2d->geometry_fields().coordinates().array(),
c0,
c1, c2, c3, result);
162 BOOST_CHECK_CLOSE(result[
XX], 0.5, 1
e-6);
163 BOOST_CHECK_CLOSE(result[
YY], 0.5, 1
e-6);
168 boost::numeric::ublas::vector<Real>
c0(2);
169 boost::numeric::ublas::vector<Real>
c1(2);
170 boost::numeric::ublas::vector<Real> c2(2);
171 boost::numeric::ublas::vector<Real> c3(2);
172 boost::numeric::ublas::vector<Real> result(2);
174 centroid_2d( find_component_recursively_with_filter<Elements>( *grid_2d,
IsElementsVolume() ).geometry_space().connectivity().array(), grid_2d->geometry_fields().coordinates().array(),
c0,
c1, c2, c3, result);
176 BOOST_CHECK_CLOSE(result[
XX], 0.5, 1
e-6);
177 BOOST_CHECK_CLOSE(result[
YY], 0.5, 1
e-6);
192 const Elements& elems = find_component_recursively_with_name<Elements>(*channel_3d,
"cf3.mesh.SF.LagrangeP1.Hexa3D");
195 centroid_3d(elems.
geometry_space().
connectivity().
array(), coords.array(),
c0,
c1, c2, c3, c4, c5, c6, c7, result);
197 BOOST_CHECK_CLOSE(result[
XX], 5., 1
e-6);
198 BOOST_CHECK_SMALL(result[
YY], 1
e-6);
199 BOOST_CHECK_CLOSE(result[
ZZ], 2.5, 1
e-6);
204 boost::numeric::ublas::c_vector<Real, 3>
c0(3);
205 boost::numeric::ublas::c_vector<Real, 3>
c1(3);
206 boost::numeric::ublas::c_vector<Real, 3> c2(3);
207 boost::numeric::ublas::c_vector<Real, 3> c3(3);
208 boost::numeric::ublas::c_vector<Real, 3> c4(3);
209 boost::numeric::ublas::c_vector<Real, 3> c5(3);
210 boost::numeric::ublas::c_vector<Real, 3> c6(3);
211 boost::numeric::ublas::c_vector<Real, 3> c7(3);
212 boost::numeric::ublas::c_vector<Real, 3> result(3);
214 const Elements& elems = find_component_recursively_with_name<Elements>(*channel_3d,
"cf3.mesh.LagrangeP1.Hexa3D");
217 centroid_3d(elems.
geometry_space().
connectivity().
array(), coords.array(),
c0,
c1, c2, c3, c4, c5, c6, c7, result);
219 BOOST_CHECK_CLOSE(result[
XX], 5., 1
e-6);
220 BOOST_CHECK_SMALL(result[
YY], 1
e-6);
221 BOOST_CHECK_CLOSE(result[
ZZ], 2.5, 1
e-6);
226 boost::numeric::ublas::vector<Real>
c0(3);
227 boost::numeric::ublas::vector<Real>
c1(3);
228 boost::numeric::ublas::vector<Real> c2(3);
229 boost::numeric::ublas::vector<Real> c3(3);
230 boost::numeric::ublas::vector<Real> c4(3);
231 boost::numeric::ublas::vector<Real> c5(3);
232 boost::numeric::ublas::vector<Real> c6(3);
233 boost::numeric::ublas::vector<Real> c7(3);
234 boost::numeric::ublas::vector<Real> result(3);
236 const Elements& elems = find_component_recursively_with_name<Elements>(*channel_3d,
"cf3.mesh.LagrangeP1.Hexa3D");
239 centroid_3d(elems.
geometry_space().
connectivity().
array(), coords.array(),
c0,
c1, c2, c3, c4, c5, c6, c7, result);
241 BOOST_CHECK_CLOSE(result[
XX], 5., 1
e-6);
242 BOOST_CHECK_SMALL(result[
YY], 1
e-6);
243 BOOST_CHECK_CLOSE(result[
ZZ], 2.5, 1
e-6);
248 Eigen::Vector2d
c0(2);
249 Eigen::Vector2d
c1(2);
250 Eigen::Vector2d c2(2);
251 Eigen::Vector2d c3(2);
252 Eigen::Vector2d result(2);
254 centroid_2d( find_component_recursively_with_filter<Elements>( *grid_2d,
IsElementsVolume() ).geometry_space().connectivity().array(), grid_2d->geometry_fields().coordinates().array(),
c0,
c1, c2, c3, result);
256 BOOST_CHECK_CLOSE(result[
XX], 0.5, 1
e-6);
257 BOOST_CHECK_CLOSE(result[
YY], 0.5, 1
e-6);
262 Eigen::VectorXd
c0(2);
263 Eigen::VectorXd
c1(2);
264 Eigen::VectorXd c2(2);
265 Eigen::VectorXd c3(2);
266 Eigen::VectorXd result(2);
268 centroid_2d( find_component_recursively_with_filter<Elements>( *grid_2d,
IsElementsVolume() ).geometry_space().connectivity().array(), grid_2d->geometry_fields().coordinates().array(),
c0,
c1, c2, c3, result);
270 BOOST_CHECK_CLOSE(result[
XX], 0.5, 1
e-6);
271 BOOST_CHECK_CLOSE(result[
YY], 0.5, 1
e-6);
276 Eigen::Vector3d
c0(3);
277 Eigen::Vector3d
c1(3);
278 Eigen::Vector3d c2(3);
279 Eigen::Vector3d c3(3);
280 Eigen::Vector3d c4(3);
281 Eigen::Vector3d c5(3);
282 Eigen::Vector3d c6(3);
283 Eigen::Vector3d c7(3);
284 Eigen::Vector3d result(3);
286 const Elements& elems = find_component_recursively_with_name<Elements>(*channel_3d,
"cf3.mesh.LagrangeP1.Hexa3D");
289 centroid_3d(elems.
geometry_space().
connectivity().
array(), coords.array(),
c0,
c1, c2, c3, c4, c5, c6, c7, result);
291 BOOST_CHECK_CLOSE(result[
XX], 5., 1
e-6);
292 BOOST_CHECK_SMALL(result[
YY], 1
e-6);
293 BOOST_CHECK_CLOSE(result[
ZZ], 2.5, 1
e-6);
298 Eigen::VectorXd
c0(3);
299 Eigen::VectorXd
c1(3);
300 Eigen::VectorXd c2(3);
301 Eigen::VectorXd c3(3);
302 Eigen::VectorXd c4(3);
303 Eigen::VectorXd c5(3);
304 Eigen::VectorXd c6(3);
305 Eigen::VectorXd c7(3);
306 Eigen::VectorXd result(3);
308 const Elements& elems = find_component_recursively_with_name<Elements>(*channel_3d,
"cf3.mesh.LagrangeP1.Hexa3D");
311 centroid_3d(elems.
geometry_space().
connectivity().
array(), coords.array(),
c0,
c1, c2, c3, c4, c5, c6, c7, result);
313 BOOST_CHECK_CLOSE(result[
XX], 5., 1
e-6);
314 BOOST_CHECK_SMALL(result[
YY], 1
e-6);
315 BOOST_CHECK_CLOSE(result[
ZZ], 2.5, 1
e-6);
318 BOOST_AUTO_TEST_SUITE_END()
void centroid_2d(const Table< Uint >::ArrayT &connectivity, const Table< Real >::ArrayT &coords, VectorType c0, VectorType c1, VectorType c2, VectorType c3, VectorType &result)
Calculates the centroid of all centroids over a set of quads.
BOOST_FIXTURE_TEST_CASE(CreateMesh, VectorBenchmarkFixture)
Space & geometry_space() const
Basic Classes for Mathematical applications used by COOLFluiD.
static Handle< Mesh > channel_3d
const Field & coordinates() const
def build_mesh(mesh, parent)
Real e()
Definition of the Unit charge [C].
Dictionary & geometry_fields() const
Const access to the coordinates.
static Handle< Mesh > grid_2d
Basic Classes for Mesh applications used by COOLFluiD.
Library for I/O of the OpenFOAM BlockMesh dict files.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Top-level namespace for coolfluid.
void centroid_3d(const Table< Uint >::ArrayT &connectivity, const Table< Real >::ArrayT &coords, VectorType c0, VectorType c1, VectorType c2, VectorType c3, VectorType c4, VectorType c5, VectorType c6, VectorType c7, VectorType &result)
Calculates the centroid of all centroids over a set of hexahedra.
Component holding a 2 dimensional array of a templated type.
unsigned int Uint
typedef for unsigned int
Base class for defining CF components.
Most basic kernel library.
Connectivity & connectivity()
connectivity table to dictionary entries