Skip to content

Commit

Permalink
WIP lengthscale tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timofeymukha committed Nov 17, 2021
1 parent eca1c1b commit 40c0b44
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
37 changes: 37 additions & 0 deletions tests/samplers/MultiCellSampler/testMultiCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ TEST_F(MultiCellSamplerTest, ConstructorDefaults)
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -64,6 +65,7 @@ TEST_F(MultiCellSamplerTest, ConstructorCellCrawling)
3.0,
"cell",
"Crawling",
"CubeRootVol",
true
);

Expand Down Expand Up @@ -107,6 +109,7 @@ TEST_F(MultiCellSamplerTest, ConstructorAttemptCellPoint)
3.0,
"cellPoint",
"Crawling",
"CubeRootVol",
false
);
},
Expand Down Expand Up @@ -138,6 +141,7 @@ TEST_F(MultiCellSamplerTest, ConstructorAttemptTreeHIsIndex)
3.0,
"cell",
"Tree",
"CubeRootVol",
true
);
},
Expand Down Expand Up @@ -173,6 +177,7 @@ TEST_F(MultiCellSamplerTest, ConstructorTree)
3.0,
"cell",
"Tree",
"CubeRootVol",
false
);

Expand Down Expand Up @@ -218,6 +223,7 @@ TEST_F(MultiCellSamplerTest, AttemptInvalidCellFinderName)
3.0,
"cell",
"RandomName",
"CubeRootCol",
true
);
},
Expand All @@ -226,6 +232,35 @@ TEST_F(MultiCellSamplerTest, AttemptInvalidCellFinderName)
}


TEST_F(MultiCellSamplerTest, AttemptInvalidLengthScaleName)
{
extern argList * mainArgs;
const argList & args = *mainArgs;
Time runTime(Foam::Time::controlDictName, args);

autoPtr<fvMesh> meshPtr = createMesh(runTime);
const fvMesh & mesh = meshPtr();
createSamplingHeightField(mesh);

const fvPatch & patch = mesh.boundary()["bottomWall"];

ASSERT_DEATH
(
{
MultiCellSampler sampler
(
"MultiCellSampler",
patch,
3.0,
"cell",
"Tree",
"RandomName",
true
);
},
"FATAL ERROR"
);
}
TEST_F(MultiCellSamplerTest, Sample)
{
extern argList * mainArgs;
Expand Down Expand Up @@ -260,6 +295,7 @@ TEST_F(MultiCellSamplerTest, Sample)
0.02,
"cell",
"Crawling",
"CubeRootVol",
3
);

Expand Down Expand Up @@ -309,6 +345,7 @@ TEST_F(MultiCellSamplerTest, AddField)
0.02,
"cell",
"Crawling",
"CubeRootVol",
3
);

Expand Down
13 changes: 11 additions & 2 deletions tests/samplers/Sampler/testSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ namespace Foam
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex

)
:
Sampler(p, averagingTime, interpolationType, cellFinderType,
hIsIndex)
lengthScaleType, hIsIndex)
{}

DummySampler
Expand All @@ -37,11 +38,12 @@ namespace Foam
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
:
Sampler(p, averagingTime, interpolationType, cellFinderType,
hIsIndex)
lengthScaleType, hIsIndex)
{}

DummySampler(const DummySampler &) = default;
Expand Down Expand Up @@ -83,13 +85,15 @@ TEST_F(SamplerTest, FullConstructor)
3.0,
"cell",
"crawling",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.Sampler::patch(), &patch);
ASSERT_EQ(sampler.Sampler::averagingTime(), 3.0);
ASSERT_EQ(sampler.Sampler::interpolationType(), "cell");
ASSERT_EQ(sampler.Sampler::cellFinderType(), "crawling");
ASSERT_EQ(sampler.Sampler::lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.Sampler::hIsIndex(), false);
ASSERT_EQ(&sampler.Sampler::mesh(), &mesh);
ASSERT_EQ(sampler.Sampler::nSampledFields(), 0);
Expand Down Expand Up @@ -121,6 +125,7 @@ TEST_F(SamplerTest, NewNamePatchAveragingTime)
3.0,
"cell",
"crawling",
"CubeRootVol",
false
)
);
Expand All @@ -130,6 +135,7 @@ TEST_F(SamplerTest, NewNamePatchAveragingTime)
ASSERT_EQ(sampler().Sampler::averagingTime(), 3.0);
ASSERT_EQ(sampler().Sampler::interpolationType(), "cell");
ASSERT_EQ(sampler().Sampler::cellFinderType(), "crawling");
ASSERT_EQ(sampler().Sampler::lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler().Sampler::hIsIndex(), false);
ASSERT_EQ(&sampler().Sampler::mesh(), &mesh);
ASSERT_EQ(sampler().Sampler::nSampledFields(), 0);
Expand Down Expand Up @@ -193,6 +199,7 @@ TEST_F(SamplerTest, CreateFields)
3.0,
"cell",
"crawling",
"CubeRootVol",
false
);

