ENH: code modernization for decompose/reconstruct

- simplify procAddressing read/write

- avoid accessing points in faMeshReconstructor.
  Can rely on the patch meshPoints (labelList), which does not need
  access to a pointField

- report number of points on decomposed mesh.
  Can be useful additional information.
  Additional statistics for finite area decomposition

- provide bundled reconstructAllFields for various reconstructors

- remove reconstructPar checks for very old face addressing
  (from foam2.0 - ie, older than OpenFOAM itself)

- bundle all reading into fieldsDistributor tools,
  where it can be reused by various utilities as required.

- combine decomposition fields as respective fieldsCache
  which eliminates most of the clutter from decomposePar
  and similfies reuse in the future.

STYLE: remove old wordHashSet selection (deprecated in 2018)

BUG: incorrect face flip handling for faMeshReconstructor

- a latent bug which is not yet triggered since the faMesh faces are
  currently only definable on boundary faces (which never flip)
This commit is contained in:
Mark Olesen
2022-04-24 15:06:40 +02:00
committed by Andrew Heather
parent eccc998ed2
commit 3b6761afed
51 changed files with 3270 additions and 2443 deletions

View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
fieldsDistributor
Description
Common methods/utilities for field decomposers/distributors etc.
SourceFiles
fieldsDistributorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef Foam_fieldsDistributor_H
#define Foam_fieldsDistributor_H
#include "IOobjectList.H"
#include "boolList.H"
#include "PtrList.H"
#include "GeometricField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class fieldsDistributor Declaration
\*---------------------------------------------------------------------------*/
class fieldsDistributor
{
public:
// Reading helpers
//- Generic mesh-based field reading
template<class GeoField>
static void readField
(
const IOobject& io,
const typename GeoField::Mesh& mesh,
const label i,
PtrList<GeoField>& fields
);
//- Definition of readField for GeometricFields only
template<class Type, template<class> class PatchField, class GeoMesh>
static void readField
(
const IOobject& io,
const typename GeoMesh::Mesh& mesh,
const label i,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields
);
//- Read fields and store on the pointer list
template
<
class Type,
template<class> class PatchField,
class GeoMesh
>
static void readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
);
//- Read fields and hold on the pointer list
template<class Mesh, class GeoField>
static void readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
);
//- Read volume/surface/point/area fields that may or may not exist
//- on all processors
template<class GeoField, class MeshSubsetter>
static void readFields
(
const boolList& haveMeshOnProc,
const typename GeoField::Mesh& mesh,
const autoPtr<MeshSubsetter>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields,
const bool deregister = false
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldsDistributorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,330 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::fieldsDistributor::readField
(
const IOobject& io,
const typename GeoField::Mesh& mesh,
const label i,
PtrList<GeoField>& fields
)
{
fields.set(i, new GeoField(io, mesh));
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::fieldsDistributor::readField
(
const IOobject& io,
const typename GeoMesh::Mesh& mesh,
const label i,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields
)
{
fields.set
(
i,
new GeometricField<Type, PatchField, GeoMesh>(io, mesh, false)
);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::fieldsDistributor::readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
)
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// GeoField fields - sorted for consistent order on all processors
UPtrList<const IOobject> fieldObjects(objects.sorted<GeoField>());
// Construct the fields
fields.resize(fieldObjects.size());
forAll(fieldObjects, i)
{
fields.set(i, new GeoField(fieldObjects[i], mesh, readOldTime));
}
}
template<class Mesh, class GeoField>
void Foam::fieldsDistributor::readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
)
{
// GeoField fields - sorted for consistent order on all processors
UPtrList<const IOobject> fieldObjects(objects.sorted<GeoField>());
// Construct the fields
fields.resize(fieldObjects.size());
forAll(fieldObjects, i)
{
fields.set(i, new GeoField(fieldObjects[i], mesh));
}
}
template<class GeoField, class MeshSubsetter>
void Foam::fieldsDistributor::readFields
(
const boolList& haveMeshOnProc,
const typename GeoField::Mesh& mesh,
const autoPtr<MeshSubsetter>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields,
const bool deregister
)
{
// Get my objects of type
IOobjectList objects(allObjects.lookupClass<GeoField>());
// Check that we all have all objects
wordList objectNames = objects.sortedNames();
// Get master names
wordList masterNames(objectNames);
Pstream::broadcast(masterNames);
if (haveMeshOnProc[Pstream::myProcNo()] && objectNames != masterNames)
{
FatalErrorInFunction
<< "Objects not synchronised across processors." << nl
<< "Master has " << flatOutput(masterNames) << nl
<< "Processor " << Pstream::myProcNo()
<< " has " << flatOutput(objectNames)
<< exit(FatalError);
}
fields.clear();
fields.resize(masterNames.size());
if (fields.empty())
{
if (deregister)
{
// Extra safety - remove all such types
HashTable<const GeoField*> other
(
mesh.thisDb().objectRegistry::template lookupClass<GeoField>()
);
forAllConstIters(other, iter)
{
GeoField& fld = const_cast<GeoField&>(*iter.val());
if (!fld.ownedByRegistry())
{
fld.checkOut();
}
}
}
// Early exit
return;
}
// Have master send all fields to processors that don't have a mesh. The
// issue is if a patchField does any parallel operations inside its
// construct-from-dictionary. This will not work when going to more
// processors (e.g. decompose = 1 -> many) ! We could make a special
// exception for decomposePar but nicer would be to have read-communicator
// ... For now detect if decomposing & disable parRun
if (Pstream::master())
{
// Work out if we're decomposing - none of the subprocs has a mesh
bool decompose = true;
for (const int proci : Pstream::subProcs())
{
if (haveMeshOnProc[proci])
{
decompose = false;
}
}
const bool oldParRun = Pstream::parRun();
if (decompose)
{
Pstream::parRun(false);
}
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
// Load field (but not oldTime)
readField(io, mesh, i, fields);
}
Pstream::parRun(oldParRun); // Restore any changes
}
else if (haveMeshOnProc[Pstream::myProcNo()])
{
// Have mesh so just try to load
forAll(masterNames, i)
{
const word& name = masterNames[i];
IOobject& io = *objects[name];
io.writeOpt(IOobject::AUTO_WRITE);
/// Pout<< "Attempt read: " << name << endl;
// Load field (but not oldTime)
readField(io, mesh, i, fields);
}
}
// Missing fields on any processors?
// - construct from dictionary
PtrList<dictionary> fieldDicts;
if (Pstream::master())
{
// Broadcast zero sized fields everywhere (if needed)
// Send like a list of dictionaries
OPBstream toProcs(UPstream::masterNo()); // worldComm
const label nDicts = (subsetterPtr ? fields.size() : label(0));
toProcs << nDicts << token::BEGIN_LIST; // Begin list
if (nDicts)
{
// Disable communication for interpolate() method
const bool oldParRun = Pstream::parRun(false);
const auto& subsetter = subsetterPtr();
forAll(fields, i)
{
tmp<GeoField> tsubfld = subsetter.interpolate(fields[i]);
// Surround each with {} as dictionary entry
toProcs.beginBlock();
toProcs << tsubfld();
toProcs.endBlock();
}
Pstream::parRun(oldParRun); // Restore state
}
toProcs << token::END_LIST << token::NL; // End list
}
else
{
// Receive the broadcast...
IPBstream fromMaster(UPstream::masterNo()); // worldComm
// But only consume where needed...
if (!haveMeshOnProc[Pstream::myProcNo()])
{
fromMaster >> fieldDicts;
}
}
// Use the received dictionaries to create fields
// (will be empty if we didn't require them)
// Disable communication when constructing from dictionary
const bool oldParRun = Pstream::parRun(false);
forAll(fieldDicts, i)
{
fields.set
(
i,
new GeoField
(
IOobject
(
masterNames[i],
mesh.time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
fieldDicts[i]
)
);
}
Pstream::parRun(oldParRun); // Restore any changes
// Finally. Can checkOut of registry as required
if (deregister)
{
/// Info<< "De-registering fields:";
for (auto& fld : fields)
{
/// Info<< " " << fld.name();
// Ensure it is not destroyed by polyMesh deletion
fld.checkOut();
}
/// Info<< nl;
// Extra safety - remove all such types
HashTable<const GeoField*> other
(
mesh.thisDb().objectRegistry::template lookupClass<GeoField>()
);
forAllConstIters(other, iter)
{
GeoField& fld = const_cast<GeoField&>(*iter.val());
if (!fld.ownedByRegistry())
{
fld.checkOut();
}
}
}
}
// ************************************************************************* //

View File

@ -2,7 +2,14 @@ decompositionInformation.C
decompositionModel.C
dimFieldDecomposer.C
fvFieldDecomposer.C
fvFieldDecomposerCache.C
pointFieldDecomposer.C
pointFieldDecomposerCache.C
lagrangianFieldDecomposer.C
lagrangianFieldDecomposerCache.C
LIB = $(FOAM_LIBBIN)/libdecompose

View File

