Skip to content
Snippets Groups Projects
Commit ff537226 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: redistributePar support for finiteArea (#2436)

parent 0ddbfd95
Branches
Tags
No related merge requests found
......@@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/
#include "loadOrCreateMesh.H"
#include "faMesh.H"
#include "Pstream.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)
{
IOobject ioAddr
......
......@@ -45,6 +45,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class faMesh;
//- Check for availability of specified mesh file (default: "faces")
boolList haveMeshFile
(
......@@ -55,6 +58,9 @@ boolList haveMeshFile
);
//- Remove procAddressing
void removeProcAddressing(const faMesh& mesh);
//- Remove procAddressing
void removeProcAddressing(const polyMesh& mesh);
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::redistributeFieldArea
Description
Simple container to manage read/write, redistribute
of finiteArea fields.
\*---------------------------------------------------------------------------*/
#ifndef Foam_redistributeFiniteArea_H
#define Foam_redistributeFiniteArea_H
#include "PtrList.H"
#include "areaFields.H"
#include "edgeFields.H"
#include "fieldsDistributor.H"
#include "faMeshDistributor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class parFaFieldDistributorCache Declaration
\*---------------------------------------------------------------------------*/
struct parFaFieldDistributorCache
{
// Exposed Data
// Area fields storage
PtrList<areaScalarField> area_scalar;
PtrList<areaVectorField> area_vector;
PtrList<areaTensorField> area_tensor;
PtrList<areaSphericalTensorField> area_sphericalTensor;
PtrList<areaSymmTensorField> area_symmTensor;
// Edge fields storage
PtrList<edgeScalarField> edge_scalar;
PtrList<edgeVectorField> edge_vector;
PtrList<edgeTensorField> edge_tensor;
PtrList<edgeSphericalTensorField> edge_sphericalTensor;
PtrList<edgeSymmTensorField> edge_symmTensor;
// Constructors
//- No copy construct
parFaFieldDistributorCache(const parFaFieldDistributorCache&) = delete;
//- No copy assignment
void operator=(const parFaFieldDistributorCache&) = delete;
//- Default construct
parFaFieldDistributorCache() = default;
// Member Functions
template<class GeoField>
static void redistributeAndWrite
(
const faMeshDistributor& distributor,
PtrList<GeoField>& flds,
const bool isWriteProc
)
{
for (auto& fld : flds)
{
tmp<GeoField> tfld = distributor.distributeField(fld);
if (isWriteProc)
{
tfld().write();
}
}
}
void redistributeAndWrite
(
const faMeshDistributor& distributor,
const bool isWrite
)
{
redistributeAndWrite(distributor, area_scalar, isWrite);
redistributeAndWrite(distributor, area_vector, isWrite);
redistributeAndWrite(distributor, area_sphericalTensor, isWrite);
redistributeAndWrite(distributor, area_symmTensor, isWrite);
redistributeAndWrite(distributor, area_tensor, isWrite);
redistributeAndWrite(distributor, edge_scalar, isWrite);
redistributeAndWrite(distributor, edge_vector, isWrite);
redistributeAndWrite(distributor, edge_sphericalTensor, isWrite);
redistributeAndWrite(distributor, edge_symmTensor, isWrite);
redistributeAndWrite(distributor, edge_tensor, isWrite);
}
//- 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
)
{
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(area_scalar);
doFieldReading(area_vector);
doFieldReading(area_tensor);
doFieldReading(area_sphericalTensor);
doFieldReading(area_symmTensor);
// edgeFields
// Not yet
// doFieldReading(edge_scalar);
// doFieldReading(edge_vector);
// doFieldReading(edge_tensor);
// doFieldReading(edge_sphericalTensor);
// doFieldReading(edge_symmTensor);
#undef doFieldReading
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment