Skip to content

Commit

Permalink
WIP selection of lengthscales
Browse files Browse the repository at this point in the history
  • Loading branch information
timofeymukha committed Oct 12, 2021
1 parent 9645bec commit eca1c1b
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 15 deletions.
10 changes: 7 additions & 3 deletions samplers/MultiCellSampler/MultiCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void Foam::MultiCellSampler::createIndexList()
}
}

void Foam::MultiCellSampler::createLengthList()
void Foam::MultiCellSampler::createLengthList(const word lengthScaleType)
{
// Cell volumes
const scalarField & V = mesh_.V();
Expand All @@ -176,11 +176,13 @@ Foam::MultiCellSampler::MultiCellSampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex,
bool excludeWallAdjacent
)
:
Sampler(p, averagingTime, interpolationType, cellFinderType, hIsIndex),
Sampler(p, averagingTime, interpolationType, cellFinderType,
lengthScaleType, hIsIndex),
indexList_(p.size()),
h_(p.size()),
lengthList_(p.size()),
Expand All @@ -198,7 +200,7 @@ Foam::MultiCellSampler::MultiCellSampler
}

createIndexList();
createLengthList();
createLengthList(lengthScaleType);

addField
(
Expand All @@ -219,6 +221,7 @@ Foam::MultiCellSampler::MultiCellSampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex,
bool excludeWallAdjacent
)
Expand All @@ -229,6 +232,7 @@ Foam::MultiCellSampler::MultiCellSampler
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex,
excludeWallAdjacent
)
Expand Down
6 changes: 4 additions & 2 deletions samplers/MultiCellSampler/MultiCellSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ protected:
// Protected Member Functions

//- Create list of cell-indices from where data is sampled
virtual void createIndexList();
void createIndexList() override;

//- Compute the length-scales
virtual void createLengthList();
void createLengthList(const word lengthScaleType) override;

public:

Expand All @@ -91,6 +91,7 @@ public:
scalar averagingTime,
const word interpolationType="cell",
const word cellFinderType="Tree",
const word lengthScaleType="CubeRootVol",
bool hIsIndex=false,
bool excludeWallAdjacent=false
);
Expand All @@ -103,6 +104,7 @@ public:
scalar averagingTime,
const word interpolationType="cell",
const word cellFinderType="Tree",
const word lengthScaleType="CubeRootVol",
bool hIsIndex=false,
bool excludeWallAdjacent=false
);
Expand Down
19 changes: 18 additions & 1 deletion samplers/Sampler/Sampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Foam::autoPtr<Foam::Sampler> Foam::Sampler::New
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
{
Expand All @@ -75,6 +76,7 @@ Foam::autoPtr<Foam::Sampler> Foam::Sampler::New
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex
);
}
Expand All @@ -91,6 +93,8 @@ Foam::autoPtr<Foam::Sampler> Foam::Sampler::New
dict.lookupOrDefault<word>("interpolationType", "cell");
word cellFinderType =
dict.lookupOrDefault<word>("sampler", "Tree");
word lengthScaleType =
dict.lookupOrDefault<word>("lengthScale", "CubeRootVol");
bool hIsIndex =
dict.lookupOrDefault<bool>("hIsIndex", false);

Expand All @@ -101,6 +105,7 @@ Foam::autoPtr<Foam::Sampler> Foam::Sampler::New
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex
);
}
Expand Down Expand Up @@ -149,6 +154,7 @@ Foam::Sampler::Sampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
:
Expand All @@ -158,6 +164,7 @@ Foam::Sampler::Sampler
sampledFields_(0),
interpolationType_(interpolationType),
cellFinderType_(cellFinderType),
lengthScaleType_(lengthScaleType),
hIsIndex_(hIsIndex)
{
if (debug)
Expand Down Expand Up @@ -213,10 +220,19 @@ Foam::Sampler::Sampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
:
Sampler(p, averagingTime, interpolationType, cellFinderType, hIsIndex)
Sampler
(
p,
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex
)
{
}

Expand All @@ -228,6 +244,7 @@ Foam::Sampler::Sampler(const Sampler & copy)
sampledFields_(copy.sampledFields_),
interpolationType_(copy.interpolationType_),
cellFinderType_(copy.cellFinderType_),
lengthScaleType_(copy.lengthScaleType_),
hIsIndex_(copy.hIsIndex_)
{
if (debug)
Expand Down
15 changes: 14 additions & 1 deletion samplers/Sampler/Sampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ protected:
//- Type of cellFinder to use for finding sampling cells.
word cellFinderType_;

//- Way to compute the length-scale for the cells
word lengthScaleType_;

//- Whether the h field is the consecutive index of the samping cell
bool hIsIndex_;

Expand All @@ -85,7 +88,7 @@ protected:
virtual void createIndexList() = 0;

//- Compute the length-scales
virtual void createLengthList(){}
virtual void createLengthList(const word lengthScaleType){}

//- Create fields
virtual void createFields();
Expand All @@ -106,6 +109,7 @@ public:
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
);

Expand All @@ -117,6 +121,7 @@ public:
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
);