Expand All @@ -217,6 +224,7 @@ TEST_F(SamplerTest, Copy)
3.0,
"cell",
"crawling",
"CubeRootVol",
false
);
sampler.addField(new SampledVelocityField(patch));
Expand Down Expand Up @@ -272,6 +280,7 @@ TEST_F(SamplerTest, AddField)
3.0,
"cell",
"crawling",
"CubeRootVol",
false
);

Expand Down
55 changes: 55 additions & 0 deletions tests/samplers/SingleCellSampler/testSingleCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TEST_F(SingleCellSamplerTest, ConstructorDefaults)
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand All @@ -58,13 +59,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellCrawlingHIsIndex)
3.0,
"cell",
"Crawling",
"CubeRootVol",
true
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), true);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -96,13 +99,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellCrawlingHIsDistance)
3.0,
"cell",
"Crawling",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -135,13 +140,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellPointCrawlingHIsIndex)
3.0,
"cellPoint",
"Crawling",
"CubeRootVol",
true
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), true);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -181,13 +188,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellPointCrawlingHIsDistance)
3.0,
"cellPoint",
"Crawling",
"WallNormalDistance",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cellPoint");
ASSERT_EQ(sampler.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.lengthScaleType(), "WallNormalDistance");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -228,13 +237,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellPointCrawlingHIsDistanceFirstCell)
3.0,
"cellPoint",
"Crawling",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cellPoint");
ASSERT_EQ(sampler.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.cellFinderType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -270,6 +281,7 @@ TEST_F(SingleCellSamplerTest, ConstructorCellTreeHIsIndex)
3.0,
"cell",
"Tree",
"CubeRootVol",
true
);
},
Expand All @@ -296,13 +308,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellTreeHIsDistance)
3.0,
"cell",
"Tree",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -341,13 +355,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellPointTreeHIsDistance)
3.0,
"cellPoint",
"Tree",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cellPoint");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -388,13 +404,15 @@ TEST_F(SingleCellSamplerTest, ConstructorCellPointTreeHIsDistanceFirstCell)
3.0,
"cellPoint",
"Tree",
"CubeRootVol",
false
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cellPoint");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.lengthScaleType(), "CubeRootVol");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
Expand Down Expand Up @@ -443,6 +461,7 @@ TEST_F(SingleCellSamplerTest, Sample)
0.02,
"cell",
"Crawling",
"CubeRootVol",
3
);

Expand Down Expand Up @@ -492,11 +511,47 @@ TEST_F(SingleCellSamplerTest, AddField)
0.02,
"cell",
"Crawling",
"CubeRootVol",
3
);

sampler.addField(new SampledPGradField(patch));

ASSERT_EQ(sampler.nSampledFields(), 3);
ASSERT_TRUE(sampler.db().foundObject<scalarListIOList>("pGrad"));
}


TEST_F(SingleCellSamplerTest, CreateLengthList)
{
extern argList * mainArgs;
const argList & args = *mainArgs;
Time runTime(Foam::Time::controlDictName, args);

autoPtr<fvMesh> meshPtr = createMesh(runTime);
const fvMesh & mesh = meshPtr();
createSamplingHeightField(mesh);

volScalarField & h = const_cast<volScalarField &>
(
mesh.thisDb().lookupObject<volScalarField>("h")
);

const fvPatch & patch = mesh.boundary()["bottomWall"];

h.boundaryFieldRef()[patch.index()] == 0.5;

SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0
);

ASSERT_EQ(sampler.lengthList().size(), patch.size());

for (int i=0; i< sampler.lengthList().size(); i++)
{
ASSERT_FLOAT_EQ(sampler.lengthList()[i], 0.2);
}
}

0 comments on commit 40c0b44

Please sign in to comment.