COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-lss-system-emptylss.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 //
7 
8 #define BOOST_TEST_DYN_LINK
9 #define BOOST_TEST_MODULE "Test module for cf3::math::LSS where testing LSS::System and the dummy EmptyLSS."
10 
12 
13 #include <boost/test/unit_test.hpp>
14 #include <boost/assign/std/vector.hpp>
15 
16 #include "common/Log.hpp"
17 #include "math/LSS/System.hpp"
20 
22 
23 using namespace cf3;
24 using namespace cf3::math;
25 using namespace cf3::math::LSS;
26 
27 using namespace boost::assign;
28 
30 
32 {
35  {
36  m_argc = boost::unit_test::framework::master_test_suite().argc;
37  m_argv = boost::unit_test::framework::master_test_suite().argv;
38  }
39 
42  {
43  }
44 
47  {
48  cp = common::allocate_component<common::PE::CommPattern>("commpattern");
49  gid += 0,1,2,3,4,5,6,7,8,9;
50  rnk += 0,0,0,0,0,0,0,0,0,0;
51  conn += 0,2,1,2,2,7,3,8,4,5,5,2,6,0,7,1,8,7,9,8;
52  startidx += 0,2,4,6,8,10,12,14,16,18,20;
53  cp->insert("gid",gid,1,false);
54  cp->setup(Handle<common::PE::CommWrapper>(cp->get_child("gid")),rnk);
55  }
56  std::vector<Uint> gid;
57  std::vector<Uint> conn;
58  std::vector<Uint> startidx;
59  std::vector<Uint> rnk;
60  boost::shared_ptr<common::PE::CommPattern> cp;
61 
63  void build_system()
64  {
65  sys = common::allocate_component<LSS::System>("system");
66  std::string solvertype("cf3.math.LSS.EmptyLSSMatrix");
67  sys->options().option("matrix_builder").change_value(solvertype);
68  BOOST_CHECK_EQUAL(sys->is_created(),false);
69  sys->create(*cp,4u,conn,startidx);
70  ba.resize(2,4);
71  diag.resize(20,5.);
72  }
73  boost::shared_ptr<LSS::System> sys;
75  Real testval;
76  std::vector<Real> diag;
77 
79  int m_argc;
80  char** m_argv;
81 };
82 
84 
85 #define CHECK_BLOCKACCUMULATOR_IS_CONSTANT(ba,refval) { \
86  BOOST_CHECK_EQUAL(ba.mat.isConstant(refval,1.e-10),true); \
87  Real sum=ba.mat.sum(); \
88  Real numentries=(Real)(ba.mat.rows()*ba.mat.cols()); \
89  BOOST_CHECK_CLOSE(sum,numentries*refval,1.e-10); \
90  BOOST_CHECK_EQUAL(ba.rhs.isConstant(refval,1.e-10),true); \
91  sum=ba.rhs.sum(); \
92  numentries=(Real)(ba.rhs.rows()*ba.rhs.cols()); \
93  BOOST_CHECK_CLOSE(sum,numentries*refval,1.e-10); \
94  BOOST_CHECK_EQUAL(ba.sol.isConstant(refval,1.e-10),true); \
95  sum=ba.sol.sum(); \
96  numentries=(Real)(ba.sol.rows()*ba.sol.cols()); \
97  BOOST_CHECK_CLOSE(sum,numentries*refval,1.e-10); \
98 }
99 
101 
102 BOOST_FIXTURE_TEST_SUITE( LSSSystem_EmptyLSSSuite, LSSSystem_EmptyLSSFixture )
103 
104 
107 {
108  common::PE::Comm::instance().init(m_argc,m_argv);
109  BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),true);
110  CFinfo.setFilterRankZero(false);
111 }
112 
114 
115 BOOST_AUTO_TEST_CASE( is_created )
116 {
117  build_input_data();
118  build_system();
119  // redundant check of state of creation
120  BOOST_CHECK_EQUAL(sys->matrix()->is_created(),true);
121  BOOST_CHECK_EQUAL(sys->rhs()->is_created(),true);
122  BOOST_CHECK_EQUAL(sys->solution()->is_created(),true);
123  BOOST_CHECK_EQUAL(sys->is_created(),true);
124  sys->destroy();
125  BOOST_CHECK_EQUAL(sys->is_created(),false);
126 }
127 
129 
130 BOOST_AUTO_TEST_CASE( check_properties )
131 {
132  build_input_data();
133  build_system();
134  BOOST_CHECK_EQUAL(sys->matrix()->blockrow_size(),10);
135  BOOST_CHECK_EQUAL(sys->matrix()->blockcol_size(),10);
136  BOOST_CHECK_EQUAL(sys->matrix()->neq(),4);
137  BOOST_CHECK_EQUAL(sys->solution()->blockrow_size(),10);
138  BOOST_CHECK_EQUAL(sys->solution()->neq(),4);
139  BOOST_CHECK_EQUAL(sys->rhs()->blockrow_size(),10);
140  BOOST_CHECK_EQUAL(sys->rhs()->neq(),4);
141  BOOST_CHECK_EQUAL(sys->matrix()->solvertype(),"EmptyLSS");
142  BOOST_CHECK_EQUAL(sys->solution()->solvertype(),"EmptyLSS");
143  BOOST_CHECK_EQUAL(sys->rhs()->solvertype(),"EmptyLSS");
144  BOOST_CHECK_EQUAL(sys->solvertype(),"EmptyLSS");
145 }
146 
148 
149 BOOST_AUTO_TEST_CASE( blockaccumulator )
150 {
151  ba.resize(2,4);
152  ba.reset(1.0);
154  ba.reset();
156  BOOST_CHECK_EQUAL(ba.mat.rows(),8);
157  BOOST_CHECK_EQUAL(ba.mat.cols(),8);
158  BOOST_CHECK_EQUAL(ba.rhs.rows(),8);
159  BOOST_CHECK_EQUAL(ba.rhs.cols(),1);
160  BOOST_CHECK_EQUAL(ba.sol.rows(),8);
161  BOOST_CHECK_EQUAL(ba.sol.cols(),1);
162 
163  ba.resize(5,2);
164  ba.reset(1.0);
166  ba.reset();
168  BOOST_CHECK_EQUAL(ba.mat.rows(),10);
169  BOOST_CHECK_EQUAL(ba.mat.cols(),10);
170  BOOST_CHECK_EQUAL(ba.rhs.rows(),10);
171  BOOST_CHECK_EQUAL(ba.rhs.cols(),1);
172  BOOST_CHECK_EQUAL(ba.sol.rows(),10);
173  BOOST_CHECK_EQUAL(ba.sol.cols(),1);
174 }
175 
177 
178 BOOST_AUTO_TEST_CASE( check_emptylss_implementations )
179 {
180  // this test case just calls functions to check if emptylss is implemented in a non-crashing way
181  build_input_data();
182  build_system();
183 
184  BOOST_TEST_CHECKPOINT( "get_values" );
185  ba.reset(1.0);
186  sys->get_values(ba);
188 
189  BOOST_TEST_CHECKPOINT( "set_values" );
190  sys->set_values(ba);
191 
192  BOOST_TEST_CHECKPOINT( "add_values" );
193  sys->add_values(ba);
194 
195  BOOST_TEST_CHECKPOINT( "dirichlet" );
196  sys->dirichlet(0,0,0.,true);
197 
198  BOOST_TEST_CHECKPOINT( "periodicity" );
199  sys->periodicity (0,0);
200 
201  BOOST_TEST_CHECKPOINT( "get_diagonal" );
202  sys->get_diagonal(diag);
203  BOOST_CHECK_EQUAL(diag.size(),sys->matrix()->blockrow_size()*sys->matrix()->neq());
204  testval=0.;
205  BOOST_FOREACH(Real i, diag) testval+=i;
206  BOOST_CHECK_CLOSE(testval,0., 1.e-10);
207 
208  BOOST_TEST_CHECKPOINT( "set_diagonal" );
209  sys->set_diagonal(diag);
210 
211  BOOST_TEST_CHECKPOINT( "add_diagonal" );
212  sys->add_diagonal(diag);
213 
214  BOOST_TEST_CHECKPOINT( "reset" );
215  sys->reset(0.);
216 
217  BOOST_TEST_CHECKPOINT( "print" );
218  sys->print(CFinfo);
219 
220  BOOST_TEST_CHECKPOINT( "matrix::get_value" );
221  testval=1.;
222  sys->matrix()->get_value(0,0,testval);
223  BOOST_CHECK_EQUAL(testval,0.);
224 
225  BOOST_TEST_CHECKPOINT( "matrix::set_value" );
226  sys->matrix()->set_value(0,0,testval);
227 
228  BOOST_TEST_CHECKPOINT( "matrix::add_value" );
229  sys->matrix()->add_value(0,0,testval);
230 
231  BOOST_TEST_CHECKPOINT( "rhs::get_value" );
232  testval=1.;
233  sys->rhs()->get_value(0,testval);
234  BOOST_CHECK_EQUAL(testval,0.);
235 
236  BOOST_TEST_CHECKPOINT( "rhs::set_value" );
237  sys->rhs()->set_value(0,testval);
238 
239  BOOST_TEST_CHECKPOINT( "rhs::add_value" );
240  sys->rhs()->add_value(0,testval);
241 }
242 
244 
245 BOOST_AUTO_TEST_CASE( swap_matrix_vector )
246 {
247  build_input_data();
248  build_system();
249 
250  boost::shared_ptr<LSS::System> sys2 = common::allocate_component<LSS::System>("system2");
251  std::string solvertype("cf3.math.LSS.EmptyLSSMatrix");
252  sys2->options().option("matrix_builder").change_value(solvertype);
253  sys2->create(*cp,4u,conn,startidx);
254  sys2->matrix()->rename("Matrix2");
255  sys2->rhs()->rename("RHS2");
256  sys2->solution()->rename("Solution2");
257 
258  boost::shared_ptr<Matrix> sw_mat = boost::dynamic_pointer_cast<Matrix>(sys2->remove_component("Matrix2"));
259  boost::shared_ptr<Vector> sw_sol = boost::dynamic_pointer_cast<Vector>(sys2->remove_component("Solution2"));
260  boost::shared_ptr<Vector> sw_rhs = boost::dynamic_pointer_cast<Vector>(sys2->remove_component("RHS2"));
261 
262  sys->swap(sw_mat, sw_sol, sw_rhs);
263  BOOST_CHECK_EQUAL(sys->matrix()->name(),"Matrix2");
264  BOOST_CHECK_EQUAL(sys->solution()->name(),"Solution2");
265  BOOST_CHECK_EQUAL(sys->rhs()->name(),"RHS2");
266 }
267 
269 
270 BOOST_AUTO_TEST_CASE( finalize_mpi )
271 {
272  CFinfo.setFilterRankZero(true);
274  BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),false);
275 }
276 
278 
279 BOOST_AUTO_TEST_SUITE_END()
280 
281 
283 
#define CFinfo
these are always defined
Definition: Log.hpp:104
void build_input_data()
create a dummy commpattern
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
#define CHECK_BLOCKACCUMULATOR_IS_CONSTANT(ba, refval)
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.
boost::shared_ptr< common::PE::CommPattern > cp
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
~LSSSystem_EmptyLSSFixture()
common tear-down for each test case
boost::shared_ptr< LSS::System > sys
LSSSystem_EmptyLSSFixture()
common setup for each test case
void init(int argc=0, char **args=0)
Definition: Comm.cpp:80
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(init_mpi)
static Comm & instance()
Return a reference to the current PE.
Definition: Comm.cpp:44
Send comments to:
COOLFluiD Web Admin