Skip to content

Commit

Permalink
Added: Unit test that provokes the mixed/periodicity failure.
Browse files Browse the repository at this point in the history
Changed: Mainly cosmetics in TestSIM2D::InjectPatchSolution.
  • Loading branch information
kmokstad committed Feb 7, 2019
1 parent c2162ab commit f672dbd
Showing 1 changed file with 57 additions and 34 deletions.
91 changes: 57 additions & 34 deletions src/SIM/Test/TestSIM.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

#include "SIM2D.h"
#include "SIM3D.h"
#include "ASMs3D.h"
#include "ASMmxBase.h"
#include "IntegrandBase.h"
#include "ASMmxBase.h"

#include "gtest/gtest.h"
#include "tinyxml.h"


template<class Dim> class TestProjectSIM : public Dim
Expand Down Expand Up @@ -45,7 +46,7 @@ private:
const std::vector<int>&) const
{
s.resize(1);
s(1) = X[0] + X[1] + X[2];
s(1) = X.sum();
return true;
}

Expand All @@ -57,7 +58,7 @@ private:
class DummyIntegrand : public IntegrandBase {};


TEST(TestSIM, UniqueBoundaryNodes)
TEST(TestSIM2D, UniqueBoundaryNodes)
{
SIM2D sim(new DummyIntegrand(),1);
ASSERT_TRUE(sim.read("src/SIM/Test/refdata/boundary_nodes.xinp"));
Expand All @@ -75,94 +76,116 @@ TEST(TestSIM2D, ProjectSolution)
{
TestProjectSIM<SIM2D> sim({1});

Matrix ssol;
ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs())));
Vector ssol, psol(sim.getNoDOFs());
ASSERT_TRUE(sim.project(ssol,psol));

size_t n = 1;
for (size_t j = 0; j < 2; ++j)
for (size_t i = 0; i < 2; ++i)
EXPECT_FLOAT_EQ(ssol(1, n++), i + j);
EXPECT_FLOAT_EQ(ssol(n++), i + j);
}


TEST(TestSIM2D, ProjectSolutionMixed)
{
TestProjectSIM<SIM2D> sim({1,1});

Matrix ssol;
ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs())));
Vector ssol, psol(sim.getNoDOFs());
ASSERT_TRUE(sim.project(ssol,psol));

size_t n = 1;
for (size_t j = 0; j < 3; ++j)
for (size_t i = 0; i < 3; ++i)
EXPECT_FLOAT_EQ(ssol(1, n++), i/2.0 + j/2.0);
EXPECT_FLOAT_EQ(ssol(n++), i/2.0 + j/2.0);
}


TEST(TestSIM3D, ProjectSolution)
{
TestProjectSIM<SIM3D> sim({1});

Matrix ssol;
ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs())));
Vector ssol, psol(sim.getNoDOFs());
ASSERT_TRUE(sim.project(ssol,psol));

size_t n = 1;
for (size_t k = 0; k < 2; ++k)
for (size_t j = 0; j < 2; ++j)
for (size_t i = 0; i < 2; ++i)
EXPECT_FLOAT_EQ(ssol(1, n++), i + j + k);
EXPECT_FLOAT_EQ(ssol(n++), i + j + k);
}


TEST(TestSIM3D, ProjectSolutionMixed)
{
TestProjectSIM<SIM3D> sim({1,1});

Matrix ssol;
ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs())));
Vector ssol, psol(sim.getNoDOFs());
ASSERT_TRUE(sim.project(ssol,psol));

size_t n = 1;
for (size_t k = 0; k < 3; ++k)
for (size_t j = 0; j < 3; ++j)
for (size_t i = 0; i < 3; ++i)
EXPECT_FLOAT_EQ(ssol(1, n++), i/2.0 + j/2.0 + k/2.0);
EXPECT_FLOAT_EQ(ssol(n++), i/2.0 + j/2.0 + k/2.0);
}


