8 #define BOOST_TEST_DYN_LINK
9 #define BOOST_TEST_MODULE "Test module for some LSS vector ops"
15 #include <boost/test/unit_test.hpp>
16 #include <boost/assign/std/vector.hpp>
17 #include <boost/lexical_cast.hpp>
19 #include <Teuchos_VerboseObject.hpp>
20 #include <Thyra_VectorStdOps.hpp>
47 solvertype(
"Trilinos"),
56 if (common::PE::Comm::instance().is_initialized())
58 nproc=common::PE::Comm::instance().size();
59 irank=common::PE::Comm::instance().rank();
60 BOOST_CHECK_EQUAL(nproc,2);
62 m_argc = boost::unit_test::framework::master_test_suite().argc;
63 m_argv = boost::unit_test::framework::master_test_suite().argv;
79 rank_updatable += 0,0,0,1;
82 rank_updatable += 0,1,1,1,1;
84 cp.
insert(
"gid",gid,1,
false);
91 starting_indices.clear();
92 node_connectivity.clear();
95 node_connectivity += 0,3,1,3,2,3,3;
96 starting_indices += 0,2,4,6,7;
98 node_connectivity += 0,4,1,4,2,4,3,4,4;
99 starting_indices += 0,2,4,6,8,9;
101 sys.
create(cp,neq,node_connectivity,starting_indices);
105 std::string solvertype;
116 std::vector<Uint> gid;
117 std::vector<Uint> rank_updatable;
120 std::vector<Uint> node_connectivity;
121 std::vector<Uint> starting_indices;
133 common::PE::Comm::instance().init(m_argc,m_argv);
134 BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),
true);
135 CFinfo.setFilterRankZero(
false);
136 common::Core::instance().environment().options().set(
"log_level", 4u);
137 common::Core::instance().environment().options().set(
"exception_backtrace",
false);
138 common::Core::instance().environment().options().set(
"exception_outputs",
false);
146 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
148 build_commpattern(cp);
149 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
150 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
151 build_system(*sys,cp);
158 sol->epetra_vector()->Random();
159 sys->rhs()->
reset(1.);
160 if(common::PE::Comm::instance().rank() == 1)
161 sol->set_value(4, 2.);
163 mat->
apply(sys->rhs(), sys->solution(), 2., 1.);
165 const Uint nb_blocks = sys->rhs()->blockrow_size();
166 const Uint neq = sys->rhs()->neq();
168 for(
Uint i = 0; i != nb_blocks; ++i)
170 for(
Uint j = 0; j != neq; ++j)
172 if(!cp.isUpdatable()[i])
175 sys->rhs()->get_value(i, j, result);
176 sys->solution()->get_value(i, j, val);
177 if(common::PE::Comm::instance().rank() == 1 && i == 4)
179 BOOST_CHECK_CLOSE(result, 1.+val*2., 1
e-12);
183 BOOST_CHECK_CLOSE(result, 1.+(val+2.)*2., 1
e-12);
191 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
193 build_commpattern(cp);
194 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
195 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
196 build_system(*sys,cp);
200 Teuchos::RCP< Thyra::VectorBase<Real> > thyra_vec = sol->thyra_vector();
202 const Epetra_Vector& esol = *sol->epetra_vector();
203 const int edim = esol.Map().NumMyElements();
204 for(
int i = 0; i != edim; ++i)
206 BOOST_CHECK_EQUAL(esol[i], 1.);
209 Thyra::assign(thyra_vec.ptr(), 2.);
210 for(
int i = 0; i != edim; ++i)
212 BOOST_CHECK_EQUAL(esol[i], 2.);
215 sol->print_native(std::cout);
218 BOOST_CHECK_EQUAL(Thyra::get_ele(*thyra_vec, 0), 3.);
219 BOOST_CHECK_EQUAL(Thyra::get_ele(*thyra_vec, 1), 3.);
220 BOOST_CHECK_EQUAL(Thyra::get_ele(*thyra_vec, 2), 3.);
221 thyra_vec->describe(*Teuchos::VerboseObjectBase::getDefaultOStream(), Teuchos::VERB_EXTREME);
226 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
228 build_commpattern(cp);
229 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
230 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
231 build_system(*sys,cp);
233 sys->solution()->reset(1.);
234 sys->rhs()->reset(2.);
236 sys->solution()->assign(*sys->rhs());
238 const Uint nb_blocks = sys->solution()->blockrow_size();
240 for(
Uint i = 0; i != nb_blocks; ++i)
242 for(
Uint j = 0; j != neq; ++j)
245 sys->solution()->get_value(i, j, val);
246 BOOST_CHECK_EQUAL(val, 2.);
250 sys->solution()->update(*sys->rhs(), 2.);
252 for(
Uint i = 0; i != nb_blocks; ++i)
254 for(
Uint j = 0; j != neq; ++j)
257 sys->solution()->get_value(i, j, val);
258 BOOST_CHECK_EQUAL(val, 6.);
265 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
267 build_commpattern(cp);
268 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
269 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
270 build_system(*sys,cp);
274 Teuchos::RCP< Thyra::VectorBase<Real> > thyra_vec = sol->thyra_vector();
276 Thyra::assign(thyra_vec.ptr(), 2.);
279 const Uint nb_blocks = sys->solution()->blockrow_size();
280 for(
Uint i = 0; i != nb_blocks; ++i)
282 for(
Uint j = 0; j != neq; ++j)
285 sol->get_value(i, j, val);
286 BOOST_CHECK_EQUAL(val, 2.);
293 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
295 build_commpattern(cp);
296 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
297 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
298 build_system(*sys,cp);
302 Teuchos::RCP< Thyra::VectorBase<Real> > thyra_vec = sol->thyra_vector();
306 const Uint nb_blocks = sys->solution()->blockrow_size();
307 for(
Uint i = 0; i != nb_blocks; ++i)
309 for(
Uint j = 0; j != neq; ++j)
312 sol->get_value(i, j, val);
313 BOOST_CHECK_EQUAL(val, 2.);
322 CFinfo.setFilterRankZero(
true);
323 common::PE::Comm::instance().finalize();
324 BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),
false);
329 BOOST_AUTO_TEST_SUITE_END()
void build_system(LSS::System &sys, common::PE::CommPattern &cp)
build a test system
#define CFinfo
these are always defined
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 >())
void reset()
Set the handle to null.
virtual void reset(Real reset_to=0.)=0
Reset Matrix.
Safe pointer to an object. This is the supported method for referring to components.
This header collects all the headers needed for the linear system solver, also including configure-ti...
BOOST_AUTO_TEST_CASE(init_mpi)
Basic Classes for Mathematical applications used by COOLFluiD.
void setup(const Handle< CommWrapper > &gid, std::vector< Uint > &rank)
void build_commpattern(common::PE::CommPattern &cp)
create a test commpattern
void insert(const std::string &name, T *&data, const int size, const unsigned int stride=1, const bool needs_update=true)
Real e()
Definition of the Unit charge [C].
Handle< Component > get_child(const std::string &name)
Top-level namespace for coolfluid.
~LSSAtomicFixture()
common tear-down for each test case
unsigned int Uint
typedef for unsigned int
LSSAtomicFixture()
common setup for each test case
virtual void apply(const Handle< Vector > &y, const Handle< Vector const > &x, const Real alpha=1., const Real beta=0.)=0
Compute y = alpha*A*x + beta*y.