preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SVDFactorizationTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <Eigen/Dense>
5#include <Eigen/src/Core/Matrix.h>
6
11#include "testing/Testing.hpp"
12
13BOOST_AUTO_TEST_SUITE(AccelerationTests)
14
15using namespace precice;
16using namespace precice::acceleration;
17using namespace precice::acceleration::impl;
18
20BOOST_AUTO_TEST_CASE(testSVDFactorization)
21{
23 int m = 2; // size of a*
24 int n = 3; // size of b*
25 double eps = 1.2e-3;
26 const bool cyclicCommunication = false;
27 std::vector<double> factors(1.0, 1.0);
28 Eigen::VectorXd a1(2);
29 Eigen::VectorXd a2(2);
30 Eigen::VectorXd a3(2);
31 Eigen::VectorXd b1(3);
32 Eigen::VectorXd b2(3);
33 Eigen::VectorXd b3(3);
34 SVDFactorization::Vector singleValues = SVDFactorization::Vector::Zero(2);
35
36 a1 << 1., -1.;
37 a2 << 1., -1.;
38 a3 << 1., 0.;
39 b1 << 2., 4., 4.;
40 b2 << 2., 4., 4.;
41 b3 << -2., -10., -7.;
42 singleValues(0) = 12.;
43 singleValues(1) = 3.;
44
45 // prepare preConditioner to be used to construct a SVD factorization class
47
48 // prepare matrix operation to be used in SVD update
49 ParallelMatrixOperations matOperation;
50 matOperation.initialize(cyclicCommunication);
51 auto ptrParMatrixOp = std::make_shared<ParallelMatrixOperations>(matOperation);
52
53 // construct a SVD factorization object
54 SVDFactorization svd_1(eps, prec);
55
56 svd_1.initialize(ptrParMatrixOp, m, n);
57
58 svd_1.update(a1, b1);
59 svd_1.update(a2, b2);
60 svd_1.update(a3, b3);
61
62 // check if the over small single values have been correctly truncated
63 BOOST_TEST(svd_1.rank() == 2);
64 BOOST_TEST(testing::equals(svd_1.singularValues(), singleValues, 1e-10));
65}
66
68
69#endif
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testSVDFactorization)
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
void initialize(const bool needCyclicComm)
Initializes the acceleration.
Class that provides functionality to maintain a SVD decomposition of a matrix via successive rank-1 u...
void initialize(PtrParMatrixOps parMatOps, int globalRowsA, int globalRowsB)
: initializes the updated SVD factorization, i.e., sets the object for parallel matrix-matrix operati...
Vector & singularValues()
: returns a matrix representation of the orthogonal matrix Sigma, A = Psi * Sigma * Phi^T
Rank rank()
: returns the rank of the truncated SVD factorization
void update(const Eigen::MatrixBase< Derived1 > &A, const Eigen::MatrixBase< Derived2 > &B)
: updates the SVD decomposition with the rank-1 update A*B^T, i.e., _psi * _sigma * _phi^T + A*B^T an...
T make_unique(T... args)
contains implementations of acceleration schemes.
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:93
Main namespace of the precice library.