7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test teko matrix blocking functions"
10 #include <boost/assign.hpp>
11 #include <boost/test/unit_test.hpp>
13 #include <Teko_EpetraHelpers.hpp>
14 #include <Teko_Utilities.hpp>
16 #include <Thyra_EpetraLinearOp.hpp>
17 #include <Thyra_VectorStdOps.hpp>
64 void apply_block(
const int i,
const int j, Teuchos::RCP<Epetra_Vector>& output)
66 const Teuchos::RCP<const Epetra_Operator> block = blocked_op->GetBlock(i,j);
67 Epetra_Vector testvec(block->OperatorDomainMap());
68 int num_entries = block->OperatorDomainMap().NumMyElements();
69 std::vector<int> indices(num_entries);
70 for(
int i = 0; i != num_entries; ++i)
73 testvec.ReplaceMyValues(num_entries, &u_test_vec[0], &indices[0]);
75 testvec.ReplaceMyValues(num_entries, &p_test_vec[0], &indices[0]);
77 output = Teuchos::rcp(
new Epetra_Vector(block->OperatorRangeMap()));
78 block->Apply(testvec, *output);
82 Teuchos::RCP<Teko::Epetra::BlockedEpetraOperator>
blocked_op;
102 const Uint nb_segments = 3;
103 const Uint nb_nodes = (nb_segments+1) * (nb_segments+1);
112 lss_action->options().set(
"blocked_system",
false);
119 boost::mpl::vector1<mesh::LagrangeP1::Quad2D> allowed_elements;
138 lss_action->system_matrix +=
_A
149 *blocks.
create_points(2, 4) << 0. << 0. << length << 0. << length << length << 0. <<
length;
150 *blocks.create_blocks(1) << 0 << 1 << 2 << 3;
151 *blocks.create_block_subdivisions() << nb_segments << nb_segments;
152 *blocks.create_block_gradings() << 1. << 1. << 1. << 1.;
154 *blocks.create_patch(
"bottom", 1) << 0 << 1;
155 *blocks.create_patch(
"right", 1) << 1 << 2;
156 *blocks.create_patch(
"top", 1) << 2 << 3;
157 *blocks.create_patch(
"left", 1) << 3 << 0;
159 blocks.partition_blocks(PE::Comm::instance().size(),
YY);
160 blocks.create_mesh(mesh);
162 lss_action->options().set(
"matrix_builder", std::string(
"cf3.math.LSS.TrilinosCrsMatrix"));
164 lss_action->options().set(
"regions", std::vector<URI>(1, mesh.
topology().
uri()));
169 u_test_vec.resize(nb_nodes*2);
170 p_test_vec.resize(nb_nodes);
171 for(
Uint i = 0; i != nb_nodes; ++i)
173 lss.
solution()->set_value(i, 0, i*3);
174 lss.
solution()->set_value(i, 1, i*3+1);
175 lss.
solution()->set_value(i, 2, i*3+2);
176 u_test_vec[i*2] = i*3;
177 u_test_vec[i*2+1] = i*3+1;
178 p_test_vec[i] = i*3+2;
185 BOOST_CHECK(crs_mat);
186 crs_mat->epetra_matrix()->Apply(*tri_sol->epetra_vector(), *tri_rhs->epetra_vector());
192 Teuchos::RCP<Epetra_Vector> uu_output;
193 apply_block(0, 0, uu_output);
195 Teuchos::RCP<Epetra_Vector> up_output;
196 apply_block(0, 1, up_output);
198 Teuchos::RCP<Epetra_Vector> pu_output;
199 apply_block(1, 0, pu_output);
201 Teuchos::RCP<Epetra_Vector> pp_output;
202 apply_block(1, 1, pp_output);
205 for(
Uint i = 0; i != nb_nodes; ++i)
207 Real u_check, v_check, p_check;
208 tri_rhs->get_value(i, 0, u_check);
209 tri_rhs->get_value(i, 1, v_check);
210 tri_rhs->get_value(i, 2, p_check);
212 BOOST_CHECK_CLOSE((*uu_output)[i*2] + (*up_output)[i*2], u_check, 1
e-8);
213 BOOST_CHECK_CLOSE((*uu_output)[i*2+1] + (*up_output)[i*2+1], v_check, 1
e-8);
214 BOOST_CHECK_CLOSE((*pu_output)[i] + (*pp_output)[i], p_check, 1
e-8);
217 Teuchos::RCP<const Thyra::LinearOpBase<Real> > Aup = Thyra::epetraLinearOp(blocked_op->GetBlock(0,1));
218 Teuchos::RCP<const Thyra::LinearOpBase<Real> > Apu = Thyra::epetraLinearOp(blocked_op->GetBlock(1,0));
219 Teuchos::RCP<const Thyra::LinearOpBase<Real> >
K = Teko::explicitMultiply(Apu,Aup);
220 Teuchos::RCP<Thyra::VectorBase<Real> >
b = Thyra::createMember(K->range());
221 Teuchos::RCP<Thyra::VectorBase<Real> >
x = Thyra::createMember(K->domain());
223 for(
Uint i = 0; i != nb_nodes; ++i)
225 Thyra::set_ele(i, p_test_vec[i], b.ptr());
227 Thyra::apply(*K, Thyra::NOTRANS, *b, x.ptr());
229 for(
Uint i = 0; i != nb_nodes; ++i)
231 BOOST_CHECK((*pp_output)[i] != Thyra::get_ele(*x, i));
234 Teuchos::RCP<std::ofstream> k_out = Teuchos::rcp(
new std::ofstream(
"K.txt", std::ios::out));
235 Teuchos::RCP<Teuchos::FancyOStream> k_fancy_out = Teuchos::fancyOStream(k_out);
236 Thyra::describeLinearOp(*K, *k_fancy_out, Teuchos::VERB_EXTREME);
238 Teuchos::RCP<const Thyra::LinearOpBase<Real> > App = Thyra::epetraLinearOp(blocked_op->GetBlock(1,1));
239 Teuchos::RCP<std::ofstream> app_out = Teuchos::rcp(
new std::ofstream(
"App.txt", std::ios::out));
240 Teuchos::RCP<Teuchos::FancyOStream> app_fancy_out = Teuchos::fancyOStream(app_out);
241 Thyra::describeLinearOp(*App, *app_fancy_out, Teuchos::VERB_EXTREME);
251 BOOST_AUTO_TEST_SUITE_END()
253 boost::proto::terminal< SFOp< ShapeFunctionOp > >::type const N
Handle< LSS::Vector > solution()
Accessor to solution.
static boost::proto::terminal< ZeroTag >::type _0
Placeholder for the zero matrix.
virtual mesh::Domain & create_domain(const std::string &name)
creates a domain in this model
Safe pointer to an object. This is the supported method for referring to components.
virtual physics::PhysModel & create_physics(const std::string &builder)
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 ...
Handle< common::Action > add_direct_solver(const std::string &builder_name)
CGAL::Exact_predicates_inexact_constructions_kernel K
UFEMBuildSparsityFixture()
This header collects all the headers needed for the linear system solver, also including configure-ti...
Basic Classes for Mathematical applications used by COOLFluiD.
Parallel Communication Pattern. This class provides functionality to collect communication. For efficiency it works such a way that you submit your request via the constructor or the add/remove/move magic triangle and then call setup to modify the commpattern. The data needed to be kept synchronous can be registered via the insert function. The word node here means any kind of "point of storage", in this context it is not directly related with the computational mesh.
Basic Classes for Solver applications used by CF.
URI uri() const
Construct the full path.
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)
Manage a collection of UFEM solvers.
Real e()
Definition of the Unit charge [C].
BOOST_AUTO_TEST_CASE(InitMPI)
Static functions for mathematical constants.
void apply_block(const int i, const int j, Teuchos::RCP< Epetra_Vector > &output)
boost::proto::terminal< TransposeFunction >::type const transpose
boost::proto::terminal< SFOp< NablaOp > >::type const nabla
Basic Classes for Mesh applications used by COOLFluiD.
std::vector< Real > u_test_vec
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.
Teuchos::RCP< Teko::Epetra::BlockedEpetraOperator > blocked_op
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
virtual void simulate()
Simulates this model.
boost::shared_ptr< ProtoAction > create_proto_action(const std::string &name, const boost::shared_ptr< Expression > &expression)
Create a new ProtoAction, immediatly setting the expression.
Region & topology() const
math::VariableManager & variable_manager()
Access to the VariableManager.
Teuchos::RCP< Teko::Epetra::BlockedEpetraOperator > create_teko_blocked_operator(TrilinosCrsMatrix &matrix, const math::VariablesDescriptor &vars)
static Comm & instance()
Return a reference to the current PE.
Base class for defining CF components.
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.
Handle< common::Table< Real > > create_points(const Uint dimensions, const Uint nb_points)
Create the table that holds the points for the blocks.