mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: redistributePar support for finiteArea (#2436)
This commit is contained in:
committed by
Andrew Heather
parent
6644cf8ddb
commit
cc1e6c12bb
@ -1,7 +1,10 @@
|
|||||||
passivePositionParticleCloud.C
|
passivePositionParticleCloud.C
|
||||||
|
|
||||||
parLagrangianDistributor.C
|
parLagrangianDistributor.C
|
||||||
parLagrangianDistributorFields.C
|
parLagrangianDistributorFields.C
|
||||||
|
|
||||||
parPointFieldDistributor.C
|
parPointFieldDistributor.C
|
||||||
|
parFaFieldDistributorCache.C
|
||||||
parFvFieldDistributor.C
|
parFvFieldDistributor.C
|
||||||
parFvFieldDistributorFields.C
|
parFvFieldDistributorFields.C
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "loadOrCreateMesh.H"
|
#include "loadOrCreateMesh.H"
|
||||||
|
#include "faMesh.H"
|
||||||
#include "Pstream.H"
|
#include "Pstream.H"
|
||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
|
|
||||||
@ -66,6 +67,26 @@ Foam::boolList Foam::haveMeshFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::removeProcAddressing(const faMesh& mesh)
|
||||||
|
{
|
||||||
|
IOobject ioAddr
|
||||||
|
(
|
||||||
|
"procAddressing",
|
||||||
|
mesh.facesInstance(),
|
||||||
|
faMesh::meshSubDir,
|
||||||
|
mesh.thisDb()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const auto prefix : {"boundary", "edge", "face", "point"})
|
||||||
|
{
|
||||||
|
ioAddr.rename(prefix + word("ProcAddressing"));
|
||||||
|
|
||||||
|
const fileName procFile(ioAddr.objectPath());
|
||||||
|
Foam::rm(procFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::removeProcAddressing(const polyMesh& mesh)
|
void Foam::removeProcAddressing(const polyMesh& mesh)
|
||||||
{
|
{
|
||||||
IOobject ioAddr
|
IOobject ioAddr
|
||||||
|
|||||||
@ -45,6 +45,9 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
class faMesh;
|
||||||
|
|
||||||
//- Check for availability of specified mesh file (default: "faces")
|
//- Check for availability of specified mesh file (default: "faces")
|
||||||
boolList haveMeshFile
|
boolList haveMeshFile
|
||||||
(
|
(
|
||||||
@ -55,6 +58,9 @@ boolList haveMeshFile
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Remove procAddressing
|
||||||
|
void removeProcAddressing(const faMesh& mesh);
|
||||||
|
|
||||||
//- Remove procAddressing
|
//- Remove procAddressing
|
||||||
void removeProcAddressing(const polyMesh& mesh);
|
void removeProcAddressing(const polyMesh& mesh);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,164 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "parFaFieldDistributorCache.H"
|
||||||
|
|
||||||
|
#include "areaFields.H"
|
||||||
|
#include "edgeFields.H"
|
||||||
|
#include "fieldsDistributor.H"
|
||||||
|
#include "faMeshDistributor.H"
|
||||||
|
#include "faMeshSubset.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class GeoField>
|
||||||
|
void Foam::parFaFieldDistributorCache::redistributeAndWrite
|
||||||
|
(
|
||||||
|
const faMeshDistributor& distributor,
|
||||||
|
PtrList<GeoField>& fields,
|
||||||
|
const bool isWriteProc
|
||||||
|
)
|
||||||
|
{
|
||||||
|
for (GeoField& fld : fields)
|
||||||
|
{
|
||||||
|
tmp<GeoField> tfld = distributor.distributeField(fld);
|
||||||
|
|
||||||
|
if (isWriteProc)
|
||||||
|
{
|
||||||
|
tfld().write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::parFaFieldDistributorCache::read
|
||||||
|
(
|
||||||
|
const Time& baseRunTime,
|
||||||
|
const fileName& proc0CaseName,
|
||||||
|
const bool decompose, // i.e. read from undecomposed case
|
||||||
|
|
||||||
|
const boolList& areaMeshOnProc,
|
||||||
|
const fileName& areaMeshInstance,
|
||||||
|
faMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Time& runTime = const_cast<Time&>(mesh.time());
|
||||||
|
const bool oldProcCase = runTime.processorCase();
|
||||||
|
|
||||||
|
autoPtr<faMeshSubset> subsetterPtr;
|
||||||
|
|
||||||
|
// Missing an area mesh somewhere?
|
||||||
|
if (areaMeshOnProc.found(false))
|
||||||
|
{
|
||||||
|
// A zero-sized mesh with boundaries.
|
||||||
|
// This is used to create zero-sized fields.
|
||||||
|
subsetterPtr.reset(new faMeshSubset(mesh, zero{}));
|
||||||
|
|
||||||
|
// Deregister from polyMesh ...
|
||||||
|
auto& obr = const_cast<objectRegistry&>
|
||||||
|
(
|
||||||
|
subsetterPtr->subMesh().thisDb()
|
||||||
|
);
|
||||||
|
|
||||||
|
obr.checkOut(faMesh::typeName);
|
||||||
|
obr.checkOut("faBoundaryMesh");
|
||||||
|
obr.checkOut("faSchemes");
|
||||||
|
obr.checkOut("faSolution");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get original objects (before incrementing time!)
|
||||||
|
if (Pstream::master() && decompose)
|
||||||
|
{
|
||||||
|
runTime.caseName() = baseRunTime.caseName();
|
||||||
|
runTime.processorCase(false);
|
||||||
|
}
|
||||||
|
IOobjectList objects(mesh.mesh(), runTime.timeName());
|
||||||
|
if (Pstream::master() && decompose)
|
||||||
|
{
|
||||||
|
runTime.caseName() = proc0CaseName;
|
||||||
|
runTime.processorCase(oldProcCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "From time " << runTime.timeName()
|
||||||
|
<< " mesh:" << mesh.mesh().objectRegistry::objectRelPath()
|
||||||
|
<< " have objects:" << objects.names() << endl;
|
||||||
|
|
||||||
|
if (Pstream::master() && decompose)
|
||||||
|
{
|
||||||
|
runTime.caseName() = baseRunTime.caseName();
|
||||||
|
runTime.processorCase(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef doFieldReading
|
||||||
|
#define doFieldReading(Storage) \
|
||||||
|
fieldsDistributor::readFields \
|
||||||
|
( \
|
||||||
|
areaMeshOnProc, mesh, subsetterPtr, objects, Storage, \
|
||||||
|
true /* (deregister field) */ \
|
||||||
|
);
|
||||||
|
|
||||||
|
// areaFields
|
||||||
|
doFieldReading(scalarAreaFields_);
|
||||||
|
doFieldReading(vectorAreaFields_);
|
||||||
|
doFieldReading(sphericalTensorAreaFields_);
|
||||||
|
doFieldReading(symmTensorAreaFields_);
|
||||||
|
doFieldReading(tensorAreaFields_);
|
||||||
|
|
||||||
|
// edgeFields
|
||||||
|
doFieldReading(scalarEdgeFields_);
|
||||||
|
doFieldReading(vectorEdgeFields_);
|
||||||
|
doFieldReading(tensorEdgeFields_);
|
||||||
|
doFieldReading(sphericalTensorEdgeFields_);
|
||||||
|
doFieldReading(symmTensorEdgeFields_);
|
||||||
|
#undef doFieldReading
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::parFaFieldDistributorCache::redistributeAndWrite
|
||||||
|
(
|
||||||
|
const faMeshDistributor& distributor,
|
||||||
|
const bool isWriteProc
|
||||||
|
)
|
||||||
|
{
|
||||||
|
redistributeAndWrite(distributor, scalarAreaFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, vectorAreaFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, sphericalTensorAreaFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, symmTensorAreaFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, tensorAreaFields_, isWriteProc);
|
||||||
|
|
||||||
|
redistributeAndWrite(distributor, scalarEdgeFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, vectorEdgeFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, sphericalTensorEdgeFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, symmTensorEdgeFields_, isWriteProc);
|
||||||
|
redistributeAndWrite(distributor, tensorEdgeFields_, isWriteProc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::parFaFieldDistributorCache
|
||||||
|
|
||||||
|
Description
|
||||||
|
Simple container to manage read/write, redistribute finiteArea fields.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
parFaFieldDistributorCache.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_parFaFieldDistributorCache_H
|
||||||
|
#define Foam_parFaFieldDistributorCache_H
|
||||||
|
|
||||||
|
#include "faMesh.H"
|
||||||
|
#include "faMeshDistributor.H"
|
||||||
|
#include "areaFieldsFwd.H"
|
||||||
|
#include "edgeFieldsFwd.H"
|
||||||
|
#include "PtrList.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class parFaFieldDistributorCache Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class parFaFieldDistributorCache
|
||||||
|
{
|
||||||
|
// Private Data
|
||||||
|
|
||||||
|
#undef declareField
|
||||||
|
#define declareField(Type) \
|
||||||
|
PtrList<GeometricField<Type, faPatchField, areaMesh>> Type##AreaFields_; \
|
||||||
|
PtrList<GeometricField<Type, faePatchField, edgeMesh>> Type##EdgeFields_;
|
||||||
|
|
||||||
|
declareField(scalar);
|
||||||
|
declareField(vector);
|
||||||
|
declareField(sphericalTensor);
|
||||||
|
declareField(symmTensor);
|
||||||
|
declareField(tensor);
|
||||||
|
#undef declareField
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Redistribute and write fields of given type (file-scope use)
|
||||||
|
template<class GeoField>
|
||||||
|
static void redistributeAndWrite
|
||||||
|
(
|
||||||
|
const faMeshDistributor& distributor,
|
||||||
|
PtrList<GeoField>& fields,
|
||||||
|
const bool isWriteProc
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- No copy construct
|
||||||
|
parFaFieldDistributorCache(const parFaFieldDistributorCache&) = delete;
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const parFaFieldDistributorCache&) = delete;
|
||||||
|
|
||||||
|
//- Default construct
|
||||||
|
parFaFieldDistributorCache() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Read distributed fields
|
||||||
|
void read
|
||||||
|
(
|
||||||
|
const Time& baseRunTime,
|
||||||
|
const fileName& proc0CaseName,
|
||||||
|
const bool decompose, // i.e. read from undecomposed case
|
||||||
|
|
||||||
|
const boolList& areaMeshOnProc,
|
||||||
|
const fileName& areaMeshInstance,
|
||||||
|
faMesh& mesh
|
||||||
|
);
|
||||||
|
|
||||||
|
void redistributeAndWrite
|
||||||
|
(
|
||||||
|
const faMeshDistributor& distributor,
|
||||||
|
const bool isWriteProc
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
File diff suppressed because it is too large
Load Diff
@ -186,6 +186,16 @@ public:
|
|||||||
const bool allowUnmapped = false
|
const bool allowUnmapped = false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Map edge field.
|
||||||
|
// Optionally allow unmapped faces not to produce a warning
|
||||||
|
template<class Type>
|
||||||
|
static tmp<GeometricField<Type, faePatchField, edgeMesh>>
|
||||||
|
interpolate
|
||||||
|
(
|
||||||
|
const GeometricField<Type, faePatchField, edgeMesh>&,
|
||||||
|
const faMesh& sMesh
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Field Mapping
|
// Field Mapping
|
||||||
|
|
||||||
@ -198,6 +208,15 @@ public:
|
|||||||
const GeometricField<Type, faPatchField, areaMesh>&,
|
const GeometricField<Type, faPatchField, areaMesh>&,
|
||||||
const bool allowUnmapped = false
|
const bool allowUnmapped = false
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
//- Map edge field.
|
||||||
|
template<class Type>
|
||||||
|
tmp<GeometricField<Type, faePatchField, edgeMesh>>
|
||||||
|
interpolate
|
||||||
|
(
|
||||||
|
const GeometricField<Type, faePatchField, edgeMesh>&,
|
||||||
|
const bool allowUnmapped = false
|
||||||
|
) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -144,6 +144,88 @@ Foam::faMeshSubset::interpolate
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::tmp
|
||||||
|
<
|
||||||
|
Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>
|
||||||
|
>
|
||||||
|
Foam::faMeshSubset::interpolate
|
||||||
|
(
|
||||||
|
const GeometricField<Type, faePatchField, edgeMesh>& vf,
|
||||||
|
const faMesh& sMesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// 1. Create the complete field with dummy patch fields
|
||||||
|
PtrList<faePatchField<Type>> patchFields(sMesh.boundary().size());
|
||||||
|
|
||||||
|
forAll(patchFields, patchi)
|
||||||
|
{
|
||||||
|
patchFields.set
|
||||||
|
(
|
||||||
|
patchi,
|
||||||
|
faePatchField<Type>::New
|
||||||
|
(
|
||||||
|
calculatedFaePatchField<Type>::typeName,
|
||||||
|
sMesh.boundary()[patchi],
|
||||||
|
DimensionedField<Type, edgeMesh>::null()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto tresult = tmp<GeometricField<Type, faePatchField, edgeMesh>>::New
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
"subset"+vf.name(),
|
||||||
|
sMesh.time().timeName(),
|
||||||
|
sMesh.thisDb(),
|
||||||
|
IOobject::NO_READ,
|
||||||
|
IOobject::NO_WRITE
|
||||||
|
),
|
||||||
|
sMesh,
|
||||||
|
vf.dimensions(),
|
||||||
|
Field<Type>(),
|
||||||
|
// Field<Type>
|
||||||
|
// (
|
||||||
|
// vf.primitiveField(),
|
||||||
|
// SubList<label>(edgeMap, sMesh.nInternalEdges())
|
||||||
|
// ),
|
||||||
|
patchFields
|
||||||
|
);
|
||||||
|
auto& result = tresult.ref();
|
||||||
|
result.oriented() = vf.oriented();
|
||||||
|
|
||||||
|
|
||||||
|
// 2. Change the faePatchFields to the correct type using a mapper
|
||||||
|
// constructor (with reference to the now correct internal field)
|
||||||
|
|
||||||
|
auto& bf = result.boundaryFieldRef();
|
||||||
|
|
||||||
|
forAll(bf, patchi)
|
||||||
|
{
|
||||||
|
// Construct addressing
|
||||||
|
const faPatch& subPatch = sMesh.boundary()[patchi];
|
||||||
|
|
||||||
|
labelList directAddressing;
|
||||||
|
directFaPatchFieldMapper mapper(directAddressing);
|
||||||
|
|
||||||
|
bf.set
|
||||||
|
(
|
||||||
|
patchi,
|
||||||
|
faePatchField<Type>::New
|
||||||
|
(
|
||||||
|
vf.boundaryField()[patchi],
|
||||||
|
subPatch,
|
||||||
|
result(),
|
||||||
|
mapper
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
@ -166,4 +248,24 @@ Foam::faMeshSubset::interpolate
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::tmp
|
||||||
|
<
|
||||||
|
Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>
|
||||||
|
>
|
||||||
|
Foam::faMeshSubset::interpolate
|
||||||
|
(
|
||||||
|
const GeometricField<Type, faePatchField, edgeMesh>& vf,
|
||||||
|
const bool allowUnmapped
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (subMeshPtr_)
|
||||||
|
{
|
||||||
|
return interpolate(vf, *subMeshPtr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user