Changed: Removed need for a dummy integrand in some unit tests
This commit is contained in:
@@ -10,84 +10,59 @@
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "IFEM.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SIMMultiPatchModelGen.h"
|
||||
#include "SIM2D.h"
|
||||
#include "SIM3D.h"
|
||||
#include <fstream>
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
template<class Dim>
|
||||
class DummySIM : public SIMMultiPatchModelGen<Dim> {
|
||||
public:
|
||||
class DummyIntegrand : public IntegrandBase {};
|
||||
DummySIM() : SIMMultiPatchModelGen<Dim>(1)
|
||||
{ Dim::myProblem = new DummyIntegrand; }
|
||||
};
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
static void check_intvectors_equal (const std::vector<int>& A,
|
||||
const std::string& Bfile)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
std::ifstream f(Bfile);
|
||||
|
||||
return result;
|
||||
}
|
||||
size_t Bsize;
|
||||
f >> Bsize;
|
||||
if (!f) Bsize = 0;
|
||||
|
||||
|
||||
auto&& check_intvectors_equal = [](const IntVec& A,
|
||||
const IntVec& B)
|
||||
{
|
||||
ASSERT_EQ(A.size(), B.size());
|
||||
auto it = B.begin();
|
||||
for (auto& it2 : A) {
|
||||
ASSERT_EQ(it2, *it);
|
||||
++it;
|
||||
}
|
||||
ASSERT_EQ(A.size(),Bsize);
|
||||
std::vector<int> B(Bsize);
|
||||
for (int& bi : B) f >> bi;
|
||||
for (size_t i = 0; i < A.size(); i++)
|
||||
EXPECT_EQ(A[i],B[i]);
|
||||
};
|
||||
|
||||
|
||||
TEST(TestMultiPatchModelGenerator2D, SubdivisionsMPI)
|
||||
{
|
||||
DummySIM<SIM2D> sim;
|
||||
SIMMultiPatchModelGen<SIM2D> sim(1);
|
||||
ASSERT_TRUE(sim.read("Test/refdata/modelgen2d_subdivision.xinp"));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
std::stringstream str;
|
||||
str << "Test/refdata/modelgen2d_subdivision_nodes" << adm.getProcId() << ".ref";
|
||||
IntVec B = readIntVector(str.str());
|
||||
check_intvectors_equal(adm.dd.getMLGN(), B);
|
||||
check_intvectors_equal(adm.dd.getMLGN(), str.str());
|
||||
str.str("");
|
||||
str << "Test/refdata/modelgen2d_subdivision_eqs" << adm.getProcId() << ".ref";
|
||||
B = readIntVector(str.str());
|
||||
check_intvectors_equal(adm.dd.getMLGEQ(), B);
|
||||
check_intvectors_equal(adm.dd.getMLGEQ(), str.str());
|
||||
}
|
||||
|
||||
/*
|
||||
TES(TestMultiPatchModelGenerator3D, SubdivisionsMPI)
|
||||
{
|
||||
DummySIM<SIM3D> sim;
|
||||
SIMMultiPatchModelGen<SIM3D> sim;
|
||||
ASSERT_TRUE(sim.read("Test/refdata/modelgen3d_subdivision.xinp"));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
for (auto& it : adm.dd.getMLGN())
|
||||
IFEM::cout << it << " ";
|
||||
IFEM::cout << std::endl;
|
||||
for (int i : adm.dd.getMLGN()) std::cout <<" "<< i;
|
||||
std::cout << std::endl;
|
||||
// std::stringstream str;
|
||||
// str << "Test/refdata/modelgen3d_subdivision_nodes" << adm.getProcId() << ".ref";
|
||||
// IntVec B = readIntVector(str.str());
|
||||
// check_intvectors_equal(adm.dd.getMLGN(), B);
|
||||
// check_intvectors_equal(adm.dd.getMLGN(), str.str());
|
||||
// str.str("");
|
||||
// str << "Test/refdata/modelgen2d_subdivision_eqs" << adm.getProcId() << ".ref";
|
||||
// B = readIntVector(str.str());
|
||||
// check_intvectors_equal(adm.dd.getMLGEQ(), B);
|
||||
// check_intvectors_equal(adm.dd.getMLGEQ(), str.str());
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -40,9 +40,9 @@ class TiXmlElement;
|
||||
class IntegrandBase : public Integrand
|
||||
{
|
||||
protected:
|
||||
//! \brief The default constructor is protected to allow sub-classes only.
|
||||
explicit IntegrandBase(unsigned short int n = 0) : nsd(n), npv(1),
|
||||
m_mode(SIM::INIT) {}
|
||||
//! \brief The constructor is protected to allow sub-classes only.
|
||||
explicit IntegrandBase(unsigned short int n) : nsd(n), npv(1),
|
||||
m_mode(SIM::INIT) {}
|
||||
|
||||
public:
|
||||
//! \brief Empty destructor.
|
||||
|
||||
@@ -13,22 +13,18 @@
|
||||
#include "DomainDecomposition.h"
|
||||
#include "SAM.h"
|
||||
#include "ASMbase.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SIM2D.h"
|
||||
#include "SIM3D.h"
|
||||
#include "IFEM.h"
|
||||
#include "../../LinAlg/readIntVec.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <fstream>
|
||||
|
||||
|
||||
template<class Dim>
|
||||
class TestGlobalLMSIM : public Dim {
|
||||
public:
|
||||
TestGlobalLMSIM(unsigned char n1 = 2, bool check = false) :
|
||||
Dim(n1, check) {}
|
||||
|
||||
TestGlobalLMSIM(const std::vector<unsigned char>& nf, bool check = false) :
|
||||
Dim(nf, check) {}
|
||||
TestGlobalLMSIM(unsigned char n1) : Dim(n1) {}
|
||||
TestGlobalLMSIM(const std::vector<unsigned char>& nf) : Dim(nf) {}
|
||||
|
||||
protected:
|
||||
bool preprocessBeforeAsmInit(int& nnod)
|
||||
@@ -45,39 +41,11 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
template<class Dim>
|
||||
class DummySIM : public Dim {
|
||||
public:
|
||||
class DummyIntegrand : public IntegrandBase {};
|
||||
DummySIM() : Dim(1) { Dim::myProblem = new DummyIntegrand; }
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
auto&& check_intvectors_equal = [](const IntVec& A,
|
||||
const IntVec& B)
|
||||
static void check_intvectors_equal (const IntVec& A, const IntVec& B)
|
||||
{
|
||||
ASSERT_EQ(A.size(), B.size());
|
||||
auto it = B.begin();
|
||||
for (auto& it2 : A) {
|
||||
ASSERT_EQ(it2, *it);
|
||||
++it;
|
||||
}
|
||||
for (size_t i = 0; i < A.size(); i++)
|
||||
ASSERT_EQ(A[i], B[i]);
|
||||
};
|
||||
|
||||
|
||||
@@ -95,18 +63,19 @@ class TestDomainDecomposition3D : public testing::Test,
|
||||
|
||||
TEST_P(TestDomainDecomposition2D, Corner)
|
||||
{
|
||||
DummySIM<SIM2D> sim;
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_corner";
|
||||
std::string file = "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_corner";
|
||||
if (GetParam() == 1)
|
||||
str << "_fail";
|
||||
str << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
file += "_fail.xinp";
|
||||
else
|
||||
file += ".xinp";
|
||||
|
||||
SIM2D sim;
|
||||
ASSERT_TRUE(sim.read(file.c_str()));
|
||||
|
||||
if (GetParam() == 0) {
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_corner_nodes";
|
||||
str << adm.getProcId() << ".ref";
|
||||
IntVec B = readIntVector(str.str());
|
||||
@@ -118,19 +87,21 @@ TEST_P(TestDomainDecomposition2D, Corner)
|
||||
|
||||
TEST_P(TestDomainDecomposition2D, CornerLR)
|
||||
{
|
||||
DummySIM<SIM2D> sim;
|
||||
sim.opt.discretization = ASM::LRSpline;
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_corner";
|
||||
std::string file = "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_corner";
|
||||
if (GetParam() == 1)
|
||||
str << "_fail";
|
||||
str << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
file += "_fail.xinp";
|
||||
else
|
||||
file += ".xinp";
|
||||
|
||||
SIM2D sim;
|
||||
sim.opt.discretization = ASM::LRSpline;
|
||||
ASSERT_TRUE(sim.read(file.c_str()));
|
||||
|
||||
if (GetParam() == 0) {
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_cornerLR_nodes";
|
||||
str << adm.getProcId() << ".ref";
|
||||
IntVec B = readIntVector(str.str());
|
||||
@@ -146,8 +117,8 @@ TEST_P(TestDomainDecomposition2D, SetupSingleBasis)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -175,8 +146,8 @@ TEST_P(TestDomainDecomposition2D, SetupSingleBasisLR)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -197,8 +168,8 @@ TEST_P(TestDomainDecomposition2D, SetupSingleBasisPeriodic)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_periodic";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -217,8 +188,8 @@ TEST_P(TestDomainDecomposition2D, SetupSingleBasisGlobalLM)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -243,8 +214,8 @@ TEST_P(TestDomainDecomposition2D, SetupSingleBasisBlockEqsComponent)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_blocks_components_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -266,8 +237,8 @@ TEST_P(TestDomainDecomposition2D, SetupMixedBasis)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -297,8 +268,8 @@ TEST_P(TestDomainDecomposition2D, SetupMixedBasisLR)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -320,8 +291,8 @@ TEST_P(TestDomainDecomposition2D, SetupMixedBasisPeriodic)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_periodic";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -346,8 +317,8 @@ TEST_P(TestDomainDecomposition2D, SetupMixedBasisBlockEqsBasis)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_blocks_basis_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -374,8 +345,8 @@ TEST_P(TestDomainDecomposition2D, SetupMixedBasisBlockEqsBasisGlobalLM)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_blocks_basis_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -418,8 +389,8 @@ TEST_P(TestDomainDecomposition3D, SetupSingleBasis)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -447,8 +418,8 @@ TEST_P(TestDomainDecomposition3D, SetupSingleBasisLR)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -472,8 +443,8 @@ TEST_P(TestDomainDecomposition3D, SetupSingleBasisPeriodic)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_periodic";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -493,8 +464,8 @@ TEST_P(TestDomainDecomposition3D, SetupSingleBasisBlockEqsComponent)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_blocks_components_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -519,8 +490,8 @@ TEST_P(TestDomainDecomposition3D, SetupMixedBasis)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_orient";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
const SAM* sam = sim.getSAM();
|
||||
@@ -549,8 +520,8 @@ TEST_P(TestDomainDecomposition3D, SetupMixedBasisPeriodic)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_periodic";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -576,8 +547,8 @@ TEST_P(TestDomainDecomposition3D, SetupMixedBasisPeriodicLM)
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_periodiclm";
|
||||
str << GetParam() << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
sim.preprocess();
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
str.str("");
|
||||
@@ -599,13 +570,13 @@ TEST_P(TestDomainDecomposition3D, Corner)
|
||||
if (GetParam() > 1)
|
||||
return;
|
||||
|
||||
DummySIM<SIM3D> sim;
|
||||
SIM3D sim;
|
||||
std::stringstream str;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_corner";
|
||||
if (GetParam() > 0)
|
||||
str << "_fail";
|
||||
str << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
|
||||
if (GetParam() < 1) {
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
@@ -625,7 +596,7 @@ TEST_P(TestDomainDecomposition3D, CornerLR)
|
||||
if (GetParam() > 1)
|
||||
return;
|
||||
|
||||
DummySIM<SIM3D> sim;
|
||||
SIM3D sim;
|
||||
sim.opt.discretization = ASM::LRSpline;
|
||||
|
||||
std::stringstream str;
|
||||
@@ -633,7 +604,7 @@ TEST_P(TestDomainDecomposition3D, CornerLR)
|
||||
if (GetParam() > 0)
|
||||
str << "_fail";
|
||||
str << ".xinp";
|
||||
sim.read(str.str().c_str());
|
||||
ASSERT_TRUE(sim.read(str.str().c_str()));
|
||||
|
||||
if (GetParam() < 1) {
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
#include "DomainDecomposition.h"
|
||||
#include "SAM.h"
|
||||
#include "SIM2D.h"
|
||||
#include "IntegrandBase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <fstream>
|
||||
|
||||
|
||||
TEST(TestDomainDecomposition, LocalGroups1DO1)
|
||||
@@ -176,8 +175,7 @@ TEST(TestDomainDecomposition, LocalGroups3DO2)
|
||||
|
||||
TEST(TestDomainDecomposition, Setup)
|
||||
{
|
||||
class Dummy : public IntegrandBase {};
|
||||
SIM2D sim(new Dummy());
|
||||
SIM2D sim;
|
||||
ASSERT_TRUE(sim.read("src/ASM/Test/refdata/DomainDecomposition_2D_1P.xinp"));
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
|
||||
|
||||
@@ -10,72 +10,37 @@
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "AlgEqSystem.h"
|
||||
#include "ISTLMatrix.h"
|
||||
#include "SIM2D.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SAM.h"
|
||||
#include "readIntVec.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class DummyIntegrandForDummies : public IntegrandBase {
|
||||
public:
|
||||
DummyIntegrandForDummies(unsigned short int n = 0) : IntegrandBase(n) {}
|
||||
};
|
||||
|
||||
|
||||
class InspectMatrixSIM : public SIM2D {
|
||||
public:
|
||||
InspectMatrixSIM(unsigned char n1 = 2, bool check = false) :
|
||||
SIM2D(n1, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
InspectMatrixSIM(const std::vector<unsigned char>& n, bool check = false) :
|
||||
SIM2D(n, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
SystemMatrix* getMatrix() { return myEqSys->getMatrix(0); }
|
||||
SystemVector* getVector() { return myEqSys->getVector(0); }
|
||||
};
|
||||
|
||||
|
||||
TEST(TestISTLMatrix, AssembleMPI)
|
||||
{
|
||||
InspectMatrixSIM sim(1);
|
||||
SIM2D sim(1);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test.xinp");
|
||||
sim.opt.solver = LinAlg::ISTL;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
ISTLMatrix* myMat = dynamic_cast<ISTLMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4,4);
|
||||
stencil(1,1) = stencil(2,2) = stencil(3,3) = stencil(4,4) = 1.0;
|
||||
stencil.diag(1.0);
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
ISTL::Mat& mat = static_cast<ISTLMatrix*>(sim.getMatrix())->getMatrix();
|
||||
ISTL::Mat& mat = myMat->getMatrix();
|
||||
ISTL::Vec b(mat.N()), b2(mat.N());
|
||||
|
||||
try {
|
||||
@@ -103,5 +68,5 @@ TEST(TestISTLMatrix, AssembleMPI)
|
||||
|
||||
IntVec v = readIntVector("src/LinAlg/Test/refdata/petsc_matrix_diagonal.ref");
|
||||
for (size_t i = 1; i <= adm.dd.getMLGEQ().size(); ++i)
|
||||
ASSERT_FLOAT_EQ(v[adm.dd.getGlobalEq(i)-1], b2[i-1]);
|
||||
EXPECT_FLOAT_EQ(v[adm.dd.getGlobalEq(i)-1], b2[i-1]);
|
||||
}
|
||||
|
||||
@@ -10,70 +10,36 @@
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "AlgEqSystem.h"
|
||||
#include "PETScMatrix.h"
|
||||
#include "SIM2D.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SAM.h"
|
||||
#include "readIntVec.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class DummyIntegrandForDummies : public IntegrandBase {
|
||||
public:
|
||||
DummyIntegrandForDummies(unsigned short int n = 0) : IntegrandBase(n) {}
|
||||
};
|
||||
|
||||
|
||||
class InspectMatrixSIM : public SIM2D {
|
||||
public:
|
||||
InspectMatrixSIM(unsigned char n1 = 2, bool check = false) :
|
||||
SIM2D(n1, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
InspectMatrixSIM(const std::vector<unsigned char>& n, bool check = false) :
|
||||
SIM2D(n, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
SystemMatrix* getMatrix() { return myEqSys->getMatrix(0); }
|
||||
};
|
||||
|
||||
|
||||
TEST(TestPETScMatrix, AssembleMPI)
|
||||
{
|
||||
InspectMatrixSIM sim(1);
|
||||
SIM2D sim(1);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4,4);
|
||||
stencil(1,1) = stencil(2,2) = stencil(3,3) = stencil(4,4) = 1.0;
|
||||
stencil.diag(1.0);
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix
|
||||
Mat& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getMatrix();
|
||||
Mat& mat = myMat->getMatrix();
|
||||
|
||||
PetscInt r, c;
|
||||
MatGetLocalSize(mat, &r, &c);
|
||||
@@ -91,7 +57,7 @@ TEST(TestPETScMatrix, AssembleMPI)
|
||||
|
||||
// check that we have the correct diagonal values
|
||||
for (int i = r; i < c; ++i)
|
||||
ASSERT_FLOAT_EQ(v[i], a[i-r]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i-r]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -104,7 +70,7 @@ TEST(TestPETScMatrix, AssembleMPI)
|
||||
MatGetRow(mat, r, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat, r, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
@@ -112,26 +78,28 @@ TEST(TestPETScMatrix, AssembleMPI)
|
||||
|
||||
TEST(TestPETScMatrix, AssembleBasisBlocksMPI)
|
||||
{
|
||||
InspectMatrixSIM sim({1,1});
|
||||
SIM2D sim({1,1});
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_basis.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(13,13);
|
||||
for (size_t i = 1; i<= 9; ++i)
|
||||
stencil(i,i) = 1.0;
|
||||
for (size_t i = 10; i<= 13; ++i)
|
||||
stencil.diag(1.0);
|
||||
for (size_t i = 10; i <= 13; i++)
|
||||
stencil(i,i) = 2.0;
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix blocks
|
||||
const std::vector<Mat>& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getBlockMatrices();
|
||||
const std::vector<Mat>& mat = myMat->getBlockMatrices();
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
|
||||
for (size_t b = 0; b < mat.size(); ++b) {
|
||||
@@ -153,7 +121,7 @@ TEST(TestPETScMatrix, AssembleBasisBlocksMPI)
|
||||
PetscInt r,c;
|
||||
VecGetOwnershipRange(vec, &r, &c);
|
||||
for (int i = r; i < c; ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), a[i-r]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i-r]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -167,7 +135,7 @@ TEST(TestPETScMatrix, AssembleBasisBlocksMPI)
|
||||
MatGetRow(mat[b], r+adm.dd.getMinEq(b/2+1)-1, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r+adm.dd.getMinEq(b/2+1)-1)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat[b], r+adm.dd.getMinEq(b/2+1)-1, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
@@ -176,12 +144,15 @@ TEST(TestPETScMatrix, AssembleBasisBlocksMPI)
|
||||
|
||||
TEST(TestPETScMatrix, AssembleComponentBlocksMPI)
|
||||
{
|
||||
InspectMatrixSIM sim(2);
|
||||
SIM2D sim(2);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_components.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4*2,4*2);
|
||||
for (size_t i = 1; i<= 4; ++i) {
|
||||
stencil(2*i-1,2*i-1) = 1.0;
|
||||
@@ -189,13 +160,13 @@ TEST(TestPETScMatrix, AssembleComponentBlocksMPI)
|
||||
}
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix blocks
|
||||
const std::vector<Mat>& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getBlockMatrices();
|
||||
const std::vector<Mat>& mat = myMat->getBlockMatrices();
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
|
||||
for (size_t b = 0; b < mat.size(); ++b) {
|
||||
@@ -217,7 +188,7 @@ TEST(TestPETScMatrix, AssembleComponentBlocksMPI)
|
||||
PetscInt r,c;
|
||||
VecGetOwnershipRange(vec, &r, &c);
|
||||
for (int i = r; i < c; ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), a[i-r]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i-r]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -231,7 +202,7 @@ TEST(TestPETScMatrix, AssembleComponentBlocksMPI)
|
||||
MatGetRow(mat[b], r+adm.dd.getMinEq(b/2+1)-1, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r+adm.dd.getMinEq(b/2+1)-1)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat[b], r+adm.dd.getMinEq(b/2+1)-1, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,52 +10,15 @@
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "AlgEqSystem.h"
|
||||
#include "ISTLMatrix.h"
|
||||
#include "SIM2D.h"
|
||||
#include "ASMmxBase.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SAM.h"
|
||||
#include "readIntVec.h"
|
||||
#include <dune/istl/io.hh>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class DummyIntegrandForDummies : public IntegrandBase {
|
||||
public:
|
||||
DummyIntegrandForDummies(unsigned short int n = 0) : IntegrandBase(n) {}
|
||||
};
|
||||
|
||||
|
||||
class InspectMatrixSIM : public SIM2D {
|
||||
public:
|
||||
InspectMatrixSIM(unsigned char n1 = 2, bool check = false) :
|
||||
SIM2D(n1, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
InspectMatrixSIM(const std::vector<unsigned char>& n, bool check = false) :
|
||||
SIM2D(n, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
SystemMatrix* getMatrix() { return myEqSys->getMatrix(0); }
|
||||
};
|
||||
|
||||
|
||||
class InspectBlockPreconditioner : public ISTL::BlockPreconditioner {
|
||||
public:
|
||||
@@ -75,56 +38,60 @@ public:
|
||||
|
||||
TEST(TestISTLMatrix, Assemble)
|
||||
{
|
||||
InspectMatrixSIM sim(1);
|
||||
SIM2D sim(1);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test.xinp");
|
||||
sim.opt.solver = LinAlg::ISTL;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
ISTLMatrix* myMat = dynamic_cast<ISTLMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4,4);
|
||||
stencil(1,1) = stencil(2,2) = stencil(3,3) = stencil(4,4) = 1.0;
|
||||
stencil.diag(1.0);
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix
|
||||
ISTL::Mat& mat = static_cast<ISTLMatrix*>(sim.getMatrix())->getMatrix();
|
||||
ISTL::Mat& A = myMat->getMatrix();
|
||||
IntVec v = readIntVector("src/LinAlg/Test/refdata/petsc_matrix_diagonal.ref");
|
||||
|
||||
ASSERT_EQ(mat.N(), v.size());
|
||||
|
||||
ASSERT_EQ(A.N(), v.size());
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), mat[i][i]);
|
||||
EXPECT_FLOAT_EQ(double(v[i]), A[i][i]);
|
||||
}
|
||||
|
||||
|
||||
TEST(TestISTLMatrix, AssembleBasisBlocks)
|
||||
{
|
||||
InspectMatrixSIM sim({1,1});
|
||||
ASMmxBase::Type = ASMmxBase::FULL_CONT_RAISE_BASIS1;
|
||||
ASMmxBase::geoBasis = 2;
|
||||
SIM2D sim({1,1});
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_basis.xinp");
|
||||
sim.opt.solver = LinAlg::ISTL;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
ISTLMatrix* myMat = dynamic_cast<ISTLMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(13,13);
|
||||
for (size_t i = 1; i<= 9; ++i)
|
||||
stencil(i,i) = 1.0;
|
||||
for (size_t i = 10; i<= 13; ++i)
|
||||
stencil.diag(1.0);
|
||||
for (size_t i = 10; i <= 13; i++)
|
||||
stencil(i,i) = 2.0;
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
ISTL::Mat& A = myMat->getMatrix();
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
ISTL::Mat& A = static_cast<ISTLMatrix*>(sim.getMatrix())->getMatrix();
|
||||
InspectBlockPreconditioner block(A, adm.dd);
|
||||
|
||||
// now inspect the matrix blocks
|
||||
@@ -142,27 +109,29 @@ TEST(TestISTLMatrix, AssembleBasisBlocks)
|
||||
IntVec v = readIntVector(str.str());
|
||||
ASSERT_EQ(v.size(), mat[b].N());
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), mat[b][i][i]);
|
||||
EXPECT_FLOAT_EQ(double(v[i]), mat[b][i][i]);
|
||||
}
|
||||
|
||||
// check that no values outside the diagonal are != 0
|
||||
for (auto r = mat[b].begin(); r != mat[b].end(); ++r) {
|
||||
for (auto r = mat[b].begin(); r != mat[b].end(); ++r)
|
||||
for (auto it = r->begin(); it != r->end(); ++it)
|
||||
if (r.index() != it.index())
|
||||
ASSERT_FLOAT_EQ(*it, 0.0);
|
||||
}
|
||||
EXPECT_FLOAT_EQ(*it, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(TestISTLMatrix, AssembleComponentBlocks)
|
||||
{
|
||||
InspectMatrixSIM sim(2);
|
||||
SIM2D sim(2);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_components.xinp");
|
||||
sim.opt.solver = LinAlg::ISTL;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
ISTLMatrix* myMat = dynamic_cast<ISTLMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4*2,4*2);
|
||||
for (size_t i = 1; i<= 4; ++i) {
|
||||
stencil(2*i-1,2*i-1) = 1.0;
|
||||
@@ -170,13 +139,13 @@ TEST(TestISTLMatrix, AssembleComponentBlocks)
|
||||
}
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
ISTL::Mat& A = myMat->getMatrix();
|
||||
const ProcessAdm& adm = sim.getProcessAdm();
|
||||
ISTL::Mat& A = static_cast<ISTLMatrix*>(sim.getMatrix())->getMatrix();
|
||||
InspectBlockPreconditioner block(A, adm.dd);
|
||||
|
||||
// now inspect the matrix blocks
|
||||
@@ -194,14 +163,13 @@ TEST(TestISTLMatrix, AssembleComponentBlocks)
|
||||
IntVec v = readIntVector(str.str());
|
||||
ASSERT_EQ(v.size(), mat[b].N());
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), mat[b][i][i]);
|
||||
EXPECT_FLOAT_EQ(double(v[i]), mat[b][i][i]);
|
||||
}
|
||||
|
||||
// check that no values outside the diagonal are != 0
|
||||
for (auto r = mat[b].begin(); r != mat[b].end(); ++r) {
|
||||
for (auto r = mat[b].begin(); r != mat[b].end(); ++r)
|
||||
for (auto it = r->begin(); it != r->end(); ++it)
|
||||
if (r.index() != it.index())
|
||||
ASSERT_FLOAT_EQ(*it, 0.0);
|
||||
}
|
||||
EXPECT_FLOAT_EQ(*it, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,71 +10,37 @@
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "AlgEqSystem.h"
|
||||
#include "PETScMatrix.h"
|
||||
#include "SIM2D.h"
|
||||
#include "ASMmxBase.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SAM.h"
|
||||
#include "readIntVec.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef std::vector<int> IntVec;
|
||||
|
||||
static IntVec readIntVector(const std::string& file)
|
||||
{
|
||||
std::vector<int> result;
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
result.resize(size);
|
||||
for (size_t j=0;j<size;++j)
|
||||
f >> result[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class DummyIntegrandForDummies : public IntegrandBase {
|
||||
public:
|
||||
DummyIntegrandForDummies(unsigned short int n = 0) : IntegrandBase(n) {}
|
||||
};
|
||||
|
||||
|
||||
class InspectMatrixSIM : public SIM2D {
|
||||
public:
|
||||
InspectMatrixSIM(unsigned char n1 = 2, bool check = false) :
|
||||
SIM2D(n1, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
InspectMatrixSIM(const std::vector<unsigned char>& n, bool check = false) :
|
||||
SIM2D(n, check) { myProblem = new DummyIntegrandForDummies; }
|
||||
|
||||
SystemMatrix* getMatrix() { return myEqSys->getMatrix(0); }
|
||||
};
|
||||
|
||||
|
||||
TEST(TestPETScMatrix, Assemble)
|
||||
{
|
||||
InspectMatrixSIM sim(1);
|
||||
SIM2D sim(1);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4,4);
|
||||
stencil(1,1) = stencil(2,2) = stencil(3,3) = stencil(4,4) = 1.0;
|
||||
stencil.diag(1.0);
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix
|
||||
Mat& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getMatrix();
|
||||
Mat& mat = myMat->getMatrix();
|
||||
|
||||
PetscInt mr, mc;
|
||||
MatGetSize(mat, &mr, &mc);
|
||||
@@ -87,12 +53,11 @@ TEST(TestPETScMatrix, Assemble)
|
||||
MatGetDiagonal(mat, vec);
|
||||
PetscScalar* a;
|
||||
VecGetArray(vec, &a);
|
||||
std::vector<int> ref;
|
||||
// check that we have the correct diagonal values
|
||||
IntVec v = readIntVector("src/LinAlg/Test/refdata/petsc_matrix_diagonal.ref");
|
||||
ASSERT_EQ(mr, (int)v.size());
|
||||
for (int i = 0; i < mr; ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), a[i]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -105,7 +70,7 @@ TEST(TestPETScMatrix, Assemble)
|
||||
MatGetRow(mat, r, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat, r, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
@@ -113,28 +78,30 @@ TEST(TestPETScMatrix, Assemble)
|
||||
|
||||
TEST(TestPETScMatrix, AssembleBasisBlocks)
|
||||
{
|
||||
InspectMatrixSIM sim({1,1});
|
||||
ASMmxBase::Type = ASMmxBase::FULL_CONT_RAISE_BASIS1;
|
||||
ASMmxBase::geoBasis = 2;
|
||||
SIM2D sim({1,1});
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_basis.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(13,13);
|
||||
for (size_t i = 1; i<= 9; ++i)
|
||||
stencil(i,i) = 1.0;
|
||||
for (size_t i = 10; i<= 13; ++i)
|
||||
stencil.diag(1.0);
|
||||
for (size_t i = 10; i <= 13; i++)
|
||||
stencil(i,i) = 2.0;
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix blocks
|
||||
const std::vector<Mat>& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getBlockMatrices();
|
||||
const std::vector<Mat>& mat = myMat->getBlockMatrices();
|
||||
|
||||
for (size_t b = 0; b < mat.size(); ++b) {
|
||||
PetscInt mr, mc;
|
||||
@@ -155,7 +122,7 @@ TEST(TestPETScMatrix, AssembleBasisBlocks)
|
||||
IntVec v = readIntVector(str.str());
|
||||
ASSERT_EQ(mr, (int)v.size());
|
||||
for (int i = 0; i < mr; ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), a[i]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -169,7 +136,7 @@ TEST(TestPETScMatrix, AssembleBasisBlocks)
|
||||
MatGetRow(mat[b], r, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat[b], r, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
@@ -178,12 +145,15 @@ TEST(TestPETScMatrix, AssembleBasisBlocks)
|
||||
|
||||
TEST(TestPETScMatrix, AssembleComponentBlocks)
|
||||
{
|
||||
InspectMatrixSIM sim(2);
|
||||
SIM2D sim(2);
|
||||
sim.read("src/LinAlg/Test/refdata/petsc_test_blocks_components.xinp");
|
||||
sim.opt.solver = LinAlg::PETSC;
|
||||
ASSERT_TRUE(sim.preprocess());
|
||||
ASSERT_TRUE(sim.initSystem(sim.opt.solver));
|
||||
|
||||
PETScMatrix* myMat = dynamic_cast<PETScMatrix*>(sim.getLHSmatrix());
|
||||
ASSERT_TRUE(myMat != nullptr);
|
||||
|
||||
Matrix stencil(4*2,4*2);
|
||||
for (size_t i = 1; i<= 4; ++i) {
|
||||
stencil(2*i-1,2*i-1) = 1.0;
|
||||
@@ -191,13 +161,13 @@ TEST(TestPETScMatrix, AssembleComponentBlocks)
|
||||
}
|
||||
|
||||
for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
|
||||
sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);
|
||||
myMat->assemble(stencil, *sim.getSAM(), iel);
|
||||
|
||||
sim.getMatrix()->beginAssembly();
|
||||
sim.getMatrix()->endAssembly();
|
||||
myMat->beginAssembly();
|
||||
myMat->endAssembly();
|
||||
|
||||
// now inspect the matrix blocks
|
||||
const std::vector<Mat>& mat = static_cast<PETScMatrix*>(sim.getMatrix())->getBlockMatrices();
|
||||
const std::vector<Mat>& mat = myMat->getBlockMatrices();
|
||||
|
||||
for (size_t b = 0; b < mat.size(); ++b) {
|
||||
PetscInt mr, mc;
|
||||
@@ -212,14 +182,13 @@ TEST(TestPETScMatrix, AssembleComponentBlocks)
|
||||
MatGetDiagonal(mat[b], vec);
|
||||
PetscScalar* a;
|
||||
VecGetArray(vec, &a);
|
||||
std::vector<int> ref;
|
||||
// check that we have the correct diagonal values
|
||||
std::stringstream str;
|
||||
str << "src/LinAlg/Test/refdata/petsc_matrix_diagonal_components_block" << b/2 + 1 << ".ref";
|
||||
IntVec v = readIntVector(str.str());
|
||||
ASSERT_EQ(mr, (int)v.size());
|
||||
for (int i = 0; i < mr; ++i)
|
||||
ASSERT_FLOAT_EQ(double(v[i]), a[i]);
|
||||
EXPECT_FLOAT_EQ(v[i], a[i]);
|
||||
|
||||
VecRestoreArray(vec, &a);
|
||||
VecDestroy(&vec);
|
||||
@@ -233,7 +202,7 @@ TEST(TestPETScMatrix, AssembleComponentBlocks)
|
||||
MatGetRow(mat[b], r, &ncols, &cols, &vals);
|
||||
for (PetscInt i = 0; i < ncols; ++i)
|
||||
if (cols[i] != r)
|
||||
ASSERT_FLOAT_EQ(vals[i], 0.0);
|
||||
EXPECT_FLOAT_EQ(vals[i], 0.0);
|
||||
MatRestoreRow(mat[b], r, &ncols, &cols, &vals);
|
||||
}
|
||||
}
|
||||
|
||||
38
src/LinAlg/readIntVec.h
Normal file
38
src/LinAlg/readIntVec.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file readIntVec.h
|
||||
//!
|
||||
//! \date Apr 27 2016
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief Read an integer array from a named file, for unit testing.
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#ifndef _READ_INT_VEC_H
|
||||
#define _READ_INT_VEC_H
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
typedef std::vector<int> IntVec; //!< General integer vector
|
||||
|
||||
|
||||
/*!
|
||||
\brief Reads an integer array from a named file, for unit testing.
|
||||
*/
|
||||
|
||||
static IntVec readIntVector (const std::string& file)
|
||||
{
|
||||
std::ifstream f(file);
|
||||
size_t size;
|
||||
f >> size;
|
||||
if (!f) size = 0;
|
||||
IntVec result(size);
|
||||
for (int& i : result) f >> i;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -61,7 +61,7 @@ bool AdaptiveSIM::initAdaptor (size_t normGroup)
|
||||
bool AdaptiveSIM::assembleAndSolveSystem ()
|
||||
{
|
||||
// Assemble the linear FE equation system
|
||||
if (!model.setMode(SIM::STATIC,true))
|
||||
if (!model.setMode(SIM::STATIC,true,true))
|
||||
return false;
|
||||
|
||||
model.setQuadratureRule(opt.nGauss[0],true);
|
||||
|
||||
@@ -220,11 +220,9 @@ ConvStatus NonLinSIM::solveStep (TimeStep& param, SolutionMode mode,
|
||||
if (subiter&FIRST && !model.updateDirichlet(param.time.t,&solution.front()))
|
||||
return FAILURE;
|
||||
|
||||
if (!model.setMode(mode))
|
||||
return FAILURE;
|
||||
|
||||
bool poorConvg = false;
|
||||
bool newTangent = true;
|
||||
model.setMode(mode,false);
|
||||
model.setQuadratureRule(opt.nGauss[0],true);
|
||||
if (!this->assembleSystem(param.time,solution,newTangent))
|
||||
return model.getProblem()->diverged() ? DIVERGED : FAILURE;
|
||||
@@ -267,10 +265,10 @@ ConvStatus NonLinSIM::solveStep (TimeStep& param, SolutionMode mode,
|
||||
if (param.iter > nupdat)
|
||||
{
|
||||
newTangent = false;
|
||||
model.setMode(RHS_ONLY);
|
||||
model.setMode(RHS_ONLY,false);
|
||||
}
|
||||
else
|
||||
model.setMode(mode);
|
||||
model.setMode(mode,false);
|
||||
|
||||
if (!this->assembleSystem(param.time,solution,newTangent,poorConvg))
|
||||
return model.getProblem()->diverged() ? DIVERGED : FAILURE;
|
||||
@@ -298,8 +296,7 @@ SIM::ConvStatus NonLinSIM::solveIteration (TimeStep& param)
|
||||
else if (param.iter == 1 && !model.updateDirichlet())
|
||||
return FAILURE;
|
||||
|
||||
if (!model.setMode(SIM::STATIC))
|
||||
return SIM::FAILURE;
|
||||
model.setMode(SIM::STATIC,false);
|
||||
|
||||
if (!this->assembleSystem(param.time,solution))
|
||||
return SIM::FAILURE;
|
||||
@@ -336,8 +333,7 @@ bool NonLinSIM::lineSearch (TimeStep& param)
|
||||
{
|
||||
if (eta <= 0.0) return true; // No line search
|
||||
|
||||
if (!model.setMode(SIM::RHS_ONLY))
|
||||
return false;
|
||||
model.setMode(SIM::RHS_ONLY,false);
|
||||
|
||||
double s0 = residual.dot(linsol);
|
||||
double smin = fabs(s0);
|
||||
|
||||
@@ -395,13 +395,6 @@ bool SIMbase::preprocess (const IntVec& ignored, bool fixDup)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!myProblem)
|
||||
{
|
||||
std::cerr <<"\n *** SIMbase::preprocess(): No problem integrand for the "
|
||||
<< this->getName() <<"-simulator."<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now perform the sub-class specific final preprocessing, if any
|
||||
return this->preprocessB() && ierr == 0;
|
||||
}
|
||||
@@ -485,9 +478,9 @@ bool SIMbase::setAssociatedRHS (size_t iMat, size_t iVec)
|
||||
}
|
||||
|
||||
|
||||
bool SIMbase::setMode (int mode, bool resetSol)
|
||||
bool SIMbase::setMode (int mode, bool needIntegr, bool resetSol)
|
||||
{
|
||||
if (myInts.empty())
|
||||
if (myInts.empty() && (myProblem || needIntegr))
|
||||
myInts.insert(std::make_pair(0,myProblem));
|
||||
|
||||
for (IntegrandMap::iterator it = myInts.begin(); it != myInts.end(); ++it)
|
||||
|
||||
@@ -118,8 +118,9 @@ public:
|
||||
|
||||
//! \brief Defines the solution mode before the element assembly is started.
|
||||
//! \param[in] mode The solution mode to use
|
||||
//! \param[in] needIntegr If \e false, silently ignore non-existing integrand
|
||||
//! \param[in] resetSol If \e true, the internal solution vectors are cleared
|
||||
bool setMode(int mode, bool resetSol = false);
|
||||
bool setMode(int mode, bool needIntegr = true, bool resetSol = false);
|
||||
|
||||
//! \brief Initializes an integration parameter for the integrand.
|
||||
//! \param[in] i Index of the integration parameter to define
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
//==============================================================================
|
||||
|
||||
#include "SAM.h"
|
||||
#include "IntegrandBase.h"
|
||||
#include "SIMoutput.h"
|
||||
#include "SIMdummy.h"
|
||||
|
||||
@@ -42,20 +41,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Dummy integrand class.
|
||||
class Dummy : public IntegrandBase
|
||||
{
|
||||
public:
|
||||
Dummy() : IntegrandBase(1) {}
|
||||
virtual ~Dummy() {}
|
||||
};
|
||||
|
||||
|
||||
// Simulator class for a single-DOF skew bar.
|
||||
class Bar1DOF : public SIMdummy<SIMoutput>
|
||||
{
|
||||
public:
|
||||
Bar1DOF(IntegrandBase* p) : SIMdummy<SIMoutput>(p) { mySam = new SAM1DOF(); }
|
||||
Bar1DOF() { mySam = new SAM1DOF(); }
|
||||
virtual ~Bar1DOF() {}
|
||||
virtual bool assembleSystem(const TimeDomain&, const Vectors& prevSol,
|
||||
bool newLHSmatrix, bool)
|
||||
@@ -122,7 +112,7 @@ static void runSingleDof (NonLinSIM& solver, int& n, double& s)
|
||||
|
||||
TEST(TestNonLinSIM, SingleDOF)
|
||||
{
|
||||
Bar1DOF simulator(new Dummy());
|
||||
Bar1DOF simulator;
|
||||
ASSERT_TRUE(simulator.initSystem(LinAlg::DENSE));
|
||||
|
||||
TestNonLinSIM integrator1(simulator);
|
||||
|
||||
@@ -203,8 +203,7 @@ class TestSIM2D : public testing::Test,
|
||||
|
||||
TEST_P(TestSIM2D, ElmConnectivites)
|
||||
{
|
||||
class Dummy : public IntegrandBase {};
|
||||
SIM2D sim(new Dummy());
|
||||
SIM2D sim;
|
||||
std::stringstream str;
|
||||
sim.opt.discretization = GetParam().second;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_2D_4_orient";
|
||||
@@ -285,8 +284,7 @@ class TestSIM3D : public testing::Test,
|
||||
|
||||
TEST_P(TestSIM3D, ElmConnectivities)
|
||||
{
|
||||
class Dummy : public IntegrandBase {};
|
||||
SIM3D sim(new Dummy());
|
||||
SIM3D sim;
|
||||
std::stringstream str;
|
||||
sim.opt.discretization = GetParam().second;
|
||||
str << "src/ASM/Test/refdata/DomainDecomposition_MPI_3D_4_orient";
|
||||
|
||||
Reference in New Issue
Block a user