Skip to content
Permalink
Browse files

mapFieldsPar: updated to enable mapping from source patches (instead …

…of recreating)

  - patchFields now get mapped (instead of created)
  - with -consistent it now maps all patches except for processor ones (they are
    the only ones that are processor-local)
  - all constraint patches get evaluated after mapping to bring them up to date.

Patch contributed by Mattijs Janssens
  • Loading branch information...
Henry Weller
Henry Weller committed Jun 21, 2016
1 parent e392826 commit d67a1df92eacc0f69912a44a817cb36f72ad2e0d
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -35,6 +35,88 @@ License
namespace Foam
{

template<class Type>
void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
{
typename GeometricField<Type, fvPatchField, volMesh>::
Boundary& fldBf = fld.boundaryFieldRef();

if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
label nReq = Pstream::nRequests();

forAll(fldBf, patchi)
{
fvPatchField<Type>& tgtField = fldBf[patchi];

if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
tgtField.initEvaluate(Pstream::defaultCommsType);
}
}

// Block for any outstanding requests
if
(
Pstream::parRun()
&& Pstream::defaultCommsType == Pstream::nonBlocking
)
{
Pstream::waitRequests(nReq);
}

forAll(fldBf, patchi)
{
fvPatchField<Type>& tgtField = fldBf[patchi];

if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
tgtField.evaluate(Pstream::defaultCommsType);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule =
fld.mesh().globalData().patchSchedule();

forAll(patchSchedule, patchEvali)
{
label patchi = patchSchedule[patchEvali].patch;
fvPatchField<Type>& tgtField = fldBf[patchi];

if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
if (patchSchedule[patchEvali].init)
{
tgtField.initEvaluate(Pstream::scheduled);
}
else
{
tgtField.evaluate(Pstream::scheduled);
}
}
}
}
}


