preCICE v3.1.2
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#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
19BOOST_AUTO_TEST_CASE(testSVDFactorization)
20{
21 PRECICE_TEST(1_rank);
22 int m = 8;
23 double eps = 1.2e-3;
24 const bool cyclicCommunication = false;
25 std::vector<double> factors(1.0, 1.0);
26 Eigen::VectorXd a(m);
27 Eigen::VectorXd b(m);
28 SVDFactorization::Vector singleValues = SVDFactorization::Vector::Zero(2);
29 singleValues(0) = 0.000578589774323541;
30 singleValues(1) = 8.13011257500996e-05;
31
32 // prepare preConditioner to be used to construct a SVD factorization class
33 auto prec(std::make_shared<impl::ConstantPreconditioner>(factors));
34
35 // prepare matrix operation to be used in SVD update
36 ParallelMatrixOperations matOperation;
37 matOperation.initialize(cyclicCommunication);
38 auto ptrParMatrixOp = std::make_shared<ParallelMatrixOperations>(matOperation);
39
40 // construct a SVD factorization object
41 SVDFactorization svd_1(eps, prec);
42
43 svd_1.initialize(ptrParMatrixOp, m);
44 // update 4 times
45 for (int i = 0; i < 4; i++) {
46 for (int j = 0; j < m; j++) {
47 a(j) = j * 0.001 - i * 0.001;
48 b(j) = j * 0.001 - i * 0.007;
49 }
50 svd_1.update(a, b);
51 }
52 // check if the over small single values have been correctly truncated
53 BOOST_TEST(svd_1.rank() == 2);
54 BOOST_TEST(testing::equals(svd_1.singularValues(), singleValues, 1e-10));
55}
56
58
59#endif
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(testSVDFactorization)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
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 globalRows)
: 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:65
Main namespace of the precice library.