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>
18 #include <Thyra_describeLinearOp.hpp>
19 #include <Thyra_MultiVectorStdOps.hpp>
20 #include <Teuchos_VerboseObject.hpp>
88 mesh = dom.create_component<
Mesh>(
"mesh");
97 const Uint nb_nodes =
mesh->geometry_fields().size();
98 std::vector< std::set<Uint> > connectivity_sets(nb_nodes);
102 const Uint nb_elems = connectivity.
size();
106 std::cout <<
"Connectivity for element " <<
elem <<
":";
107 BOOST_FOREACH(
const Uint node_a, connectivity[elem])
109 std::cout <<
" " << node_a;
110 BOOST_FOREACH(
const Uint node_b, connectivity[elem])
112 connectivity_sets[node_a].insert(node_b);
115 std::cout << std::endl;
120 for(
Uint i = 0; i != nb_nodes; ++i)
122 std::cout <<
"node " << i <<
": " << coords[i][0] <<
", " << coords[i][1] << std::endl;
125 starting_indices.push_back(0);
126 BOOST_FOREACH(
const std::set<Uint>&
nodes, connectivity_sets)
128 starting_indices.push_back(starting_indices.back() + nodes.size());
129 node_connectivity.insert(node_connectivity.end(), nodes.begin(), nodes.end());
132 loop_regions.push_back(
mesh->topology().uri());
160 using
boost::proto::lit;
167 template<
typename Signature>
170 template<
typename This,
typename DataT>
173 typedef const Eigen::Matrix<Real, DataT::SupportShapeFunction::nb_nodes, DataT::SupportShapeFunction::nb_nodes>&
type;
176 template<
typename StorageT,
typename DataT>
179 result.setConstant(m_constant);
199 action->
options().
set(
"physical_model", physical_model);
200 action->
options().
set(solver::Tags::regions(), loop_regions);
202 my_term.op.set_constant(2.);
211 template<
typename Signature>
214 template<
typename This,
typename DataT>
217 typedef const Eigen::Matrix<Real, DataT::SupportShapeFunction::nb_nodes, 1>&
type;
220 template<
typename StorageT,
typename DataT>
223 cf3_assert(result.rows() == data.block_accumulator.sol.rows());
224 m_vector->get_sol_values(data.block_accumulator);
225 result = data.block_accumulator.sol;
241 template<
typename Signature>
244 template<
typename This,
typename DataT>
247 typedef const Eigen::Matrix<Real, DataT::dimension*DataT::SupportShapeFunction::nb_nodes, 1>&
type;
250 template<
typename StorageT,
typename DataT>
253 cf3_assert(result.rows() == data.block_accumulator.sol.rows());
254 m_vector->get_sol_values(data.block_accumulator);
256 for(
Uint j = 0; j != DataT::dimension; ++j)
258 const Uint offset = j*DataT::SupportShapeFunction::nb_nodes;
259 for(
Uint i = 0; i != DataT::SupportShapeFunction::nb_nodes; ++i)
261 result[offset + i] = data.block_accumulator.sol[i*DataT::dimension + j];
279 template<
typename Signature>
282 template<
typename This,
typename TempT,
typename MatrixT,
typename VectorT>
283 struct result<This(TempT, MatrixT, VectorT)>
288 template<
typename StorageT,
typename TempT,
typename MatrixT,
typename VectorT>
289 const StorageT&
operator()(StorageT&
result, TempT&
T,
const MatrixT& m,
const VectorT& vec)
const
301 lss->
options().
set(
"matrix_builder", std::string(
"cf3.math.LSS.TrilinosCrsMatrix"));
302 lss->
create(
mesh->geometry_fields().comm_pattern(), 1, node_connectivity, starting_indices);
309 Thyra::randomize(0., 1., solution->thyra_vector().ptr());
320 lss->
solution()->clone_to(*vec_copy);
322 scalar_vector.op.set_vector(vec_copy);
334 sys_rhs +=
_A * scalar_vector
338 action->options().set(
"physical_model", physical_model);
339 action->options().set(solver::Tags::regions(), loop_regions);
341 field_manager->create_field(
"scalar",
mesh->geometry_fields());
349 Teuchos::RCP< Thyra::MultiVectorBase<Real> > rhs2 = Thyra::createMembers(op->thyra_operator()->range(), 1);
350 Thyra::apply(*op->thyra_operator(), Thyra::NOTRANS, *solution->thyra_vector(), rhs2.ptr());
352 std::vector<Real> diff_norm(1);
354 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
355 std::cout <<
"rhs2 norm: " << diff_norm.front() << std::endl;
356 BOOST_CHECK(diff_norm.front() > 1
e-6);
358 Thyra::update(-1., *rhs->thyra_vector(), rhs2.ptr());
359 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
360 std::cout <<
"diff norm: " << diff_norm.front() << std::endl;
361 BOOST_CHECK_SMALL(diff_norm.front(), 1
e-10);
367 lss->
options().
set(
"matrix_builder", std::string(
"cf3.math.LSS.TrilinosCrsMatrix"));
375 SystemMatrix matrix(solve_action->options().option(
"lss"));
376 SystemRHS sys_rhs(solve_action->options().option(
"lss"));
390 sys_rhs +=
_A * vector_vector
394 action->
options().
set(
"physical_model", physical_model);
395 action->
options().
set(solver::Tags::regions(), loop_regions);
397 field_manager->create_field(
"vector",
mesh->geometry_fields());
401 solve_action->options().set(
"lss", lss);
408 Thyra::randomize(0., 1., solution->thyra_vector().ptr());
411 lss->
solution()->clone_to(*vec_copy);
412 vector_vector.op.set_vector(vec_copy);
419 Teuchos::RCP< Thyra::MultiVectorBase<Real> > rhs2 = Thyra::createMembers(op->thyra_operator()->range(), 1);
420 Thyra::apply(*op->thyra_operator(), Thyra::NOTRANS, *solution->thyra_vector(), rhs2.ptr());
422 std::vector<Real> diff_norm(1);
424 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
425 std::cout <<
"rhs2 norm: " << diff_norm.front() << std::endl;
426 BOOST_CHECK(diff_norm.front() > 1
e-6);
428 Thyra::update(-1., *rhs->thyra_vector(), rhs2.ptr());
429 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
430 std::cout <<
"diff norm: " << diff_norm.front() << std::endl;
431 BOOST_CHECK_SMALL(diff_norm.front(), 1
e-10);
437 lss->
options().
set(
"matrix_builder", std::string(
"cf3.math.LSS.TrilinosCrsMatrix"));
438 lss->
create(
mesh->geometry_fields().comm_pattern(), 1, node_connectivity, starting_indices);
445 Thyra::randomize(0., 1., solution->thyra_vector().ptr());
456 lss->
solution()->clone_to(*vec_copy);
458 scalar_vector.op.set_vector(vec_copy);
460 boost::mpl::vector1<mesh::LagrangeP1::Line1D> etype;
476 action->options().set(
"physical_model", physical_model);
477 action->options().set(solver::Tags::regions(), loop_regions);
479 field_manager->create_field(
"scalar2",
mesh->geometry_fields());
487 Teuchos::RCP< Thyra::MultiVectorBase<Real> > rhs2 = Thyra::createMembers(op->thyra_operator()->range(), 1);
488 Thyra::apply(*op->thyra_operator(), Thyra::NOTRANS, *solution->thyra_vector(), rhs2.ptr());
490 std::vector<Real> diff_norm(1);
492 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
493 std::cout <<
"rhs2 norm: " << diff_norm.front() << std::endl;
494 BOOST_CHECK(diff_norm.front() > 1
e-6);
496 Thyra::update(-1., *rhs->thyra_vector(), rhs2.ptr());
497 Thyra::norms(*rhs2, Teuchos::arrayViewFromVector(diff_norm));
498 std::cout <<
"diff norm: " << diff_norm.front() << std::endl;
499 BOOST_CHECK_SMALL(diff_norm.front(), 1
e-10);
505 lss->
options().
set(
"matrix_builder", std::string(
"cf3.math.LSS.TrilinosCrsMatrix"));
506 lss->
create(
mesh->geometry_fields().comm_pattern(), 1, node_connectivity, starting_indices);
513 boost::mpl::vector1<mesh::LagrangeP1::Triag2D> etype;
528 action->
options().
set(
"physical_model", physical_model);
529 action->
options().
set(solver::Tags::regions(), loop_regions);
531 field_manager->create_field(
"massvar",
mesh->geometry_fields());
535 lss->
matrix()->print(std::cout);
540 root.remove_component(
"scalar_lss");
541 root.remove_component(
"vector_lss");
544 BOOST_AUTO_TEST_SUITE_END()
546 boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
Handle< LSS::Vector > solution()
Accessor to solution.
void create(cf3::common::PE::CommPattern &cp, Uint neq, std::vector< Uint > &node_connectivity, std::vector< Uint > &starting_indices, const std::vector< Uint > &periodic_links_nodes=std::vector< Uint >(), const std::vector< bool > &periodic_links_active=std::vector< bool >())
static boost::proto::terminal< ZeroTag >::type _0
Placeholder for the zero matrix.
bool is_null(T ptr)
predicate for comparison to nullptr
const StorageT & operator()(StorageT &result, const DataT &data) const
external boost library namespace
static boost::proto::terminal< ElementSystemMatrix< boost::mpl::int_< 0 > > >::type const _A
Some predefined element matrices (more can be user-defined, but you have to change the number in the ...
Space & geometry_space() const
void set_constant(const Real c)
const StorageT & operator()(StorageT &result, const DataT &data) const
void set_expression(const boost::shared_ptr< Expression > &expression)
This header collects all the headers needed for the linear system solver, also including configure-ti...
const Eigen::Matrix< Real, DataT::dimension *DataT::SupportShapeFunction::nb_nodes, 1 > & type
MakeSFOp< CustomLaplacianApply >::type laplacian_apply
Class to encapsulate Proto actions.
Custom ops must implement the TR1 result_of protocol.
Custom ops must implement the TR1 result_of protocol.
static Handle< physics::PhysModel > physical_model
static Handle< FieldManager > field_manager
void set_vector(const Handle< math::LSS::Vector > &v)
Basic Classes for Solver applications used by CF.
Handle< LSS::Matrix > matrix()
Accessor to matrix.
static boost::proto::terminal< ElementQuadratureTag >::type element_quadrature
Use element_quadrature(expr1, expr2, ..., exprN) to evaluate a group of expressions.
boost::shared_ptr< ElementsExpression< ExprT, ElementTypes > > elements_expression(ElementTypes, const ExprT &expr)
const StorageT & operator()(StorageT &result, TempT &T, const MatrixT &m, const VectorT &vec) const
void create_blocked(cf3::common::PE::CommPattern &cp, const VariablesDescriptor &vars, std::vector< Uint > &node_connectivity, std::vector< Uint > &starting_indices, const std::vector< Uint > &periodic_links_nodes=std::vector< Uint >(), const std::vector< bool > &periodic_links_active=std::vector< bool >())
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.
boost::proto::terminal< SFOp< CustomSFOp< OpT > > >::type type
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
static std::vector< URI > loop_regions
static std::vector< Uint > starting_indices
Basic Classes for Mesh applications used by COOLFluiD.
Handle< math::LSS::Vector > m_vector
tuple model
Global confifuration.
void init(int argc=0, char **args=0)
Top-level namespace for coolfluid.
Handle< LSS::Vector > rhs()
Accessor to right hand side.
static boost::proto::terminal< IndexTag< boost::mpl::int_< 0 > > >::type const _i
Index looping over the dimensions of a variable.
BOOST_AUTO_TEST_CASE(MyTerminal)
const StorageT & operator()(StorageT &result, const DataT &field) const
Uint row_size(Uint i=0) const
static Handle< Model > model
Wrap all operations in a template, so we can detect ops using a wildcard.
const Eigen::Matrix< Real, DataT::SupportShapeFunction::nb_nodes, 1 > & type
common::Component & root() const
Gives the default root component.
static boost::proto::terminal< ExpressionGroupTag >::type group
Use group(expr1, expr2, ..., exprN) to evaluate a group of expressions.
common::Environment & environment() const
unsigned int Uint
typedef for unsigned int
Custom ops must implement the TR1 result_of protocol.
void set_vector(const Handle< math::LSS::Vector > &v)
Handle< math::LSS::Vector > m_vector
static Handle< Mesh > mesh
static Comm & instance()
Return a reference to the current PE.
virtual void execute()
execute the action
Base class for defining CF components.
const Eigen::Matrix< Real, DataT::SupportShapeFunction::nb_nodes, DataT::SupportShapeFunction::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.
Connectivity & connectivity()
connectivity table to dictionary entries
static std::vector< Uint > node_connectivity