TEST(TestSIM, InjectPatchSolution)
TEST(TestSIM2D, InjectPatchSolution)
{
ASMmxBase::Type = ASMmxBase::REDUCED_CONT_RAISE_BASIS1;
ASMmxBase::geoBasis = 2;
TestProjectSIM<SIM2D> sim({1,1});
ASMbase* pch = sim.getPatch(1);
size_t n1 = sim.getNoNodes(1);
size_t n2 = sim.getNoNodes(2);

Vector sol(2*sim.getNoNodes(1) + sim.getNoNodes(2));
Vector lsol(2*sim.getNoNodes(1));
Vector sol(2*n1 + n2);
Vector lsol(2*n1);
size_t i, ofs;
for (i = 0; i < sim.getNoNodes(1); i++)
for (i = 0; i < n1; i++)
lsol[2*i] = lsol[2*i+1] = i+1;

ASSERT_TRUE(sim.addMixedMADOF(1, 2));
sim.injectPatchSolution(sol, lsol, pch, 2, 1);
for (i = ofs = 0; i < sim.getNoNodes(1); i++, ofs += 2) {
EXPECT_FLOAT_EQ(sol[ofs], i+1);
EXPECT_FLOAT_EQ(sol[ofs+1], i+1);
for (i = ofs = 0; i < n1; i++) {
EXPECT_FLOAT_EQ(sol[ofs++], i+1);
EXPECT_FLOAT_EQ(sol[ofs++], i+1);
}
for (i = 0; i < sim.getNoNodes(2); i++, ofs++)
EXPECT_FLOAT_EQ(sol[ofs], 0);
for (i = 0; i < n2; i++)
EXPECT_FLOAT_EQ(sol[ofs++], 0);

ASSERT_TRUE(sim.addMixedMADOF(2, 2));
Vector sol2(sim.getNoNodes(1) + 2*sim.getNoNodes(2));
Vector lsol2(2*sim.getNoNodes(2));
for (i = 0; i < sim.getNoNodes(2); i++)
Vector sol2(n1 + 2*n2);
Vector lsol2(2*n2);
for (i = 0; i < n2; i++)
lsol2[2*i] = lsol2[2*i+1] = i+1;

ASSERT_TRUE(sim.addMixedMADOF(2, 2));
sim.injectPatchSolution(sol2, lsol2, pch, 2, 2);
for (i = ofs = 0; i < sim.getNoNodes(1); i++, ofs++)
EXPECT_FLOAT_EQ(sol2[ofs], 0);

for (i = 0; i < sim.getNoNodes(2); i++, ofs += 2) {
EXPECT_FLOAT_EQ(sol2[ofs], i+1);
EXPECT_FLOAT_EQ(sol2[ofs+1], i+1);
for (i = ofs = 0; i < n1; i++)
EXPECT_FLOAT_EQ(sol2[ofs++], 0);
for (i = 0; i < n2; i++) {
EXPECT_FLOAT_EQ(sol2[ofs++], i+1);
EXPECT_FLOAT_EQ(sol2[ofs++], i+1);
}
}


TEST(TestSIM3D, Periodic)
{
ASMmxBase::Type = ASMmxBase::REDUCED_CONT_RAISE_BASIS1;

SIM3D sim({3,1});
ASSERT_TRUE(sim.createDefaultModel());

ASMs3D* pch = dynamic_cast<ASMs3D*>(sim.getPatch(1));
ASSERT_TRUE(pch != nullptr);
ASSERT_TRUE(pch->uniformRefine(0,1));
ASSERT_TRUE(pch->uniformRefine(1,1));
ASSERT_TRUE(pch->uniformRefine(2,1));
ASSERT_TRUE(sim.createFEMmodel());

pch->closeBoundaries(1,0,1);
pch->closeBoundaries(3,0,1);

ASSERT_TRUE(sim.preprocess());
}

0 comments on commit f672dbd

Please sign in to comment.