COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-lss-symmetric-dirichlet.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 indivdual operations."
10 
12 
13 #include <fstream>
14 
15 #include <boost/test/unit_test.hpp>
16 #include <boost/assign/std/vector.hpp>
17 #include <boost/lexical_cast.hpp>
18 
19 #include "common/Log.hpp"
20 #include "math/LSS/System.hpp"
22 
24 #include "common/PE/debug.hpp"
25 #include "common/Environment.hpp"
26 
28 
29 using namespace boost::assign;
30 
31 using namespace cf3;
32 using namespace cf3::math;
33 using namespace cf3::math::LSS;
34 
36 
38 {
41  solvertype("Trilinos"),
42  gid(0),
43  irank(0),
44  nproc(1),
45  neq(1),
46  rank_updatable(0),
47  node_connectivity(0),
48  starting_indices(0),
49  blockcol_size(0),
50  blockrow_size(0)
51  {
52  if (common::PE::Comm::instance().is_initialized())
53  {
54  nproc=common::PE::Comm::instance().size();
55  irank=common::PE::Comm::instance().rank();
56  BOOST_CHECK_EQUAL(nproc,2);
57  }
58  m_argc = boost::unit_test::framework::master_test_suite().argc;
59  m_argv = boost::unit_test::framework::master_test_suite().argv;
60 
61  if(m_argc != 2)
62  throw common::ParsingFailed(FromHere(), "Failed to parse command line arguments: expected one argument: builder name for the matrix");
63  matrix_builder = m_argv[1];
64  }
65 
68  {
69  }
70 
73  {
74  if (irank==0)
75  {
76  gid += 0,1,2;
77  rank_updatable += 0,0,1;
78  } else {
79  gid += 1,2,3;
80  rank_updatable += 0,1,1;
81  }
82  cp.insert("gid",gid,1,false);
83  cp.setup(Handle<common::PE::CommWrapper>(cp.get_child("gid")),rank_updatable);
84  }
85 
88  {
89  if (irank==0)
90  {
91  node_connectivity += 0,1,0,1,2,1,2;
92  starting_indices += 0,2,5,7;
93  blockcol_size = 3;
94  blockrow_size = 2;
95  } else {
96  node_connectivity += 0,1,0,1,2,1,2;
97  starting_indices += 0,2,5,7;
98  blockcol_size = 3;
99  blockrow_size = 2;
100  }
101  sys.create(cp,neq,node_connectivity,starting_indices);
102  }
103 
105  std::string solvertype;
106  std::string matrix_builder;
107 
109  int irank;
110  int nproc;
111  int neq;
112  int m_argc;
113  char** m_argv;
114 
116  std::vector<Uint> gid;
117  std::vector<Uint> rank_updatable;
118 
120  std::vector<Uint> node_connectivity;
121  std::vector<Uint> starting_indices;
124 
125 };
126 
128 
129 BOOST_FIXTURE_TEST_SUITE( LSSSymmetricDirichletSuite, LSSSymmetricDirichletFixture )
130 
131 
134 {
135  common::PE::Comm::instance().init(m_argc,m_argv);
136  BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),true);
137  CFinfo.setFilterRankZero(false);
138  common::Core::instance().environment().options().set("log_level", 4u);
139  common::Core::instance().environment().options().set("exception_backtrace", false);
140  common::Core::instance().environment().options().set("exception_outputs", false);
141  //common::PE::wait_for_debugger(0);
142 }
143 
145 
146 BOOST_AUTO_TEST_CASE( test_complete_system )
147 {
148  // build a commpattern and the system
149  boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>("commpattern");
150  common::PE::CommPattern& cp = *cp_ptr;
151  build_commpattern(cp);
152  boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>("sys"));
153  sys->options().option("matrix_builder").change_value(matrix_builder);
154  build_system(*sys,cp);
155  BOOST_CHECK_EQUAL(sys->is_created(),true);
156  BOOST_CHECK_EQUAL(sys->solvertype(),solvertype);
157 
158  sys->matrix()->set_row(0, 0, 2, 1);
159  sys->matrix()->set_row(1, 0, 2, 1);
160  sys->matrix()->set_row(2, 0, 2, 1);
161 
162  if(irank == 0)
163  sys->matrix()->symmetric_dirichlet(1, 0, 10., *sys->rhs());
164  else
165  sys->matrix()->symmetric_dirichlet(0, 0, 10., *sys->rhs());
166 
167  sys->rhs()->print_native(std::cout);
168 
169  Real val;
170  if(irank == 0)
171  {
172  sys->matrix()->get_value(0, 0, val);
173  BOOST_CHECK_EQUAL(val, 2.);
174  sys->matrix()->get_value(1, 0, val);
175  BOOST_CHECK_EQUAL(val, 0.);
176  sys->matrix()->get_value(0, 1, val);
177  BOOST_CHECK_EQUAL(val, 0.);
178  sys->matrix()->get_value(1, 1, val);
179  BOOST_CHECK_EQUAL(val, 1.);
180  sys->matrix()->get_value(2, 1, val);
181  BOOST_CHECK_EQUAL(val, 0.);
182 
183  sys->rhs()->get_value(0, val);
184  BOOST_CHECK_EQUAL(val, -10.);
185  sys->rhs()->get_value(1, val);
186  BOOST_CHECK_EQUAL(val, 10.);
187  }
188  else
189  {
190  sys->matrix()->get_value(0, 1, val);
191  BOOST_CHECK_EQUAL(val, 0.);
192  sys->matrix()->get_value(1, 1, val);
193  BOOST_CHECK_EQUAL(val, 2.);
194  sys->matrix()->get_value(2, 1, val);
195  BOOST_CHECK_EQUAL(val, 1.);
196  sys->matrix()->get_value(1, 2, val);
197  BOOST_CHECK_EQUAL(val, 1.);
198  sys->matrix()->get_value(2, 2, val);
199  BOOST_CHECK_EQUAL(val, 2.);
200 
201  sys->rhs()->get_value(0, val);
202  BOOST_CHECK_EQUAL(val, 10.);
203  sys->rhs()->get_value(1, val);
204  BOOST_CHECK_EQUAL(val, -10.);
205  sys->rhs()->get_value(2, val);
206  BOOST_CHECK_EQUAL(val, 0.);
207  }
208 }
209 
211 
212 BOOST_AUTO_TEST_CASE( finalize_mpi )
213 {
214  CFinfo.setFilterRankZero(true);
215  common::PE::Comm::instance().finalize();
216  BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),false);
217 }
218 
220 
221 BOOST_AUTO_TEST_SUITE_END()
222 
223 
#define CFinfo
these are always defined
Definition: Log.hpp:104
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 >())
Definition: System.cpp:82
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
~LSSSymmetricDirichletFixture()
common tear-down for each test case
This header collects all the headers needed for the linear system solver, also including configure-ti...
Basic Classes for Mathematical applications used by COOLFluiD.
void setup(const Handle< CommWrapper > &gid, std::vector< Uint > &rank)
void build_system(LSS::System &sys, common::PE::CommPattern &cp)
build a test system
std::vector< Uint > node_connectivity
system builds
void insert(const std::string &name, T *&data, const int size, const unsigned int stride=1, const bool needs_update=true)
void build_commpattern(common::PE::CommPattern &cp)
create a test commpattern
LSSSymmetricDirichletFixture()
common setup for each test case
Handle< Component > get_child(const std::string &name)
Definition: Component.cpp:441
Top-level namespace for coolfluid.
Definition: Action.cpp:18
std::vector< Uint > gid
commpattern builds
BOOST_AUTO_TEST_CASE(init_mpi)
std::string solvertype
main solver selector
#define FromHere()
Send comments to:
COOLFluiD Web Admin