Added support for patch manipulation of pointFields

e.g. during createBaffles

Added a test application and test case for meshTools: test/fvMeshTools

Patch contributed by Mattijs Janssens
This commit is contained in:
Henry Weller
2019-04-12 18:44:32 +01:00
parent 181f110a2f
commit 3cbb932be8
49 changed files with 2296 additions and 779 deletions

View File

@ -46,6 +46,7 @@ Description
#include "ReadFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
#include "fvMeshMapper.H"
#include "faceSelection.H"
@ -504,7 +505,7 @@ int main(int argc, char *argv[])
#include "readVolFields.H"
#include "readSurfaceFields.H"
// #include "readPointFields.H"
#include "readPointFields.H"
// Creating (if necessary) faceZones

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -254,7 +254,7 @@ template<class GeoField>
void readFields
(
const boolList& haveMesh,
const fvMesh& mesh,
const typename GeoField::Mesh& mesh,
const autoPtr<fvMeshSubset>& subsetterPtr,
IOobjectList& allObjects,
PtrList<GeoField>& fields
@ -335,8 +335,8 @@ void readFields
IOobject
(
name,
mesh.time().timeName(),
mesh,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
@ -723,6 +723,60 @@ int main(int argc, char *argv[])
);
// pointFields
pointMesh& pMesh =
const_cast<pointMesh&>(pointMesh::New(mesh));
PtrList<pointScalarField> pointScalarFields;
readFields
(
haveMesh,
pMesh,
subsetterPtr,
objects,
pointScalarFields
);
PtrList<pointVectorField> pointVectorFields;
readFields
(
haveMesh,
pMesh,
subsetterPtr,
objects,
pointVectorFields
);
PtrList<pointSphericalTensorField> pointSphereTensorFields;
readFields
(
haveMesh,
pMesh,
subsetterPtr,
objects,
pointSphereTensorFields
);
PtrList<pointSymmTensorField> pointSymmTensorFields;
readFields
(
haveMesh,
pMesh,
subsetterPtr,
objects,
pointSymmTensorFields
);
PtrList<pointTensorField> pointTensorFields;
readFields
(
haveMesh,
pMesh,
subsetterPtr,
objects,
pointTensorFields
);
// Debugging: Create additional volField that will be mapped.
// Used to test correctness of mapping
// volVectorField mapCc("mapCc", 1*mesh.C());

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -244,6 +244,25 @@ void Foam::PtrList<T>::reorder(const labelUList& oldToNew)
}
template<class T>
void Foam::PtrList<T>::shuffle(const labelUList& newToOld)
{
List<T*> newPtrs_(newToOld.size(), reinterpret_cast<T*>(0));
forAll(newToOld, newI)
{
label oldI = newToOld[newI];
if (oldI >= 0 && oldI < this->size())
{
newPtrs_[newI] = this->ptrs_[oldI];
}
}
this->ptrs_.transfer(newPtrs_);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -165,7 +165,12 @@ public:
//- Reorders elements. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// (is shuffle)
void reorder(const labelUList&);
void reorder(const labelUList& oldToNew);
//- Reorders elements. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// Note: can create unset elements
void shuffle(const labelUList& newToOld);
// Member operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -145,6 +145,25 @@ void Foam::UPtrList<T>::reorder(const labelUList& oldToNew)
}
template<class T>
void Foam::UPtrList<T>::shuffle(const labelUList& newToOld)
{
List<T*> newPtrs_(newToOld.size(), reinterpret_cast<T*>(0));
forAll(newToOld, newI)
{
label oldI = newToOld[newI];
if (oldI >= 0 && oldI < this->size())
{
newPtrs_[newI] = this->ptrs_[oldI];
}
}
this->ptrs_.transfer(newPtrs_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "UPtrListIO.C"

View File

@ -148,7 +148,12 @@ public:
//- Reorders elements. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// (is shuffle)
void reorder(const labelUList&);
void reorder(const labelUList& oldToNew);
//- Reorders elements. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// Note: can create unset elements
void shuffle(const labelUList& newToOld);
// Member operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -155,6 +155,83 @@ void MapGeometricFields
}
template<class GeoField>
void AddPatchFields
(
objectRegistry& obr,
const label insertPatchi,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const typename GeoField::value_type& defaultPatchValue
)
{
HashTable<GeoField*> flds(obr.lookupClass<GeoField>());
const wordList fldNames(flds.sortedToc());
forAll(fldNames, i)
{
GeoField& fld = *flds[fldNames[i]];
typename GeoField::Boundary& bfld = fld.boundaryFieldRef();
if (bfld.size() != fld.mesh().boundary().size())
{
FatalErrorInFunction << "bfld size:" << bfld.size()
<< " mesh size:" << fld.mesh().boundary().size()
<< exit(FatalError);
}
if (patchFieldDict.found(fld.name()))
{
bfld.set
(
insertPatchi,
GeoField::Patch::New
(
fld.mesh().boundary()[insertPatchi],
fld(),
patchFieldDict.subDict(fld.name())
)
);
}
else
{
bfld.set
(
insertPatchi,
GeoField::Patch::New
(
defaultPatchFieldType,
fld.mesh().boundary()[insertPatchi],
fld()
)
);
bfld[insertPatchi] == defaultPatchValue;
}
}
}
template<class GeoField>
void ReorderPatchFields
(
objectRegistry& obr,
const labelUList& newToOld
)
{
HashTable<GeoField*> flds(obr.lookupClass<GeoField>());
const wordList fldNames(flds.sortedToc());
forAll(fldNames, i)
{
GeoField& fld = *flds[fldNames[i]];
typename GeoField::Boundary& bfld = fld.boundaryFieldRef();
bfld.shuffle(newToOld);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -366,6 +366,99 @@ void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm)
}
template<class Mesh>
void Foam::meshObject::addPatch(objectRegistry& obr, const label patchi)
{
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
obr.lookupClass<GeometricMeshObject<Mesh>>()
);
if (meshObject::debug)
{
Pout<< "meshObject::addPatch(objectRegistry&, "
"const label patchi) : updating " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
if (isA<PatchMeshObject<Mesh>>(*iter()))
{
if (meshObject::debug)
{
Pout<< " Adding patch to " << iter()->name() << endl;
}
dynamic_cast<PatchMeshObject<Mesh>*>(iter())->addPatch(patchi);
}
else
{
if (meshObject::debug)
{
Pout<< " Destroying " << iter()->name() << endl;
}
obr.checkOut(*iter());
}
}
}
template<class Mesh>
void Foam::meshObject::reorderPatches
(
objectRegistry& obr,
const labelUList& newToOld,
const bool validBoundary
)
{
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
obr.lookupClass<GeometricMeshObject<Mesh>>()
);
if (meshObject::debug)
{
Pout<< "meshObject::addPatch(objectRegistry&, "
"const labelUList&, const bool) : updating " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
if (isA<PatchMeshObject<Mesh>>(*iter()))
{
if (meshObject::debug)
{
Pout<< " Adding patch to " << iter()->name() << endl;
}
dynamic_cast<PatchMeshObject<Mesh>*>(iter())->reorderPatches
(
newToOld,
validBoundary
);
}
else
{
if (meshObject::debug)
{
Pout<< " Destroying " << iter()->name() << endl;
}
obr.checkOut(*iter());
}
}
}
template<class Mesh, template<class> class MeshObjectType>
void Foam::meshObject::clear(objectRegistry& obr)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,6 +53,7 @@ Description
- MoveableMeshObject: mesh object to be updated in movePoints
- UpdateableMeshObject: mesh object to be updated in updateMesh or
movePoints
- PatchMeshObject: mesh object to be additionally updated patch changes
Note
movePoints must be provided for MeshObjects of type MoveableMeshObject
@ -184,6 +185,16 @@ public:
template<class Mesh>
static void updateMesh(objectRegistry&, const mapPolyMesh&);
template<class Mesh>
static void addPatch(objectRegistry&, const label patchi);
template<class Mesh>
static void reorderPatches
(
objectRegistry&,
const labelUList& newToOld,
const bool validBoundary
);
template<class Mesh, template<class> class MeshObjectType>
static void clear(objectRegistry&);
@ -275,6 +286,35 @@ public:
};
/*---------------------------------------------------------------------------*\
Class PatchMeshObject Declaration
\*---------------------------------------------------------------------------*/
template<class Mesh>
class PatchMeshObject
:
public UpdateableMeshObject<Mesh>
{
public:
PatchMeshObject(const word& typeName, const objectRegistry& obr)
:
UpdateableMeshObject<Mesh>(typeName, obr)
{}
//- Reordered/removed trailing patches. If validBoundary call is parallel
// synced and all add the same patch with same settings
virtual void reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
) = 0;
//- Inserted patch at patchi
virtual void addPatch(const label patchi) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,17 +42,7 @@ Foam::pointBoundaryMesh::pointBoundaryMesh
pointPatchList(basicBdry.size()),
mesh_(m)
{
// Set boundary patches
pointPatchList& Patches = *this;
forAll(Patches, patchi)
{
Patches.set
(
patchi,
facePointPatch::New(basicBdry[patchi], *this).ptr()
);
}
reset(basicBdry);
}
@ -212,4 +202,34 @@ void Foam::pointBoundaryMesh::updateMesh()
}
void Foam::pointBoundaryMesh::reset(const polyBoundaryMesh& basicBdry)
{
// Set boundary patches
pointPatchList& Patches = *this;
forAll(Patches, patchi)
{
Patches.set
(
patchi,
facePointPatch::New(basicBdry[patchi], *this).ptr()
);
}
}
void Foam::pointBoundaryMesh::shuffle
(
const labelUList& newToOld,
const bool validBoundary
)
{
pointPatchList::shuffle(newToOld);
if (validBoundary)
{
updateMesh();
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -102,11 +102,21 @@ public:
//- Find patch indices given a name
labelList findIndices(const keyType&, const bool useGroups) const;
//- Correct polyBoundaryMesh after moving points
//- Correct pointBoundaryMesh after moving points
void movePoints(const pointField&);
//- Correct polyBoundaryMesh after topology update
//- Correct pointBoundaryMesh after topology update
void updateMesh();
//- Create pointBoundaryMesh from polyBoundaryMesh
void reset(const polyBoundaryMesh&);
//- Reorders patches. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// (is shuffle). If validBoundary calls updateMesh()
// after reordering to recalculate data (so call needs to be parallel
// sync in that case)
void shuffle(const labelUList& newToOld, const bool validBoundary);
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,7 +29,7 @@ License
#include "pointFields.H"
#include "MapGeometricFields.H"
#include "MapPointField.H"
#include "facePointPatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -72,7 +72,7 @@ void Foam::pointMesh::mapFields(const mapPolyMesh& mpm)
Foam::pointMesh::pointMesh(const polyMesh& pMesh)
:
MeshObject<polyMesh, Foam::UpdateableMeshObject, pointMesh>(pMesh),
MeshObject<polyMesh, Foam::PatchMeshObject, pointMesh>(pMesh),
GeoMesh<polyMesh>(pMesh),
boundary_(*this, pMesh.boundaryMesh())
{
@ -96,12 +96,31 @@ Foam::pointMesh::~pointMesh()
{
Pout<< "~pointMesh::pointMesh()"
<< endl;
error::printStack(Pout);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::pointMesh::reset(const bool validBoundary)
{
const polyMesh& pm = operator()();
if (debug)
{
Pout<< "pointMesh::reset(const bool validBoundary): "
<< "Resetting from polyMesh " << pm.name() << endl;
}
boundary_.reset(pm.boundaryMesh());
if (validBoundary)
{
// Calculate the geometry for the patches (transformation tensors etc.)
boundary_.calcGeometry();
}
}
bool Foam::pointMesh::movePoints()
{
if (debug)
@ -131,4 +150,67 @@ void Foam::pointMesh::updateMesh(const mapPolyMesh& mpm)
}
void Foam::pointMesh::reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
)
{
if (debug)
{
Pout<< "pointMesh::reorderPatches( const labelUList&, const bool): "
<< "Updating for reordered patches." << endl;
Pout<< endl;
}
boundary_.shuffle(newToOld, validBoundary);
objectRegistry& db = const_cast<objectRegistry&>(thisDb());
ReorderPatchFields<pointScalarField>(db, newToOld);
ReorderPatchFields<pointVectorField>(db, newToOld);
ReorderPatchFields<pointSphericalTensorField>(db, newToOld);
ReorderPatchFields<pointSymmTensorField>(db, newToOld);
ReorderPatchFields<pointTensorField>(db, newToOld);
}
void Foam::pointMesh::addPatch(const label patchi)
{
if (debug)
{
Pout<< "pointMesh::addPatch(const label): "
<< "Adding patch at " << patchi << endl;
Pout<< endl;
}
const polyBoundaryMesh& pbm = mesh().boundaryMesh();
if (pbm.size() != boundary_.size())
{
FatalErrorInFunction << "Problem :"
<< " pointBoundaryMesh size :" << boundary_.size()
<< " polyBoundaryMesh size :" << pbm.size()
<< exit(FatalError);
}
boundary_.set(patchi, facePointPatch::New(pbm[patchi], boundary_).ptr());
objectRegistry& db = const_cast<objectRegistry&>(thisDb());
const dictionary d;
const word patchFieldType("calculated");
AddPatchFields<pointScalarField>(db, patchi, d, patchFieldType, Zero);
AddPatchFields<pointVectorField>(db, patchi, d, patchFieldType, Zero);
AddPatchFields<pointSphericalTensorField>
(
db,
patchi,
d,
patchFieldType,
Zero
);
AddPatchFields<pointSymmTensorField>(db, patchi, d, patchFieldType, Zero);
AddPatchFields<pointTensorField>(db, patchi, d, patchFieldType, Zero);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -48,7 +48,7 @@ namespace Foam
class pointMesh
:
public MeshObject<polyMesh, UpdateableMeshObject, pointMesh>,
public MeshObject<polyMesh, PatchMeshObject, pointMesh>,
public GeoMesh<polyMesh>
{
// Permanent data
@ -121,14 +121,28 @@ public:
return GeoMesh<polyMesh>::mesh_.thisDb();
}
//- Reset for changed polyMesh
void reset(const bool validBoundary);
// Mesh motion
// Mesh callbacks
//- Move points
bool movePoints();
virtual bool movePoints();
//- Update the mesh corresponding to given map
void updateMesh(const mapPolyMesh& mpm);
virtual void updateMesh(const mapPolyMesh& mpm);
//- Reordered/removed trailing patches. If validBoundary call is
// parallel synced and all add the same patch with same settings
virtual void reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
);
//- Inserted patch at patchi
virtual void addPatch(const label patchi);
// Member Operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -196,10 +196,13 @@ Foam::polyBoundaryMesh::~polyBoundaryMesh()
void Foam::polyBoundaryMesh::clearGeom()
{
forAll(*this, patchi)
{
if (this->set(patchi))
{
operator[](patchi).clearGeom();
}
}
}
void Foam::polyBoundaryMesh::clearAddressing()
@ -209,10 +212,13 @@ void Foam::polyBoundaryMesh::clearAddressing()
groupPatchIDsPtr_.clear();
forAll(*this, patchi)
{
if (this->set(patchi))
{
operator[](patchi).clearAddressing();
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -1100,22 +1106,25 @@ void Foam::polyBoundaryMesh::updateMesh()
}
void Foam::polyBoundaryMesh::reorder
void Foam::polyBoundaryMesh::shuffle
(
const labelUList& oldToNew,
const labelUList& newToOld,
const bool validBoundary
)
{
// Change order of patches
polyPatchList::reorder(oldToNew);
polyPatchList::shuffle(newToOld);
// Adapt indices
polyPatchList& patches = *this;
forAll(patches, patchi)
{
if (patches.set(patchi))
{
patches[patchi].index() = patchi;
}
}
if (validBoundary)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -226,7 +226,7 @@ public:
// (is shuffle) If validBoundary calls updateMesh()
// after reordering to recalculate data (so call needs to be parallel
// sync in that case)
void reorder(const labelUList&, const bool validBoundary);
void shuffle(const labelUList& newToOld, const bool validBoundary);
//- writeData member function required by regIOobject
bool writeData(Ostream&) const;

View File

@ -1006,6 +1006,127 @@ void Foam::polyMesh::addZones
}
void Foam::polyMesh::reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
)
{
// Clear local fields and e.g. polyMesh parallelInfo. Do not clearGeom
// so we keep PatchMeshObjects intact.
boundary_.clearGeom();
clearAddressing(true);
// Clear all but PatchMeshObjects
meshObject::clearUpto
<
polyMesh,
TopologicalMeshObject,
PatchMeshObject
>
(
*this
);
meshObject::clearUpto
<
pointMesh,
TopologicalMeshObject,
PatchMeshObject
>
(
*this
);
boundary_.shuffle(newToOld, validBoundary);
// Warn mesh objects
meshObject::reorderPatches<polyMesh>(*this, newToOld, validBoundary);
meshObject::reorderPatches<pointMesh>(*this, newToOld, validBoundary);
}
void Foam::polyMesh::addPatch
(
const label insertPatchi,
const polyPatch& patch,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const bool validBoundary
)
{
const label sz = boundary_.size();
label startFacei = nFaces();
if (insertPatchi < sz)
{
startFacei = boundary_[insertPatchi].start();
}
// Create reordering list
// patches before insert position stay as is
// patches after insert position move one up
labelList newToOld(boundary_.size()+1);
for (label i = 0; i < insertPatchi; i++)
{
newToOld[i] = i;
}
for (label i = insertPatchi; i < sz; i++)
{
newToOld[i+1] = i;
}
newToOld[insertPatchi] = -1;
reorderPatches(newToOld, false);
// Clear local fields and e.g. polyMesh parallelInfo.
//clearGeom(); // would clear out pointMesh as well
boundary_.clearGeom();
clearAddressing(true);
// Clear all but PatchMeshObjects
meshObject::clearUpto
<
polyMesh,
TopologicalMeshObject,
PatchMeshObject
>
(
*this
);
meshObject::clearUpto
<
pointMesh,
TopologicalMeshObject,
PatchMeshObject
>
(
*this
);
// Insert polyPatch
boundary_.set
(
insertPatchi,
patch.clone
(
boundary_,
insertPatchi, // index
0, // size
startFacei // start
)
);
if (validBoundary)
{
boundary_.updateMesh();
}
// Warn mesh objects
meshObject::addPatch<polyMesh>(*this, insertPatchi);
meshObject::addPatch<pointMesh>(*this, insertPatchi);
}
const Foam::pointField& Foam::polyMesh::points() const
{
if (clearedPrimitives_)

View File

@ -587,6 +587,25 @@ public:
const List<cellZone*>& cz
);
//- Add/insert single patch. If validBoundary the new situation
// is consistent across processors.
virtual void addPatch
(
const label insertPatchi,
const polyPatch& patch,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const bool validBoundary
);
//- Reorder and trim existing patches. If validBoundary the new
// situation is consistent across processors
virtual void reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
);
//- Update the mesh based on the mesh files saved in
// time directories
virtual readUpdateState readUpdate();

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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::directPointPatchFieldMapper
Description
direct PointPatchFieldMapper
\*---------------------------------------------------------------------------*/
#ifndef directPointPatchFieldMapper_H
#define directPointPatchFieldMapper_H
#include "pointPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class directPointPatchFieldMapper Declaration
\*---------------------------------------------------------------------------*/
class directPointPatchFieldMapper
:
public pointPatchFieldMapper
{
//- Addressing from new back to old
const labelUList& directAddressing_;
//- Does map contain any unmapped values
bool hasUnmapped_;
public:
// Constructors
//- Construct given addressing
directPointPatchFieldMapper(const labelUList& directAddressing)
:
directAddressing_(directAddressing),
hasUnmapped_(false)
{
if (directAddressing_.size() && min(directAddressing_) < 0)
{
hasUnmapped_ = true;
}
}
//- Destructor
virtual ~directPointPatchFieldMapper()
{}
// Member Functions
label size() const
{
return directAddressing_.size();
}
bool direct() const
{
return true;
}
bool hasUnmapped() const
{
return hasUnmapped_;
}
const labelUList& directAddressing() const
{
return directAddressing_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -75,7 +75,19 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
const bool validBoundary
)
{
mesh0.clearOut();
// Store old mesh0 point maps
labelListList oldMeshPoints0;
const bool havePointMesh =
mesh0.foundObject<pointMesh>(pointMesh::typeName);
if (havePointMesh)
{
const polyBoundaryMesh& pbm0 = mesh0.boundaryMesh();
oldMeshPoints0.setSize(pbm0.size());
forAll(pbm0, patchi)
{
oldMeshPoints0[patchi] = pbm0[patchi].meshPoints();
}
}
// Resulting merged mesh (polyMesh only!)
autoPtr<mapAddedPolyMesh> mapPtr
@ -101,23 +113,41 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
// Do the mapping of the stored fields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fvMeshAdder::MapVolFields<scalar>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<vector>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<sphericalTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<symmTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapVolFields<tensor>(mapPtr, mesh0, mesh1);
MapVolFields<scalar>(mapPtr, mesh0, mesh1);
MapVolFields<vector>(mapPtr, mesh0, mesh1);
MapVolFields<sphericalTensor>(mapPtr, mesh0, mesh1);
MapVolFields<symmTensor>(mapPtr, mesh0, mesh1);
MapVolFields<tensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<scalar>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<vector>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<sphericalTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<symmTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapSurfaceFields<tensor>(mapPtr, mesh0, mesh1);
MapSurfaceFields<scalar>(mapPtr, mesh0, mesh1);
MapSurfaceFields<vector>(mapPtr, mesh0, mesh1);
MapSurfaceFields<sphericalTensor>(mapPtr, mesh0, mesh1);
MapSurfaceFields<symmTensor>(mapPtr, mesh0, mesh1);
MapSurfaceFields<tensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapDimFields<scalar>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapDimFields<vector>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapDimFields<sphericalTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapDimFields<symmTensor>(mapPtr, mesh0, mesh1);
fvMeshAdder::MapDimFields<tensor>(mapPtr, mesh0, mesh1);
if (havePointMesh)
{
// Recreate point mesh
const pointMesh& pointMesh0 = pointMesh::New(mesh0);
MapPointFields<scalar>(mapPtr, pointMesh0, oldMeshPoints0, mesh1);
MapPointFields<vector>(mapPtr, pointMesh0, oldMeshPoints0, mesh1);
MapPointFields<sphericalTensor>
(
mapPtr,
pointMesh0,
oldMeshPoints0,
mesh1
);
MapPointFields<symmTensor>(mapPtr, pointMesh0, oldMeshPoints0, mesh1);
MapPointFields<tensor>(mapPtr, pointMesh0, oldMeshPoints0, mesh1);
}
MapDimFields<scalar>(mapPtr, mesh0, mesh1);
MapDimFields<vector>(mapPtr, mesh0, mesh1);
MapDimFields<sphericalTensor>(mapPtr, mesh0, mesh1);
MapDimFields<symmTensor>(mapPtr, mesh0, mesh1);
MapDimFields<tensor>(mapPtr, mesh0, mesh1);
return mapPtr;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -43,6 +43,7 @@ SourceFiles
#include "fvsPatchFieldsFwd.H"
#include "fvPatchFieldMapper.H"
#include "DimensionedField.H"
#include "pointFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -102,6 +103,18 @@ private:
const GeometricField<Type, fvsPatchField, surfaceMesh>& fldToAdd
);
//- Update single pointField.
template<class Type>
static void MapPointField
(
const pointMesh& mesh,
const mapAddedPolyMesh& meshMap,
const labelListList& oldMeshPoints,
GeometricField<Type, pointPatchField, pointMesh>& fld,
const GeometricField<Type, pointPatchField, pointMesh>& fldToAdd
);
//- Update single dimensionedField.
template<class Type>
static void MapDimField
@ -147,6 +160,16 @@ public:
const fvMesh& meshToAdd
);
//- Map all surfaceFields of Type
template<class Type>
static void MapPointFields
(
const mapAddedPolyMesh&,
const pointMesh& mesh,
const labelListList& oldMeshPoints,
const objectRegistry& meshToAdd
);
//- Map all DimensionedFields of Type
template<class Type>
static void MapDimFields

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,8 +25,9 @@ License
#include "volFields.H"
#include "surfaceFields.H"
#include "emptyFvPatchField.H"
#include "pointFields.H"
#include "directFvPatchFieldMapper.H"
#include "directPointPatchFieldMapper.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -640,6 +641,316 @@ void Foam::fvMeshAdder::MapSurfaceFields
}
template<class Type>
void Foam::fvMeshAdder::MapPointField
(
const pointMesh& mesh,
const mapAddedPolyMesh& meshMap,
const labelListList& oldMeshPoints,
GeometricField<Type, pointPatchField, pointMesh>& fld,
const GeometricField<Type, pointPatchField, pointMesh>& fldToAdd
)
{
// This is a bit tricky:
// - mesh pointed to by fld is invalid
// - pointPatches pointed to be fld are invalid
typename GeometricField<Type, pointPatchField, pointMesh>::
Boundary& bfld = fld.boundaryFieldRef();
// Internal field
// ~~~~~~~~~~~~~~
// Store old internal field
{
Field<Type> oldField(fld);
// Modify internal field
Field<Type>& intFld = fld.primitiveFieldRef();
intFld.setSize(mesh.size());
intFld.rmap(oldField, meshMap.oldPointMap());
intFld.rmap(fldToAdd, meshMap.addedPointMap());
}
// Patch fields from old mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& oldPatchMap = meshMap.oldPatchMap();
// Reorder old patches in order of new ones. Put removed patches at end.
label unusedPatchi = 0;
forAll(oldPatchMap, patchi)
{
label newPatchi = oldPatchMap[patchi];
if (newPatchi != -1)
{
unusedPatchi++;
}
}
label nUsedPatches = unusedPatchi;
// Reorder list for patchFields
labelList oldToNew(oldPatchMap.size());
forAll(oldPatchMap, patchi)
{
label newPatchi = oldPatchMap[patchi];
if (newPatchi != -1)
{
oldToNew[patchi] = newPatchi;
}
else
{
oldToNew[patchi] = unusedPatchi++;
}
}
// Sort deleted ones last so is now in newPatch ordering
bfld.reorder(oldToNew);
// Extend to covers all patches
bfld.setSize(mesh.boundary().size());
// Delete unused patches
for
(
label newPatchi = nUsedPatches;
newPatchi < bfld.size();
newPatchi++
)
{
bfld.set(newPatchi, nullptr);
}
// Map old values
// ~~~~~~~~~~~~~~
forAll(oldPatchMap, patchi)
{
label newPatchi = oldPatchMap[patchi];
if (newPatchi != -1)
{
const labelList& oldMp = oldMeshPoints[patchi];
const pointPatch& newPp = mesh.boundary()[newPatchi];
const labelList& newMeshPoints = newPp.meshPoints();
Map<label> newMeshPointMap(2*newMeshPoints.size());
forAll(newMeshPoints, ppi)
{
newMeshPointMap.insert(newMeshPoints[ppi], ppi);
}
labelList newToOld(newPp.size(), -1);
forAll(oldMp, oldPointi)
{
label newPointi = oldMp[oldPointi];
Map<label>::const_iterator fnd =
newMeshPointMap.find(newPointi);
if (fnd == newMeshPointMap.end())
{
// Possibly an internal point
}
else
{
// Part of new patch
newToOld[fnd()] = oldPointi;
}
}
directPointPatchFieldMapper patchMapper(newToOld);
// Create new patchField with same type as existing one.
// Note:
// - boundaryField already in new order so access with newPatchi
// - bfld[newPatchi] both used for type and old
// value
// - hope that field mapping allows aliasing since old and new
// are same memory!
bfld.set
(
newPatchi,
pointPatchField<Type>::New
(
bfld[newPatchi], // old field
mesh.boundary()[newPatchi], // new pointPatch
fld(), // new internal field
patchMapper // mapper (new to old)
)
);
}
}
}
// Patch fields from added mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const labelList& addedPatchMap = meshMap.addedPatchMap();
// Add addedMesh patches
forAll(addedPatchMap, patchi)
{
label newPatchi = addedPatchMap[patchi];
if (newPatchi != -1)
{
const pointPatch& oldPatch = fldToAdd.mesh().boundary()[patchi];
const labelList& oldMp = oldPatch.meshPoints();
const pointPatch& newPp = mesh.boundary()[newPatchi];
const labelList& newMeshPoints = newPp.meshPoints();
Map<label> newMpm(2*newMeshPoints.size());
forAll(newMeshPoints, ppi)
{
newMpm.insert(newMeshPoints[ppi], ppi);
}
if (!bfld(newPatchi))
{
// First occurrence of newPatchi. Map from existing
// patchField
labelList newToAdded(newPp.size(), -1);
forAll(oldMp, oldPointi)
{
label newPointi = oldMp[oldPointi];
Map<label>::const_iterator fnd = newMpm.find(newPointi);
if (fnd == newMpm.end())
{
// Possibly an internal point
}
else
{
// Part of new patch
newToAdded[fnd()] = oldPointi;
}
}
directPointPatchFieldMapper patchMapper(newToAdded);
bfld.set
(
newPatchi,
pointPatchField<Type>::New
(
fldToAdd.boundaryField()[patchi],// added field
mesh.boundary()[newPatchi], // new pointPatch
fld(), // new int. field
patchMapper // mapper
)
);
}
else
{
// PatchField will have correct size already. Just slot in
// my elements.
labelList oldToNew(oldPatch.size(), -1);
forAll(oldMp, oldPointi)
{
label newPointi = oldMp[oldPointi];
Map<label>::const_iterator fnd = newMpm.find(newPointi);
if (fnd != newMpm.end())
{
// Part of new patch
oldToNew[oldPointi] = fnd();
}
}
bfld[newPatchi].rmap
(
fldToAdd.boundaryField()[patchi],
oldToNew
);
}
}
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapPointFields
(
const mapAddedPolyMesh& meshMap,
const pointMesh& mesh,
const labelListList& oldMeshPoints,
const objectRegistry& meshToAdd
)
{
typedef GeometricField<Type, pointPatchField, pointMesh> fldType;
HashTable<const fldType*> fields(mesh.thisDb().lookupClass<fldType>());
HashTable<const fldType*> fieldsToAdd(meshToAdd.lookupClass<fldType>());
// It is necessary to enforce that all old-time fields are stored
// before the mapping is performed. Otherwise, if the
// old-time-level field is mapped before the field itself, sizes
// will not match.
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
if (debug)
{
Pout<< "MapPointFields : Storing old time for "
<< fieldIter()->name() << endl;
}
const_cast<fldType*>(fieldIter())->storeOldTimes();
}
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
if (fieldsToAdd.found(fld.name()))
{
const fldType& fldToAdd = *fieldsToAdd[fld.name()];
if (debug)
{
Pout<< "MapPointFields : mapping " << fld.name()
<< " and " << fldToAdd.name() << endl;
}
MapPointField<Type>(mesh, meshMap, oldMeshPoints, fld, fldToAdd);
}
else
{
WarningInFunction
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
}
}
}
template<class Type>
void Foam::fvMeshAdder::MapDimField
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,6 +37,7 @@ License
#include "polyRemovePoint.H"
#include "mapDistributePolyMesh.H"
#include "surfaceFields.H"
#include "pointFields.H"
#include "syncTools.H"
#include "CompactListList.H"
#include "fvMeshTools.H"
@ -1746,7 +1747,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
// Remove meshPhi. Since this would otherwise disappear anyway
// during topo changes and we have to guarantee that all the fields
// can be sent.
mesh_.clearOut();
//mesh_.clearOut();
mesh_.resetMotion();
// Get data to send. Make sure is synchronised
@ -1781,6 +1782,25 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
const wordList surfTensors(mesh_.names(surfaceTensorField::typeName));
checkEqualWordList("surfaceTensorFields", surfTensors);
const wordList pointScalars(mesh_.names(pointScalarField::typeName));
checkEqualWordList("pointScalarFields", pointScalars);
const wordList pointVectors(mesh_.names(pointVectorField::typeName));
checkEqualWordList("pointVectorFields", pointVectors);
const wordList pointSphereTensors
(
mesh_.names(pointSphericalTensorField::typeName)
);
checkEqualWordList("pointSphericalTensorFields", pointSphereTensors);
const wordList pointSymmTensors
(
mesh_.names(pointSymmTensorField::typeName)
);
checkEqualWordList("pointSymmTensorFields", pointSymmTensors);
const wordList pointTensors(mesh_.names(pointTensorField::typeName));
checkEqualWordList("pointTensorFields", pointTensors);
typedef volScalarField::Internal dimScalType;
const wordList dimScalars(mesh_.names(dimScalType::typeName));
checkEqualWordList("volScalarField::Internal", dimScalars);
@ -1860,6 +1880,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_);
printFieldInfo<pointScalarField>(mesh_);
printFieldInfo<pointVectorField>(mesh_);
printFieldInfo<pointSphericalTensorField>(mesh_);
printFieldInfo<pointSymmTensorField>(mesh_);
printFieldInfo<pointTensorField>(mesh_);
Pout<< nl << endl;
}
@ -2054,6 +2079,43 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
str
);
// pointFields
sendFields<pointScalarField>
(
recvProc,
pointScalars,
subsetter,
str
);
sendFields<pointVectorField>
(
recvProc,
pointVectors,
subsetter,
str
);
sendFields<pointSphericalTensorField>
(
recvProc,
pointSphereTensors,
subsetter,
str
);
sendFields<pointSymmTensorField>
(
recvProc,
pointSymmTensors,
subsetter,
str
);
sendFields<pointTensorField>
(
recvProc,
pointTensors,
subsetter,
str
);
// dimensionedFields
sendFields<volScalarField::Internal>
(
@ -2204,6 +2266,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_);
printFieldInfo<pointScalarField>(mesh_);
printFieldInfo<pointVectorField>(mesh_);
printFieldInfo<pointSphericalTensorField>(mesh_);
printFieldInfo<pointSymmTensorField>(mesh_);
printFieldInfo<pointTensorField>(mesh_);
Pout<< nl << endl;
}
@ -2259,6 +2326,12 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
PtrList<surfaceSymmTensorField> ssytf;
PtrList<surfaceTensorField> stf;
PtrList<pointScalarField> psf;
PtrList<pointVectorField> pvf;
PtrList<pointSphericalTensorField> psptf;
PtrList<pointSymmTensorField> psytf;
PtrList<pointTensorField> ptf;
PtrList<volScalarField::Internal> dsf;
PtrList<volVectorField::Internal> dvf;
PtrList<volSphericalTensorField::Internal> dstf;
@ -2376,6 +2449,50 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
fieldDicts.subDict(surfaceTensorField::typeName)
);
// Point fields
pointMesh& domainPointMesh =
const_cast<pointMesh&>(pointMesh::New(domainMesh));
receiveFields<pointScalarField>
(
sendProc,
pointScalars,
domainPointMesh,
psf,
fieldDicts.subDict(pointScalarField::typeName)
);
receiveFields<pointVectorField>
(
sendProc,
pointVectors,
domainPointMesh,
pvf,
fieldDicts.subDict(pointVectorField::typeName)
);
receiveFields<pointSphericalTensorField>
(
sendProc,
pointSphereTensors,
domainPointMesh,
psptf,
fieldDicts.subDict(pointSphericalTensorField::typeName)
);
receiveFields<pointSymmTensorField>
(
sendProc,
pointSymmTensors,
domainPointMesh,
psytf,
fieldDicts.subDict(pointSymmTensorField::typeName)
);
receiveFields<pointTensorField>
(
sendProc,
pointTensors,
domainPointMesh,
ptf,
fieldDicts.subDict(pointTensorField::typeName)
);
// Dimensioned fields
receiveFields<volScalarField::Internal>
(
@ -2459,6 +2576,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(domainMesh);
printFieldInfo<surfaceSymmTensorField>(domainMesh);
printFieldInfo<surfaceTensorField>(domainMesh);
printFieldInfo<pointScalarField>(domainMesh);
printFieldInfo<pointVectorField>(domainMesh);
printFieldInfo<pointSphericalTensorField>(domainMesh);
printFieldInfo<pointSymmTensorField>(domainMesh);
printFieldInfo<pointTensorField>(domainMesh);
}
@ -2645,6 +2767,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_);
printFieldInfo<pointScalarField>(mesh_);
printFieldInfo<pointVectorField>(mesh_);
printFieldInfo<pointSphericalTensorField>(mesh_);
printFieldInfo<pointSymmTensorField>(mesh_);
printFieldInfo<pointTensorField>(mesh_);
Pout<< nl << endl;
}
}
@ -2667,6 +2794,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_);
printFieldInfo<pointScalarField>(mesh_);
printFieldInfo<pointVectorField>(mesh_);
printFieldInfo<pointSphericalTensorField>(mesh_);
printFieldInfo<pointSymmTensorField>(mesh_);
printFieldInfo<pointTensorField>(mesh_);
Pout<< nl << endl;
}
@ -2752,6 +2884,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_);
printFieldInfo<pointScalarField>(mesh_);
printFieldInfo<pointVectorField>(mesh_);
printFieldInfo<pointSphericalTensorField>(mesh_);
printFieldInfo<pointSymmTensorField>(mesh_);
printFieldInfo<pointTensorField>(mesh_);
Pout<< nl << endl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -323,7 +323,7 @@ class fvMeshDistribute
(
const label domain,
const wordList& fieldNames,
fvMesh&,
typename GeoField::Mesh&,
PtrList<GeoField>&,
const dictionary& fieldDicts
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -342,7 +342,7 @@ void Foam::fvMeshDistribute::receiveFields
(
const label domain,
const wordList& fieldNames,
fvMesh& mesh,
typename GeoField::Mesh& mesh,
PtrList<GeoField>& fields,
const dictionary& fieldDicts
)
@ -371,8 +371,8 @@ void Foam::fvMeshDistribute::receiveFields
IOobject
(
fieldNames[i],
mesh.time().timeName(),
mesh,
mesh.thisDb().time().timeName(),
mesh.thisDb(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "fvMeshTools.H"
#include "pointFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,7 +51,6 @@ Foam::label Foam::fvMeshTools::addPatch
// Append at end unless there are processor patches
label insertPatchi = polyPatches.size();
label startFacei = mesh.nFaces();
if (!isA<processorPolyPatch>(patch))
{
@ -61,150 +61,19 @@ Foam::label Foam::fvMeshTools::addPatch
if (isA<processorPolyPatch>(pp))
{
insertPatchi = patchi;
startFacei = pp.start();
break;
}
}
}
// Below is all quite a hack. Feel free to change once there is a better
// mechanism to insert and reorder patches.
// Clear local fields and e.g. polyMesh parallelInfo.
mesh.clearOut();
label sz = polyPatches.size();
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh.boundary());
// Add polyPatch at the end
polyPatches.setSize(sz+1);
polyPatches.set
mesh.addPatch
(
sz,
patch.clone
(
polyPatches,
insertPatchi, // index
0, // size
startFacei // start
)
);
fvPatches.setSize(sz+1);
fvPatches.set
(
sz,
fvPatch::New
(
polyPatches[sz], // point to newly added polyPatch
mesh.boundary()
)
);
addPatchFields<volScalarField>
(
mesh,
insertPatchi,
patch,
patchFieldDict,
defaultPatchFieldType,
Zero
validBoundary
);
addPatchFields<volVectorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<volSphericalTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<volSymmTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<volTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
// Surface fields
addPatchFields<surfaceScalarField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<surfaceVectorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<surfaceSphericalTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<surfaceSymmTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
addPatchFields<surfaceTensorField>
(
mesh,
patchFieldDict,
defaultPatchFieldType,
Zero
);
// Create reordering list
// patches before insert position stay as is
labelList oldToNew(sz+1);
for (label i = 0; i < insertPatchi; i++)
{
oldToNew[i] = i;
}
// patches after insert position move one up
for (label i = insertPatchi; i < sz; i++)
{
oldToNew[i] = i+1;
}
// appended patch gets moved to insert position
oldToNew[sz] = insertPatchi;
// Shuffle into place
polyPatches.reorder(oldToNew, validBoundary);
fvPatches.reorder(oldToNew);
reorderPatchFields<volScalarField>(mesh, oldToNew);
reorderPatchFields<volVectorField>(mesh, oldToNew);
reorderPatchFields<volSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<volSymmTensorField>(mesh, oldToNew);
reorderPatchFields<volTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceScalarField>(mesh, oldToNew);
reorderPatchFields<surfaceVectorField>(mesh, oldToNew);
reorderPatchFields<surfaceSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceSymmTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceTensorField>(mesh, oldToNew);
return insertPatchi;
}
@ -222,16 +91,22 @@ void Foam::fvMeshTools::setPatchFields
setPatchFields<volSphericalTensorField>(mesh, patchi, patchFieldDict);
setPatchFields<volSymmTensorField>(mesh, patchi, patchFieldDict);
setPatchFields<volTensorField>(mesh, patchi, patchFieldDict);
setPatchFields<surfaceScalarField>(mesh, patchi, patchFieldDict);
setPatchFields<surfaceVectorField>(mesh, patchi, patchFieldDict);
setPatchFields<surfaceSphericalTensorField>
(
mesh,
patchi,
patchFieldDict
);
setPatchFields<surfaceSphericalTensorField>(mesh, patchi, patchFieldDict);
setPatchFields<surfaceSymmTensorField>(mesh, patchi, patchFieldDict);
setPatchFields<surfaceTensorField>(mesh, patchi, patchFieldDict);
if (mesh.foundObject<pointMesh>(pointMesh::typeName))
{
pointMesh& pm = const_cast<pointMesh&>(pointMesh::New(mesh));
setPatchFields<pointScalarField>(pm, patchi, patchFieldDict);
setPatchFields<pointVectorField>(pm, patchi, patchFieldDict);
setPatchFields<pointSphericalTensorField>(pm, patchi, patchFieldDict);
setPatchFields<pointSymmTensorField>(pm, patchi, patchFieldDict);
setPatchFields<pointTensorField>(pm, patchi, patchFieldDict);
}
}
@ -239,84 +114,25 @@ void Foam::fvMeshTools::zeroPatchFields(fvMesh& mesh, const label patchi)
{
setPatchFields<volScalarField>(mesh, patchi, Zero);
setPatchFields<volVectorField>(mesh, patchi, Zero);
setPatchFields<volSphericalTensorField>
(
mesh,
patchi,
Zero
);
setPatchFields<volSymmTensorField>
(
mesh,
patchi,
Zero
);
setPatchFields<volSphericalTensorField>(mesh, patchi, Zero);
setPatchFields<volSymmTensorField>(mesh, patchi, Zero);
setPatchFields<volTensorField>(mesh, patchi, Zero);
setPatchFields<surfaceScalarField>(mesh, patchi, Zero);
setPatchFields<surfaceVectorField>(mesh, patchi, Zero);
setPatchFields<surfaceSphericalTensorField>
(
mesh,
patchi,
Zero
);
setPatchFields<surfaceSymmTensorField>
(
mesh,
patchi,
Zero
);
setPatchFields<surfaceSphericalTensorField>(mesh, patchi, Zero);
setPatchFields<surfaceSymmTensorField>(mesh, patchi, Zero);
setPatchFields<surfaceTensorField>(mesh, patchi, Zero);
}
// Deletes last patch
void Foam::fvMeshTools::trimPatches(fvMesh& mesh, const label nPatches)
if (mesh.foundObject<pointMesh>(pointMesh::typeName))
{
// Clear local fields and e.g. polyMesh globalMeshData.
mesh.clearOut();
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh.boundary());
if (polyPatches.empty())
{
FatalErrorInFunction
<< "No patches in mesh"
<< abort(FatalError);
pointMesh& pm = const_cast<pointMesh&>(pointMesh::New(mesh));
setPatchFields<pointScalarField>(pm, patchi, Zero);
setPatchFields<pointVectorField>(pm, patchi, Zero);
setPatchFields<pointSphericalTensorField>(pm, patchi, Zero);
setPatchFields<pointSymmTensorField>(pm, patchi, Zero);
setPatchFields<pointTensorField>(pm, patchi, Zero);
}
label nFaces = 0;
for (label patchi = nPatches; patchi < polyPatches.size(); patchi++)
{
nFaces += polyPatches[patchi].size();
}
reduce(nFaces, sumOp<label>());
if (nFaces)
{
FatalErrorInFunction
<< "There are still " << nFaces
<< " faces in " << polyPatches.size()-nPatches
<< " patches to be deleted" << abort(FatalError);
}
// Remove actual patches
polyPatches.setSize(nPatches);
fvPatches.setSize(nPatches);
trimPatchFields<volScalarField>(mesh, nPatches);
trimPatchFields<volVectorField>(mesh, nPatches);
trimPatchFields<volSphericalTensorField>(mesh, nPatches);
trimPatchFields<volSymmTensorField>(mesh, nPatches);
trimPatchFields<volTensorField>(mesh, nPatches);
trimPatchFields<surfaceScalarField>(mesh, nPatches);
trimPatchFields<surfaceVectorField>(mesh, nPatches);
trimPatchFields<surfaceSphericalTensorField>(mesh, nPatches);
trimPatchFields<surfaceSymmTensorField>(mesh, nPatches);
trimPatchFields<surfaceTensorField>(mesh, nPatches);
}
@ -328,27 +144,20 @@ void Foam::fvMeshTools::reorderPatches
const bool validBoundary
)
{
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh.boundary());
// Note: oldToNew might have entries beyond nNewPatches so
// cannot use invert
//const labelList newToOld(invert(nNewPatches, oldToNew));
labelList newToOld(nNewPatches, -1);
forAll(oldToNew, i)
{
label newi = oldToNew[i];
// Shuffle into place
polyPatches.reorder(oldToNew, validBoundary);
fvPatches.reorder(oldToNew);
reorderPatchFields<volScalarField>(mesh, oldToNew);
reorderPatchFields<volVectorField>(mesh, oldToNew);
reorderPatchFields<volSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<volSymmTensorField>(mesh, oldToNew);
reorderPatchFields<volTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceScalarField>(mesh, oldToNew);
reorderPatchFields<surfaceVectorField>(mesh, oldToNew);
reorderPatchFields<surfaceSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceSymmTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceTensorField>(mesh, oldToNew);
// Remove last.
trimPatches(mesh, nNewPatches);
if (newi >= 0 && newi < nNewPatches)
{
newToOld[newi] = i;
}
}
mesh.reorderPatches(newToOld, validBoundary);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -48,20 +48,11 @@ namespace Foam
class fvMeshTools
{
template<class GeoField>
static void addPatchFields
(
fvMesh&,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const typename GeoField::value_type& defaultPatchValue
);
//- Set patchFields according to dictionary
template<class GeoField>
static void setPatchFields
(
fvMesh& mesh,
typename GeoField::Mesh& mesh,
const label patchi,
const dictionary& patchFieldDict
);
@ -70,21 +61,11 @@ class fvMeshTools
template<class GeoField>
static void setPatchFields
(
fvMesh& mesh,
typename GeoField::Mesh& mesh,
const label patchi,
const typename GeoField::value_type& value
);
// Remove last patch fields
template<class GeoField>
static void trimPatchFields(fvMesh&, const label nPatches);
template<class GeoField>
static void reorderPatchFields(fvMesh&, const labelList& oldToNew);
// Remove trialing patches
static void trimPatches(fvMesh&, const label nPatches);
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,73 +29,17 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::fvMeshTools::addPatchFields
(
fvMesh& mesh,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const typename GeoField::value_type& defaultPatchValue
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
label sz = bfld.size();
bfld.setSize(sz+1);
if (patchFieldDict.found(fld.name()))
{
bfld.set
(
sz,
GeoField::Patch::New
(
mesh.boundary()[sz],
fld(),
patchFieldDict.subDict(fld.name())
)
);
}
else
{
bfld.set
(
sz,
GeoField::Patch::New
(
defaultPatchFieldType,
mesh.boundary()[sz],
fld()
)
);
bfld[sz] == defaultPatchValue;
}
}
}
template<class GeoField>
void Foam::fvMeshTools::setPatchFields
(
fvMesh& mesh,
typename GeoField::Mesh& mesh,
const label patchi,
const dictionary& patchFieldDict
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
objectRegistry& obr = const_cast<objectRegistry&>(mesh.thisDb());
HashTable<GeoField*> flds(obr.lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
@ -121,20 +65,17 @@ void Foam::fvMeshTools::setPatchFields
}
template<class GeoField>
void Foam::fvMeshTools::setPatchFields
(
fvMesh& mesh,
typename GeoField::Mesh& mesh,
const label patchi,
const typename GeoField::value_type& value
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
objectRegistry& obr = const_cast<objectRegistry&>(mesh.thisDb());
HashTable<GeoField*> flds(obr.lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
@ -148,46 +89,4 @@ void Foam::fvMeshTools::setPatchFields
}
// Remove last patch field
template<class GeoField>
void Foam::fvMeshTools::trimPatchFields(fvMesh& mesh, const label nPatches)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
GeoField& fld = *iter();
fld.boundaryFieldRef().setSize(nPatches);
}
}
// Reorder patch field
template<class GeoField>
void Foam::fvMeshTools::reorderPatchFields
(
fvMesh& mesh,
const labelList& oldToNew
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
bfld.reorder(oldToNew);
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -36,6 +36,9 @@ License
#include "polyRemovePoint.H"
#include "polyTopoChange.H"
#include "pointMesh.H"
#include "facePointPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Get index of patch in new set of patchnames/types
@ -1813,11 +1816,8 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
// Inplace extend mesh0 patches (note that patches0.size() now also
// has changed)
polyBoundaryMesh& allPatches =
const_cast<polyBoundaryMesh&>(mesh0.boundaryMesh());
allPatches.setSize(allPatchNames.size());
labelList patchSizes(allPatches.size());
labelList patchStarts(allPatches.size());
labelList patchSizes(allPatchNames.size());
labelList patchStarts(allPatchNames.size());
label startFacei = nInternalFaces;
@ -1830,7 +1830,7 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
// Originates from mesh0. Clone with new size & filter out empty
// patch.
if (nFaces[patch0] == 0 && isA<processorPolyPatch>(allPatches[patch0]))
if (nFaces[patch0] == 0 && isA<processorPolyPatch>(patches0[patch0]))
{
// Pout<< "Removing zero sized mesh0 patch "
// << allPatchNames[patch0]
@ -1845,20 +1845,6 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
}
else
{
// Clone. Note dummy size and start. Gets overwritten later in
// resetPrimitives. This avoids getting temporarily illegal
// SubList construction in polyPatch.
allPatches.set
(
allPatchi,
allPatches[patch0].clone
(
allPatches,
allPatchi,
0, // dummy size
0 // dummy start
)
);
patchSizes[allPatchi] = nFaces[patch0];
patchStarts[allPatchi] = startFacei;
@ -1877,6 +1863,22 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
}
}
// Trim the existing patches
{
const label sz0 = from0ToAllPatches.size();
labelList newToOld(sz0, sz0-1);
label nNew = 0;
forAll(from0ToAllPatches, patchi)
{
if (from0ToAllPatches[patchi] != -1)
{
newToOld[nNew++] = patchi;
}
}
newToOld.setSize(nNew);
mesh0.reorderPatches(newToOld, false);
}
// Copy unique patches of mesh1.
forAll(from1ToAllPatches, patch1)
{
@ -1898,21 +1900,21 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
}
else
{
// Clone.
allPatches.set
(
allPatchi,
patches1[patch1].clone
(
allPatches,
allPatchi,
0, // dummy size
0 // dummy start
)
);
patchSizes[allPatchi] = nFaces[uncompactAllPatchi];
patchStarts[allPatchi] = startFacei;
// Clone. Note dummy size and start. Gets overwritten later in
// resetPrimitives. This avoids getting temporarily illegal
// SubList construction in polyPatch.
mesh0.addPatch
(
allPatchi,
patches1[patch1],
dictionary(),
"calculated",
false
);
// Record new index in allPatches
from1ToAllPatches[patch1] = allPatchi;
@ -1922,8 +1924,6 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
}
}
}
allPatches.setSize(allPatchi);
patchSizes.setSize(allPatchi);
patchStarts.setSize(allPatchi);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -111,6 +111,17 @@ void Foam::fvBoundaryMesh::movePoints()
}
void Foam::fvBoundaryMesh::shuffle
(
const labelUList& newToOld,
const bool validBoundary
)
{
fvPatchList& patches = *this;
patches.shuffle(newToOld);
}
Foam::lduInterfacePtrsList Foam::fvBoundaryMesh::interfaces() const
{
lduInterfacePtrsList interfaces(size());

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -116,6 +116,12 @@ public:
//- Correct patches after moving points
void movePoints();
//- Reorders patches. Ordering does not have to be done in
// ascending or descending order. Reordering has to be unique.
// (is shuffle). If validBoundary call needs to be parallel
// sync
void shuffle(const labelUList& newToOld, const bool validBoundary);
// Member Operators

View File

@ -49,6 +49,11 @@ namespace Foam
void Foam::fvMesh::clearGeomNotOldVol()
{
if (debug)
{
Pout<< FUNCTION_NAME << "clearGeomNotOldVol" << endl;
}
meshObject::clearUpto
<
fvMesh,
@ -111,6 +116,11 @@ void Foam::fvMesh::updateGeomNotOldVol()
void Foam::fvMesh::clearGeom()
{
if (debug)
{
Pout<< FUNCTION_NAME << "Clearing geometric data" << endl;
}
clearGeomNotOldVol();
deleteDemandDrivenData(V0Ptr_);
@ -125,7 +135,7 @@ void Foam::fvMesh::clearAddressing(const bool isMeshUpdate)
{
if (debug)
{
InfoInFunction << "isMeshUpdate: " << isMeshUpdate << endl;
Pout<< FUNCTION_NAME << "isMeshUpdate: " << isMeshUpdate << endl;
}
if (isMeshUpdate)
@ -166,7 +176,7 @@ void Foam::fvMesh::storeOldVol(const scalarField& V)
{
if (debug)
{
InfoInFunction
Pout<< FUNCTION_NAME
<< " Storing old time volumes since from time " << curTimeIndex_
<< " and time now " << time().timeIndex()
<< " V:" << V.size()
@ -213,12 +223,12 @@ void Foam::fvMesh::storeOldVol(const scalarField& V)
if (debug)
{
InfoInFunction
Pout<< FUNCTION_NAME
<< " Stored old time volumes V0:" << V0Ptr_->size()
<< endl;
if (V00Ptr_)
{
InfoInFunction
Pout<< FUNCTION_NAME
<< " Stored oldold time volumes V00:" << V00Ptr_->size()
<< endl;
}
@ -264,7 +274,7 @@ Foam::fvMesh::fvMesh(const IOobject& io)
{
if (debug)
{
InfoInFunction << "Constructing fvMesh from IOobject" << endl;
Pout<< FUNCTION_NAME << "Constructing fvMesh from IOobject" << endl;
}
// Check the existence of the cell volumes and read if present
@ -374,7 +384,7 @@ Foam::fvMesh::fvMesh
{
if (debug)
{
InfoInFunction << "Constructing fvMesh from cellShapes" << endl;
Pout<< FUNCTION_NAME << "Constructing fvMesh from cellShapes" << endl;
}
}
@ -408,7 +418,7 @@ Foam::fvMesh::fvMesh
{
if (debug)
{
InfoInFunction << "Constructing fvMesh from components" << endl;
Pout<< FUNCTION_NAME << "Constructing fvMesh from components" << endl;
}
}
@ -441,7 +451,7 @@ Foam::fvMesh::fvMesh
{
if (debug)
{
InfoInFunction << "Constructing fvMesh from components" << endl;
Pout<< FUNCTION_NAME << "Constructing fvMesh from components" << endl;
}
}
@ -479,7 +489,7 @@ void Foam::fvMesh::removeFvBoundary()
{
if (debug)
{
InfoInFunction << "Removing boundary patches." << endl;
Pout<< FUNCTION_NAME << "Removing boundary patches." << endl;
}
// Remove fvBoundaryMesh data first.
@ -495,7 +505,7 @@ Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate()
{
if (debug)
{
InfoInFunction << "Updating fvMesh. ";
Pout<< FUNCTION_NAME << "Updating fvMesh. ";
}
polyMesh::readUpdateState state = polyMesh::readUpdate();
@ -563,7 +573,7 @@ void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap)
{
if (debug)
{
InfoInFunction
Pout<< FUNCTION_NAME
<< " nOldCells:" << meshMap.nOldCells()
<< " nCells:" << nCells()
<< " nOldFaces:" << meshMap.nOldFaces()
@ -856,6 +866,163 @@ void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
}
void Foam::fvMesh::addPatch
(
const label insertPatchi,
const polyPatch& patch,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const bool validBoundary
)
{
// Remove my local data (see updateMesh)
// Clear mesh motion flux
deleteDemandDrivenData(phiPtr_);
// Clear the sliced fields
clearGeomNotOldVol();
// Clear the current volume and other geometry factors
surfaceInterpolation::clearOut();
// Clear any non-updateable addressing
clearAddressing(true);
const label sz = boundary_.size();
polyMesh::addPatch
(
insertPatchi,
patch,
patchFieldDict,
defaultPatchFieldType,
validBoundary
);
boundary_.setSize(sz+1);
boundary_.set
(
insertPatchi,
fvPatch::New
(
boundaryMesh()[insertPatchi],
boundary_
)
);
objectRegistry& db = const_cast<objectRegistry&>(thisDb());
AddPatchFields<volScalarField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<volVectorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<volSphericalTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<volSymmTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<volTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
// Surface fields
AddPatchFields<surfaceScalarField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<surfaceVectorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<surfaceSphericalTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<surfaceSymmTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
AddPatchFields<surfaceTensorField>
(
db,
insertPatchi,
patchFieldDict,
defaultPatchFieldType,
Zero
);
}
void Foam::fvMesh::reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
)
{
polyMesh::reorderPatches(newToOld, validBoundary);
boundary_.shuffle(newToOld, validBoundary);
objectRegistry& db = const_cast<objectRegistry&>(thisDb());
ReorderPatchFields<volScalarField>(db, newToOld);
ReorderPatchFields<volVectorField>(db, newToOld);
ReorderPatchFields<volSphericalTensorField>(db, newToOld);
ReorderPatchFields<volSymmTensorField>(db, newToOld);
ReorderPatchFields<volTensorField>(db, newToOld);
ReorderPatchFields<surfaceScalarField>(db, newToOld);
ReorderPatchFields<surfaceVectorField>(db, newToOld);
ReorderPatchFields<surfaceSphericalTensorField>(db, newToOld);
ReorderPatchFields<surfaceSymmTensorField>(db, newToOld);
ReorderPatchFields<surfaceTensorField>(db, newToOld);
}
bool Foam::fvMesh::writeObject
(
IOstream::streamFormat fmt,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -345,6 +345,25 @@ public:
//- Map all fields in time using given map.
virtual void mapFields(const mapPolyMesh& mpm);
//- Add/insert single patch. If validBoundary the new situation
// is consistent across processors.
virtual void addPatch
(
const label insertPatchi,
const polyPatch& patch,
const dictionary& patchFieldDict,
const word& defaultPatchFieldType,
const bool validBoundary
);
//- Reorder and trim existing patches. If validBoundary the new
// situation is consistent across processors
virtual void reorderPatches
(
const labelUList& newToOld,
const bool validBoundary
);
//- Remove boundary patches. Warning: fvPatchFields hold ref to
// these fvPatches.
void removeFvBoundary();

View File

@ -1970,221 +1970,62 @@ void Foam::meshRefinement::calculateEdgeWeights
}
Foam::label Foam::meshRefinement::appendPatch
(
fvMesh& mesh,
const label insertPatchi,
const word& patchName,
const dictionary& patchDict
)
{
// Clear local fields and e.g. polyMesh parallelInfo.
mesh.clearOut();
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh.boundary());
label patchi = polyPatches.size();
// Add polyPatch at the end
polyPatches.setSize(patchi+1);
polyPatches.set
(
patchi,
polyPatch::New
(
patchName,
patchDict,
insertPatchi,
polyPatches
)
);
fvPatches.setSize(patchi+1);
fvPatches.set
(
patchi,
fvPatch::New
(
polyPatches[patchi], // point to newly added polyPatch
mesh.boundary()
)
);
addPatchFields<volScalarField>
(
mesh,
calculatedFvPatchField<scalar>::typeName
);
addPatchFields<volVectorField>
(
mesh,
calculatedFvPatchField<vector>::typeName
);
addPatchFields<volSphericalTensorField>
(
mesh,
calculatedFvPatchField<sphericalTensor>::typeName
);
addPatchFields<volSymmTensorField>
(
mesh,
calculatedFvPatchField<symmTensor>::typeName
);
addPatchFields<volTensorField>
(
mesh,
calculatedFvPatchField<tensor>::typeName
);
// Surface fields
addPatchFields<surfaceScalarField>
(
mesh,
calculatedFvPatchField<scalar>::typeName
);
addPatchFields<surfaceVectorField>
(
mesh,
calculatedFvPatchField<vector>::typeName
);
addPatchFields<surfaceSphericalTensorField>
(
mesh,
calculatedFvPatchField<sphericalTensor>::typeName
);
addPatchFields<surfaceSymmTensorField>
(
mesh,
calculatedFvPatchField<symmTensor>::typeName
);
addPatchFields<surfaceTensorField>
(
mesh,
calculatedFvPatchField<tensor>::typeName
);
return patchi;
}
Foam::label Foam::meshRefinement::addPatch
(
fvMesh& mesh,
const word& patchName,
const dictionary& patchInfo
)
{
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh.boundary());
const label patchi = polyPatches.findPatchID(patchName);
if (patchi != -1)
{
// Already there
return patchi;
}
label insertPatchi = polyPatches.size();
label startFacei = mesh.nFaces();
forAll(polyPatches, patchi)
{
const polyPatch& pp = polyPatches[patchi];
if (isA<processorPolyPatch>(pp))
{
insertPatchi = patchi;
startFacei = pp.start();
break;
}
}
dictionary patchDict(patchInfo);
patchDict.set("nFaces", 0);
patchDict.set("startFace", startFacei);
// Below is all quite a hack. Feel free to change once there is a better
// mechanism to insert and reorder patches.
label addedPatchi = appendPatch(mesh, insertPatchi, patchName, patchDict);
// Create reordering list
// patches before insert position stay as is
labelList oldToNew(addedPatchi+1);
for (label i = 0; i < insertPatchi; i++)
{
oldToNew[i] = i;
}
// patches after insert position move one up
for (label i = insertPatchi; i < addedPatchi; i++)
{
oldToNew[i] = i+1;
}
// appended patch gets moved to insert position
oldToNew[addedPatchi] = insertPatchi;
// Shuffle into place
polyPatches.reorder(oldToNew, true);
fvPatches.reorder(oldToNew);
reorderPatchFields<volScalarField>(mesh, oldToNew);
reorderPatchFields<volVectorField>(mesh, oldToNew);
reorderPatchFields<volSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<volSymmTensorField>(mesh, oldToNew);
reorderPatchFields<volTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceScalarField>(mesh, oldToNew);
reorderPatchFields<surfaceVectorField>(mesh, oldToNew);
reorderPatchFields<surfaceSphericalTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceSymmTensorField>(mesh, oldToNew);
reorderPatchFields<surfaceTensorField>(mesh, oldToNew);
return insertPatchi;
}
Foam::label Foam::meshRefinement::addMeshedPatch
(
const word& name,
const dictionary& patchInfo
)
{
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
label meshedI = findIndex(meshedPatches_, name);
if (meshedI != -1)
{
// Already there. Get corresponding polypatch
return mesh_.boundaryMesh().findPatchID(name);
return pbm.findPatchID(name);
}
else
{
// Add patch
label patchi = addPatch(mesh_, name, patchInfo);
// dictionary patchDict(patchInfo);
// patchDict.set("nFaces", 0);
// patchDict.set("startFace", 0);
// autoPtr<polyPatch> ppPtr
// (
// polyPatch::New
// (
// name,
// patchDict,
// 0,
// mesh_.boundaryMesh()
// )
// );
// label patchi = fvMeshTools::addPatch
// (
// mesh_,
// ppPtr(),
// dictionary(), // optional field values
// calculatedFvPatchField<scalar>::typeName,
// true
// );
label patchi = pbm.findPatchID(name);
if (patchi == -1)
{
patchi = pbm.size();
forAll(pbm, i)
{
const polyPatch& pp = pbm[i];
if (isA<processorPolyPatch>(pp))
{
patchi = i;
break;
}
}
dictionary patchDict(patchInfo);
patchDict.set("nFaces", 0);
patchDict.set("startFace", 0);
autoPtr<polyPatch> ppPtr
(
polyPatch::New
(
name,
patchDict,
0,
pbm
)
);
mesh_.addPatch
(
patchi,
ppPtr(),
dictionary(), // optional field values
fvPatchField<scalar>::calculatedType(),
true // validBoundary
);
}
// Store
meshedPatches_.append(name);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -196,14 +196,6 @@ private:
// Private Member Functions
//- Add patchfield of given type to all fields on mesh
template<class GeoField>
static void addPatchFields(fvMesh&, const word& patchFieldType);
//- Reorder patchfields of all fields on mesh
template<class GeoField>
static void reorderPatchFields(fvMesh&, const labelList& oldToNew);
//- Find out which faces have changed given cells (old mesh labels)
// that were marked for refinement.
static labelList getChangedFaces
@ -900,19 +892,6 @@ public:
// Other topo changes
//- Helper:append patch to end of mesh.
static label appendPatch
(
fvMesh&,
const label insertPatchi,
const word&,
const dictionary&
);
//- Helper:add patch to mesh. Update all registered fields.
// Used by addMeshedPatch to add patches originating from surfaces.
static label addPatch(fvMesh&, const word& name, const dictionary&);
//- Add patch originating from meshing. Update meshedPatches_.
label addMeshedPatch(const word& name, const dictionary&);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -199,59 +199,6 @@ void Foam::meshRefinement::collectAndPrint
}
template<class GeoField>
void Foam::meshRefinement::addPatchFields
(
fvMesh& mesh,
const word& patchFieldType
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& fldBf =
fld.boundaryFieldRef();
label sz = fldBf.size();
fldBf.setSize(sz+1);
fldBf.set
(
sz,
GeoField::Patch::New
(
patchFieldType,
mesh.boundary()[sz],
fld()
)
);
}
}
template<class GeoField>
void Foam::meshRefinement::reorderPatchFields
(
fvMesh& mesh,
const labelList& oldToNew
)
{
HashTable<GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
{
iter()->boundaryFieldRef().reorder(oldToNew);
}
}
template<class Enum>
int Foam::meshRefinement::readFlags
(

View File

@ -1008,25 +1008,24 @@ void Foam::snappyLayerDriver::determineSidePatches
for (label patchi = nOldPatches; patchi < nPatches; patchi++)
{
label nbrProci = patchToNbrProc[patchi];
word name
const label nbrProci = patchToNbrProc[patchi];
const label procPatchi = mesh.boundaryMesh().size();
const processorPolyPatch pp
(
processorPolyPatch::newName(Pstream::myProcNo(), nbrProci)
0, // size
0, // start
procPatchi, // index
mesh.boundaryMesh(),
Pstream::myProcNo(),
nbrProci
);
dictionary patchDict;
patchDict.add("type", processorPolyPatch::typeName);
patchDict.add("myProcNo", Pstream::myProcNo());
patchDict.add("neighbProcNo", nbrProci);
patchDict.add("nFaces", 0);
patchDict.add("startFace", mesh.nFaces());
label procPatchi = meshRefiner_.appendPatch
mesh.addPatch
(
mesh,
mesh.boundaryMesh().size(), // new patch index
name,
patchDict
procPatchi, // new patch index
pp,
dictionary(), // patchField dict
fvPatchField<scalar>::calculatedType(),
false
);
wantedToAddedPatch.insert(patchi, procPatchi);
}

11
test/fvMeshTools/Allrun Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
wmake Test-fvMeshTools
( cd cavity && ./Allrun $* )
#------------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
Test-fvMeshTools.C
EXE = $(FOAM_USER_APPBIN)/Test-fvMeshTools

View File

@ -0,0 +1,11 @@
EXE_INC = \
-IfaceSelection \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-ldynamicMesh \
-lmeshTools \
-lfiniteVolume \
-lgenericPatchFields

View File

@ -0,0 +1,217 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
Application
Test-fvMeshTools
Description
Testing of adding and removing patches.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "ReadFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
#include "fvMeshTools.H"
#include "wallPolyPatch.H"
#include "processorFvPatchField.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote("Test patch manipulation");
#include "addRegionOption.H"
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
#include "createNamedMesh.H"
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
Info<< "Reading geometric fields" << nl << endl;
const bool fields = true;
#include "readVolFields.H"
#include "readSurfaceFields.H"
#include "readPointFields.H"
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
// Add/insert a (global) wall patch
{
wallPolyPatch pp
(
"myWall",
0, // dummy
0, // dummy
0, // dummy
pbm,
wallPolyPatch::typeName
);
label newPatchi = fvMeshTools::addPatch
(
mesh,
pp,
dictionary(), // no specialised patch fields
calculatedFvPatchField<scalar>::typeName,
true // parallel sync'ed addition
);
Info<< "Inserted patch " << mesh.boundaryMesh()[newPatchi].name()
<< " type " << mesh.boundaryMesh()[newPatchi].type()
<< " at index " << newPatchi << endl;
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with added patch to " << runTime.timeName()
<< endl;
mesh.write();
}
// Remove a (zero-sized!) patch everywhere
const label removei = 0;
if (!isA<processorPolyPatch>(pbm[removei]) && pbm[removei].size() == 0)
{
Info<< "Removing patch " << pbm[removei].name() << endl;
labelList oldToNew(pbm.size());
for (label i = 0; i < removei; i++)
{
oldToNew[i] = i;
}
oldToNew[removei] = pbm.size()-1;
for (label i = removei+1; i < oldToNew.size(); i++)
{
oldToNew[i] = i-1;
}
fvMeshTools::reorderPatches(mesh, oldToNew, pbm.size()-1, true);
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with removed patch to " << runTime.timeName()
<< endl;
mesh.write();
}
// Add a pair of processor patches
if (Pstream::parRun())
{
word newPatchName;
if (Pstream::myProcNo() == 0 || Pstream::myProcNo() == 1)
{
const label nbrProcNo = (1-Pstream::myProcNo());
newPatchName =
processorPolyPatch::newName(Pstream::myProcNo(), nbrProcNo)
+ "_extra";
dictionary dict;
dict.add("myProcNo", Pstream::myProcNo());
dict.add("neighbProcNo", nbrProcNo);
dict.add("startFace", 0);
dict.add("nFaces", 0);
processorPolyPatch pp
(
newPatchName,
dict,
0, // dummy index
pbm,
processorPolyPatch::typeName
);
label newPatchi = fvMeshTools::addPatch
(
mesh,
pp,
dictionary(), // no specialised patch fields
processorFvPatchField<scalar>::typeName,
false // parallel sync'ed addition
);
Pout<< "Inserted patch " << mesh.boundaryMesh()[newPatchi].name()
<< " type " << mesh.boundaryMesh()[newPatchi].type()
<< " at index " << newPatchi << endl;
}
// Note: write on all processors. There is a slight problem in
// reconstructPar: mesh.readUpdate checks that the boundary file is
// different. On proc 0 and 1 it will be different, on proc2.. it
// stays the same. This causes a failure in reconstructPar.
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with added (local) patch to " << runTime.timeName()
<< endl;
mesh.write();
// Remove the added patch
if (newPatchName.size())
{
label removei = pbm.findPatchID(newPatchName);
if (removei == -1)
{
FatalErrorInFunction << "Problem" << exit(FatalError);
}
Info<< "Removing patch " << pbm[removei].name() << endl;
labelList oldToNew(pbm.size());
for (label i = 0; i < removei; i++)
{
oldToNew[i] = i;
}
oldToNew[removei] = pbm.size()-1;
for (label i = removei+1; i < oldToNew.size(); i++)
{
oldToNew[i] = i-1;
}
fvMeshTools::reorderPatches(mesh, oldToNew, pbm.size()-1, false);
}
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with removed local patch to " << runTime.timeName()
<< endl;
mesh.write();
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,45 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
zeroSizedPatch
{
type noSlip;
}
movingWall
{
type fixedValue;
value uniform (1 0 0);
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
zeroSizedPatch
{
type zeroGradient;
}
movingWall
{
type zeroGradient;
}
fixedWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class pointVectorField;
location "0";
object pointDisplacement;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 0 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
zeroSizedPatch
{
type noSlip;
}
movingWall
{
type noSlip;
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

23
test/fvMeshTools/cavity/Allrun Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
runApplication blockMesh
runApplication $(getApplication)
runApplication checkMesh
runApplication foamToVTK
runApplication decomposePar
runParallel -s par $(getApplication)
runParallel -s par checkMesh
runParallel -s par foamToEnsight
runApplication reconstructParMesh -mergeTol 1e-6
# This will fail for any processors that does not have any local patches
# added so exclude that time
runApplication reconstructPar -time '0:0.01'
runApplication -s latestTime reconstructPar -latestTime
#------------------------------------------------------------------------------

View File

@ -0,0 +1,82 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.1;
vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 0.1)
(1 0 0.1)
(1 1 0.1)
(0 1 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
zeroSizedPatch
{
type wall;
faces
(
);
}
movingWall
{
type wall;
faces
(
(3 7 6 2)
);
}
fixedWalls
{
type wall;
faces
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application Test-fvMeshTools;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.01;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //

View File

@ -0,0 +1,21 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 3;
method scotch;
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ddtSchemes
{
#ifeq ${FOAM_APPLICATION} icoFoam
default steadyState;
#else
default Euler;
#endif
}
gradSchemes
{
default Gauss linear;
grad(p) Gauss linear;
}
divSchemes
{
default none;
div(phi,U) Gauss linear;
}
laplacianSchemes
{
default Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
// ************************************************************************* //

View File

@ -0,0 +1,52 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0.05;
}
pFinal
{
$p;
relTol 0;
}
U
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-05;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //