Commit 12be710c authored by Tommaso Bianucci's avatar Tommaso Bianucci

Fix for build failure when EIGEN3 is not available.

Now DCPSE-related unit tests which require EMatrix (and therefore Eigen) are compiled only if EIGEN3 is available, to avoid build failures on systems where EIGEN3 is not installed.
parent 542b8cd2
......@@ -156,7 +156,10 @@ else()
endif()
if(EIGEN3_FOUND)
set(DEFINE_HAVE_EIGEN "#define HAVE_EIGEN")
message("-- EIGEN3 found.")
set(DEFINE_HAVE_EIGEN "#define HAVE_EIGEN")
else()
message("-- EIGEN3 not found!")
endif()
if(LIBHILBERT_FOUND)
......
......@@ -5,7 +5,6 @@
#ifndef OPENFPM_PDATA_DCPSERHS_HPP
#define OPENFPM_PDATA_DCPSERHS_HPP
#include "../../openfpm_numerics/src/DMatrix/EMatrix.hpp"
#include "MonomialBasis.hpp"
template<unsigned int dim>
......
......@@ -5,7 +5,6 @@
#ifndef OPENFPM_PDATA_VANDERMONDE_HPP
#define OPENFPM_PDATA_VANDERMONDE_HPP
#include "../../openfpm_numerics/src/DMatrix/EMatrix.hpp"
#include "MonomialBasis.hpp"
#include "VandermondeRowBuilder.hpp"
#include "Support.hpp"
......
......@@ -5,7 +5,6 @@
#ifndef OPENFPM_PDATA_VANDERMONDEROW_HPP
#define OPENFPM_PDATA_VANDERMONDEROW_HPP
#include "../../openfpm_numerics/src/DMatrix/EMatrix.hpp"
#include "MonomialBasis.hpp"
template <unsigned int dim, typename T>
......
......@@ -5,12 +5,14 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <DCPSE/MonomialBasis.hpp>
#include <DCPSE/DcpseRhs.hpp>
#include "../../openfpm_numerics/src/DMatrix/EMatrix.hpp"
BOOST_AUTO_TEST_SUITE(DcpseRhs_tests)
// If EIGEN is not present, EMatrix is not available and we don't need to build this test
#ifdef HAVE_EIGEN
BOOST_AUTO_TEST_CASE(DcpseRhs_dx_test)
{
unsigned int r = 2;
......@@ -96,4 +98,6 @@ BOOST_AUTO_TEST_SUITE(DcpseRhs_tests)
BOOST_REQUIRE_CLOSE(b(9), Dmb.getElement(9).evaluate(p0), 1e-16);
}
#endif // HAVE_EIGEN
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
......@@ -30,6 +30,9 @@ void check_small_or_close_abs(T value, T expected, T absTolerance)
BOOST_AUTO_TEST_SUITE(Dcpse_tests)
// If EIGEN is not present, EMatrix is not available and we don't need to build this test
#ifdef HAVE_EIGEN
BOOST_AUTO_TEST_CASE(Dcpse_2D_test)
{
int rank;
......@@ -418,4 +421,6 @@ BOOST_AUTO_TEST_SUITE(Dcpse_tests)
BOOST_REQUIRE(check);
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
#endif // HAVE_EIGEN
BOOST_AUTO_TEST_SUITE_END()
......@@ -6,7 +6,6 @@
#include <boost/test/unit_test.hpp>
#include <Space/Shape/Point.hpp>
#include <DCPSE/Monomial.hpp>
#include <DCPSE/MonomialBasis.hpp>
BOOST_AUTO_TEST_SUITE(MonomialBasis_tests)
......
......@@ -12,11 +12,14 @@
BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
// If EIGEN is not present, EMatrix is not available and we don't need to build this test
#ifdef HAVE_EIGEN
BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_AllOnes_test)
{
MonomialBasis<2> mb({1, 0}, 2);
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
Point<2, double> x({2,2});
Point<2, double> x({2, 2});
double eps = 2;
VandermondeRowBuilder<2, double> vrb(mb);
vrb.buildRow(row, 0, x, eps);
......@@ -24,7 +27,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
bool isRowAllOnes = true;
for (int i = 0; i < mb.size(); ++i)
{
isRowAllOnes = isRowAllOnes && (row(0,i)==1);
isRowAllOnes = isRowAllOnes && (row(0, i) == 1);
}
BOOST_REQUIRE(isRowAllOnes);
}
......@@ -33,7 +36,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
{
MonomialBasis<2> mb({1, 0}, 2);
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
Point<2, double> x({1,0});
Point<2, double> x({1, 0});
double eps = 1;
VandermondeRowBuilder<2, double> vrb(mb);
vrb.buildRow(row, 0, x, eps);
......@@ -42,7 +45,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
for (int i = 0; i < mb.size(); ++i)
{
bool isThereY = mb.getElement(i).getExponent(1) > 0;
bool curCheck = (row(0,i)==!isThereY);
bool curCheck = (row(0, i) == !isThereY);
areValuesOk = areValuesOk && curCheck;
}
BOOST_REQUIRE(areValuesOk);
......@@ -52,7 +55,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
{
MonomialBasis<2> mb({1, 0}, 2);
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
Point<2, double> x({0,1});
Point<2, double> x({0, 1});
double eps = 1;
VandermondeRowBuilder<2, double> vrb(mb);
vrb.buildRow(row, 0, x, eps);
......@@ -61,7 +64,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
for (int i = 0; i < mb.size(); ++i)
{
bool isThereX = mb.getElement(i).getExponent(0) > 0;
bool curCheck = (row(0,i)==!isThereX);
bool curCheck = (row(0, i) == !isThereX);
areValuesOk = areValuesOk && curCheck;
}
BOOST_REQUIRE(areValuesOk);
......@@ -71,29 +74,59 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
{
MonomialBasis<2> mb({1, 0}, 2);
// std::cout << mb << std::endl; // Debug
Point<2, double> x({0,0});
Point<2, double> x({0, 0});
std::vector<Point<2, double>> neighbours;
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> V(mb.size(), mb.size());
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> ExpectedV(mb.size(), mb.size());
// Now push 4 points on diagonal as neighbours
neighbours.push_back({1,1});
neighbours.push_back({-1,-1});
neighbours.push_back({1,-1});
neighbours.push_back({-1,1});
neighbours.push_back({0,1});
neighbours.push_back({0,-1});
neighbours.push_back({1, 1});
neighbours.push_back({-1, -1});
neighbours.push_back({1, -1});
neighbours.push_back({-1, 1});
neighbours.push_back({0, 1});
neighbours.push_back({0, -1});
// ...and get the matrix V
Vandermonde<2, double, EMatrix<double, Eigen::Dynamic, Eigen::Dynamic>> vandermonde(x, neighbours, mb);
vandermonde.getMatrix(V);
// Now build the matrix of expected values
ExpectedV(0,0) = 1; ExpectedV(0,1) = -0.3; ExpectedV(0,2) = 0.09; ExpectedV(0,3) = -0.3; ExpectedV(0,4) = +0.09; ExpectedV(0,5) = 0.09;
ExpectedV(1,0) = 1; ExpectedV(1,1) = +0.3; ExpectedV(1,2) = 0.09; ExpectedV(1,3) = +0.3; ExpectedV(1,4) = +0.09; ExpectedV(1,5) = 0.09;
ExpectedV(2,0) = 1; ExpectedV(2,1) = -0.3; ExpectedV(2,2) = 0.09; ExpectedV(2,3) = +0.3; ExpectedV(2,4) = -0.09; ExpectedV(2,5) = 0.09;
ExpectedV(3,0) = 1; ExpectedV(3,1) = +0.3; ExpectedV(3,2) = 0.09; ExpectedV(3,3) = -0.3; ExpectedV(3,4) = -0.09; ExpectedV(3,5) = 0.09;
ExpectedV(4,0) = 1; ExpectedV(4,1) = 0; ExpectedV(4,2) = 0; ExpectedV(4,3) = -0.3; ExpectedV(4,4) = 0; ExpectedV(4,5) = 0.09;
ExpectedV(5,0) = 1; ExpectedV(5,1) = 0; ExpectedV(5,2) = 0; ExpectedV(5,3) = +0.3; ExpectedV(5,4) = 0; ExpectedV(5,5) = 0.09;
ExpectedV(0, 0) = 1;
ExpectedV(0, 1) = -0.3;
ExpectedV(0, 2) = 0.09;
ExpectedV(0, 3) = -0.3;
ExpectedV(0, 4) = +0.09;
ExpectedV(0, 5) = 0.09;
ExpectedV(1, 0) = 1;
ExpectedV(1, 1) = +0.3;
ExpectedV(1, 2) = 0.09;
ExpectedV(1, 3) = +0.3;
ExpectedV(1, 4) = +0.09;
ExpectedV(1, 5) = 0.09;
ExpectedV(2, 0) = 1;
ExpectedV(2, 1) = -0.3;
ExpectedV(2, 2) = 0.09;
ExpectedV(2, 3) = +0.3;
ExpectedV(2, 4) = -0.09;
ExpectedV(2, 5) = 0.09;
ExpectedV(3, 0) = 1;
ExpectedV(3, 1) = +0.3;
ExpectedV(3, 2) = 0.09;
ExpectedV(3, 3) = -0.3;
ExpectedV(3, 4) = -0.09;
ExpectedV(3, 5) = 0.09;
ExpectedV(4, 0) = 1;
ExpectedV(4, 1) = 0;
ExpectedV(4, 2) = 0;
ExpectedV(4, 3) = -0.3;
ExpectedV(4, 4) = 0;
ExpectedV(4, 5) = 0.09;
ExpectedV(5, 0) = 1;
ExpectedV(5, 1) = 0;
ExpectedV(5, 2) = 0;
ExpectedV(5, 3) = +0.3;
ExpectedV(5, 4) = 0;
ExpectedV(5, 5) = 0.09;
// Now check that the values in V are all the expected ones
for (int i = 0; i < mb.size(); ++i)
......@@ -102,7 +135,7 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
for (int j = 0; j < mb.size(); ++j)
{
// std::cout << ">> V[" << i << "," << j << "] = " << V(i,j) << std::endl;
BOOST_REQUIRE_CLOSE(V(i,j), ExpectedV(i,j), 1e-6);
BOOST_REQUIRE_CLOSE(V(i, j), ExpectedV(i, j), 1e-6);
}
}
}
......@@ -111,28 +144,58 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
{
MonomialBasis<2> mb({1, 0}, 2);
// std::cout << mb << std::endl; // Debug
Point<2, double> x({1,1});
Point<2, double> x({1, 1});
std::vector<Point<2, double>> neighbours;
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> V(mb.size(), mb.size());
EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> ExpectedV(mb.size(), mb.size());
// Now push 4 points on diagonal as neighbours
neighbours.push_back({2,2});
neighbours.push_back({0,0});
neighbours.push_back({2,0});
neighbours.push_back({0,2});
neighbours.push_back({1,2});
neighbours.push_back({1,0});
neighbours.push_back({2, 2});
neighbours.push_back({0, 0});
neighbours.push_back({2, 0});
neighbours.push_back({0, 2});
neighbours.push_back({1, 2});
neighbours.push_back({1, 0});
// ...and get the matrix V
Vandermonde<2, double, EMatrix<double, Eigen::Dynamic, Eigen::Dynamic>> vandermonde(x, neighbours, mb);
vandermonde.getMatrix(V);
// Now build the matrix of expected values
ExpectedV(0,0) = 1; ExpectedV(0,1) = -0.3; ExpectedV(0,2) = 0.09; ExpectedV(0,3) = -0.3; ExpectedV(0,4) = +0.09; ExpectedV(0,5) = 0.09;
ExpectedV(1,0) = 1; ExpectedV(1,1) = +0.3; ExpectedV(1,2) = 0.09; ExpectedV(1,3) = +0.3; ExpectedV(1,4) = +0.09; ExpectedV(1,5) = 0.09;
ExpectedV(2,0) = 1; ExpectedV(2,1) = -0.3; ExpectedV(2,2) = 0.09; ExpectedV(2,3) = +0.3; ExpectedV(2,4) = -0.09; ExpectedV(2,5) = 0.09;
ExpectedV(3,0) = 1; ExpectedV(3,1) = +0.3; ExpectedV(3,2) = 0.09; ExpectedV(3,3) = -0.3; ExpectedV(3,4) = -0.09; ExpectedV(3,5) = 0.09;
ExpectedV(4,0) = 1; ExpectedV(4,1) = 0; ExpectedV(4,2) = 0; ExpectedV(4,3) = -0.3; ExpectedV(4,4) = 0; ExpectedV(4,5) = 0.09;
ExpectedV(5,0) = 1; ExpectedV(5,1) = 0; ExpectedV(5,2) = 0; ExpectedV(5,3) = +0.3; ExpectedV(5,4) = 0; ExpectedV(5,5) = 0.09;
ExpectedV(0, 0) = 1;
ExpectedV(0, 1) = -0.3;
ExpectedV(0, 2) = 0.09;
ExpectedV(0, 3) = -0.3;
ExpectedV(0, 4) = +0.09;
ExpectedV(0, 5) = 0.09;
ExpectedV(1, 0) = 1;
ExpectedV(1, 1) = +0.3;
ExpectedV(1, 2) = 0.09;
ExpectedV(1, 3) = +0.3;
ExpectedV(1, 4) = +0.09;
ExpectedV(1, 5) = 0.09;
ExpectedV(2, 0) = 1;
ExpectedV(2, 1) = -0.3;
ExpectedV(2, 2) = 0.09;
ExpectedV(2, 3) = +0.3;
ExpectedV(2, 4) = -0.09;
ExpectedV(2, 5) = 0.09;
ExpectedV(3, 0) = 1;
ExpectedV(3, 1) = +0.3;
ExpectedV(3, 2) = 0.09;
ExpectedV(3, 3) = -0.3;
ExpectedV(3, 4) = -0.09;
ExpectedV(3, 5) = 0.09;
ExpectedV(4, 0) = 1;
ExpectedV(4, 1) = 0;
ExpectedV(4, 2) = 0;
ExpectedV(4, 3) = -0.3;
ExpectedV(4, 4) = 0;
ExpectedV(4, 5) = 0.09;
ExpectedV(5, 0) = 1;
ExpectedV(5, 1) = 0;
ExpectedV(5, 2) = 0;
ExpectedV(5, 3) = +0.3;
ExpectedV(5, 4) = 0;
ExpectedV(5, 5) = 0.09;
// Now check that the values in V are all the expected ones
for (int i = 0; i < mb.size(); ++i)
......@@ -141,9 +204,11 @@ BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
for (int j = 0; j < mb.size(); ++j)
{
// std::cout << ">> V[" << i << "," << j << "] = " << V(i,j) << std::endl;
BOOST_REQUIRE_CLOSE(V(i,j), ExpectedV(i,j), 1e-6);
BOOST_REQUIRE_CLOSE(V(i, j), ExpectedV(i, j), 1e-6);
}
}
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
#endif // HAVE_EIGEN
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment