7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for proto operators"
10 #include <boost/accumulators/accumulators.hpp>
11 #include <boost/accumulators/statistics/stats.hpp>
12 #include <boost/accumulators/statistics/mean.hpp>
13 #include <boost/accumulators/statistics/max.hpp>
15 #include <boost/foreach.hpp>
16 #include <boost/test/unit_test.hpp>
17 #include <boost/proto/debug.hpp>
64 for(
Uint i = 0; i != a.rows(); ++i)
65 for(
Uint j = 0; j != a.cols(); ++j)
66 BOOST_CHECK_CLOSE(
a(i,j),
b(i,j), threshold);
69 static boost::proto::terminal< void(*)(const RealMatrix2&, const RealMatrix2&, Real) >::type
const _check_close = {&
check_close};
86 BOOST_AUTO_TEST_SUITE( ProtoOperatorsSuite )
88 using
boost::proto::lit;
98 center_coords.setZero();
102 std::cout << std::endl;
112 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
118 BOOST_CHECK_CLOSE(vol1, vol2, 1
e-5);
132 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
155 mapped_coords.setZero();
160 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
168 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
171 boost::proto::lit(result) = integral<1>(
transpose(
nabla(temperature))*
nabla(temperature)) * 0.5
178 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
184 exact << 0.2, 0.1, 0.1, 0.2;
190 const Real radius = 1.;
193 const Real circulation = 975.;
194 const Real rho = 1.225;
199 typedef boost::mpl::vector1< LagrangeP1::Line2D> SurfaceTypes;
204 for_each_element<SurfaceTypes>
216 BOOST_CHECK_CLOSE(force[
YY], rho*u*circulation, 0.001);
217 BOOST_CHECK_SMALL(force[
XX], 1
e-8);
223 const Real radius = 1.;
226 const Real circulation = 975.;
227 const Real rho = 1.225;
236 typedef boost::mpl::vector1< LagrangeP1::Line2D> SurfaceTypes;
254 for_each_element<SurfaceTypes>
257 force += integral<1>(p *
normal)
260 BOOST_CHECK_CLOSE(force[
YY], rho*u*circulation, 0.001);
261 BOOST_CHECK_SMALL(force[
XX], 1
e-8);
267 template<
typename Signature>
270 template<
typename This,
typename FieldDataT>
273 typedef const Eigen::Matrix<Real, FieldDataT::dimension*FieldDataT::EtypeT::nb_nodes, FieldDataT::dimension*FieldDataT::EtypeT::nb_nodes>&
type;
276 template<
typename StorageT,
typename FieldDataT>
279 typedef typename FieldDataT::EtypeT EtypeT;
280 const Eigen::Matrix<Real, EtypeT::nb_nodes, EtypeT::nb_nodes> m = field.nabla().transpose() * field.nabla();
281 for(
Uint d = 0; d != FieldDataT::dimension; ++d)
283 result.template block<EtypeT::nb_nodes, EtypeT::nb_nodes>(EtypeT::nb_nodes*d, EtypeT::nb_nodes*d).noalias() = m;
303 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
306 boost::proto::lit(result) = integral<1>(
laplacian_cust(temperature)) * 0.5
340 counter.op.increment = 2.;
347 boost::mpl::vector1<LagrangeP1::Line1D>(),
348 add_count(lit(count))
351 BOOST_CHECK_EQUAL(count, 20);
364 mapped_coords.setZero();
370 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
375 boost::proto::lit(result) = zero,
382 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
387 boost::proto::lit(result) = zero,
409 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
414 boost::proto::lit(total) +=
volume,
415 boost::proto::lit(total) +=
volume
419 BOOST_CHECK_CLOSE(total, 2., 1
e-10);
428 boost::proto::terminal<IntegralConstantTag>,
429 boost::proto::_make_terminal(boost::mpl::int_<I>())
437 boost::proto::terminal<IntegralConstantTag>::type integral_const;
452 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
457 boost::proto::lit(result_i) += boost::proto::lit(idx)[
_i],
458 boost::proto::lit(result_j) += boost::proto::lit(idx)[
_j],
459 boost::proto::lit(result_ij) += boost::proto::lit(idx)[_i] + boost::proto::lit(idx)[_j]
463 BOOST_CHECK_EQUAL(result_i, 3.);
464 BOOST_CHECK_EQUAL(result_j, 3.);
465 BOOST_CHECK_EQUAL(result_ij, 12.);
480 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
485 group(
_cout <<
"i: " << _i <<
", j: " << _j <<
"\n"),
486 result1d +=
nabla(u, center)[_i]
490 BOOST_CHECK_CLOSE(result1d[0], -1., 1
e-6);
491 BOOST_CHECK_CLOSE(result1d[1], 1., 1
e-6);
515 init->register_variables(physics);
516 init_temp->register_variables(physics);
529 boost::mpl::vector1<LagrangeP1::Quad2D>(),
533 std::cout <<
"advection: " << result.transpose() << std::endl;
536 Real gradient_result = 0.;
540 boost::mpl::vector1<LagrangeP1::Quad2D>(),
544 std::cout <<
"gradient: " << gradient_result << std::endl;
565 boost::proto::lit(total) += T
571 BOOST_CHECK_EQUAL(total, 50.);
586 f.
functions(std::vector<std::string>(1,
"x+1"));
596 T = boost::proto::lit(f) + one,
598 boost::proto::lit(total) += T
604 BOOST_CHECK_EQUAL(total[0], 20.);
614 boost::accumulators::accumulator_set< Real, boost::accumulators::stats<boost::accumulators::tag::mean, boost::accumulators::tag::max> > acc;
641 for_each_element< boost::mpl::vector1<LagrangeP1::Line1D> >
647 std::cout <<
"tmp=\n" << tmp << std::endl;
657 center_coords.setZero();
660 std::cout << std::endl;
663 std::cout << std::endl;
671 boost::proto::terminal< RestrictToElementTypeTag< boost::mpl::vector1<LagrangeP1::Quad2D> > >::type quads_only;
672 boost::proto::terminal< RestrictToElementTypeTag< boost::mpl::vector1<LagrangeP1::Line2D> > >::type lines_only;
677 for_each_element< boost::mpl::vector2<LagrangeP1::Quad2D, LagrangeP1::Line2D> >(mesh->
topology(),
680 quads_only(boost::proto::lit(nb_cells) += 1),
681 lines_only(boost::proto::lit(nb_faces) += 1)
685 BOOST_CHECK_EQUAL(nb_cells, 10);
686 BOOST_CHECK_EQUAL(nb_faces, 16);
688 std::cout <<
"mesh has " << nb_cells <<
" cells and " << nb_faces <<
" faces" << std::endl;
700 Eigen::Matrix<Real, 8, 8> vals; vals.setConstant(0.125);
702 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
717 BOOST_CHECK_EQUAL(check, 72);
719 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
734 boost::proto::lit(x_check) += T[0],
735 boost::proto::lit(y_check) += T[1],
739 BOOST_CHECK_EQUAL(x_check, 0.);
740 BOOST_CHECK_EQUAL(y_check, 0.);
760 lit(v2)[
_i] += lit(v)[
_i],
765 BOOST_CHECK_EQUAL(v2[0], 8.);
766 BOOST_CHECK_EQUAL(v2[1], 16.);
779 lit(total_sum) += u[_i]
783 BOOST_CHECK_EQUAL(x_sum, 8.);
784 BOOST_CHECK_EQUAL(y_sum, 16.);
785 BOOST_CHECK_EQUAL(total_sum, 24.);
804 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
810 std::cout << elvec.transpose() << std::endl;
811 BOOST_CHECK_EQUAL(elvec.rows(), 8);
813 ref << 0,1,1,0,0,0,1,1;
814 BOOST_CHECK_EQUAL(elvec, ref);
830 result1.setZero(); result2.setZero();
832 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
837 _cout <<
"u*gradient(u): " << u(result1) *
gradient(u, result1) <<
"\n",
839 lit(result1) = result1 /
volume,
844 BOOST_CHECK_EQUAL(result1[0], 2.);
845 BOOST_CHECK_EQUAL(result2[0], 2.);
846 BOOST_CHECK_EQUAL(result1[1], 0.);
847 BOOST_CHECK_EQUAL(result2[1], 0.);
865 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
871 lit(result1) = result1 /
volume,
876 BOOST_CHECK_EQUAL(result1, 2.);
877 BOOST_CHECK_EQUAL(result2, 2.);
884 template<
typename Signature>
887 template<
typename This,
typename DataT>
890 typedef const typename DataT::SupportShapeFunction::JacobianT&
type;
893 template<
typename StorageT,
typename DataT>
897 data.support().compute_jacobian(GaussT::instance().
coords.col(0));
898 result = data.support().jacobian_inverse().transpose() * data.support().jacobian_inverse();
910 for_each_element< boost::mpl::vector1<LagrangeP1::Quad2D> >
913 _cout << metric_tensor <<
"\n"
927 BOOST_CHECK_EQUAL(idx_total, 6);
930 BOOST_AUTO_TEST_SUITE_END()
932 boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
static boost::proto::terminal< void(*)(const RealMatrix2 &, const RealMatrix2 &, Real) >::type const _check_close
#define CFinfo
these are always defined
static boost::proto::terminal< LumpTag >::type const lump
Eigen::Matrix< Real, 1, 1 > RealVector1
Fixed size 1x1 column vector.
boost::proto::terminal< SFOp< NormalOp > >::type const normal
Field & create_field(const std::string &name, const Uint cols)
Create a new field in this group.
boost::proto::terminal< SFOp< CustomSFOp< OpT > > & >::type reference_type
virtual mesh::Domain & create_domain(const std::string &name)
creates a domain in this model
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
external boost library namespace
virtual physics::PhysModel & create_physics(const std::string &builder)
Stores pre-computed mapped coords and weights for all gauss point locations.
boost::proto::terminal< SFOp< VolumeOp > >::type const volume
Static terminals that can be used in proto expressions.
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Basic Classes for Solver applications used by CF.
void result_type
Dummy result.
static boost::proto::terminal< GaussPointTag< GaussOrder< 1 > > >::type gauss_points_1
static boost::proto::terminal< NodalValuesTag >::type const nodal_values
static boost::proto::terminal< ElementQuadratureTag >::type element_quadrature
Use element_quadrature(expr1, expr2, ..., exprN) to evaluate a group of expressions.
boost::mpl::vector3< LagrangeP1::Line1D, LagrangeP1::Quad2D, LagrangeP1::Hexa3D > HigherIntegrationElements
List of all supported shapefunctions that allow high order integration.
BOOST_AUTO_TEST_CASE(ProtoBasics)
boost::shared_ptr< ElementsExpression< ExprT, ElementTypes > > elements_expression(ElementTypes, const ExprT &expr)
result_type operator()(int &arg) const
static boost::proto::terminal< ColTag >::type _col
static boost::proto::terminal< RowTag >::type _row
Real max(const Real a, const Real b)
Maximum between two scalars.
Real e()
Definition of the Unit charge [C].
boost::proto::terminal< SFOp< NodesOp > >::type const nodes
void for_each_node(mesh::Region &root_region, const ExprT &expr)
static boost::proto::terminal< std::ostream & >::type _cout
Wrap std::cout.
Static functions for mathematical constants.
boost::proto::terminal< SFOp< CustomSFOp< OpT > > >::type type
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
static boost::proto::terminal< IndexTag< boost::mpl::int_< 1 > > >::type const _j
Index looping over the dimensions of a variable.
Represents an element vector.
void check_close(const RealMatrix2 &a, const RealMatrix2 &b, const Real threshold)
Check close, for testing purposes.
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing the ...
Real pi()
Definition of the Pi constant.
Custom ops must implement the TR1 result_of protocol.
void variables(const std::vector< std::string > &vars)
sets the variable strings to be parsed
const StorageT & operator()(StorageT &result, const FieldDataT &field) const
boost::proto::terminal< NodeIdxOp >::type const node_index
Basic Classes for Mesh applications used by COOLFluiD.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
tuple model
Global confifuration.
Custom ops must implement the TR1 result_of protocol.
static boost::proto::terminal< GaussWeightTag< GaussOrder< 2 > > >::type gauss_weights_2
static MakeSFOp< DivOp >::type const divergence
Top-level namespace for coolfluid.
static boost::proto::terminal< double(*)(double, double) >::type const _atan2
MakeSFOp< CustomLaplacian >::type laplacian_cust
static boost::proto::terminal< IndexTag< boost::mpl::int_< 0 > > >::type const _i
Index looping over the dimensions of a variable.
boost::mpl::vector5< LagrangeP1::Line1D, LagrangeP1::Triag2D, LagrangeP1::Quad2D, LagrangeP1::Hexa3D, LagrangeP1::Tetra3D > VolumeTypes
void add_tag(const std::string &tag)
const StorageT & operator()(StorageT &result, const DataT &data) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
static boost::proto::terminal< double(*)(double) >::type const _sin
Wrap all operations in a template, so we can detect ops using a wildcard.
const DataT::SupportShapeFunction::JacobianT & type
static boost::proto::terminal< GaussPointTag< GaussOrder< 2 > > >::type gauss_points_2
common::Component & root() const
Gives the default root component.
static boost::proto::terminal< ElementVectorTag >::type const element_vector
boost::proto::terminal< ExtractDiagTag >::type const diagonal
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
unsigned int Uint
typedef for unsigned int
Eigen::Matrix< Real, 2, 2 > RealMatrix2
Fixed size 2x2 matrix.
Eigen::Matrix< Real, 4, 1 > RealVector4
Fixed size 4x1 column vector.
std::vector< Real > predefined_values
static MakeSFOp< GradientOp >::type const gradient
void functions(const std::vector< std::string > &functions)
sets the function strings to be parsed
Eigen::Matrix< Real, 2, 1 > RealVector2
Fixed size 2x1 column vector.
static boost::proto::terminal< NormTag >::type const _norm
Region & topology() const
Handle< Component > handle()
Get a handle to the component.
void create_field(const std::string &tag, cf3::mesh::Dictionary &dict)
Create fields. Looks up the VariablesDescriptor with the given tag, and creates a field with the same...
boost::shared_ptr< NodesExpression< ExprT, boost::mpl::range_c< Uint, 1, 4 > > > nodes_expression(const ExprT &expr)
math::VariableManager & variable_manager()
Access to the VariableManager.
Dictionary & geometry_fields() const
static boost::proto::terminal< GaussWeightTag< GaussOrder< 1 > > >::type gauss_weights_1
const Eigen::Matrix< Real, FieldDataT::dimension *FieldDataT::EtypeT::nb_nodes, FieldDataT::dimension *FieldDataT::EtypeT::nb_nodes > & type
void set(const std::string &pname, const boost::any &val)
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
Most basic kernel library.
2D Lagrange P1 Quadrilateral Element type This class provides the lagrangian shape function describin...
Uint count(const RangeT &range)
Count the elements in a range.
2D Lagrange P1 Triangular Element type This class provides the lagrangian shape function describing t...
Custom op that just modifies its argument.
Real mean(const T &vector)