Skip to content
Snippets Groups Projects
Commit 7474c377 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Add a test for the VectorSpaceOperations

parent 4730a0bd
Branches
No related tags found
No related merge requests found
......@@ -179,3 +179,6 @@ dune_add_test(SOURCES UniqueBorderPartitionTest.cpp
dune_add_test(SOURCES ValidTreePathTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES VectorFacadeTest.cpp
LINK_LIBRARIES amdis)
#include <amdis/AMDiS.hpp>
#include <amdis/DOFVector.hpp>
#include <dune/common/test/testsuite.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
using namespace AMDiS;
int main (int argc, char** argv)
{
Environment env(argc, argv);
using namespace Dune::Functions::BasisFactory;
Dune::YaspGrid<2> grid({1.0,1.0}, {1,1});
auto dv = DOFVector{grid.leafGridView(),lagrange<1>()};
auto& basis = dv.basis();
// extract the pure vector facade
auto& v = dv.coefficients();
Dune::TestSuite test;
// check the size of the vector
test.check(v.localSize() <= v.globalSize());
test.check(v.localSize() == basis.dimension());
// check that the resize has no effect
auto ls = v.localSize();
auto gs = v.globalSize();
v.resize(basis);
test.check(v.localSize() == ls);
test.check(v.globalSize() == gs);
// check that resize with zeroing out gives components with value 0
v.resizeZero(basis);
auto lv = basis.localView();
lv.bind(*basis.gridView().begin<0>());
test.check(v.get(lv.index(0)) == 0.0);
test.check(v.state() == VectorState::synchronized);
v.init(basis, true);
test.check(v.state() == VectorState::synchronized);
v.finish();
// create a copy
auto v2 = v;
v = 0.0;
v2 = 1.0;
test.check(v.get(lv.index(0)) == 0.0);
test.check(v2.get(lv.index(0)) == 1.0);
// call linear algebra operations
v.axpy(2.0, v2); // v += 2.0 * v2
test.check(v.get(lv.index(0)) == 2.0);
v.aypx(1.5, v2); // v = 1.0 * v + v2
test.check(v.get(lv.index(0)) == 4.0);
v += v2;
test.check(v.get(lv.index(0)) == 5.0);
v -= v2;
test.check(v.get(lv.index(0)) == 4.0);
return test.exit();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment