Skip to content

Commit

Permalink
TreeCellFinder tests and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Timofey Mukha committed Nov 11, 2019
1 parent 49ee5cc commit 221502e
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 188 deletions.
79 changes: 0 additions & 79 deletions cellFinders/CellFinder/CellFinder.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ License
#include "objectRegistry.H"
#include "IOField.H"
#include "codeRules.H"
#include "patchDistMethod.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down Expand Up @@ -83,87 +82,9 @@ Foam::autoPtr<Foam::CellFinder> Foam::CellFinder::New

void Foam::CellFinder::createFields() const
{

}


Foam::tmp<Foam::volScalarField> Foam::CellFinder::distanceField() const
{

// Grab h for the current patch
const volScalarField & h = mesh_.lookupObject<volScalarField> ("h");
if (debug)
{
Info<< "CellFinder: Creating dist field" << nl;
}

tmp<volScalarField> dist
(
new volScalarField
(
IOobject
(
"dist",
mesh_.time().timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("dist", dimLength, 0),
h.boundaryField().types()
)
);

bool precomputedDist =
#ifdef FOAM_NEW_GEOMFIELD_RULES
mag(max(dist().primitiveField())) > VSMALL;
#else
mag(max(dist().internalField())) > VSMALL;
#endif

if (debug)
{
Info<<"CellFinder: using precumputed distance field" << nl;
}

if (!precomputedDist)
{
labelHashSet patchIDs(1);
patchIDs.insert(patch().index());

dictionary methodDict = dictionary();
methodDict.lookupOrAddDefault(word("method"), word("meshWave"));

if (debug)
{
Info<< "Initializing patchDistanceMethod" << nl;
}

autoPtr<patchDistMethod> pdm
(
patchDistMethod::New
(
methodDict,
mesh_,
patchIDs
)
);

if (debug)
{
Info<< "CellFinder: Computing dist field" << nl;
}
#ifdef FOAM_NEW_TMP_RULES
pdm->correct(dist.ref());
#else
pdm->correct(dist());
#endif
}

return dist;
}


// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Expand Down
3 changes: 0 additions & 3 deletions cellFinders/CellFinder/CellFinder.H
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ protected:

// Protected Member Functions

//- Compute distance field
tmp<volScalarField> distanceField() const;

void createFields() const;

public:
Expand Down
101 changes: 96 additions & 5 deletions cellFinders/TreeCellFinder/TreeCellFinder.C
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,38 @@ void Foam::TreeCellFinder::findCellIndices
point = faceCentres[i] - faceNormals[i]*h[i];

// If h is zero, or the point is outside the domain,
// set it to distance to adjacent cell's centre
// Set the cellIndexList component accordingly
// grab the wall-adjacent cell
bool inside =
#ifdef FOAM_VOLUMETYPE_NOT_CAPITAL
boundaryTreePtr->getVolumeType(point) == volumeType::inside;
#else
boundaryTreePtr->getVolumeType(point) == volumeType::INSIDE;
#endif
if ((h[i] == 0) || (!inside) || (treePtr->nodes().empty()))
if ((h[i] <= 0) || (!inside) || (treePtr->nodes().empty()))
{
//h_[i] = mag(cellCentres[i] - faceCentres[i]);
if (h[i] < 0)
{
Warning
<< "TreeCellFinder: " << h[i]
<< " is negative and thus not a valid distance. "
<< "Will fall back to wall-adjacent cell for face "
<< i << " on patch " << patch().name() << nl;
}
else if (!inside)
{
Warning
<< "TreeCellFinder: the point " << h[i]
<< " away from the wall is outside the domain. "
<< "Will fall back to wall-adjacent cell for face "
<< i << " on patch " << patch().name() << nl;
}
indexList[i] = faceCells[i];
}
else
{

pih = treePtr->findNearest(point, treePtr->bb().mag());
indexList[i] = searchCellLabels[pih.index()];
//h_[i] = mag(C[indexList_[i]] - faceCentres[i]);
}
}
if (debug)
Expand Down Expand Up @@ -477,4 +490,82 @@ Foam::TreeCellFinder::findCandidateCellLabels
return tCandidates;
}

Foam::tmp<Foam::volScalarField> Foam::TreeCellFinder::distanceField() const
{

// Grab h for the current patch
const volScalarField & h = mesh_.lookupObject<volScalarField> ("h");
if (debug)
{
Info<< "CellFinder: Creating dist field" << nl;
}

tmp<volScalarField> dist
(
new volScalarField
(
IOobject
(
"dist",
mesh_.time().timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("dist", dimLength, 0),
h.boundaryField().types()
)
);

bool precomputedDist =
#ifdef FOAM_NEW_GEOMFIELD_RULES
mag(max(dist().primitiveField())) > VSMALL;
#else
mag(max(dist().internalField())) > VSMALL;
#endif

if (debug)
{
Info<<"CellFinder: using precumputed distance field" << nl;
}

if (!precomputedDist)
{
labelHashSet patchIDs(1);
patchIDs.insert(patch().index());

dictionary methodDict = dictionary();
methodDict.lookupOrAddDefault(word("method"), word("meshWave"));

if (debug)
{
Info<< "Initializing patchDistanceMethod" << nl;
}

autoPtr<patchDistMethod> pdm
(
patchDistMethod::New
(
methodDict,
mesh_,
patchIDs
)
);

if (debug)
{
Info<< "CellFinder: Computing dist field" << nl;
}
#ifdef FOAM_NEW_TMP_RULES
pdm->correct(dist.ref());
#else
pdm->correct(dist());
#endif
}

return dist;
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
4 changes: 4 additions & 0 deletions cellFinders/TreeCellFinder/TreeCellFinder.H
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SourceFiles
#include "runTimeSelectionTables.H"
#include "addToRunTimeSelectionTable.H"
#include "CellFinder.H"
#include "patchDistMethod.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Expand Down Expand Up @@ -88,6 +89,9 @@ public:

// Member functions

//- Compute distance field
tmp<volScalarField> distanceField() const;

//- Find the sampling cell indices for a single cell sampler
void findCellIndices
(
Expand Down
Loading

0 comments on commit 221502e

Please sign in to comment.