Commit c42f04e8 authored by mattijs's avatar mattijs
Browse files

multi-region directMapped

parent 485ea4c8
......@@ -103,8 +103,8 @@ public:
const dictionary&
);
//- Construct by mapping given solidWallMixedTemperatureCoupledFvPatchScalarField
// onto a new patch
//- Construct by mapping given
// solidWallMixedTemperatureCoupledFvPatchScalarField onto a new patch
solidWallMixedTemperatureCoupledFvPatchScalarField
(
const solidWallMixedTemperatureCoupledFvPatchScalarField&,
......
......@@ -360,7 +360,7 @@ DebugSwitches
diagonal 0;
dictionary 0;
dimensionSet 1;
directMapped 0;
directMappedBase 0;
directMappedPatch 0;
directMappedVelocityFlux 0;
directionMixed 0;
......
......@@ -131,18 +131,36 @@ public:
return constructSize_;
}
//- Constructed data size
label& constructSize()
{
return constructSize_;
}
//- From subsetted data back to original data
const labelListList& subMap() const
{
return subMap_;
}
//- From subsetted data back to original data
labelListList& subMap()
{
return subMap_;
}
//- From subsetted data to new reconstructed data
const labelListList& constructMap() const
{
return constructMap_;
}
//- From subsetted data to new reconstructed data
labelListList& constructMap()
{
return constructMap_;
}
//- Calculate a schedule. See above.
static List<labelPair> schedule
(
......
......@@ -24,6 +24,7 @@ $(constraintFvPatches)/processor/processorFvPatch.C
derivedFvPatches = $(fvPatches)/derived
$(derivedFvPatches)/wall/wallFvPatch.C
$(derivedFvPatches)/directMapped/directMappedFvPatch.C
$(derivedFvPatches)/directMapped/directMappedWallFvPatch.C
wallDist = fvMesh/wallDist
$(wallDist)/wallPointYPlus/wallPointYPlus.C
......
......@@ -25,7 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "directMappedFixedValueFvPatchField.H"
#include "directMappedFvPatch.H"
#include "directMappedPatchBase.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -61,7 +61,7 @@ directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
setAverage_(ptf.setAverage_),
average_(ptf.average_)
{
if (!isType<directMappedFvPatch>(this->patch()))
if (!isA<directMappedPatchBase>(this->patch().patch()))
{
FatalErrorIn
(
......@@ -74,7 +74,7 @@ directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
" const fvPatchFieldMapper&\n"
")\n"
) << "\n patch type '" << p.type()
<< "' not type '" << typeName << "'"
<< "' not type '" << directMappedPatchBase::typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << this->dimensionedInternalField().name()
<< " in file " << this->dimensionedInternalField().objectPath()
......@@ -95,7 +95,7 @@ directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
setAverage_(readBool(dict.lookup("setAverage"))),
average_(pTraits<Type>(dict.lookup("average")))
{
if (!isType<directMappedFvPatch>(this->patch()))
if (!isA<directMappedPatchBase>(this->patch().patch()))
{
FatalErrorIn
(
......@@ -107,12 +107,19 @@ directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
" const dictionary& dict\n"
")\n"
) << "\n patch type '" << p.type()
<< "' not type '" << typeName << "'"
<< "' not type '" << directMappedPatchBase::typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << this->dimensionedInternalField().name()
<< " in file " << this->dimensionedInternalField().objectPath()
<< exit(FatalError);
}
// Force calculation of schedule (uses parallel comms)
const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
(
this->patch().patch()
);
(void)mpp.map().schedule();
}
......@@ -143,70 +150,6 @@ directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void directMappedFixedValueFvPatchField<Type>::getNewValues
(
const directMappedPolyPatch& mpp,
const Field<Type>& sendValues,
Field<Type>& newValues
) const
{
// Get the scheduling information
const List<labelPair>& schedule = mpp.schedule();
const labelListList& sendLabels = mpp.sendLabels();
const labelListList& receiveFaceLabels = mpp.receiveFaceLabels();
forAll(schedule, i)
{
const labelPair& twoProcs = schedule[i];
label sendProc = twoProcs[0];
label recvProc = twoProcs[1];
if (Pstream::myProcNo() == sendProc)
{
OPstream toProc(Pstream::scheduled, recvProc);
toProc<< UIndirectList<Type>(sendValues, sendLabels[recvProc])();
}
else
{
// I am receiver. Receive from sendProc.
IPstream fromProc(Pstream::scheduled, sendProc);
Field<Type> fromFld(fromProc);
// Destination faces
const labelList& faceLabels = receiveFaceLabels[sendProc];
forAll(fromFld, i)
{
label patchFaceI = faceLabels[i];
newValues[patchFaceI] = fromFld[i];
}
}
}
// Do data from myself
{
UIndirectList<Type> fromFld
(
sendValues,
sendLabels[Pstream::myProcNo()]
);
// Destination faces
const labelList& faceLabels = receiveFaceLabels[Pstream::myProcNo()];
forAll(fromFld, i)
{
label patchFaceI = faceLabels[i];
newValues[patchFaceI] = fromFld[i];
}
}
}
template<class Type>
void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
{
......@@ -215,65 +158,94 @@ void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
return;
}
// Get the directMappedPolyPatch
const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
// Get the scheduling information from the directMappedPatchBase
const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
(
directMappedFixedValueFvPatchField<Type>::patch().patch()
);
const mapDistribute& distMap = mpp.map();
const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
const word& fldName = this->dimensionedInternalField().name();
Field<Type> newValues(this->size());
// Result of obtaining remote values
Field<Type> newValues;
switch (mpp.mode())
{
case directMappedPolyPatch::NEARESTCELL:
case directMappedPatchBase::NEARESTCELL:
{
getNewValues(mpp, this->internalField(), newValues);
if (mpp.sameRegion())
{
newValues = this->internalField();
}
else
{
newValues = nbrMesh.lookupObject<fieldType>
(
fldName
).internalField();
}
mapDistribute::distribute
(
Pstream::defaultCommsType,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
distMap.constructMap(),
newValues
);
break;
}
case directMappedPolyPatch::NEARESTPATCHFACE:
case directMappedPatchBase::NEARESTPATCHFACE:
{
const label patchID =
this->patch().patch().boundaryMesh().findPatchID
(
mpp.samplePatch()
);
if (patchID < 0)
const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
(
mpp.samplePatch()
);
if (nbrPatchID < 0)
{
FatalErrorIn
(
"void directMappedFixedValueFvPatchField<Type>::"
"updateCoeffs()"
)<< "Unable to find sample patch " << mpp.samplePatch()
<< " in region " << mpp.sampleRegion()
<< " for patch " << this->patch().name() << nl
<< abort(FatalError);
}
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const word& fieldName = this->dimensionedInternalField().name();
const fieldType& sendField =
this->db().objectRegistry::lookupObject<fieldType>(fieldName);
getNewValues(mpp, sendField.boundaryField()[patchID], newValues);
const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
(
fldName
);
newValues = nbrField.boundaryField()[nbrPatchID];
mapDistribute::distribute
(
Pstream::defaultCommsType,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
distMap.constructMap(),
newValues
);
break;
}
case directMappedPolyPatch::NEARESTFACE:
case directMappedPatchBase::NEARESTFACE:
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const word& fieldName = this->dimensionedInternalField().name();
const fieldType& sendField =
this->db().objectRegistry::lookupObject<fieldType>(fieldName);
Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
Field<Type> allValues
const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
(
this->patch().patch().boundaryMesh().mesh().nFaces(),
pTraits<Type>::zero
fldName
);
forAll(sendField.boundaryField(), patchI)
forAll(nbrField.boundaryField(), patchI)
{
const fvPatchField<Type>& pf =
sendField.boundaryField()[patchI];
nbrField.boundaryField()[patchI];
label faceStart = pf.patch().patch().start();
forAll(pf, faceI)
......@@ -282,9 +254,17 @@ void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
}
}
getNewValues(mpp, allValues, newValues);
mapDistribute::distribute
(
Pstream::defaultCommsType,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
distMap.constructMap(),
allValues
);
newValues = this->patch().patchSlice(newValues);
newValues = this->patch().patchSlice(allValues);
break;
}
......
......@@ -62,18 +62,6 @@ class directMappedFixedValueFvPatchField
// setAverage_ is set true
Type average_;
// Private member functions
// Helper function to return the new field values
void getNewValues
(
const directMappedPolyPatch& mpp,
const Field<Type>& sendValues,
Field<Type>& newValues
) const;
public:
//- Runtime type information
......
......@@ -26,7 +26,7 @@ License
#include "directMappedVelocityFluxFixedValueFvPatchField.H"
#include "fvPatchFieldMapper.H"
#include "directMappedFvPatch.H"
#include "directMappedPatchBase.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "addToRunTimeSelectionTable.H"
......@@ -62,12 +62,12 @@ directMappedVelocityFluxFixedValueFvPatchField
fixedValueFvPatchVectorField(ptf, p, iF, mapper),
phiName_(ptf.phiName_)
{
if (!isType<directMappedFvPatch>(patch()))
if (!isType<directMappedPatchBase>(this->patch().patch()))
{
FatalErrorIn
(
"directMappedVelocityFluxFixedValueFvPatchField::"
"directMappedFixedValueFvPatchField\n"
"directMappedVelocityFluxFixedValueFvPatchField\n"
"(\n"
" const directMappedVelocityFluxFixedValueFvPatchField&,\n"
" const fvPatch&,\n"
......@@ -75,7 +75,7 @@ directMappedVelocityFluxFixedValueFvPatchField
" const fvPatchFieldMapper&\n"
")\n"
) << "\n patch type '" << p.type()
<< "' not type '" << typeName << "'"
<< "' not type '" << directMappedPatchBase::typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << dimensionedInternalField().name()
<< " in file " << dimensionedInternalField().objectPath()
......@@ -95,24 +95,31 @@ directMappedVelocityFluxFixedValueFvPatchField
fixedValueFvPatchVectorField(p, iF, dict),
phiName_(dict.lookup("phi"))
{
if (!isType<directMappedFvPatch>(patch()))
if (!isType<directMappedPatchBase>(this->patch().patch()))
{
FatalErrorIn
(
"directMappedVelocityFluxFixedValueFvPatchField::"
"directMappedFixedValueFvPatchField\n"
"directMappedVelocityFluxFixedValueFvPatchField\n"
"(\n"
" const fvPatch& p,\n"
" const DimensionedField<vector, volMesh>& iF,\n"
" const dictionary& dict\n"
")\n"
) << "\n patch type '" << p.type()
<< "' not type '" << typeName << "'"
<< "' not type '" << directMappedPatchBase::typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << dimensionedInternalField().name()
<< " in file " << dimensionedInternalField().objectPath()
<< exit(FatalError);
}
// Force calculation of schedule (uses parallel comms)
const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
(
patch().patch()
);
(void)mpp.map().schedule();
}
......@@ -139,85 +146,6 @@ directMappedVelocityFluxFixedValueFvPatchField
{}
void directMappedVelocityFluxFixedValueFvPatchField::getNewValues
(
const directMappedPolyPatch& mpp,
const vectorField& sendUValues,
const scalarField& sendPhiValues,
vectorField& newUValues,
scalarField& newPhiValues
) const
{
// Get the scheduling information
const List<labelPair>& schedule = mpp.schedule();
const labelListList& sendLabels = mpp.sendLabels();
const labelListList& receiveFaceLabels = mpp.receiveFaceLabels();
forAll(schedule, i)
{
const labelPair& twoProcs = schedule[i];
label sendProc = twoProcs[0];
label recvProc = twoProcs[1];
if (Pstream::myProcNo() == sendProc)
{
OPstream toProc(Pstream::scheduled, recvProc);
toProc<< UIndirectList<vector>(sendUValues, sendLabels[recvProc])();
toProc<< UIndirectList<scalar>
(
sendPhiValues,
sendLabels[recvProc]
)();
}
else
{
// I am receiver. Receive from sendProc.
IPstream fromProc(Pstream::scheduled, sendProc);
vectorField fromUFld(fromProc);
scalarField fromPhiFld(fromProc);
// Destination faces
const labelList& faceLabels = receiveFaceLabels[sendProc];
forAll(fromUFld, i)
{
label patchFaceI = faceLabels[i];
newUValues[patchFaceI] = fromUFld[i];
newPhiValues[patchFaceI] = fromPhiFld[i];
}
}
}
// Do data from myself
{
UIndirectList<vector> fromUFld
(
sendUValues,
sendLabels[Pstream::myProcNo()]
);
UIndirectList<scalar> fromPhiFld
(
sendPhiValues,
sendLabels[Pstream::myProcNo()]
);
// Destination faces
const labelList& faceLabels = receiveFaceLabels[Pstream::myProcNo()];
forAll(fromUFld, i)
{
label patchFaceI = faceLabels[i];
newUValues[patchFaceI] = fromUFld[i];
newPhiValues[patchFaceI] = fromPhiFld[i];
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
......@@ -227,37 +155,33 @@ void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
return;
}
// Get the directMappedPolyPatch
const directMappedPolyPatch& mpp = refCast<const directMappedPolyPatch>
// Get the directMappedPatchBase
const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
(
directMappedVelocityFluxFixedValueFvPatchField::patch().patch()
);
vectorField newUValues(size());
scalarField newPhiValues(size());
const mapDistribute& distMap = mpp.map();
const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
const word& fieldName = dimensionedInternalField().name();
const volVectorField& UField = db().lookupObject<volVectorField>(fieldName);
const volVectorField& UField = nbrMesh.lookupObject<volVectorField>
(
fieldName
);
surfaceScalarField& phiField = const_cast<surfaceScalarField&>
(
db().lookupObject<surfaceScalarField>(phiName_)
nbrMesh.lookupObject<surfaceScalarField>(phiName_)
);
vectorField newUValues;
scalarField newPhiValues;
switch (mpp.mode())
{
case directMappedPolyPatch::NEARESTFACE:
{
vectorField allUValues
(
patch().patch().boundaryMesh().mesh().nFaces(),
vector::zero
);
scalarField allPhiValues
(
patch().patch().boundaryMesh().mesh().nFaces(),
0.0
);
vectorField allUValues(nbrMesh.nFaces(), vector::zero);
scalarField allPhiValues(nbrMesh.nFaces(), 0.0);
forAll(UField.boundaryField(), patchI)
{
......@@ -273,34 +197,58 @@ void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()