8 #define BOOST_TEST_DYN_LINK
9 #define BOOST_TEST_MODULE "Test module for cf3::math::LSS where testing indivdual operations."
15 #include <boost/test/unit_test.hpp>
16 #include <boost/assign/std/vector.hpp>
17 #include <boost/lexical_cast.hpp>
41 solvertype(
"Trilinos"),
52 if (common::PE::Comm::instance().is_initialized())
54 nproc=common::PE::Comm::instance().size();
55 irank=common::PE::Comm::instance().rank();
56 BOOST_CHECK_EQUAL(nproc,2);
58 m_argc = boost::unit_test::framework::master_test_suite().argc;
59 m_argv = boost::unit_test::framework::master_test_suite().argv;
76 gid += 1,2,8,7,3,4,5,6;
77 rank_updatable += 0,1,0,0,1,0,0,1;
79 gid += 5,0,2,7,1,3,8,4,6;
80 rank_updatable += 0,1,1,0,0,1,0,0,1;
82 cp.
insert(
"gid",gid,1,
false);
89 starting_indices.clear();
90 node_connectivity.clear();
93 node_connectivity += 0,2,4,6,1,2,3,5,1,3,5,7,1,2,3,5,0,1,3,4,5,6;
94 starting_indices += 0,4,4,8,12,12,16,22,22;
98 node_connectivity += 1,2,5,2,5,8,0,7,3,1,2,4,5,6,7,8,2,5,8;
99 starting_indices += 0,0,3,9,9,9,16,16,16,19;
103 sys.
create(cp,neq,node_connectivity,starting_indices);
137 common::PE::Comm::instance().init(m_argc,m_argv);
138 BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),
true);
139 CFinfo.setFilterRankZero(
false);
140 common::Core::instance().environment().options().set(
"log_level", 4u);
141 common::Core::instance().environment().options().set(
"exception_backtrace",
false);
142 common::Core::instance().environment().options().set(
"exception_outputs",
false);
152 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
154 build_commpattern(cp);
155 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
156 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
157 build_system(*sys,cp);
160 BOOST_CHECK_EQUAL(mat->
solvertype(),solvertype);
161 BOOST_CHECK_EQUAL(mat->
neq(),neq);
168 mat->
print(
"test_matrix_" + boost::lexical_cast<std::string>(irank) +
".plt");
171 std::vector<Uint> cols(0);
172 std::vector<Uint> rows(0);
173 std::vector<Real> vals(0);
178 BOOST_CHECK_EQUAL(cols.size(),node_connectivity.size()*neq*neq);
179 BOOST_CHECK_EQUAL(rows.size(),node_connectivity.size()*neq*neq);
180 BOOST_CHECK_EQUAL(vals.size(),node_connectivity.size()*neq*neq);
181 BOOST_FOREACH(
double v, vals) BOOST_CHECK_EQUAL(v,1.);
184 BOOST_FOREACH(
double v, vals) BOOST_CHECK_EQUAL(v,0.);
188 std::vector<Real> diag(blockcol_size*neq);
189 for (
int i=0; i<diag.size(); i++) diag[i]=i;
194 BOOST_CHECK_EQUAL(diag.size(),blockcol_size*neq);
196 for (
int i=0; i<(
const int)vals.size(); i++)
198 if (cp.isUpdatable()[rows[i]/neq]) { BOOST_CHECK_EQUAL(diag[rows[i]],2.*rows[i]); }
199 else { BOOST_CHECK_EQUAL(diag[rows[i]],0.); }
200 if (rows[i]==cols[i]) { BOOST_CHECK_EQUAL(vals[i],diag[rows[i]]); }
201 else { BOOST_CHECK_EQUAL(vals[i],0.); }
215 BOOST_CHECK_EQUAL(v,1.);
217 BOOST_CHECK_EQUAL(v,2.);
219 BOOST_CHECK_EQUAL(v,3.);
221 BOOST_CHECK_EQUAL(v,4.);
223 for (
int i=0; i<(
const int)vals.size(); i++)
224 if ((rows[i]<6)||(rows[i]>7))
225 BOOST_CHECK_EQUAL(vals[i],0.);
226 for (
int i=0; i<(
const int)vals.size(); i++)
227 if ((cols[i]<6)||(cols[i]>7))
228 BOOST_CHECK_EQUAL(vals[i],0.);
237 ba.
mat << 53., 54., 51., 52., 55., 56.,
238 59., 60., 57., 58., 61., 62.,
239 23., 24., 21., 22., 25., 26.,
240 29., 30., 27., 28., 31., 32.,
241 83., 84., 81., 82., 85., 86.,
242 89., 90., 87., 88., 91., 92.;
254 mat->
print(
"test_ba_assembly_" + boost::lexical_cast<std::string>(irank) +
".plt");
256 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(0,i-1),(double)((ba.
indices[0]*10+i+0)*2));
257 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(1,i-1),(double)((ba.
indices[0]*10+i+6)*2));
258 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(2,i-1),(double)((ba.
indices[1]*10+i+0)*2));
259 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(3,i-1),(double)((ba.
indices[1]*10+i+6)*2));
260 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(4,i-1),(double)((ba.
indices[2]*10+i+0)*2));
261 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(5,i-1),(double)((ba.
indices[2]*10+i+6)*2));
264 for (
int i=0; i<(
const int)vals.size(); i++)
268 BOOST_CHECK_EQUAL(vals[i],(
double)((rows[i]/neq*10.+ctr)*2));
270 if (ctr==13.) ctr=1.;
272 BOOST_CHECK_EQUAL(vals[i],0.);
284 ba.
mat << 99., 99., 99., 99., 99., 99.,
285 99., 99., 99., 99., 99., 99.,
286 23., 24., 21., 22., 25., 26.,
287 29., 30., 27., 28., 31., 32.,
288 99., 99., 99., 99., 99., 99.,
289 99., 99., 99., 99., 99., 99.;
300 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(0,i-1),0.);
301 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(1,i-1),0.);
302 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(2,i-1),0.);
303 for (
int i=1; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(3,i-1),0.);
304 for (
int i=1; i<3; i++) BOOST_CHECK_EQUAL(ba.
mat(4,i-1),(double)((ba.
indices[2]*10+i+4+0)*2));
305 for (
int i=1; i<3; i++) BOOST_CHECK_EQUAL(ba.
mat(5,i-1),(double)((ba.
indices[2]*10+i+4+6)*2));
306 for (
int i=3; i<5; i++) BOOST_CHECK_EQUAL(ba.
mat(4,i-1),(double)((ba.
indices[2]*10+i+0+0)*2));
307 for (
int i=3; i<5; i++) BOOST_CHECK_EQUAL(ba.
mat(5,i-1),(double)((ba.
indices[2]*10+i+0+6)*2));
308 for (
int i=5; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(4,i-1),(double)((ba.
indices[2]*10+i-4+0)*2));
309 for (
int i=5; i<7; i++) BOOST_CHECK_EQUAL(ba.
mat(5,i-1),(double)((ba.
indices[2]*10+i-4+6)*2));
312 for (
int i=0; i<(
const int)vals.size(); i++)
313 if ((rows[i]/neq==ba.
indices[2])&&
316 BOOST_CHECK_EQUAL(vals[i],(
double)((rows[i]/neq*10.+ctr)*2));
318 if (ctr==13.) ctr=1.;
320 BOOST_CHECK_EQUAL(vals[i],0.);
330 for (
int i=0; i<(
const int)vals.size(); i++)
334 if (cols[i]==7) { BOOST_CHECK_EQUAL(vals[i],1.); }
335 else { BOOST_CHECK_EQUAL(vals[i],0.); }
337 BOOST_CHECK_EQUAL(vals[i],-1.);
348 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,-1.);
374 for(
int i=0; i<vals.size(); i++) BOOST_CHECK_EQUAL(vals[i],(
double)(i+1));
376 for (
int i=0; i<(
const int)vals.size(); i++)
380 BOOST_CHECK_EQUAL(vals[i],0.);
382 BOOST_CHECK_EQUAL(vals[i],1.);
389 CFinfo <<
"skipping symmetric dirichlet test" <<
CFendl;
433 for (
int i=0; i<(
const int)vals.size(); i++)
434 if ((rows[i]==4)||(rows[i]==5))
436 if ((cols[i]!=10)&&(cols[i]!=11)) { BOOST_CHECK_EQUAL(vals[i],65.); }
437 else { BOOST_CHECK_EQUAL(vals[i],0.); }
440 for (
int i=0; i<(
const int)vals.size(); i++)
443 if (cols[i]==4) { BOOST_CHECK_EQUAL(vals[i],-1.); }
444 else if (cols[i]==10) { BOOST_CHECK_EQUAL(vals[i],1.); }
445 else { BOOST_CHECK_EQUAL(vals[i],0.); }
448 for (
int i=0; i<(
const int)vals.size(); i++)
451 if (cols[i]==5) { BOOST_CHECK_EQUAL(vals[i],-1.); }
452 else if (cols[i]==11) { BOOST_CHECK_EQUAL(vals[i],1.); }
453 else { BOOST_CHECK_EQUAL(vals[i],0.); }
456 for (
int i=0; i<(
const int)vals.size(); i++)
457 if ((rows[i]!=4)&&(rows[i]!=5)&&(rows[i]!=10)&&(rows[i]!=11))
458 BOOST_CHECK_EQUAL(vals[i],-2.);
467 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,-2.);
480 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
482 build_commpattern(cp);
483 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
484 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
485 build_system(*sys,cp);
490 BOOST_CHECK_EQUAL(sol->
solvertype(),solvertype);
491 BOOST_CHECK_EQUAL(rhs->
solvertype(),solvertype);
492 BOOST_CHECK_EQUAL(sol->
neq(),neq);
493 BOOST_CHECK_EQUAL(rhs->
neq(),neq);
500 sol->
print(
"test_vector_" + boost::lexical_cast<std::string>(irank) +
".plt");
503 std::vector<Real> vals(0);
509 BOOST_CHECK_EQUAL(vals.size(),gid.size()*neq);
510 BOOST_FOREACH(
double v, vals) BOOST_CHECK_EQUAL(v,1.);
513 BOOST_FOREACH(
double v, vals) BOOST_CHECK_EQUAL(v,0.);
521 BOOST_CHECK_EQUAL(val,2.);
523 for (
int i=0; i<vals.size(); i++)
525 if (i==5) { BOOST_CHECK_EQUAL(vals[i],2.); }
526 else { BOOST_CHECK_EQUAL(vals[i],0.); }
535 BOOST_CHECK_EQUAL(val,2.);
537 for (
int i=0; i<vals.size(); i++)
539 if (i==5) { BOOST_CHECK_EQUAL(vals[i],2.); }
540 else { BOOST_CHECK_EQUAL(vals[i],0.); }
547 ba.
rhs << 8.,9. , 2.,3. , 6.,7.;
556 for (
int i=0; i<vals.size(); i++)
560 BOOST_CHECK_EQUAL(vals[i],(
double)(i*2));
562 BOOST_CHECK_EQUAL(vals[i],0.);
565 BOOST_CHECK_EQUAL(ba.
rhs[0],16.);
566 BOOST_CHECK_EQUAL(ba.
rhs[1],18.);
567 BOOST_CHECK_EQUAL(ba.
rhs[2],4.);
568 BOOST_CHECK_EQUAL(ba.
rhs[3],6.);
569 BOOST_CHECK_EQUAL(ba.
rhs[4],12.);
570 BOOST_CHECK_EQUAL(ba.
rhs[5],14.);
571 BOOST_CHECK_EQUAL(ba.
sol.isConstant(0.,1.e-10),
true);
574 ba.
sol << 80.,90. , 20.,30. , 60.,70.;
580 for (
int i=0; i<vals.size(); i++)
584 BOOST_CHECK_EQUAL(vals[i],(
double)(i*20.));
586 BOOST_CHECK_EQUAL(vals[i],0.);
589 BOOST_CHECK_EQUAL(ba.
sol[0],160.);
590 BOOST_CHECK_EQUAL(ba.
sol[1],180.);
591 BOOST_CHECK_EQUAL(ba.
sol[2],40.);
592 BOOST_CHECK_EQUAL(ba.
sol[3],60.);
593 BOOST_CHECK_EQUAL(ba.
sol[4],120.);
594 BOOST_CHECK_EQUAL(ba.
sol[5],140.);
595 BOOST_CHECK_EQUAL(ba.
rhs.isConstant(0.,1.e-10),
true);
607 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
609 build_commpattern(cp);
610 boost::shared_ptr<LSS::System> sys(common::allocate_component<LSS::System>(
"sys"));
611 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
612 build_system(*sys,cp);
613 BOOST_CHECK_EQUAL(sys->is_created(),
true);
614 BOOST_CHECK_EQUAL(sys->solvertype(),solvertype);
619 sys->print(
"test_system_" + boost::lexical_cast<std::string>(irank) +
".plt");
622 std::vector<Uint> cols(0);
623 std::vector<Uint> rows(0);
624 std::vector<Real> vals(0);
628 sys->matrix()->debug_data(rows,cols,vals);
629 BOOST_CHECK_EQUAL(cols.size(),node_connectivity.size()*neq*neq);
630 BOOST_CHECK_EQUAL(rows.size(),node_connectivity.size()*neq*neq);
631 BOOST_CHECK_EQUAL(vals.size(),node_connectivity.size()*neq*neq);
632 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,1.);
633 sys->solution()->debug_data(vals);
634 BOOST_CHECK_EQUAL(vals.size(),gid.size()*neq);
635 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,1.);
636 sys->rhs()->debug_data(vals);
637 BOOST_CHECK_EQUAL(vals.size(),gid.size()*neq);
638 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,1.);
640 sys->matrix()->debug_data(rows,cols,vals);
641 BOOST_CHECK_EQUAL(cols.size(),node_connectivity.size()*neq*neq);
642 BOOST_CHECK_EQUAL(rows.size(),node_connectivity.size()*neq*neq);
643 BOOST_CHECK_EQUAL(vals.size(),node_connectivity.size()*neq*neq);
644 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,0.);
645 sys->solution()->debug_data(vals);
646 BOOST_CHECK_EQUAL(vals.size(),gid.size()*neq);
647 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,0.);
648 sys->rhs()->debug_data(vals);
649 BOOST_CHECK_EQUAL(vals.size(),gid.size()*neq);
650 BOOST_FOREACH(Real i,vals) BOOST_CHECK_EQUAL(i,0.);
653 sys->matrix()->reset(2.);
654 sys->solution()->reset(3.);
655 sys->rhs()->reset(4.);
658 sys->dirichlet(3,1,5.,
false);
659 sys->matrix()->debug_data(rows,cols,vals);
660 for (
int i=0; i<vals.size(); i++)
664 if (cols[i]==7) { BOOST_CHECK_EQUAL(vals[i],1.); }
665 else { BOOST_CHECK_EQUAL(vals[i],0.); }
673 BOOST_CHECK_EQUAL(vals[i],2.);
677 sys->solution()->debug_data(vals);
678 for (
int i=0; i<vals.size(); i++)
680 if (i==7) { BOOST_CHECK_EQUAL(vals[i],5.); }
681 else { BOOST_CHECK_EQUAL(vals[i],3.); }
683 sys->rhs()->debug_data(vals);
684 for (
int i=0; i<4; i++) BOOST_CHECK_EQUAL(vals[i],4.);
685 for (
int i=4; i<7; i++) BOOST_CHECK_EQUAL(vals[i],4.);
686 for (
int i=7; i<8; i++) BOOST_CHECK_EQUAL(vals[i],5.);
687 for (
int i=8; i<10; i++) BOOST_CHECK_EQUAL(vals[i],4.);
688 for (
int i=10; i<14; i++) BOOST_CHECK_EQUAL(vals[i],4.);
689 for (
int i=14; i<16; i++) BOOST_CHECK_EQUAL(vals[i],4.);
698 ba.
mat << 99., 99., 99., 99., 99., 99.,
699 99., 99., 99., 99., 99., 99.,
700 1., 1., 1., 1., 1., 1.,
701 1., 1., 1., 1., 1., 1.,
702 99., 99., 99., 99., 99., 99.,
703 99., 99., 99., 99., 99., 99.;
704 ba.
rhs << 2., 2., 2., 2., 2., 2.;
705 ba.
sol << 3., 3., 3., 3., 3., 3.;
716 sys->matrix()->debug_data(rows,cols,vals);
717 for (
int i=0; i<(
const int)vals.size(); i++)
719 if ((rows[i]/neq==ba.
indices[2])&&
720 ((cols[i]/neq==ba.
indices[0])||(cols[i]/neq==ba.
indices[1])||(cols[i]/neq==ba.
indices[2]))) { BOOST_CHECK_EQUAL(vals[i],2.); }
721 else { BOOST_CHECK_EQUAL(vals[i],0.); }
723 sys->rhs()->debug_data(vals);
724 for (
int i=0; i<(
const int)vals.size(); i++)
726 if ((i/neq==ba.
indices[0])||(i/neq==ba.
indices[1])||(i/neq==ba.
indices[2])) { BOOST_CHECK_EQUAL(vals[i],4.); }
727 else { BOOST_CHECK_EQUAL(vals[i],0.); }
729 sys->solution()->debug_data(vals);
730 for (
int i=0; i<(
const int)vals.size(); i++)
732 if ((i/neq==ba.
indices[0])||(i/neq==ba.
indices[1])||(i/neq==ba.
indices[2])) { BOOST_CHECK_EQUAL(vals[i],6.); }
733 else { BOOST_CHECK_EQUAL(vals[i],0.); }
738 sys->matrix()->reset(-2.);
739 sys->solution()->reset(-3.);
740 sys->rhs()->reset(-4.);
743 sys->matrix()->set_value( 2, 4,40.);
744 sys->matrix()->set_value( 3, 4,41.);
745 sys->matrix()->set_value( 4, 4,21.);
746 sys->matrix()->set_value( 5, 4,21.5);
747 sys->matrix()->set_value( 6, 4,44.);
748 sys->matrix()->set_value( 7, 4,45.);
749 sys->matrix()->set_value(10, 4,23.);
750 sys->matrix()->set_value(11, 4,23.5);
751 sys->matrix()->set_value( 2, 5,48.);
752 sys->matrix()->set_value( 3, 5,49.);
753 sys->matrix()->set_value( 4, 5,25.);
754 sys->matrix()->set_value( 5, 5,25.5);
755 sys->matrix()->set_value( 6, 5,52.);
756 sys->matrix()->set_value( 7, 5,53.);
757 sys->matrix()->set_value(10, 5,27.);
758 sys->matrix()->set_value(11, 5,27.5);
760 sys->matrix()->set_value(11,11, 5.);
761 sys->matrix()->set_value(10,11, 5.5);
762 sys->matrix()->set_value( 7,11,12.);
763 sys->matrix()->set_value( 6,11,13.);
764 sys->matrix()->set_value( 5,11, 7.);
765 sys->matrix()->set_value( 4,11, 7.5);
766 sys->matrix()->set_value( 3,11,16.);
767 sys->matrix()->set_value( 2,11,17.);
768 sys->matrix()->set_value(11,10, 9.);
769 sys->matrix()->set_value(10,10, 9.5);
770 sys->matrix()->set_value( 7,10,20.);
771 sys->matrix()->set_value( 6,10,21.);
772 sys->matrix()->set_value( 5,10,11.);
773 sys->matrix()->set_value( 4,10,11.5);
774 sys->matrix()->set_value( 3,10,24.);
775 sys->matrix()->set_value( 2,10,25.);
777 sys->solution()->set_value(4,-1.);
778 sys->solution()->set_value(5, 0.);
779 sys->solution()->set_value(10,-5.);
780 sys->solution()->set_value(11,-6.);
782 sys->rhs()->set_value(4,3.);
783 sys->rhs()->set_value(5,4.);
784 sys->rhs()->set_value(10,-7.);
785 sys->rhs()->set_value(11,-8.);
787 sys->periodicity(2,5);
789 sys->matrix()->debug_data(rows,cols,vals);
790 for (
int i=0; i<(
const int)vals.size(); i++)
791 if ((rows[i]==4)||(rows[i]==5))
793 if ((cols[i]!=10)&&(cols[i]!=11)) { BOOST_CHECK_EQUAL(vals[i],65.); }
794 else { BOOST_CHECK_EQUAL(vals[i],0.); }
797 for (
int i=0; i<(
const int)vals.size(); i++)
800 if (cols[i]==4) { BOOST_CHECK_EQUAL(vals[i],-1.); }
801 else if (cols[i]==10) { BOOST_CHECK_EQUAL(vals[i],1.); }
802 else { BOOST_CHECK_EQUAL(vals[i],0.); }
805 for (
int i=0; i<(
const int)vals.size(); i++)
808 if (cols[i]==5) { BOOST_CHECK_EQUAL(vals[i],-1.); }
809 else if (cols[i]==11) { BOOST_CHECK_EQUAL(vals[i],1.); }
810 else { BOOST_CHECK_EQUAL(vals[i],0.); }
813 for (
int i=0; i<(
const int)vals.size(); i++)
814 if ((rows[i]!=4)&&(rows[i]!=5)&&(rows[i]!=10)&&(rows[i]!=11))
815 BOOST_CHECK_EQUAL(vals[i],-2.);
817 sys->solution()->debug_data(vals);
818 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,-3.);
820 sys->rhs()->debug_data(vals);
821 for (
int i=0; i<vals.size(); i++)
823 if ((i==10)||(i==11)) { BOOST_CHECK_EQUAL(vals[i],0.); }
824 else { BOOST_CHECK_EQUAL(vals[i],-4.); }
830 std::vector<Real> diag(blockcol_size*neq);
831 for (
int i=0; i<diag.size(); i++) diag[i]=i;
832 sys->set_diagonal(diag);
833 sys->add_diagonal(diag);
835 sys->get_diagonal(diag);
836 BOOST_CHECK_EQUAL(diag.size(),blockcol_size*neq);
837 sys->matrix()->debug_data(rows,cols,vals);
838 for (
int i=0; i<(
const int)vals.size(); i++)
840 if (cp.isUpdatable()[rows[i]/neq]) { BOOST_CHECK_EQUAL(diag[rows[i]],2.*rows[i]); }
841 else { BOOST_CHECK_EQUAL(diag[rows[i]],0.); }
842 if (rows[i]==cols[i]) { BOOST_CHECK_EQUAL(vals[i],diag[rows[i]]); }
843 else { BOOST_CHECK_EQUAL(vals[i],0.); }
847 boost::shared_ptr<LSS::System> sys2(common::allocate_component<LSS::System>(
"sys2"));
848 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
849 build_system(*sys2,cp);
850 BOOST_CHECK_EQUAL(sys2->is_created(),
true);
851 BOOST_CHECK_EQUAL(sys2->solvertype(),solvertype);
854 boost::shared_ptr<Matrix> sw_mat = boost::dynamic_pointer_cast<
Matrix>(sys->remove_component(
"Matrix"));
855 boost::shared_ptr<Vector> sw_sol = boost::dynamic_pointer_cast<
Vector>(sys2->remove_component(
"Solution"));
856 boost::shared_ptr<Vector> sw_rhs = boost::dynamic_pointer_cast<
Vector>(sys2->remove_component(
"RHS"));
857 sys->swap(sw_mat,sw_sol,sw_rhs);
859 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,1.);
860 sys->solution()->debug_data(vals);
861 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,2.);
862 sys->rhs()->debug_data(vals);
863 BOOST_FOREACH(Real i, vals) BOOST_CHECK_EQUAL(i,2.);
867 BOOST_CHECK_EQUAL(sys->is_created(),
false);
881 std::vector<Real> refvals(0);
883 1.00000000000000e+00,
884 1.00000000000000e+00,
885 -1.35789473684210e+01,
886 -1.35789473684210e+01,
887 -7.78947368421052e+00,
888 -7.78947368421052e+00,
889 9.68421052631579e+00,
890 9.68421052631579e+00,
891 1.26315789473684e+01,
892 1.26315789473684e+01,
893 -3.36842105263158e+00,
894 -3.36842105263158e+00,
895 -1.43157894736842e+01,
896 -1.43157894736842e+01,
897 -3.78947368421053e+00,
898 -3.78947368421052e+00,
899 1.24210526315789e+01,
900 1.24210526315789e+01,
901 1.00000000000000e+01,
902 1.00000000000000e+01;
908 rank_updatable += 0,0,0,0,1;
910 gid += 3,4,5,6,7,8,9;
911 rank_updatable += 0,1,1,1,1,1,1;
913 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
915 cp.
insert(
"gid",gid,1,
false);
921 node_connectivity += 0,1,0,1,2,1,2,3,2,3,4,3,4;
922 starting_indices += 0,2,5,8,11,13;
924 node_connectivity += 0,1,0,1,2,1,2,3,2,3,4,3,4,5,4,5,6,5,6;
925 starting_indices += 0,2,5,8,11,14,17,19;
927 boost::shared_ptr<System> sys(common::allocate_component<System>(
"sys"));
928 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
929 sys->create(cp,2,node_connectivity,starting_indices);
931 sys->solution_strategy()->options().set(
"compute_residual",
true);
932 sys->solution_strategy()->options().set(
"verbosity_level", 3);
933 sys->solution_strategy()->access_component(
"Parameters")->options().set(
"preconditioner_type", std::string(
"None"));
934 sys->solution_strategy()->access_component(
"Parameters/LinearSolverTypes/Belos/SolverTypes/BlockGMRES")->options().set(
"verbosity", 1);
937 sys->matrix()->reset(-0.5);
938 sys->solution()->reset(1.);
939 sys->rhs()->reset(0.);
942 std::vector<Real> diag(10,1.);
943 sys->set_diagonal(diag);
944 sys->dirichlet(0,0,1.);
945 sys->dirichlet(0,1,1.);
947 std::vector<Real> diag(14,1.);
948 sys->set_diagonal(diag);
949 sys->dirichlet(6,0,10.);
950 sys->dirichlet(6,1,10.);
955 std::vector<Real> vals;
956 sys->solution()->debug_data(vals);
957 for (
int i=0; i<vals.size(); i++)
958 if (cp.isUpdatable()[i/neq])
959 BOOST_CHECK_CLOSE( vals[i], refvals[gid[i/neq]*neq], 1
e-8);
976 std::vector<Real> refvals(0);
978 1.00000000000000e+00,
979 1.00000000000000e+00,
980 -1.35789473684210e+01,
981 -1.35789473684210e+01,
982 -7.78947368421052e+00,
983 -7.78947368421052e+00,
984 9.68421052631579e+00,
985 9.68421052631579e+00,
986 1.26315789473684e+01,
987 1.26315789473684e+01,
988 -3.36842105263158e+00,
989 -3.36842105263158e+00,
990 -1.43157894736842e+01,
991 -1.43157894736842e+01,
992 -3.78947368421053e+00,
993 -3.78947368421052e+00,
994 1.24210526315789e+01,
995 1.24210526315789e+01,
996 1.00000000000000e+01,
997 1.00000000000000e+01;
1003 rank_updatable += 0,0,0,0,1;
1005 gid += 3,4,5,6,7,8,9;
1006 rank_updatable += 0,1,1,1,1,1,1;
1008 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
1010 cp.
insert(
"gid",gid,1,
false);
1016 node_connectivity += 0,1,0,1,2,1,2,3,2,3,4,3,4;
1017 starting_indices += 0,2,5,8,11,13;
1019 node_connectivity += 0,1,0,1,2,1,2,3,2,3,4,3,4,5,4,5,6,5,6;
1020 starting_indices += 0,2,5,8,11,14,17,19;
1022 boost::shared_ptr<System> sys(common::allocate_component<System>(
"sys"));
1023 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
1024 boost::shared_ptr<math::VariablesDescriptor> vars = common::allocate_component<math::VariablesDescriptor>(
"vars");
1025 vars->options().set(
"dimension", 1u);
1029 sys->create_blocked(cp,*vars,node_connectivity,starting_indices);
1031 sys->solution_strategy()->options().set(
"compute_residual",
true);
1032 sys->solution_strategy()->options().set(
"verbosity_level", 3);
1033 sys->solution_strategy()->access_component(
"Parameters")->options().set(
"preconditioner_type", std::string(
"None"));
1034 sys->solution_strategy()->access_component(
"Parameters/LinearSolverTypes/Belos/SolverTypes/BlockGMRES")->options().set(
"verbosity", 1);
1035 sys->solution_strategy()->access_component(
"Parameters/LinearSolverTypes/Belos/SolverTypes/BlockGMRES")->options().set(
"convergence_tolerance", 0.1);
1038 sys->matrix()->reset(-0.5);
1039 sys->solution()->reset(1.);
1040 sys->rhs()->reset(0.);
1043 std::vector<Real> diag(10,1.);
1044 sys->set_diagonal(diag);
1045 sys->dirichlet(0,0,1.);
1046 sys->dirichlet(0,1,1.);
1048 std::vector<Real> diag(14,1.);
1049 sys->set_diagonal(diag);
1050 sys->dirichlet(6,0,10.);
1051 sys->dirichlet(6,1,10.);
1056 std::vector<Real> vals;
1057 sys->solution()->debug_data(vals);
1058 for (
int i=0; i<vals.size(); i++)
1059 if (cp.isUpdatable()[i/neq])
1060 BOOST_CHECK_CLOSE( vals[i], refvals[gid[i/neq]*neq], 1
e-8);
1076 rank_updatable += 0,0,0,1;
1079 rank_updatable += 0,1,1,1,1;
1081 boost::shared_ptr<common::PE::CommPattern> cp_ptr = common::allocate_component<common::PE::CommPattern>(
"commpattern");
1083 cp.
insert(
"gid",gid,1,
false);
1089 node_connectivity += 0,1,0,1,2,1,2,3,2,3;
1090 starting_indices += 0,2,5,8,10;
1092 node_connectivity += 0,1,0,1,2,1,2,3,2,3,4,3,4;
1093 starting_indices += 0,2,5,8,11,13;
1095 boost::shared_ptr<System> sys(common::allocate_component<System>(
"sys"));
1096 sys->options().option(
"matrix_builder").change_value(
matrix_builder);
1097 sys->create(cp,1,node_connectivity,starting_indices);
1099 sys->solution_strategy()->options().set(
"compute_residual",
true);
1100 sys->solution_strategy()->options().set(
"verbosity_level", 3);
1101 sys->solution_strategy()->options().set(
"print_settings",
false);
1102 sys->solution_strategy()->access_component(
"Parameters")->options().set(
"preconditioner_type", std::string(
"None"));
1103 sys->solution_strategy()->access_component(
"Parameters")->options().set(
"linear_solver_type", std::string(
"Amesos"));
1107 sys->matrix()->reset(1.);
1108 sys->solution()->reset(0.);
1109 sys->rhs()->reset(0.);
1112 std::vector<Real> diag(4,-2.);
1113 sys->set_diagonal(diag);
1114 sys->dirichlet(0,0,10.);
1116 std::vector<Real> diag(5,-2.);
1117 sys->set_diagonal(diag);
1118 sys->dirichlet(4,0,16.);
1123 sys->solution()->print_native(std::cout);
1136 CFinfo.setFilterRankZero(
true);
1137 common::PE::Comm::instance().finalize();
1138 BOOST_CHECK_EQUAL(common::PE::Comm::instance().is_active(),
false);
1143 BOOST_AUTO_TEST_SUITE_END()
virtual void debug_data(std::vector< Real > &values)=0
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 >())
virtual void add_rhs_values(const BlockAccumulator &values)=0
Add a list of values to rhs.
void resize(Uint numnodes, Uint numeqs)
setting up sizes
virtual void set_rhs_values(const BlockAccumulator &values)=0
Set a list of values to rhs.
virtual void destroy()=0
Deallocate underlying data.
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...
Basic Classes for Mathematical applications used by COOLFluiD.
virtual void get_values(BlockAccumulator &values)=0
Add a list of values.
void setup(const Handle< CommWrapper > &gid, std::vector< Uint > &rank)
virtual void set_values(const BlockAccumulator &values)=0
Set a list of values.
virtual const Uint blockrow_size()=0
Accessor to the number of block rows.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > mat
void build_commpattern(common::PE::CommPattern &cp)
create a test commpattern
virtual const Uint blockrow_size()=0
Accessor to the number of block rows.
virtual void destroy()=0
Deallocate underlying data.
virtual void set_value(const Uint icol, const Uint irow, const Real value)=0
Set value at given location in the matrix.
virtual void get_diagonal(std::vector< Real > &diag)=0
Get the diagonal.
void insert(const std::string &name, T *&data, const int size, const unsigned int stride=1, const bool needs_update=true)
virtual const bool is_created()=0
Accessor to the state of create.
Real e()
Definition of the Unit charge [C].
virtual void add_values(const BlockAccumulator &values)=0
virtual void get_sol_values(BlockAccumulator &values)=0
Get a list of values from sol.
std::vector< Uint > rank_updatable
virtual void set_diagonal(const std::vector< Real > &diag)=0
Set the diagonal.
std::vector< Uint > indices
local numbering of the unknowns
virtual void set_sol_values(const BlockAccumulator &values)=0
Set a list of values to sol.
virtual void set_row(const Uint iblockrow, const Uint ieq, Real diagval, Real offdiagval)=0
Set a row, diagonal and off-diagonals values separately (dirichlet-type boundaries) ...
virtual void get_rhs_values(BlockAccumulator &values)=0
Get a list of values from rhs.
virtual void tie_blockrow_pairs(const Uint iblockrow_to, const Uint iblockrow_from)=0
Add one line to another and tie to it via dirichlet-style (applying periodicity)
virtual void get_column_and_replace_to_zero(const Uint iblockcol, Uint ieq, std::vector< Real > &values)=0
virtual void set_value(const Uint irow, const Real value)=0
Set value at given location in the matrix.
Handle< Component > get_child(const std::string &name)
Top-level namespace for coolfluid.
~LSSAtomicFixture()
common tear-down for each test case
virtual void add_diagonal(const std::vector< Real > &diag)=0
Add to the diagonal.
virtual void add_value(const Uint icol, const Uint irow, const Real value)=0
Add value at given location in the matrix.
virtual const Uint blockcol_size()=0
Accessor to the number of block columns.
virtual void get_value(const Uint irow, Real &value)=0
Get value at given location in the matrix.
RealVector sol
accessor to blockaccumulator's solution vector
std::vector< Uint > starting_indices
virtual const bool is_created()=0
Accessor to the state of create.
std::string solvertype
main solver selector
int irank
constructor builds
virtual void debug_data(std::vector< Uint > &row_indices, std::vector< Uint > &col_indices, std::vector< Real > &values)=0
void reset(Real reset_to=0.)
reset the values to the value of reset_to
virtual const Uint neq()=0
Accessor to the number of equations.
virtual void print(common::LogStream &stream)=0
Print to wherever.
LSSAtomicFixture()
common setup for each test case
std::vector< Uint > gid
commpattern builds
std::string matrix_builder
BOOST_AUTO_TEST_CASE(init_mpi)
std::vector< Uint > node_connectivity
system builds
virtual void print(common::LogStream &stream)=0
Print to wherever.
virtual void add_value(const Uint irow, const Real value)=0
Add value at given location in the matrix.
virtual const std::string solvertype()=0
Accessor to solver type.
virtual void reset(Real reset_to=0.)=0
Reset Vector.
RealVector rhs
accessor to blockaccumulator's right hand side vector
virtual const std::string solvertype()=0
Accessor to solver type.
virtual void add_sol_values(const BlockAccumulator &values)=0
Add a list of values to sol.
virtual const Uint neq()=0
Accessor to the number of equations.
virtual void get_value(const Uint icol, const Uint irow, Real &value)=0
Get value at given location in the matrix.