Expand All @@ -135,6 +140,7 @@ public:
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
);

Expand Down Expand Up @@ -184,6 +190,11 @@ public:
{
return cellFinderType_;
}

word lengthScaleType() const
{
return lengthScaleType_;
}

bool hIsIndex() const
{
Expand Down Expand Up @@ -217,6 +228,7 @@ public:
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
),
(
Expand All @@ -225,6 +237,7 @@ public:
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex
)
);
Expand Down
67 changes: 63 additions & 4 deletions samplers/SingleCellSampler/SingleCellSampler.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ License
#include "scalarListIOList.H"
#include "CrawlingCellFinder.H"
#include "TreeCellFinder.H"
#include "surfaceMesh.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down Expand Up @@ -160,7 +161,21 @@ void Foam::SingleCellSampler::createIndexList()
}


void Foam::SingleCellSampler::createLengthList()
void Foam::SingleCellSampler::createLengthList(const word lengthScaleType)
{
if (lengthScaleType == "CubeRootVol")
{
createLengthListCubeRootVol();
}
else if (lengthScaleType == "WallNormalDistance")
{

}

}


void Foam::SingleCellSampler::createLengthListCubeRootVol()
{
// Cell volumes
const scalarField & V = mesh_.V();
Expand All @@ -169,7 +184,47 @@ void Foam::SingleCellSampler::createLengthList()
{
lengthList_[i] = pow(V[indexList_[i]], 1.0/3.0);
}

}


void Foam::SingleCellSampler::createLengthListWallNormalDistance()
{

const vectorField & faceCentres = mesh().Cf().primitiveField();
const List<cell> & cells = mesh().cells();
const vectorField & patchFaceCentres = patch().Cf();
const List<face> & faces = mesh().faces();

forAll(lengthList_, i)
{
const label index = indexList_[i];
const cell cellI = cells[index];

const vector patchFaceI = patchFaceCentres[i];

// Find face with min distance from the wall face
scalar minDist = GREAT;
label minDistFace = 0;
for (int j=0; j<cellI.nFaces(); j++)
{
const vector faceJ = faceCentres[cellI[j]];

const scalar dist = mag(faceJ - patchFaceI);
if (dist < minDist)
{
minDist = dist;
minDistFace = cellI[j];
}
}

label opposingFace =
cellI.opposingFaceLabel(minDistFace, faces);
vector opposingFaceCentre = faceCentres[opposingFace];
vector minDistFaceCentre = faceCentres[minDistFace];

lengthList_[i] = mag(opposingFaceCentre - minDistFaceCentre);

}
}


Expand All @@ -181,16 +236,18 @@ Foam::SingleCellSampler::SingleCellSampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
:
Sampler(p, averagingTime, interpolationType, cellFinderType, hIsIndex),
Sampler(p, averagingTime, interpolationType, cellFinderType,
lengthScaleType, hIsIndex),
indexList_(p.size()),
lengthList_(p.size()),
h_(p.size(), 0)
{
createIndexList();
createLengthList();
createLengthList(lengthScaleType);

addField
(
Expand All @@ -211,6 +268,7 @@ Foam::SingleCellSampler::SingleCellSampler
scalar averagingTime,
const word interpolationType,
const word cellFinderType,
const word lengthScaleType,
bool hIsIndex
)
:
Expand All @@ -220,6 +278,7 @@ Foam::SingleCellSampler::SingleCellSampler
averagingTime,
interpolationType,
cellFinderType,
lengthScaleType,
hIsIndex
)
{
Expand Down
14 changes: 10 additions & 4 deletions samplers/SingleCellSampler/SingleCellSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ protected:

//- Create list of cell-indices from where data is sampled
void createIndexList() override;

//- Compute the length-scales
void createLengthList() override;
void createLengthList(const word lengthScaleType) override;

//- Compute length-scales as cubic root of the volume
void createLengthListCubeRootVol();

//- Compute length-scales as distance across wall-normal direction
void createLengthListWallNormalDistance();

public:

Expand All @@ -79,24 +85,24 @@ public:

// Constructors

//- Construct from patch and averaging time
SingleCellSampler
(
const fvPatch&,
scalar averagingTime,
const word interpolationType="cell",
const word cellFinderType="Tree",
const word lengthScaleType="CubeRootVol",
bool hIsIndex=false
);

//- Construct from type, patch and averaging time
SingleCellSampler
(
const word & samplerName,
const fvPatch & p,
scalar averagingTime,
const word interpolationType="cell",
const word cellFinderType="Tree",
const word lengthScaleType="CubeRootVol",
bool hIsIndex=false
);

Expand Down
1 change: 1 addition & 0 deletions wallModels/LOTWWallModelFvPatchScalarField.C
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ LOTWWallModelFvPatchScalarField
averagingTime(),
dict.lookupOrDefault<word>("interpolationType", "cell"),
dict.lookupOrDefault<word>("sampler", "Tree"),
dict.lookupOrDefault<word>("lengthScale", "CubeRootVol"),
dict.lookupOrDefault<bool>("hIsIndex", false)
)
)
Expand Down
Loading

0 comments on commit eca1c1b

Please sign in to comment.