@ -32,12 +32,12 @@ Description
SourceFiles
dimFieldDecomposer.C
dimFieldDecomposerFields.C
dimFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef dimFieldDecomposer_H
#define dimFieldDecomposer_H
#ifndef Foam_dimFieldDecomposer_H
#define Foam_dimFieldDecomposer_H
#include "fvMesh.H"
#include "surfaceFields.H"
@ -121,7 +121,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "dimFieldDecomposerFields.C"
#include "dimFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -47,8 +47,8 @@ Foam::dimFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,11 @@ License
#include "fvFieldDecomposer.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::fvFieldDecomposer::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvFieldDecomposer::patchFieldDecomposer::patchFieldDecomposer
@ -95,7 +100,7 @@ processorVolPatchFieldDecomposer
Foam::fvFieldDecomposer::processorVolPatchFieldDecomposer::
processorVolPatchFieldDecomposer
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelUList& addressingSlice
)
:

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,13 @@ Description
SourceFiles
fvFieldDecomposer.C
fvFieldDecomposerFields.C
fvFieldDecomposerCache.C
fvFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvFieldDecomposer_H
#define fvFieldDecomposer_H
#ifndef Foam_fvFieldDecomposer_H
#define Foam_fvFieldDecomposer_H
#include "fvMesh.H"
#include "fvPatchFieldMapper.H"
@ -48,6 +49,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
Class fvFieldDecomposer Declaration
\*---------------------------------------------------------------------------*/
@ -56,6 +60,8 @@ class fvFieldDecomposer
{
public:
// Public Classes
//- Patch field decomposer class
class patchFieldDecomposer
:
@ -126,7 +132,7 @@ public:
//- Construct given addressing from complete mesh
processorVolPatchFieldDecomposer
(
const fvMesh& mesh,
const polyMesh& mesh,
const labelUList& addressingSlice
);
@ -232,13 +238,24 @@ private:
PtrList<scalarField> faceSign_;
// Private Member Functions
//- No copy construct
fvFieldDecomposer(const fvFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const fvFieldDecomposer&) = delete;
public:
//- No copy construct
fvFieldDecomposer(const fvFieldDecomposer&) = delete;
// Public Classes
class fieldsCache;
//- No copy assignment
void operator=(const fvFieldDecomposer&) = delete;
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
@ -336,6 +353,69 @@ public:
};
/*---------------------------------------------------------------------------*\
Class fvFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class fvFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Total number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const fvMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const fvFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -343,7 +423,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fvFieldDecomposerFields.C"
#include "fvFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,228 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "fvFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All volume internal types
class fvFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<DimensionedField<Type, volMesh>> Type##DimFields_; \
PtrList<GeometricField<Type, fvPatchField, volMesh>> Type##VolFields_; \
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>> Type##SurfFields_;
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##DimFields_.size(); \
count += Type##VolFields_.size(); \
count += Type##SurfFields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const fvMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##DimFields_ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##VolFields_, \
false /* readOldTime = false */ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##SurfFields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const fvFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll
(
const fvFieldDecomposer& decomposer,
bool report
) const
{
#undef doLocalCode
#define doLocalCode(Flavour) \
{ \
decompose(decomposer, scalar##Flavour##Fields_, report); \
decompose(decomposer, vector##Flavour##Fields_, report); \
decompose(decomposer, sphericalTensor##Flavour##Fields_, report); \
decompose(decomposer, symmTensor##Flavour##Fields_, report); \
decompose(decomposer, tensor##Flavour##Fields_, report); \
}
doLocalCode(Vol);
doLocalCode(Surf);
doLocalCode(Dim);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::fvFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fvFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::fvFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::fvFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::fvFieldDecomposer::fieldsCache::readAllFields
(
const fvMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::fvFieldDecomposer::fieldsCache::decomposeAllFields
(
const fvFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -32,6 +32,8 @@ License
#include "processorCyclicFvPatchField.H"
#include "processorCyclicFvsPatchField.H"
#include "emptyFvPatchFields.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -52,8 +54,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
@ -100,8 +102,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -118,7 +120,7 @@ Foam::fvFieldDecomposer::decomposeField
// 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field)
typename VolFieldType::Boundary& bf = resF.boundaryFieldRef();
auto& bf = resF.boundaryFieldRef();
forAll(bf, patchi)
{
@ -272,8 +274,8 @@ Foam::fvFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_,
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -289,7 +291,7 @@ Foam::fvFieldDecomposer::decomposeField
// 2. Change the fvsPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field)
typename SurfaceFieldType::Boundary& bf = resF.boundaryFieldRef();
auto& bf = resF.boundaryFieldRef();
forAll(boundaryAddressing_, patchi)
{

View File

@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
-------------------------------------------------------------------------------
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/>.
Description
Lagrangian field decomposer.
\*---------------------------------------------------------------------------*/
#include "lagrangianFieldDecomposer.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianFieldDecomposer::lagrangianFieldDecomposer
(
const polyMesh& mesh,
const polyMesh& procMesh,
const labelList& faceProcAddressing,
const labelList& cellProcAddressing,
const word& cloudName,
const Cloud<indexedParticle>& lagrangianPositions,
const List<SLList<indexedParticle*>*>& cellParticles
)
:
procMesh_(procMesh),
positions_(procMesh, cloudName, IDLList<passiveParticle>()),
particleIndices_(lagrangianPositions.size())
{
label pi = 0;
labelList decodedProcFaceAddressing(faceProcAddressing.size());
forAll(faceProcAddressing, i)
{
decodedProcFaceAddressing[i] = mag(faceProcAddressing[i]) - 1;
}
forAll(cellProcAddressing, procCelli)
{
label celli = cellProcAddressing[procCelli];
if (cellParticles[celli])
{
SLList<indexedParticle*>& particlePtrs = *cellParticles[celli];
forAllConstIters(particlePtrs, iter)
{
const indexedParticle& ppi = *iter();
particleIndices_[pi++] = ppi.index();
const label mappedTetFace =
decodedProcFaceAddressing.find(ppi.tetFace());
if (mappedTetFace == -1)
{
FatalErrorInFunction
<< "Face lookup failure." << nl
<< abort(FatalError);
}
positions_.append
(
new passiveParticle
(
procMesh,
ppi.coordinates(),
procCelli,
mappedTetFace,
ppi.procTetPt(procMesh, procCelli, mappedTetFace)
)
);
}
}
}
particleIndices_.resize(pi);
IOPosition<Cloud<passiveParticle>>(positions_).write();
}
// ************************************************************************* //

View File

@ -0,0 +1,246 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
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::lagrangianFieldDecomposer
Description
Lagrangian field decomposer.
SourceFiles
lagrangianFieldDecomposer.C
lagrangianFieldDecomposerCache.C
lagrangianFieldDecomposerReadFields.C
lagrangianFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef Foam_lagrangianFieldDecomposer_H
#define Foam_lagrangianFieldDecomposer_H
#include "Cloud.H"
#include "CompactIOField.H"
#include "indexedParticle.H"
#include "passiveParticle.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
Class lagrangianFieldDecomposer Declaration
\*---------------------------------------------------------------------------*/
class lagrangianFieldDecomposer
{
// Private Data
//- Reference to processor mesh
const polyMesh& procMesh_;
//- Lagrangian positions for this processor
Cloud<passiveParticle> positions_;
//- The indices of the particles on this processor
labelList particleIndices_;
// Private Member Functions
//- No copy construct
lagrangianFieldDecomposer(const lagrangianFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const lagrangianFieldDecomposer&) = delete;
public:
// Public Classes
class fieldsCache;
// Constructors
//- Construct from components
lagrangianFieldDecomposer
(
const polyMesh& mesh, //<! unused
const polyMesh& procMesh,
const labelList& faceProcAddressing,
const labelList& cellProcAddressing,
const word& cloudName,
const Cloud<indexedParticle>& lagrangianPositions,
const List<SLList<indexedParticle*>*>& cellParticles
);
// Field Reading
//- Read the fields and store on the pointer list
template<class Type>
static void readFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOField<Type>>>& cloudFields
);
//- Read the field-fields and store on the pointer list
template<class Type>
static void readFieldFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<CompactIOField<Field<Type>, Type>>>& cloudFields
);
// Member Functions
//- Decompose volume field
template<class Type>
tmp<IOField<Type>> decomposeField
(
const word& cloudName,
const IOField<Type>& field
) const;
template<class Type>
tmp<CompactIOField<Field<Type>, Type>> decomposeFieldField
(
const word& cloudName,
const CompactIOField<Field<Type>, Type>& field
) const;
template<class GeoField>
void decomposeFields
(
const word& cloudName,
const PtrList<GeoField>& fields
) const;
template<class GeoField>
void decomposeFieldFields
(
const word& cloudName,
const PtrList<GeoField>& fields
) const;
};
/*---------------------------------------------------------------------------*\
Class lagrangianFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class lagrangianFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct (no clouds)
fieldsCache();
//- Construct for given number of clouds
explicit fieldsCache(const label nClouds);
//- Destructor
~fieldsCache();
// Member Functions
//- No clouds
bool empty() const;
//- Number of clouds
label size() const;
//- Clear out
void clear();
//- Resize for the number of clouds
void resize(const label nClouds);
//- Read all fields and field-fields for given cloud and objects
void readAllFields
(
const label cloudi,
const IOobjectList& lagrangianObjects
);
//- Decompose and write all fields and field-fields for given cloud
void decomposeAllFields
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "lagrangianFieldDecomposerReadFields.C"
#include "lagrangianFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,241 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "lagrangianFieldDecomposer.H"
#include "labelIOField.H"
#include "labelFieldIOField.H"
#include "scalarIOField.H"
#include "scalarFieldIOField.H"
#include "vectorIOField.H"
#include "vectorFieldIOField.H"
#include "sphericalTensorIOField.H"
#include "sphericalTensorFieldIOField.H"
#include "symmTensorIOField.H"
#include "symmTensorFieldIOField.H"
#include "tensorIOField.H"
#include "tensorFieldIOField.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All lagrangian field/field-field types
class lagrangianFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<PtrList<IOField<Type>>> Type##Fields_; \
PtrList<PtrList<CompactIOField<Field<Type>, Type>>> Type##FieldFields_;
declareField(label);
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
bool empty() const noexcept { return labelFields_.empty(); }
label size() const noexcept { return labelFields_.size(); }
void resize(const label len)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
Type##Fields_.resize(len); \
Type##FieldFields_.resize(len); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
void readAll(const label cloudi, const IOobjectList& lagrangianObjects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
lagrangianFieldDecomposer::readFields \
( \
cloudi, \
lagrangianObjects, \
Type##Fields_ \
); \
lagrangianFieldDecomposer::readFieldFields \
( \
cloudi, \
lagrangianObjects, \
Type##FieldFields_ \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
void decomposeAll
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report /* unused */
) const
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
decomposer.decomposeFields \
( \
cloudDir, \
Type##Fields_[cloudi] \
); \
decomposer.decomposeFieldFields \
( \
cloudDir, \
Type##FieldFields_[cloudi] \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
Foam::lagrangianFieldDecomposer::fieldsCache::fieldsCache
(
const label nClouds
)
:
cache_(new privateCache)
{
cache_->resize(nClouds);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::lagrangianFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::lagrangianFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::lagrangianFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::lagrangianFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::lagrangianFieldDecomposer::fieldsCache::resize
(
const label nClouds
)
{
if (cache_)
{
cache_->resize(nClouds);
}
}
void Foam::lagrangianFieldDecomposer::fieldsCache::readAllFields
(
const label cloudi,
const IOobjectList& lagrangianObjects
)
{
if (cache_)
{
cache_->readAll(cloudi, lagrangianObjects);
}
}
void Foam::lagrangianFieldDecomposer::fieldsCache::decomposeAllFields
(
const label cloudi,
const fileName& cloudDir,
const lagrangianFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(cloudi, cloudDir, decomposer, report);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
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 "lagrangianFieldDecomposer.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::lagrangianFieldDecomposer::readFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOField<Type>>>& lagrangianFields
)
{
// List of lagrangian field objects
UPtrList<const IOobject> fieldObjects
(
lagrangianObjects.sorted<IOField<Type>>()
);
lagrangianFields.set
(
cloudi,
new PtrList<IOField<Type>>(fieldObjects.size())
);
label fieldi = 0;
for (const IOobject& io : fieldObjects)
{
lagrangianFields[cloudi].set(fieldi++, new IOField<Type>(io));
}
}
template<class Type>
void Foam::lagrangianFieldDecomposer::readFieldFields
(
const label cloudi,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<CompactIOField<Field<Type>, Type>>>& lagrangianFields
)
{
// List of lagrangian field objects
UPtrList<const IOobject> fieldObjects;
fieldObjects.append
(
lagrangianObjects.sorted<IOField<Field<Type>>>()
);
fieldObjects.append
(
lagrangianObjects.sorted<CompactIOField<Field<Type>, Type>>()
);
Foam::sort(fieldObjects, nameOp<IOobject>());
lagrangianFields.set
(
cloudi,
new PtrList<CompactIOField<Field<Type>, Type>>(fieldObjects.size())
);
label fieldi = 0;
for (const IOobject& io : fieldObjects)
{
lagrangianFields[cloudi].set
(
fieldi++,
new CompactIOField<Field<Type>, Type>(io)
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
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 "lagrangianFieldDecomposer.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::IOField<Type>>
Foam::lagrangianFieldDecomposer::decomposeField
(
const word& cloudName,
const IOField<Type>& field
) const
{
// Create the field for the processor
return tmp<IOField<Type>>::New
(
IOobject
(
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
// Mapping internal field values
Field<Type>(field, particleIndices_)
);
}
template<class Type>
Foam::tmp<Foam::CompactIOField<Foam::Field<Type>, Type>>
Foam::lagrangianFieldDecomposer::decomposeFieldField
(
const word& cloudName,
const CompactIOField<Field<Type>, Type>& field
) const
{
// Create the field for the processor
return tmp<CompactIOField<Field<Type>, Type>>::New
(
IOobject
(
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
// Mapping internal field values
Field<Field<Type>>(field, particleIndices_)
);
}
template<class GeoField>
void Foam::lagrangianFieldDecomposer::decomposeFields
(
const word& cloudName,
const PtrList<GeoField>& fields
) const
{
const bool existsOnProc = (particleIndices_.size() > 0);
for (const GeoField& fld : fields)
{
decomposeField(cloudName, fld)().write(existsOnProc);
}
}
template<class GeoField>
void Foam::lagrangianFieldDecomposer::decomposeFieldFields
(
const word& cloudName,
const PtrList<GeoField>& fields
) const
{
const bool existsOnProc = (particleIndices_.size() > 0);
for (const GeoField& fld : fields)
{
decomposeFieldField(cloudName, fld)().write(existsOnProc);
}
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,13 @@ Description
SourceFiles
pointFieldDecomposer.C
pointFieldDecomposerFields.C
pointFieldDecomposerCache.C
pointFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef pointFieldDecomposer_H
#define pointFieldDecomposer_H
#ifndef Foam_pointFieldDecomposer_H
#define Foam_pointFieldDecomposer_H
#include "pointMesh.H"
#include "pointPatchFieldMapperPatchRef.H"
@ -48,6 +49,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class IOobjectList;
/*---------------------------------------------------------------------------*\
Class pointFieldDecomposer Declaration
\*---------------------------------------------------------------------------*/
@ -56,6 +60,8 @@ class pointFieldDecomposer
{
public:
// Public Classes
//- Point patch field decomposer class
class patchFieldDecomposer
:
@ -122,13 +128,18 @@ private:
PtrList<patchFieldDecomposer> patchFieldDecomposerPtrs_;
// Private Member Functions
//- No copy construct
pointFieldDecomposer(const pointFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const pointFieldDecomposer&) = delete;
public:
//- No copy construct
pointFieldDecomposer(const pointFieldDecomposer&) = delete;
//- No copy assignment
void operator=(const pointFieldDecomposer&) = delete;
// Public Classes
class fieldsCache;
// Constructors
@ -184,6 +195,69 @@ public:
};
/*---------------------------------------------------------------------------*\
Class pointFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class pointFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Total number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const pointMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const pointFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -191,7 +265,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "pointFieldDecomposerFields.C"
#include "pointFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,208 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "pointFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "pointFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All point field types
class pointFieldDecomposer::fieldsCache::privateCache
{
public:
#undef declareField
#define declareField(Type) \
PtrList<GeometricField<Type, pointPatchField, pointMesh>> Type##Fields_;
declareField(scalar);
declareField(vector);
declareField(sphericalTensor);
declareField(symmTensor);
declareField(tensor);
#undef declareField
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##Fields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const pointMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##Fields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const pointFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll
(
const pointFieldDecomposer& decomposer,
bool report
) const
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
decompose(decomposer, Type##Fields_, report); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pointFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::pointFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::pointFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::pointFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::pointFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::pointFieldDecomposer::fieldsCache::readAllFields
(
const pointMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::pointFieldDecomposer::fieldsCache::decomposeAllFields
(
const pointFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -82,8 +82,8 @@ Foam::pointFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_().time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false

View File

@ -1,4 +1,6 @@
faFieldDecomposer.C
faFieldDecomposerCache.C
faMeshDecomposition.C
LIB = $(FOAM_LIBBIN)/libfaDecompose

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,12 +36,13 @@ Author
SourceFiles
faFieldDecomposer.C
faFieldDecomposerFields.C
fvFieldDecomposerCache.C
faFieldDecomposerTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef faFieldDecomposer_H
#define faFieldDecomposer_H
#ifndef Foam_faFieldDecomposer_H
#define Foam_faFieldDecomposer_H
#include "faMesh.H"
#include "faPatchFieldMapper.H"
@ -63,6 +64,8 @@ class faFieldDecomposer
{
public:
// Public Classes
//- Patch field decomposer class
class patchFieldDecomposer
:
@ -270,13 +273,17 @@ private:
public:
// Public Classes
class fieldsCache;
// Constructors
//- Construct without mappers, added later with reset()
faFieldDecomposer
(
const Foam::zero,
const faMesh& procMesh,
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -285,8 +292,8 @@ public:
//- Construct from components using information from the complete mesh
faFieldDecomposer
(
const faMesh& completeMesh,
const faMesh& procMesh,
const faMesh& completeMesh, // Source mesh
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -302,7 +309,7 @@ public:
const labelUList& edgeNeigbour,
// Addressing for processor mesh
const faMesh& procMesh,
const faMesh& procMesh, // Target mesh
const labelList& edgeAddressing,
const labelList& faceAddressing,
const labelList& boundaryAddressing
@ -358,7 +365,7 @@ public:
// Reading helpers
//- Read the fields and hold on the pointer list
//- Read the fields and store on the pointer list
template
<
class Type,
@ -373,7 +380,7 @@ public:
const bool readOldTime
);
//- Read fields and hold on the pointer list
//- Read fields and store on the pointer list
template<class Mesh, class GeoField>
static void readFields
(
@ -384,6 +391,70 @@ public:
};
/*---------------------------------------------------------------------------*\
Class faFieldDecomposer::fieldsCache Declaration
\*---------------------------------------------------------------------------*/
class faFieldDecomposer::fieldsCache
{
// Private Data
class privateCache;
//- All field and field-field types for lagrangian
std::unique_ptr<privateCache> cache_;
// Private Member Functions
//- No copy construct
fieldsCache(const fieldsCache&) = delete;
//- No copy assignment
void operator=(const fieldsCache&) = delete;
public:
// Constructors
//- Default construct
fieldsCache();
//- Destructor
~fieldsCache();
// Member Functions
//- No fields
bool empty() const;
//- Number of fields
label size() const;
//- Clear out
void clear();
//- Read all fields given mesh and objects
void readAllFields
(
const faMesh& mesh,
const IOobjectList& objects
);
//- Decompose and write all fields
void decomposeAllFields
(
const faFieldDecomposer& decomposer,
bool report = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
@ -391,8 +462,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "faFieldDecomposerFields.C"
#include "faFieldDecomposerReadFields.C"
#include "faFieldDecomposerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faFieldDecomposer.H"
#include "fieldsDistributor.H"
#include "areaFields.H"
#include "edgeFields.H"
#include "IOobjectList.H"
#include "PtrListOps.H"
// * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
namespace Foam
{
// All area/edge field types
class faFieldDecomposer::fieldsCache::privateCache
{
public:
#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
label size() const noexcept
{
label count = 0;
#undef doLocalCode
#define doLocalCode(Type) \
{ \
count += Type##AreaFields_.size(); \
count += Type##EdgeFields_.size(); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
return count;
}
bool empty() const noexcept { return !size(); }
void readAll(const faMesh& mesh, const IOobjectList& objects)
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##AreaFields_ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##AreaFields_, \
false /* readOldTime = false */ \
); \
fieldsDistributor::readFields \
( \
mesh, \
objects, \
Type##EdgeFields_, \
false /* readOldTime = false */ \
); \
}
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
template<class GeoField>
static void decompose
(
const faFieldDecomposer& decomposer,
const PtrList<GeoField>& fields,
bool report
)
{
if (!fields.empty())
{
if (report)
{
Info<< " "
<< pTraits<typename GeoField::value_type>::typeName
<< "s: "
<< flatOutput(PtrListOps::names(fields)) << nl;
}
decomposer.decomposeFields(fields);
}
}
void decomposeAll(const faFieldDecomposer& decomposer, bool report) const
{
#undef doLocalCode
#define doLocalCode(Flavour) \
{ \
decompose(decomposer, scalar##Flavour##Fields_, report); \
decompose(decomposer, vector##Flavour##Fields_, report); \
decompose(decomposer, sphericalTensor##Flavour##Fields_, report); \
decompose(decomposer, symmTensor##Flavour##Fields_, report); \
decompose(decomposer, tensor##Flavour##Fields_, report); \
}
doLocalCode(Area);
doLocalCode(Edge);
#undef doLocalCode
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faFieldDecomposer::fieldsCache::fieldsCache()
:
cache_(new privateCache)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// Destructor not in header (used incomplete type)
Foam::faFieldDecomposer::fieldsCache::~fieldsCache()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::faFieldDecomposer::fieldsCache::empty() const
{
return (!cache_ || cache_->empty());
}
Foam::label Foam::faFieldDecomposer::fieldsCache::size() const
{
return (cache_ ? cache_->size() : label(0));
}
void Foam::faFieldDecomposer::fieldsCache::clear()
{
cache_.reset(new privateCache);
}
void Foam::faFieldDecomposer::fieldsCache::readAllFields
(
const faMesh& mesh,
const IOobjectList& objects
)
{
if (cache_)
{
cache_->readAll(mesh, objects);
}
}
void Foam::faFieldDecomposer::fieldsCache::decomposeAllFields
(
const faFieldDecomposer& decomposer,
bool report
) const
{
if (cache_)
{
cache_->decomposeAll(decomposer, report);
}
}
// ************************************************************************* //

View File

@ -1,92 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 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 "faFieldDecomposer.H"
#include "GeometricField.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::faFieldDecomposer::readFields
(
const typename GeoMesh::Mesh& mesh,
const IOobjectList& objects,
PtrList<GeometricField<Type, PatchField, GeoMesh>>& fields,
const bool readOldTime
)
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// Search list of objects for fields of type GeoField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh, readOldTime));
}
}
template<class Mesh, class GeoField>
void Foam::faFieldDecomposer::readFields
(
const Mesh& mesh,
const IOobjectList& objects,
PtrList<GeoField>& fields
)
{
// Search list of objects for fields of type GeomField
IOobjectList fieldObjects(objects.lookupClass<GeoField>());
// Use sorted set of names
// (different processors might read objects in different order)
const wordList masterNames(fieldObjects.sortedNames());
// Construct the fields
fields.resize(masterNames.size());
forAll(masterNames, i)
{
const IOobject& io = *fieldObjects[masterNames[i]];
fields.set(i, new GeoField(io, mesh));
}
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +27,8 @@ License
\*---------------------------------------------------------------------------*/
#include "faFieldDecomposer.H"
#include "GeometricField.H"
#include "IOobjectList.H"
#include "processorFaPatchField.H"
#include "processorFaePatchField.H"
@ -89,8 +91,8 @@ Foam::faFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -200,8 +202,8 @@ Foam::faFieldDecomposer::decomposeField
IOobject
(
field.name(),
procMesh_.time().timeName(),
procMesh_(),
procMesh_.thisDb().time().timeName(),
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),

View File

@ -47,16 +47,16 @@ void Foam::faMeshDecomposition::distributeFaces()
cpuTime decompositionTime;
for (label procI = 0; procI < nProcs(); procI++)
for (label proci = 0; proci < nProcs(); ++proci)
{
Time processorDb
(
Time::controlDictName,
time().rootPath(),
time().caseName()/("processor" + Foam::name(procI))
time().caseName()/("processor" + Foam::name(proci))
);
polyMesh procMesh
polyMesh procFvMesh
(
IOobject
(
@ -66,6 +66,24 @@ void Foam::faMeshDecomposition::distributeFaces()
)
);
IOobject ioAddr
(
"procAddressing",
"constant",
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // not registered
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
labelIOList fvFaceProcAddressing(ioAddr);
labelHashSet faceProcAddressingHash(2*fvFaceProcAddressing.size());
// If faMesh's fvPatch is a part of the global face zones, faces of that
// patch will be present on all processors. Because of that, looping
// through faceProcAddressing will decompose global faMesh faces to the
@ -76,77 +94,31 @@ void Foam::faMeshDecomposition::distributeFaces()
// Vanja Skuric, 2016-04-21
if (hasGlobalFaceZones_)
{
labelList faceProcAddressing
(
labelIOList
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
const label ownerSize =
(
labelIOList
(
IOobject
(
"owner",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
).size();
labelHashSet faceProcAddressingHash(ownerSize);
// owner (polyMesh)
ioAddr.rename("owner");
const label ownerSize = labelIOList(ioAddr).size();
for (int i = 0; i < ownerSize; ++i)
{
faceProcAddressingHash.insert(faceProcAddressing[i]);
}
forAll(faceLabels(), faceI)
{
if (faceProcAddressingHash.found(faceLabels()[faceI] + 1))
{
faceToProc_[faceI] = procI;
}
faceProcAddressingHash.insert(fvFaceProcAddressing[i]);
}
}
else
{
labelHashSet faceProcAddressingHash
faceProcAddressingHash.insert
(
labelIOList
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
static_cast<labelList&>(fvFaceProcAddressing)
);
}
forAll(faceLabels(), faceI)
forAll(faceLabels(), facei)
{
// With +1 for lookup in faceMap with flip encoding
const label index = (faceLabels()[facei] + 1);
if (faceProcAddressingHash.found(index))
{
if (faceProcAddressingHash.found(faceLabels()[faceI] + 1))
{
faceToProc_[faceI] = procI;
}
faceToProc_[facei] = proci;
}
}
}
@ -276,40 +248,37 @@ void Foam::faMeshDecomposition::decomposeMesh()
)
);
labelIOList fvPointProcAddressing
IOobject ioAddr
(
IOobject
(
"pointProcAddressing",
"constant",
procFvMesh.meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
"procAddressing",
"constant",
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // not registered
);
// pointProcAddressing (polyMesh)
ioAddr.rename("pointProcAddressing");
labelIOList fvPointProcAddressing(ioAddr);
Map<label> fvFaceProcAddressingHash;
{
labelIOList fvFaceProcAddressing
(
IOobject
(
"faceProcAddressing",
"constant",
procFvMesh.meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
labelIOList fvFaceProcAddressing(ioAddr);
forAll(fvFaceProcAddressing, faceI)
fvFaceProcAddressingHash.resize(2*fvFaceProcAddressing.size());
forAll(fvFaceProcAddressing, facei)
{
fvFaceProcAddressingHash.insert
(
fvFaceProcAddressing[faceI], faceI
fvFaceProcAddressing[facei],
facei
);
}
};
@ -365,17 +334,16 @@ void Foam::faMeshDecomposition::decomposeMesh()
const uindirectPrimitivePatch& procPatch = procMesh.patch();
const vectorField& procPoints = procPatch.localPoints();
const labelList& procMeshPoints = procPatch.meshPoints();
const edgeList& procEdges = procPatch.edges();
labelList& curPatchPointAddressing = procPatchPointAddressing_[procI];
curPatchPointAddressing.setSize(procPoints.size(), -1);
curPatchPointAddressing.resize(procMeshPoints.size(), -1);
forAll(procPoints, pointI)
forAll(procMeshPoints, pointi)
{
curPatchPointAddressing[pointI] =
map[fvPointProcAddressing[procMeshPoints[pointI]]];
curPatchPointAddressing[pointi] =
map[fvPointProcAddressing[procMeshPoints[pointi]]];
}
labelList& curPatchEdgeAddressing = procPatchEdgeAddressing_[procI];
@ -1154,9 +1122,12 @@ bool Foam::faMeshDecomposition::writeDecomposition()
sharedPointLookup.insert(globallySharedPoints_[pointi], pointi);
}
label maxProcFaces = 0;
label totProcFaces = 0;
label maxProcEdges = 0;
label totProcEdges = 0;
label maxProcPatches = 0;
label maxProcEdges = 0;
label totProcPatches = 0;
// Write out the meshes
for (label procI = 0; procI < nProcs(); procI++)
@ -1193,7 +1164,7 @@ bool Foam::faMeshDecomposition::writeDecomposition()
(
"boundaryProcAddressing",
"constant",
procFvMesh.meshSubDir,
polyMesh::meshSubDir,
procFvMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
@ -1286,19 +1257,35 @@ bool Foam::faMeshDecomposition::writeDecomposition()
procMesh.write();
Info<< endl
<< "Processor " << procI << nl
<< " Number of faces = " << procMesh.nFaces()
<< endl;
// Statistics
Info<< nl << "Processor " << procI;
if (procMesh.nFaces())
{
Info<< nl << " ";
}
else
{
Info<< ": ";
}
Info<< "Number of faces = " << procMesh.nFaces() << nl;
if (procMesh.nFaces())
{
Info<< " Number of points = " << procMesh.nPoints() << nl;
}
totProcFaces += procMesh.nFaces();
maxProcFaces = max(maxProcFaces, procMesh.nFaces());
label nBoundaryEdges = 0;
label nProcPatches = 0;
label nProcEdges = 0;
forAll(procMesh.boundary(), patchi)
for (const faPatch& fap : procMesh.boundary())
{
const auto* ppp =
isA<processorFaPatch>(procMesh.boundary()[patchi]);
const auto* ppp = isA<processorFaPatch>(fap);
if (ppp)
{
@ -1306,92 +1293,93 @@ bool Foam::faMeshDecomposition::writeDecomposition()
Info<< " Number of edges shared with processor "
<< procPatch.neighbProcNo() << " = "
<< procPatch.size() << endl;
<< procPatch.size() << nl;
nProcEdges += procPatch.size();
++nProcPatches;
}
else
{
nBoundaryEdges += procMesh.boundary()[patchi].size();
nBoundaryEdges += fap.size();
}
}
Info<< " Number of processor patches = " << nProcPatches << nl
<< " Number of processor edges = " << nProcEdges << nl
<< " Number of boundary edges = " << nBoundaryEdges << endl;
if (procMesh.nFaces() && (nBoundaryEdges || nProcEdges))
{
Info<< " Number of processor patches = " << nProcPatches << nl
<< " Number of processor edges = " << nProcEdges << nl
<< " Number of boundary edges = " << nBoundaryEdges << nl;
}
totProcEdges += nProcEdges;
maxProcPatches = max(maxProcPatches, nProcPatches);
totProcPatches += nProcPatches;
maxProcEdges = max(maxProcEdges, nProcEdges);
maxProcPatches = max(maxProcPatches, nProcPatches);
// create and write the addressing information
labelIOList pointProcAddressing
(
IOobject
(
"pointProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procPatchPointAddressing_[procI]
);
pointProcAddressing.write();
// Write the addressing information
labelIOList edgeProcAddressing
IOobject ioAddr
(
IOobject
(
"edgeProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procEdgeAddressing_[procI]
"procAddressing",
"constant",
faMesh::meshSubDir,
procMesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
edgeProcAddressing.write();
labelIOList faceProcAddressing
(
IOobject
(
"faceProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFaceAddressing_[procI]
);
faceProcAddressing.write();
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, procPatchPointAddressing_[procI]).write();
labelIOList boundaryProcAddressing
(
IOobject
(
"boundaryProcAddressing",
"constant",
procMesh.meshSubDir,
procFvMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procBoundaryAddressing_[procI]
);
boundaryProcAddressing.write();
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
IOListRef<label>(ioAddr, procEdgeAddressing_[procI]).write();
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, procFaceAddressing_[procI]).write();
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, procBoundaryAddressing_[procI]).write();
}
// Summary stats
Info<< nl
<< "Number of processor edges = " << totProcEdges/2 << nl
<< "Max number of processor patches = " << maxProcPatches << nl
<< "Max number of faces between processors = " << maxProcEdges
<< endl;
<< "Number of processor edges = " << (totProcEdges/2) << nl
<< "Max number of faces = " << maxProcFaces;
if (maxProcFaces != totProcFaces)
{
scalar avgValue = scalar(totProcFaces)/nProcs_;
Info<< " (" << 100.0*(maxProcFaces-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of processor patches = " << maxProcPatches;
if (totProcPatches)
{
scalar avgValue = scalar(totProcPatches)/nProcs_;
Info<< " (" << 100.0*(maxProcPatches-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl;
Info<< "Max number of edges between processors = " << maxProcEdges;
if (totProcEdges)
{
scalar avgValue = scalar(totProcEdges)/nProcs_;
Info<< " (" << 100.0*(maxProcEdges-avgValue)/avgValue
<< "% above average " << avgValue << ')';
}
Info<< nl << endl;
return true;
}

View File

@ -39,8 +39,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef faMeshDecomposition_H
#define faMeshDecomposition_H
#ifndef Foam_faMeshDecomposition_H
#define Foam_faMeshDecomposition_H
#include "polyMesh.H"
#include "faMesh.H"

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,13 @@ License
\*---------------------------------------------------------------------------*/
#include "faFieldReconstructor.H"
#include "areaFields.H"
#include "edgeFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::faFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -42,8 +50,42 @@ Foam::faFieldReconstructor::faFieldReconstructor
procMeshes_(procMeshes),
edgeProcAddressing_(edgeProcAddressing),
faceProcAddressing_(faceProcAddressing),
boundaryProcAddressing_(boundaryProcAddressing)
boundaryProcAddressing_(boundaryProcAddressing),
nReconstructed_(0)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::faFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
do
{
#undef doLocalCode
#define doLocalCode(Method) \
{ \
nTotal += this->Method <scalar> (objects, selected); \
nTotal += this->Method <vector> (objects, selected); \
nTotal += this->Method <sphericalTensor> (objects, selected); \
nTotal += this->Method <symmTensor> (objects, selected); \
nTotal += this->Method <tensor> (objects, selected); \
}
doLocalCode(reconstructAreaFields);
doLocalCode(reconstructEdgeFields);
#undef doLocalCode
}
while (false);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,12 +36,12 @@ Author
SourceFiles
faFieldReconstructor.C
faFieldReconstructorFields.C
faFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef faFieldReconstructor_H
#define faFieldReconstructor_H
#ifndef Foam_faFieldReconstructor_H
#define Foam_faFieldReconstructor_H
#include "PtrList.H"
#include "faMesh.H"
@ -59,7 +60,7 @@ namespace Foam
class faFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
faMesh& mesh_;
@ -76,6 +77,9 @@ class faFieldReconstructor
//- List of processor boundary addressing lists
const PtrList<labelIOList>& boundaryProcAddressing_;
//- Number of fields reconstructed
label nReconstructed_;
// Private Member Functions
@ -88,6 +92,8 @@ class faFieldReconstructor
public:
// Public Classes
class faPatchFieldReconstructor
:
public faPatchFieldMapper
@ -111,7 +117,7 @@ public:
{}
// Member functions
// Member Functions
virtual label size() const
{
@ -140,13 +146,19 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
faFieldReconstructor
(
faMesh& mesh,
const PtrList<faMesh>& procMeshes,
faMesh& mesh, // Target mesh
const PtrList<faMesh>& procMeshes, // Source meshes
const PtrList<labelIOList>& edgeProcAddressing,
const PtrList<labelIOList>& faceProcAddressing,
const PtrList<labelIOList>& boundaryProcAddressing
@ -155,34 +167,80 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const noexcept
{
return nReconstructed_;
}
//- Reconstruct area field
template<class Type>
tmp<GeometricField<Type, faPatchField, areaMesh>>
reconstructFaAreaField
reconstructField
(
const IOobject& fieldIoObject
);
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faPatchField, areaMesh>>&
) const;
//- Read and reconstruct area field
template<class Type>
tmp<GeometricField<Type, faPatchField, areaMesh>>
reconstructAreaField(const IOobject& fieldObject);
//- Reconstruct edge field
template<class Type>
tmp<GeometricField<Type, faePatchField, edgeMesh>>
reconstructFaEdgeField
reconstructField
(
const IOobject& fieldIoObject
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faePatchField, edgeMesh>>&
) const;
//- Read and reconstruct edge field
template<class Type>
tmp<GeometricField<Type, faePatchField, edgeMesh>>
reconstructEdgeField(const IOobject& fieldObject);
//- Read, reconstruct and write specified area fields
template<class Type>
label reconstructAreaFields
(
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all area fields
//- Read, reconstruct and write specified edge fields
template<class Type>
void reconstructFaAreaFields
label reconstructEdgeFields
(
const IOobjectList& objects
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all area fields
//- Read, reconstruct and write all/selected area fields
// An empty wordRes corresponds to select ALL.
template<class Type>
void reconstructFaEdgeFields
label reconstructAreaFields
(
const IOobjectList& objects
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Read, reconstruct and write all/selected edge fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructEdgeFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct all supported area/edge field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
};
@ -194,7 +252,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "faFieldReconstructorFields.C"
# include "faFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,37 +38,12 @@ License
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh>>
Foam::faFieldReconstructor::reconstructFaAreaField
Foam::faFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject
)
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faPatchField, areaMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, faPatchField, areaMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, procI)
{
procFields.set
(
procI,
new GeometricField<Type, faPatchField, areaMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[procI].time().timeName(),
procMeshes_[procI](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[procI]
)
);
}
// Create the internalField
Field<Type> internalField(mesh_.nFaces());
@ -278,9 +253,9 @@ Foam::faFieldReconstructor::reconstructFaAreaField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -294,38 +269,12 @@ Foam::faFieldReconstructor::reconstructFaAreaField
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>>
Foam::faFieldReconstructor::reconstructFaEdgeField
Foam::faFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject
)
const IOobject& fieldObject,
const PtrList<GeometricField<Type, faePatchField, edgeMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, faePatchField, edgeMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, procI)
{
procFields.set
(
procI,
new GeometricField<Type, faePatchField, edgeMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[procI].time().timeName(),
procMeshes_[procI](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[procI]
)
);
}
// Create the internalField
Field<Type> internalField(mesh_.nInternalEdges());
@ -555,9 +504,9 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -569,58 +518,209 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
}
// Reconstruct and write all area fields
template<class Type>
void Foam::faFieldReconstructor::reconstructFaAreaFields
Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh>>
Foam::faFieldReconstructor::reconstructAreaField
(
const IOobjectList& objects
const IOobject& fieldObject
)
{
const word& clsName =
GeometricField<Type, faPatchField, areaMesh>::typeName;
// Read the field for all the processors
PtrList<GeometricField<Type, faPatchField, areaMesh>> procFields
(
procMeshes_.size()
);
const wordList fieldNames = objects.sortedNames(clsName);
if (fieldNames.size())
forAll(procMeshes_, proci)
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
procFields.set
(
proci,
new GeometricField<Type, faPatchField, areaMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
reconstructFaAreaField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
// Reconstruct and write all edge fields
template<class Type>
void Foam::faFieldReconstructor::reconstructFaEdgeFields
Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh>>
Foam::faFieldReconstructor::reconstructEdgeField
(
const IOobjectList& objects
const IOobject& fieldObject
)
{
const word& clsName =
GeometricField<Type, faePatchField, edgeMesh>::typeName;
// Read the field for all the processors
PtrList<GeometricField<Type, faePatchField, edgeMesh>> procFields
(
procMeshes_.size()
);
const wordList fieldNames = objects.sortedNames(clsName);
if (fieldNames.size())
forAll(procMeshes_, proci)
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
procFields.set
(
proci,
new GeometricField<Type, faePatchField, edgeMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
reconstructFaEdgeField<Type>(*(objects[fieldName]))().write();
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructAreaFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructAreaField<Type>(io)().write();
++nReconstructed_;
}
}
if (fieldNames.size()) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructEdgeFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, faePatchField, edgeMesh> fieldType;
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructEdgeField<Type>(io)().write();
++nReconstructed_;
}
}
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructAreaFields
(
const IOobjectList& objects,
const wordRes& selectedFields
)
{
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
return reconstructAreaFields<Type>
(
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
}
template<class Type>
Foam::label Foam::faFieldReconstructor::reconstructEdgeFields
(
const IOobjectList& objects,
const wordRes& selectedFields
)
{
typedef GeometricField<Type, faePatchField, edgeMesh> fieldType;
return reconstructEdgeFields<Type>
(
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
}

View File

@ -77,7 +77,7 @@ void Foam::faMeshReconstructor::calcAddressing
for (label& facei : faFaceProcAddr_)
{
// Use finiteVolume info, ignoring face flips
facei = mag(fvFaceProcAddr[facei] - 1);
facei = mag(fvFaceProcAddr[facei])-1;
}
@ -449,7 +449,7 @@ void Foam::faMeshReconstructor::initPatch() const
void Foam::faMeshReconstructor::createMesh()
{
const Time& runTime = procMesh_.mesh().time();
const Time& runTime = procMesh_.thisDb().time();
// Time for non-parallel case (w/o functionObjects or libs)
serialRunTime_ = Time::New(runTime.globalPath().toAbsolute());
@ -654,7 +654,7 @@ void Foam::faMeshReconstructor::writeAddressing(const word& timeName) const
"procAddressing",
timeName,
faMesh::meshSubDir,
procMesh_.mesh(), // The polyMesh
procMesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
@ -662,19 +662,19 @@ void Foam::faMeshReconstructor::writeAddressing(const word& timeName) const
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
labelIOList(ioAddr, faBoundaryProcAddr_).write();
IOListRef<label>(ioAddr, faBoundaryProcAddr_).write();
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
labelIOList(ioAddr, faFaceProcAddr_).write();
IOListRef<label>(ioAddr, faFaceProcAddr_).write();
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
labelIOList(ioAddr, faPointProcAddr_).write();
IOListRef<label>(ioAddr, faPointProcAddr_).write();
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
labelIOList(ioAddr, faEdgeProcAddr_).write();
IOListRef<label>(ioAddr, faEdgeProcAddr_).write();
}
@ -699,7 +699,7 @@ void Foam::faMeshReconstructor::writeMesh(const word& timeName) const
IOobject io(fullMesh.boundary());
io.rename("faceLabels");
labelIOList(io, singlePatchFaceLabels_).write();
IOListRef<label>(io, singlePatchFaceLabels_).write();
fullMesh.boundary().write();

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,102 +28,50 @@ License
#include "processorFaMeshes.H"
#include "Time.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::processorFaMeshes::read()
{
forAll(fvMeshes_, procI)
forAll(fvMeshes_, proci)
{
meshes_.set
meshes_.set(proci, new faMesh(fvMeshes_[proci]));
// Read the addressing information
IOobject ioAddr
(
procI,
new faMesh(fvMeshes_[procI])
"procAddressing",
"constant", // Placeholder
faMesh::meshSubDir,
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
pointProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"pointProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"pointProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
const auto& runTime = meshes_[proci].thisDb().time();
const auto& meshDir = meshes_[proci].meshDir();
edgeProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"edgeProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"edgeProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// pointProcAddressing (faMesh)
ioAddr.rename("pointProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
pointProcAddressing_.set(proci, new labelIOList(ioAddr));
faceProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"faceProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"faceProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// edgeProcAddressing (faMesh)
ioAddr.rename("edgeProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
edgeProcAddressing_.set(proci, new labelIOList(ioAddr));
boundaryProcAddressing_.set
(
procI,
new labelIOList
(
IOobject
(
"boundaryProcAddressing",
meshes_[procI].time().findInstance
(
meshes_[procI].meshDir(),
"faceProcAddressing"
),
meshes_[procI].meshSubDir,
fvMeshes_[procI],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// faceProcAddressing (faMesh)
ioAddr.rename("faceProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
faceProcAddressing_.set(proci, new labelIOList(ioAddr));
// boundaryProcAddressing (faMesh)
ioAddr.rename("boundaryProcAddressing");
ioAddr.instance() = runTime.findInstance(meshDir, ioAddr.name());
boundaryProcAddressing_.set(proci, new labelIOList(ioAddr));
}
}
@ -131,11 +80,11 @@ void Foam::processorFaMeshes::read()
Foam::processorFaMeshes::processorFaMeshes
(
const UPtrList<fvMesh>& processorFvMeshes
const UPtrList<fvMesh>& procFvMeshes
)
:
fvMeshes_(processorFvMeshes),
meshes_(processorFvMeshes.size()),
fvMeshes_(procFvMeshes),
meshes_(procFvMeshes.size()),
pointProcAddressing_(meshes_.size()),
edgeProcAddressing_(meshes_.size()),
faceProcAddressing_(meshes_.size()),
@ -145,4 +94,40 @@ Foam::processorFaMeshes::processorFaMeshes
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::processorFaMeshes::removeFiles(const faMesh& mesh)
{
IOobject ioAddr
(
"procAddressing",
mesh.facesInstance(),
faMesh::meshSubDir,
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
// procAddressing
rm(ioAddr.objectPath());
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
rm(ioAddr.objectPath());
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
rm(ioAddr.objectPath());
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
rm(ioAddr.objectPath());
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
rm(ioAddr.objectPath());
}
// ************************************************************************* //

View File

@ -37,8 +37,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef processorFaMeshes_H
#define processorFaMeshes_H
#ifndef Foam_processorFaMeshes_H
#define Foam_processorFaMeshes_H
#include "PtrList.H"
#include "faMesh.H"
@ -57,7 +57,7 @@ namespace Foam
class processorFaMeshes
{
// Private data
// Private Data
//- List of processor finite volume meshes
const UPtrList<fvMesh>& fvMeshes_;
@ -95,40 +95,44 @@ public:
// Constructors
//- Construct from components
explicit processorFaMeshes(const UPtrList<fvMesh>& processorFvMeshes);
explicit processorFaMeshes(const UPtrList<fvMesh>& procFvMeshes);
// Member Functions
const PtrList<faMesh>& meshes() const
const PtrList<faMesh>& meshes() const noexcept
{
return meshes_;
}
PtrList<faMesh>& meshes()
PtrList<faMesh>& meshes() noexcept
{
return meshes_;
}
const PtrList<labelIOList>& pointProcAddressing() const
const PtrList<labelIOList>& pointProcAddressing() const noexcept
{
return pointProcAddressing_;
}
PtrList<labelIOList>& edgeProcAddressing()
PtrList<labelIOList>& edgeProcAddressing() noexcept
{
return edgeProcAddressing_;
}
const PtrList<labelIOList>& faceProcAddressing() const
const PtrList<labelIOList>& faceProcAddressing() const noexcept
{
return faceProcAddressing_;
}
const PtrList<labelIOList>& boundaryProcAddressing() const
const PtrList<labelIOList>& boundaryProcAddressing() const noexcept
{
return boundaryProcAddressing_;
}
//- Helper: remove all procAddressing files from mesh instance
static void removeFiles(const faMesh& mesh);
};

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,13 @@ License
\*---------------------------------------------------------------------------*/
#include "fvFieldReconstructor.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::fvFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -71,4 +79,38 @@ Foam::fvFieldReconstructor::fvFieldReconstructor
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::fvFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
do
{
#undef doLocalCode
#define doLocalCode(Method) \
{ \
nTotal += this->Method <scalar> (objects, selected); \
nTotal += this->Method <vector> (objects, selected); \
nTotal += this->Method <sphericalTensor> (objects, selected); \
nTotal += this->Method <symmTensor> (objects, selected); \
nTotal += this->Method <tensor> (objects, selected); \
}
doLocalCode(reconstructInternalFields);
doLocalCode(reconstructVolumeFields);
doLocalCode(reconstructSurfaceFields);
#undef doLocalCode
}
while (false);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
fvFieldReconstructor.C
fvFieldReconstructorFields.C
fvFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef fvFieldReconstructor_H
#define fvFieldReconstructor_H
#ifndef Foam_fvFieldReconstructor_H
#define Foam_fvFieldReconstructor_H
#include "PtrList.H"
#include "fvMesh.H"
@ -56,7 +56,7 @@ namespace Foam
class fvFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
fvMesh& mesh_;
@ -88,6 +88,8 @@ class fvFieldReconstructor
public:
// Public Classes
//- Mapper for sizing only - does not do any actual mapping.
class fvPatchFieldReconstructor
:
@ -130,6 +132,12 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -146,7 +154,7 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const
label nReconstructed() const noexcept
{
return nReconstructed_;
}
@ -154,76 +162,74 @@ public:
//- Reconstruct volume internal field
template<class Type>
tmp<DimensionedField<Type, volMesh>>
reconstructFvVolumeInternalField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<DimensionedField<Type, volMesh>>& procFields
) const;
//- Read and reconstruct volume internal field
template<class Type>
tmp<DimensionedField<Type, volMesh>>
reconstructFvVolumeInternalField(const IOobject& fieldIoObject) const;
reconstructInternalField(const IOobject& fieldObject) const;
//- Reconstruct volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
reconstructFvVolumeField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvPatchField, volMesh>>&
) const;
//- Read and reconstruct volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
reconstructFvVolumeField(const IOobject& fieldIoObject) const;
reconstructVolumeField(const IOobject& fieldObject) const;
//- Reconstruct surface field
template<class Type>
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
reconstructFvSurfaceField
reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>&
) const;
//- Read and reconstruct surface field
template<class Type>
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
reconstructFvSurfaceField(const IOobject& fieldIoObject) const;
reconstructSurfaceField(const IOobject& fieldObject) const;
//- Read, reconstruct and write specified volume internal fields
template<class Type>
label reconstructFvVolumeInternalFields
label reconstructInternalFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write specified volume fields
template<class Type>
label reconstructFvVolumeFields
label reconstructVolumeFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write specified surface fields
template<class Type>
label reconstructFvSurfaceFields
label reconstructSurfaceFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Read, reconstruct and write all/selected volume internal fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvVolumeInternalFields
label reconstructInternalFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
@ -232,7 +238,7 @@ public:
//- Read, reconstruct and write all/selected volume fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvVolumeFields
label reconstructVolumeFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
@ -241,40 +247,17 @@ public:
//- Read, reconstruct and write all/selected surface fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFvSurfaceFields
label reconstructSurfaceFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Read, reconstruct and write all/selected volume internal fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvVolumeInternalFields
//- Reconstruct all known field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
);
//- Read, reconstruct and write all/selected volume fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvVolumeFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
);
//- Read, reconstruct and write all/selected surface fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFvSurfaceFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
const wordRes& selectedFields = wordRes()
);
};
@ -286,7 +269,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fvFieldReconstructorFields.C"
#include "fvFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,9 +38,9 @@ License
template<class Type>
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<DimensionedField<Type, volMesh>>& procFields
) const
{
@ -61,7 +61,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField
@ -73,59 +73,11 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
}
template<class Type>
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
(
const IOobject& fieldIoObject
) const
{
// Read the field for all the processors
PtrList<DimensionedField<Type, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new DimensionedField<Type, volMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructFvVolumeInternalField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvPatchField, volMesh>>& procFields
) const
{
@ -137,8 +89,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
forAll(procFields, proci)
{
const GeometricField<Type, fvPatchField, volMesh>& procField =
procFields[proci];
const auto& procField = procFields[proci];
// Set the cell values in the reconstructed field
internalField.rmap
@ -287,7 +238,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
// setting the internalField and patchFields
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField,
@ -300,59 +251,11 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructFvVolumeField
(
const IOobject& fieldIoObject
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, fvPatchField, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructFvVolumeField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructFvSurfaceField
Foam::fvFieldReconstructor::reconstructField
(
const IOobject& fieldIoObject,
const IOobject& fieldObject,
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& procFields
) const
{
@ -365,8 +268,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
forAll(procMeshes_, proci)
{
const GeometricField<Type, fvsPatchField, surfaceMesh>& procField =
procFields[proci];
const auto& procField = procFields[proci];
// Set the face values in the reconstructed field
@ -529,7 +431,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// setting the internalField and patchFields
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
fieldIoObject,
fieldObject,
mesh_,
procFields[0].dimensions(),
internalField,
@ -543,10 +445,106 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructFvSurfaceField
Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructInternalField
(
const IOobject& fieldIoObject
const IOobject& fieldObject
) const
{
// Read the field for all the processors
PtrList<DimensionedField<Type, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new DimensionedField<Type, volMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::fvFieldReconstructor::reconstructVolumeField
(
const IOobject& fieldObject
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, fvPatchField, volMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh>>
Foam::fvFieldReconstructor::reconstructSurfaceField
(
const IOobject& fieldObject
) const
{
// Read the field for all the processors
@ -564,9 +562,9 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci].time().timeName(),
procMeshes_[proci],
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
@ -575,13 +573,13 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
);
}
return reconstructFvSurfaceField
return reconstructField
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_,
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -591,103 +589,113 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
Foam::label Foam::fvFieldReconstructor::reconstructInternalFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef DimensionedField<Type, volMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvVolumeInternalField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructInternalField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
Foam::label Foam::fvFieldReconstructor::reconstructVolumeFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvVolumeField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructVolumeField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
Foam::label Foam::fvFieldReconstructor::reconstructSurfaceFields
(
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFvSurfaceField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructSurfaceField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
Foam::label Foam::fvFieldReconstructor::reconstructInternalFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -695,19 +703,19 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
{
typedef DimensionedField<Type, volMesh> fieldType;
const wordList fieldNames =
return reconstructInternalFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvVolumeInternalFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
Foam::label Foam::fvFieldReconstructor::reconstructVolumeFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -715,19 +723,19 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const wordList fieldNames =
return reconstructVolumeFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvVolumeFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
Foam::label Foam::fvFieldReconstructor::reconstructSurfaceFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -735,74 +743,14 @@ Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
const wordList fieldNames =
return reconstructSurfaceFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFvSurfaceFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef DimensionedField<Type, volMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvVolumeInternalFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvVolumeFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvVolumeField<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::fvFieldReconstructor::reconstructFvSurfaceFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFvSurfaceFields<Type>(objects, fieldNames);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018,2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,11 @@ License
#include "lagrangianReconstructor.H"
#include "passivePositionParticleCloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::lagrangianReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianReconstructor::lagrangianReconstructor
@ -142,4 +147,44 @@ Foam::label Foam::lagrangianReconstructor::reconstructPositions
}
void Foam::lagrangianReconstructor::reconstructAllFields
(
const word& cloudName,
const IOobjectList& cloudObjs,
const wordRes& selectedFields
)
{
do
{
#undef doLocalCode
#define doLocalCode(Type) \
{ \
this->reconstructFields<Type> \
( \
cloudName, \
cloudObjs, \
selectedFields \
); \
\
this->reconstructFieldFields<Type> \
( \
cloudName, \
cloudObjs, \
selectedFields \
); \
}
doLocalCode(label);
doLocalCode(scalar);
doLocalCode(vector);
doLocalCode(sphericalTensor);
doLocalCode(symmTensor);
doLocalCode(tensor);
#undef doLocalCode
}
while (false);
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
lagrangianReconstructor.C
lagrangianReconstructorFields.C
lagrangianReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef lagrangianReconstructor_H
#define lagrangianReconstructor_H
#ifndef Foam_lagrangianReconstructor_H
#define Foam_lagrangianReconstructor_H
#include "cloud.H"
#include "polyMesh.H"
@ -56,7 +56,7 @@ namespace Foam
class lagrangianReconstructor
{
// Private data
// Private Data
//- Mesh reference
const fvMesh& mesh_;
@ -82,6 +82,12 @@ class lagrangianReconstructor
public:
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -101,7 +107,8 @@ public:
//- Reconstruct a single field for given cloud
template<class Type>
tmp<IOField<Type>> reconstructField
tmp<IOField<Type>>
reconstructField
(
const word& cloudName,
const word& fieldName
@ -109,7 +116,8 @@ public:
//- Reconstruct a single field-field for given cloud
template<class Type>
tmp<CompactIOField<Field<Type>, Type>> reconstructFieldField
tmp<CompactIOField<Field<Type>, Type>>
reconstructFieldField
(
const word& cloudName,
const word& fieldName
@ -120,8 +128,7 @@ public:
label reconstructFields
(
const word& cloudName,
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct multiple fields for given cloud
@ -141,6 +148,14 @@ public:
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct all fields for known cloud field types
void reconstructAllFields
(
const word& cloudName,
const IOobjectList& cloudObjs,
const wordRes& selectedFields = wordRes()
);
};
@ -151,7 +166,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "lagrangianReconstructorFields.C"
#include "lagrangianReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -153,30 +153,33 @@ template<class Type>
Foam::label Foam::lagrangianReconstructor::reconstructFields
(
const word& cloudName,
const IOobjectList& objects,
const UList<word>& fieldNames
const UPtrList<const IOobject>& fieldObjects
)
{
typedef IOField<Type> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (nFields++)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructField<Type>(cloudName, fieldName)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructField<Type>(cloudName, io.name())().write();
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
@ -191,14 +194,15 @@ Foam::label Foam::lagrangianReconstructor::reconstructFields
{
typedef IOField<Type> fieldType;
const wordList fieldNames =
return reconstructFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
cloudName,
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFields<Type>(cloudName, objects, fieldNames);
}
@ -211,38 +215,41 @@ Foam::label Foam::lagrangianReconstructor::reconstructFieldFields
)
{
typedef CompactIOField<Field<Type>, Type> fieldType;
typedef IOField<Field<Type>> fieldTypeB;
wordList fieldNames =
(
selectedFields.empty()
? objects.names<fieldType>()
: objects.names<fieldType>(selectedFields)
);
UPtrList<const IOobject> fieldObjects;
// Append IOField Field names
fieldNames.append
(
objects.empty()
? objects.names<IOField<Field<Type>>>()
: objects.names<IOField<Field<Type>>>(selectedFields)
);
Foam::sort(fieldNames);
label nFields = 0;
for (const word& fieldName : fieldNames)
if (selectedFields.empty())
{
if (!nFields++)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructFieldField<Type>(cloudName, fieldName)().write();
fieldObjects.append(objects.sorted<fieldType>());
fieldObjects.append(objects.sorted<fieldTypeB>());
}
else
{
fieldObjects.append(objects.sorted<fieldType>(selectedFields));
fieldObjects.append(objects.sorted<fieldTypeB>(selectedFields));
}
if (nFields) Info<< endl;
Foam::sort(fieldObjects, nameOp<IOobject>());
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructFieldField<Type>(cloudName, io.name())().write();
}
if (verbose_ && nFields) Info<< endl;
return nFields;
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +27,12 @@ License
\*---------------------------------------------------------------------------*/
#include "pointFieldReconstructor.H"
#include "pointFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
int Foam::pointFieldReconstructor::verbose_ = 1;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -95,4 +102,24 @@ Foam::pointFieldReconstructor::pointFieldReconstructor
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::pointFieldReconstructor::reconstructAllFields
(
const IOobjectList& objects,
const wordRes& selected
)
{
label nTotal = 0;
nTotal += reconstructPointFields<scalar>(objects, selected);
nTotal += reconstructPointFields<vector>(objects, selected);
nTotal += reconstructPointFields<symmTensor>(objects, selected);
nTotal += reconstructPointFields<sphericalTensor>(objects, selected);
nTotal += reconstructPointFields<tensor>(objects, selected);
return nTotal;
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ Description
SourceFiles
pointFieldReconstructor.C
pointFieldReconstructorFields.C
pointFieldReconstructorTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef pointFieldReconstructor_H
#define pointFieldReconstructor_H
#ifndef Foam_pointFieldReconstructor_H
#define Foam_pointFieldReconstructor_H
#include "pointMesh.H"
#include "pointFields.H"
@ -55,7 +55,7 @@ namespace Foam
class pointFieldReconstructor
{
// Private data
// Private Data
//- Reconstructed mesh reference
const pointMesh& mesh_;
@ -87,6 +87,8 @@ class pointFieldReconstructor
public:
// Public Classes
class pointPatchFieldReconstructor
:
public pointPatchFieldMapper
@ -128,6 +130,12 @@ public:
};
// Static Data
//- Output verbosity when writing
static int verbose_;
// Constructors
//- Construct from components
@ -143,41 +151,48 @@ public:
// Member Functions
//- Return number of fields reconstructed
label nReconstructed() const
label nReconstructed() const noexcept
{
return nReconstructed_;
}
//- Reconstruct field
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>>
reconstructField(const IOobject& fieldIoObject);
//- Reconstruct and write specified fields
template<class Type>
label reconstructFields
reconstructField
(
const IOobjectList& objects,
const UList<word>& fieldNames
const IOobject& fieldObject,
const PtrList<GeometricField<Type, pointPatchField, pointMesh>>&
) const;
//- Read and reconstruct point field
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>>
reconstructPointField(const IOobject& fieldObject);
//- Reconstruct and write specified point fields
template<class Type>
label reconstructPointFields
(
const UPtrList<const IOobject>& fieldObjects
);
//- Reconstruct and write all or selected fields
//- Reconstruct and write all or selected point fields
// An empty wordRes corresponds to select ALL.
template<class Type>
label reconstructFields
label reconstructPointFields
(
const IOobjectList& objects,
const wordRes& selectedFields = wordRes()
);
//- Reconstruct and write all or selected fields
// An empty wordHashSet corresponds to select ALL.
// \note this may be removed in the future (2018-11)
template<class Type>
label reconstructFields
//- Reconstruct and write all known field types
label reconstructAllFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
const wordRes& selectedFields = wordRes()
);
};
@ -189,7 +204,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "pointFieldReconstructorFields.C"
#include "pointFieldReconstructorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,34 +32,13 @@ License
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh>>
Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
Foam::pointFieldReconstructor::reconstructField
(
const IOobject& fieldObject,
const PtrList<GeometricField<Type, pointPatchField, pointMesh>>& procFields
) const
{
// Read the field for all the processors
PtrList<GeometricField<Type, pointPatchField, pointMesh>> procFields
(
procMeshes_.size()
);
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new GeometricField<Type, pointPatchField, pointMesh>
(
IOobject
(
fieldIoObject.name(),
procMeshes_[proci]().time().timeName(),
procMeshes_[proci](),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
// Create the internalField
Field<Type> internalField(mesh_.size());
@ -70,8 +49,7 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
forAll(procMeshes_, proci)
{
const GeometricField<Type, pointPatchField, pointMesh>&
procField = procFields[proci];
const auto& procField = procFields[proci];
// Get processor-to-global addressing for use in rmap
const labelList& procToGlobalAddr = pointProcAddressing_[proci];
@ -120,13 +98,13 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
// Construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
return tmp<fieldType>::New
(
IOobject
(
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
@ -139,39 +117,89 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh>>
Foam::pointFieldReconstructor::reconstructPointField
(
const IOobjectList& objects,
const UList<word>& fieldNames
const IOobject& fieldObject
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
// Read the field for all the processors
PtrList<fieldType> procFields(procMeshes_.size());
forAll(procMeshes_, proci)
{
procFields.set
(
proci,
new fieldType
(
IOobject
(
fieldObject.name(),
procMeshes_[proci].thisDb().time().timeName(),
procMeshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
procMeshes_[proci]
)
);
}
return reconstructField
(
IOobject
(
fieldObject.name(),
mesh_.thisDb().time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
procFields
);
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructPointFields
(
const UPtrList<const IOobject>& fieldObjects
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
label nFields = 0;
for (const word& fieldName : fieldNames)
{
const IOobject* io = objects.cfindObject<fieldType>(fieldName);
if (io)
{
if (!nFields++)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << fieldName << endl;
reconstructField<Type>(*io)().write();
for (const IOobject& io : fieldObjects)
{
if (io.isHeaderClass<fieldType>())
{
if (verbose_)
{
if (!nFields)
{
Info<< " Reconstructing "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << io.name() << endl;
}
++nFields;
reconstructPointField<Type>(io)().write();
++nReconstructed_;
}
}
if (nFields) Info<< endl;
if (verbose_ && nFields) Info<< endl;
return nFields;
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
Foam::label Foam::pointFieldReconstructor::reconstructPointFields
(
const IOobjectList& objects,
const wordRes& selectedFields
@ -179,34 +207,14 @@ Foam::label Foam::pointFieldReconstructor::reconstructFields
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
const wordList fieldNames =
return reconstructPointFields<Type>
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
(
selectedFields.empty()
? objects.sorted<fieldType>()
: objects.sorted<fieldType>(selectedFields)
)
);
return reconstructFields<Type>(objects, fieldNames);
}
template<class Type>
Foam::label Foam::pointFieldReconstructor::reconstructFields
(
const IOobjectList& objects,
const wordHashSet& selectedFields
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fieldType;
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames<fieldType>()
: objects.sortedNames<fieldType>(selectedFields)
);
return reconstructFields<Type>(objects, fieldNames);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,8 +28,9 @@ License
#include "processorMeshes.H"
#include "Time.H"
#include "IndirectList.H"
#include "primitiveMesh.H"
#include "topoSet.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -70,73 +71,33 @@ void Foam::processorMeshes::read()
)
);
pointProcAddressing_.set
// Read the addressing information
IOobject ioAddr
(
proci,
new labelIOList
(
IOobject
(
"pointProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
"procAddressing",
meshes_[proci].facesInstance(),
polyMesh::meshSubDir,
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE
);
faceProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"faceProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// pointProcAddressing (polyMesh)
ioAddr.rename("pointProcAddressing");
pointProcAddressing_.set(proci, new labelIOList(ioAddr));
cellProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"cellProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// faceProcAddressing (polyMesh)
ioAddr.rename("faceProcAddressing");
faceProcAddressing_.set(proci, new labelIOList(ioAddr));
boundaryProcAddressing_.set
(
proci,
new labelIOList
(
IOobject
(
"boundaryProcAddressing",
meshes_[proci].facesInstance(),
meshes_[proci].meshSubDir,
meshes_[proci],
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// cellProcAddressing (polyMesh)
ioAddr.rename("cellProcAddressing");
cellProcAddressing_.set(proci, new labelIOList(ioAddr));
// boundaryProcAddressing (polyMesh)
ioAddr.rename("boundaryProcAddressing");
boundaryProcAddressing_.set(proci, new labelIOList(ioAddr));
}
}
@ -163,17 +124,17 @@ Foam::processorMeshes::processorMeshes
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
Foam::polyMesh::readUpdateState Foam::processorMeshes::readUpdate()
{
fvMesh::readUpdateState stat = fvMesh::UNCHANGED;
polyMesh::readUpdateState stat = polyMesh::UNCHANGED;
forAll(databases_, proci)
{
// Check if any new meshes need to be read.
fvMesh::readUpdateState procStat = meshes_[proci].readUpdate();
polyMesh::readUpdateState procStat = meshes_[proci].readUpdate();
/*
if (procStat != fvMesh::UNCHANGED)
if (procStat != polyMesh::UNCHANGED)
{
Info<< "Processor " << proci
<< " at time " << databases_[proci].timeName()
@ -183,7 +144,7 @@ Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
*/
// Combine into overall mesh change status
if (stat == fvMesh::UNCHANGED)
if (stat == polyMesh::UNCHANGED)
{
stat = procStat;
}
@ -203,8 +164,8 @@ Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
if
(
stat == fvMesh::TOPO_CHANGE
|| stat == fvMesh::TOPO_PATCH_CHANGE
stat == polyMesh::TOPO_CHANGE
|| stat == polyMesh::TOPO_PATCH_CHANGE
)
{
// Reread all meshes and addressing
@ -231,7 +192,7 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
"points",
meshes_[proci].time().timeName(),
polyMesh::meshSubDir,
meshes_[proci],
meshes_[proci].thisDb(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
@ -247,23 +208,19 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
{
const vectorField& procPoints = procsPoints[proci];
// Set the cell values in the reconstructed field
const labelList& pointProcAddr = pointProcAddressing_[proci];
const labelList& pointProcAddressingI = pointProcAddressing_[proci];
if (pointProcAddressingI.size() != procPoints.size())
if (pointProcAddr.size() != procPoints.size())
{
FatalErrorInFunction
<< "problem :"
<< " pointProcAddressingI:" << pointProcAddressingI.size()
<< " pointProcAddr:" << pointProcAddr.size()
<< " procPoints:" << procPoints.size()
<< abort(FatalError);
}
forAll(pointProcAddressingI, pointi)
{
newPoints[pointProcAddressingI[pointi]] = procPoints[pointi];
}
UIndirectList<point>(newPoints, pointProcAddr) = procPoints;
// or: newPoints.rmap(procPoints, pointProcAddr)
}
mesh.movePoints(newPoints);
@ -273,59 +230,35 @@ void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
void Foam::processorMeshes::removeFiles(const polyMesh& mesh)
{
fileName pointPath
IOobject ioAddr
(
IOobject
(
"pointProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
"procAddressing",
mesh.facesInstance(),
polyMesh::meshSubDir,
mesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // not registered
);
if (topoSet::debug) DebugVar(pointPath);
rm(pointPath);
rm
(
IOobject
(
"faceProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"cellProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"boundaryProcAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
rm
(
IOobject
(
"procAddressing",
mesh.facesInstance(),
mesh.meshSubDir,
mesh
).objectPath()
);
// procAddressing
rm(ioAddr.objectPath());
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
rm(ioAddr.objectPath());
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
rm(ioAddr.objectPath());
// cellProcAddressing
ioAddr.rename("cellProcAddressing");
rm(ioAddr.objectPath());
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
rm(ioAddr.objectPath());
}

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef processorMeshes_H
#define processorMeshes_H
#ifndef Foam_processorMeshes_H
#define Foam_processorMeshes_H
#include "PtrList.H"
#include "fvMesh.H"
@ -54,7 +54,7 @@ namespace Foam
class processorMeshes
{
// Private data
// Private Data
const word meshName_;
@ -104,41 +104,42 @@ public:
// Member Functions
//- Update the meshes based on the mesh files saved in time directories
fvMesh::readUpdateState readUpdate();
polyMesh::readUpdateState readUpdate();
//- Reconstruct point position after motion in parallel
void reconstructPoints(fvMesh&);
const PtrList<fvMesh>& meshes() const
const PtrList<fvMesh>& meshes() const noexcept
{
return meshes_;
}
PtrList<fvMesh>& meshes()
PtrList<fvMesh>& meshes() noexcept
{
return meshes_;
}
const PtrList<labelIOList>& pointProcAddressing() const
const PtrList<labelIOList>& pointProcAddressing() const noexcept
{
return pointProcAddressing_;
}
PtrList<labelIOList>& faceProcAddressing()
PtrList<labelIOList>& faceProcAddressing() noexcept
{
return faceProcAddressing_;
}
const PtrList<labelIOList>& cellProcAddressing() const
const PtrList<labelIOList>& cellProcAddressing() const noexcept
{
return cellProcAddressing_;
}
const PtrList<labelIOList>& boundaryProcAddressing() const
const PtrList<labelIOList>& boundaryProcAddressing() const noexcept
{
return boundaryProcAddressing_;
}
//- Helper: remove all procAddressing files from mesh instance
static void removeFiles(const polyMesh& mesh);
};