Skip to content

Commit

Permalink
WIP SIngleCellSampler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Timofey Mukha committed Nov 19, 2019
1 parent 7cb961c commit 437a243
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 16 deletions.
31 changes: 29 additions & 2 deletions samplers/SingleCellSampler/SingleCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,43 @@ void Foam::SingleCellSampler::createIndexList()

scalarField hPatch = h.boundaryField()[patchIndex];

if (cellFinderType() == word("crawling"))
if (hIsIndex_ && interpolationType_ != "cell")
{
Warning
<< "SingleCellSampler: hIsIndex is set to true, there is no sense "
<< "to interpolate within the cell." << nl
<< "Will fall back to the 'cell' interpolation type, i.e. use the "
<< "cell-centred values."
<< nl;

interpolationType_ = "cell";
}

if (cellFinderType() == "Crawling")
{
CrawlingCellFinder cellFinder(patch());
cellFinder.findCellIndices(indexList_, hPatch, hIsIndex_);
}
else if (cellFinderType() == word("tree"))
else if (cellFinderType() == word("Tree"))
{
if (hIsIndex_)
{
FatalErrorInFunction
<< "SingleCellSampler: hIsIndex is not supported by the Tree "
<< "sampler. Please use the Crawling sampler or provide h as "
<< "distances."
<< abort(FatalError);
}
TreeCellFinder cellFinder(patch());
cellFinder.findCellIndices(indexList_, hPatch);
}
else
{
FatalErrorInFunction
<< "SingleCellSampler: cellFinderType should be either Tree or "
<< "Crawling. Current input is " << cellFinderType()
<< abort(FatalError);
}


const vectorField & patchFaceCentres = patch().Cf();
Expand Down
12 changes: 6 additions & 6 deletions samplers/SingleCellSampler/SingleCellSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public:
(
const fvPatch&,
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
bool hIsIndex
const word interpolationType="cell",
const word cellFinderType="Tree",
bool hIsIndex=false
);

//- Construct from type, patch and averaging time
Expand All @@ -95,9 +95,9 @@ public:
const word & samplerName,
const fvPatch & p,
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
bool hIsIndex
const word interpolationType="cell",
const word cellFinderType="Tree",
bool hIsIndex=false
);

SingleCellSampler(const SingleCellSampler &) = default;
Expand Down
269 changes: 265 additions & 4 deletions tests/samplers/SingleCellSampler/testSingleCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@
#include <functional>
#include "gtest.h"
#undef Log
#include "gmock/gmock.h"
#include "fixtures.H"


class SingleCellSamplerTest : public ChannelFlow
{};

TEST_F(SingleCellSamplerTest, FullConstructor)
TEST_F(SingleCellSamplerTest, ConstructorDefaults)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0
);

ASSERT_EQ(&sampler.patch(), &patch);
ASSERT_EQ(sampler.averagingTime(), 3.0);
ASSERT_EQ(sampler.interpolationType(), "cell");
ASSERT_EQ(sampler.cellFinderType(), "Tree");
ASSERT_EQ(sampler.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());
}

TEST_F(SingleCellSamplerTest, ConstructorCellCrawlingTrue)
{
extern argList * mainArgs;
const argList & args = *mainArgs;
Expand All @@ -27,18 +55,251 @@ TEST_F(SingleCellSamplerTest, FullConstructor)
patch,
3.0,
"cell",
"crawling",
"Crawling",
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.hIsIndex(), true);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.1);
}
}


TEST_F(SingleCellSamplerTest, ConstructorCellCrawlingFalse)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cell",
"Crawling",
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.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.1);
}

}


TEST_F(SingleCellSamplerTest, ConstructorCellPointCrawlingTrue)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cellPoint",
"Crawling",
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.cellFinderType(), "Crawling");
ASSERT_EQ(sampler.hIsIndex(), true);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.10);
}

}

TEST_F(SingleCellSamplerTest, ConstructorCellPointCrawlingFalse)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cellPoint",
"Crawling",
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.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.11);
}

}


TEST_F(SingleCellSamplerTest, ConstructorCellTreeTrue)
{
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
(
{
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cell",
"Tree",
true
);
},
"FATAL ERROR"
);
}


TEST_F(SingleCellSamplerTest, ConstructorCellTreeFalse)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cell",
"Tree",
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.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.1);
}

// const scalarField & hPatch = h.boundaryFieldRef()[patch.index()] == 10.0;

}


TEST_F(SingleCellSamplerTest, ConstructorCellPointTreeFalse)
{
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"];
SingleCellSampler sampler
(
"SingleCellSampler",
patch,
3.0,
"cellPoint",
"Tree",
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.hIsIndex(), false);
ASSERT_EQ(&sampler.mesh(), &mesh);
ASSERT_EQ(sampler.indexList().size(), patch.size());
ASSERT_EQ(sampler.lengthList().size(), patch.size());
ASSERT_EQ(sampler.h().size(), patch.size());

forAll(sampler.h(), i)
{
ASSERT_FLOAT_EQ(sampler.h()[i], 0.11);
}
}
2 changes: 1 addition & 1 deletion tests/testCases/channel_flow/0/h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ boundaryField
bottomWall
{
type fixedValue;
value uniform 0.1;
value uniform 0.11;
}
topWall
{
Expand Down

0 comments on commit 437a243

Please sign in to comment.