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 May 7, 2019
1 parent 730c548 commit 2a9a91a
Showing 1 changed file with 53 additions and 30 deletions.
83 changes: 53 additions & 30 deletions src/SIM/Test/TestSIM.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

Expand Down Expand Up @@ -102,57 +103,57 @@ 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);
}


Expand All @@ -162,34 +163,56 @@ TEST(TestSIM2D, InjectPatchSolution)
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 2a9a91a

Please sign in to comment.