template<class Type, class CombineOp>
void MapVolFields
(
@@ -57,8 +139,6 @@ void MapVolFields

if (selectedFields.empty() || selectedFields.found(fieldName))
{
Info<< " interpolating " << fieldName << endl;

const fieldType fieldSource(*fieldIter(), meshSource);

IOobject targetIO
@@ -71,21 +151,30 @@ void MapVolFields

if (targetIO.headerOk())
{
Info<< " interpolating onto existing field "
<< fieldName << endl;
fieldType fieldTarget(targetIO, meshTarget);

interp.mapSrcToTgt(fieldSource, cop, fieldTarget);

evaluateConstraintTypes(fieldTarget);

fieldTarget.write();
}
else
{
Info<< " creating new field "
<< fieldName << endl;

targetIO.readOpt() = IOobject::NO_READ;

tmp<fieldType>
tfieldTarget(interp.mapSrcToTgt(fieldSource, cop));

fieldType fieldTarget(targetIO, tfieldTarget);

evaluateConstraintTypes(fieldTarget);

fieldTarget.write();
}
}
@@ -263,11 +263,11 @@ int main(int argc, char *argv[])

if (!consistent)
{
IOdictionary mapFieldsParDict
IOdictionary mapFieldsDict
(
IOobject
(
"mapFieldsParDict",
"mapFieldsDict",
runTimeTarget.system(),
runTimeTarget,
IOobject::MUST_READ_IF_MODIFIED,
@@ -276,8 +276,8 @@ int main(int argc, char *argv[])
)
);

mapFieldsParDict.lookup("patchMap") >> patchMap;
mapFieldsParDict.lookup("cuttingPatches") >> cuttingPatches;
mapFieldsDict.lookup("patchMap") >> patchMap;
mapFieldsDict.lookup("cuttingPatches") >> cuttingPatches;
}

#include "setTimeIndex.H"
@@ -326,7 +326,7 @@ int main(int argc, char *argv[])
meshSource,
meshTarget,
patchMap,
addProcessorPatches(meshTarget, cuttingPatches),
cuttingPatches,
mapMethod,
subtract,
selectedFields,
@@ -1,5 +1,13 @@
{
instantList sourceTimes = runTimeSource.times();

if (sourceTimes.empty())
{
FatalErrorInFunction << "No result times in source "
<< runTimeSource.caseName()
<< exit(FatalError);
}

label sourceTimeIndex = runTimeSource.timeIndex();
if (args.optionFound("sourceTime"))
{
@@ -153,7 +153,7 @@ Foam::fvPatchField<Type>::fvPatchField
patchType_(ptf.patchType_)
{
// For unmapped faces set to internal field value (zero-gradient)
if (notNull(iF) && iF.size())
if (notNull(iF) && mapper.hasUnmapped())
{
fvPatchField<Type>::operator=(this->patchInternalField());
}
@@ -243,7 +243,7 @@ void Foam::fvPatchField<Type>::autoMap
{
Field<Type>& f = *this;

if (!this->size())
if (!this->size() && !mapper.distributed())
{
f.setSize(mapper.size());
if (f.size())
@@ -257,38 +257,39 @@ void Foam::fvPatchField<Type>::autoMap
Field<Type>::autoMap(mapper);

// For unmapped faces set to internal field value (zero-gradient)
if
(
mapper.direct()
&& notNull(mapper.directAddressing())
&& mapper.directAddressing().size()
)
if (mapper.hasUnmapped())
{
Field<Type> pif(this->patchInternalField());

const labelList& mapAddressing = mapper.directAddressing();

forAll(mapAddressing, i)
if
(
mapper.direct()
&& notNull(mapper.directAddressing())
&& mapper.directAddressing().size()
)
{
if (mapAddressing[i] < 0)
const labelList& mapAddressing = mapper.directAddressing();

forAll(mapAddressing, i)
{
f[i] = pif[i];
if (mapAddressing[i] < 0)
{
f[i] = pif[i];
}
}
}
}
else if (!mapper.direct() && mapper.addressing().size())
{
Field<Type> pif(this->patchInternalField());

const labelListList& mapAddressing = mapper.addressing();

forAll(mapAddressing, i)
else if (!mapper.direct() && mapper.addressing().size())
{
const labelList& localAddrs = mapAddressing[i];
const labelListList& mapAddressing = mapper.addressing();

if (!localAddrs.size())
forAll(mapAddressing, i)
{
f[i] = pif[i];
const labelList& localAddrs = mapAddressing[i];

if (!localAddrs.size())
{
f[i] = pif[i];
}
}
}
}
@@ -72,21 +72,15 @@ bool Foam::directMethod::findInitialSeeds

if (mapFlag[srcI])
{
const pointField
pts(srcCells[srcI].points(srcFaces, srcPts).xfer());

forAll(pts, ptI)
{
const point& pt = pts[ptI];
label tgtI = tgt_.cellTree().findInside(pt);
const point srcCtr(srcCells[srcI].centre(srcPts, srcFaces));
label tgtI = tgt_.cellTree().findInside(srcCtr);

if (tgtI != -1 && intersect(srcI, tgtI))
{
srcSeedI = srcI;
tgtSeedI = tgtI;

return true;
}
return true;
}
}
}
@@ -178,8 +172,6 @@ void Foam::directMethod::appendToDirectSeeds
const labelList& srcNbr = src_.cellCells()[srcSeedI];
const labelList& tgtNbr = tgt_.cellCells()[tgtSeedI];

const vectorField& srcCentre = src_.cellCentres();

forAll(srcNbr, i)
{
label srcI = srcNbr[i];
@@ -194,15 +186,7 @@ void Foam::directMethod::appendToDirectSeeds
{
label tgtI = tgtNbr[j];

if
(
tgt_.pointInCell
(
srcCentre[srcI],
tgtI,
polyMesh::FACE_PLANES
)
)
if (intersect(srcI, tgtI))
{
// new match - append to lists
found = true;

0 comments on commit d67a1df

Please sign in to comment.
You can’t perform that action at this time.