preCICE
Loading...
Searching...
No Matches
SVDFactorizationTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <Eigen/Dense>
5
10#include "testing/Testing.hpp"
11
12BOOST_AUTO_TEST_SUITE(AccelerationTests)
13
14using namespace precice;
15using namespace precice::acceleration;
16using namespace precice::acceleration::impl;
17
19BOOST_AUTO_TEST_CASE(testSVDFactorization)
20{
22 int m = 2; // size of a*
23 int n = 3; // size of b*
24 double eps = 1.2e-3;
25 const bool cyclicCommunication = false;
26 std::vector<double> factors(1.0, 1.0);
27 Eigen::VectorXd a1(2);
28 Eigen::VectorXd a2(2);
29 Eigen::VectorXd a3(2);
30 Eigen::VectorXd b1(3);
31 Eigen::VectorXd b2(3);
32 Eigen::VectorXd b3(3);
33 SVDFactorization::Vector singleValues = SVDFactorization::Vector::Zero(2);
34
35 a1 << 1., -1.;
36 a2 << 1., -1.;
37 a3 << 1., 0.;
38 b1 << 2., 4., 4.;
39 b2 << 2., 4., 4.;
40 b3 << -2., -10., -7.;
41 singleValues(0) = 12.;
42 singleValues(1) = 3.;
43
44 // prepare preConditioner to be used to construct a SVD factorization class
45 auto prec(std::make_shared<ConstantPreconditioner>(factors));
46
47 // prepare matrix operation to be used in SVD update
48 ParallelMatrixOperations matOperation;
49 matOperation.initialize(cyclicCommunication);
50 auto ptrParMatrixOp = std::make_shared<ParallelMatrixOperations>(matOperation);
51
52 // construct a SVD factorization object
53 SVDFactorization svd_1(eps, prec);
54
55 svd_1.initialize(ptrParMatrixOp, m, n);
56
57 svd_1.update(a1, b1);
58 svd_1.update(a2, b2);
59 svd_1.update(a3, b3);
60
61 // check if the over small single values have been correctly truncated
62 BOOST_TEST(svd_1.rank() == 2);
63 BOOST_TEST(testing::equals(svd_1.singularValues(), singleValues, 1e-10));
64}
65
67
68#endif
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#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...
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.