2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
|
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
|
|
\\ / O peration |
|
|
|
|
\\ / A nd | Copyright held by original author
|
|
|
|
\\/ 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 2 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, write to the Free Software Foundation,
|
|
|
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "fvFieldReconstructor.H"
|
|
|
|
#include "Time.H"
|
|
|
|
#include "PtrList.H"
|
|
|
|
#include "fvPatchFields.H"
|
|
|
|
#include "emptyFvPatch.H"
|
|
|
|
#include "emptyFvPatchField.H"
|
|
|
|
#include "emptyFvsPatchField.H"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
template<class Type>
|
|
|
|
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
|
|
|
|
Foam::fvFieldReconstructor::reconstructFvVolumeField
|
|
|
|
(
|
|
|
|
const IOobject& fieldIoObject
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// 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]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the internalField
|
|
|
|
Field<Type> internalField(mesh_.nCells());
|
|
|
|
|
|
|
|
// Create the patch fields
|
|
|
|
PtrList<fvPatchField<Type> > patchFields(mesh_.boundary().size());
|
|
|
|
|
|
|
|
|
|
|
|
forAll (procMeshes_, procI)
|
|
|
|
{
|
|
|
|
const GeometricField<Type, fvPatchField, volMesh>& procField =
|
|
|
|
procFields[procI];
|
|
|
|
|
|
|
|
// Set the cell values in the reconstructed field
|
|
|
|
internalField.rmap
|
|
|
|
(
|
|
|
|
procField.internalField(),
|
|
|
|
cellProcAddressing_[procI]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set the boundary patch values in the reconstructed field
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (boundaryProcAddressing_[procI], patchI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Get patch index of the original patch
|
|
|
|
const label curBPatch = boundaryProcAddressing_[procI][patchI];
|
|
|
|
|
|
|
|
// Get addressing slice for this patch
|
|
|
|
const labelList::subList cp =
|
|
|
|
procMeshes_[procI].boundary()[patchI].patchSlice
|
|
|
|
(
|
|
|
|
faceProcAddressing_[procI]
|
|
|
|
);
|
|
|
|
|
|
|
|
// check if the boundary patch is not a processor patch
|
|
|
|
if (curBPatch >= 0)
|
|
|
|
{
|
|
|
|
// Regular patch. Fast looping
|
|
|
|
|
|
|
|
if (!patchFields(curBPatch))
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
curBPatch,
|
|
|
|
fvPatchField<Type>::New
|
|
|
|
(
|
|
|
|
procField.boundaryField()[patchI],
|
|
|
|
mesh_.boundary()[curBPatch],
|
|
|
|
DimensionedField<Type, volMesh>::null(),
|
|
|
|
fvPatchFieldReconstructor
|
|
|
|
(
|
|
|
|
mesh_.boundary()[curBPatch].size(),
|
|
|
|
procField.boundaryField()[patchI].size()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const label curPatchStart =
|
|
|
|
mesh_.boundaryMesh()[curBPatch].start();
|
|
|
|
|
|
|
|
labelList reverseAddressing(cp.size());
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (cp, faceI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Subtract one to take into account offsets for
|
2010-09-22 18:13:13 +00:00
|
|
|
// face direction.
|
2010-05-12 13:27:55 +00:00
|
|
|
reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
patchFields[curBPatch].rmap
|
|
|
|
(
|
|
|
|
procField.boundaryField()[patchI],
|
|
|
|
reverseAddressing
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const Field<Type>& curProcPatch =
|
|
|
|
procField.boundaryField()[patchI];
|
|
|
|
|
|
|
|
// In processor patches, there's a mix of internal faces (some
|
|
|
|
// of them turned) and possible cyclics. Slow loop
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (cp, faceI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Subtract one to take into account offsets for
|
2010-09-22 18:13:13 +00:00
|
|
|
// face direction.
|
2010-05-12 13:27:55 +00:00
|
|
|
label curF = cp[faceI] - 1;
|
|
|
|
|
|
|
|
// Is the face on the boundary?
|
|
|
|
if (curF >= mesh_.nInternalFaces())
|
|
|
|
{
|
2011-02-19 01:05:24 +00:00
|
|
|
label curBPatch =
|
|
|
|
mesh_.boundaryMesh().whichPatch(curF);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
if (!patchFields(curBPatch))
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
curBPatch,
|
|
|
|
fvPatchField<Type>::New
|
|
|
|
(
|
|
|
|
mesh_.boundary()[curBPatch].type(),
|
|
|
|
mesh_.boundary()[curBPatch],
|
|
|
|
DimensionedField<Type, volMesh>::null()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the face
|
|
|
|
label curPatchFace =
|
|
|
|
mesh_.boundaryMesh()
|
|
|
|
[curBPatch].whichFace(curF);
|
|
|
|
|
|
|
|
patchFields[curBPatch][curPatchFace] =
|
|
|
|
curProcPatch[faceI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (mesh_.boundary(), patchI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// add empty patches
|
|
|
|
if
|
|
|
|
(
|
2010-09-22 18:13:13 +00:00
|
|
|
isType<emptyFvPatch>(mesh_.boundary()[patchI])
|
2010-05-12 13:27:55 +00:00
|
|
|
&& !patchFields(patchI)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
patchI,
|
|
|
|
fvPatchField<Type>::New
|
|
|
|
(
|
|
|
|
emptyFvPatchField<Type>::typeName,
|
|
|
|
mesh_.boundary()[patchI],
|
|
|
|
DimensionedField<Type, volMesh>::null()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now construct and write the field
|
|
|
|
// setting the internalField and patchFields
|
|
|
|
return tmp<GeometricField<Type, fvPatchField, volMesh> >
|
|
|
|
(
|
|
|
|
new GeometricField<Type, fvPatchField, volMesh>
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
fieldIoObject.name(),
|
|
|
|
mesh_.time().timeName(),
|
|
|
|
mesh_,
|
|
|
|
IOobject::NO_READ,
|
|
|
|
IOobject::NO_WRITE
|
|
|
|
),
|
|
|
|
mesh_,
|
|
|
|
procFields[0].dimensions(),
|
|
|
|
internalField,
|
|
|
|
patchFields
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Type>
|
|
|
|
Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
|
|
|
|
Foam::fvFieldReconstructor::reconstructFvSurfaceField
|
|
|
|
(
|
|
|
|
const IOobject& fieldIoObject
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Read the field for all the processors
|
|
|
|
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> > procFields
|
|
|
|
(
|
|
|
|
procMeshes_.size()
|
|
|
|
);
|
|
|
|
|
|
|
|
forAll (procMeshes_, procI)
|
|
|
|
{
|
|
|
|
procFields.set
|
|
|
|
(
|
|
|
|
procI,
|
|
|
|
new GeometricField<Type, fvsPatchField, surfaceMesh>
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
fieldIoObject.name(),
|
|
|
|
procMeshes_[procI].time().timeName(),
|
|
|
|
procMeshes_[procI],
|
|
|
|
IOobject::MUST_READ,
|
|
|
|
IOobject::NO_WRITE
|
|
|
|
),
|
|
|
|
procMeshes_[procI]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the internalField
|
|
|
|
Field<Type> internalField(mesh_.nInternalFaces());
|
|
|
|
|
|
|
|
// Create the patch fields
|
|
|
|
PtrList<fvsPatchField<Type> > patchFields(mesh_.boundary().size());
|
|
|
|
|
|
|
|
forAll (procMeshes_, procI)
|
|
|
|
{
|
|
|
|
const GeometricField<Type, fvsPatchField, surfaceMesh>& procField =
|
|
|
|
procFields[procI];
|
|
|
|
|
|
|
|
// Set the face values in the reconstructed field
|
|
|
|
|
|
|
|
// It is necessary to create a copy of the addressing array to
|
|
|
|
// take care of the face direction offset trick.
|
2010-09-22 18:13:13 +00:00
|
|
|
//
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
labelList curAddr(faceProcAddressing_[procI]);
|
|
|
|
|
|
|
|
forAll (curAddr, addrI)
|
|
|
|
{
|
|
|
|
curAddr[addrI] -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
internalField.rmap
|
|
|
|
(
|
|
|
|
procField.internalField(),
|
|
|
|
curAddr
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the boundary patch values in the reconstructed field
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (boundaryProcAddressing_[procI], patchI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Get patch index of the original patch
|
|
|
|
const label curBPatch = boundaryProcAddressing_[procI][patchI];
|
|
|
|
|
|
|
|
// Get addressing slice for this patch
|
|
|
|
const labelList::subList cp =
|
|
|
|
procMeshes_[procI].boundary()[patchI].patchSlice
|
|
|
|
(
|
|
|
|
faceProcAddressing_[procI]
|
|
|
|
);
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
// Check if the boundary patch is not a processor patch
|
2010-05-12 13:27:55 +00:00
|
|
|
if (curBPatch >= 0)
|
|
|
|
{
|
|
|
|
// Regular patch. Fast looping
|
|
|
|
if (!patchFields(curBPatch))
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
curBPatch,
|
|
|
|
fvsPatchField<Type>::New
|
|
|
|
(
|
|
|
|
procField.boundaryField()[patchI],
|
|
|
|
mesh_.boundary()[curBPatch],
|
|
|
|
DimensionedField<Type, surfaceMesh>::null(),
|
|
|
|
fvPatchFieldReconstructor
|
|
|
|
(
|
|
|
|
mesh_.boundary()[curBPatch].size(),
|
|
|
|
procField.boundaryField()[patchI].size()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const label curPatchStart =
|
|
|
|
mesh_.boundaryMesh()[curBPatch].start();
|
|
|
|
|
|
|
|
labelList reverseAddressing(cp.size());
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (cp, faceI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Subtract one to take into account offsets for
|
2010-09-22 18:13:13 +00:00
|
|
|
// face direction.
|
2010-05-12 13:27:55 +00:00
|
|
|
reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
patchFields[curBPatch].rmap
|
|
|
|
(
|
|
|
|
procField.boundaryField()[patchI],
|
|
|
|
reverseAddressing
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const Field<Type>& curProcPatch =
|
|
|
|
procField.boundaryField()[patchI];
|
|
|
|
|
|
|
|
// In processor patches, there's a mix of internal faces (some
|
|
|
|
// of them turned) and possible cyclics. Slow loop
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (cp, faceI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
label curF = cp[faceI] - 1;
|
|
|
|
|
|
|
|
// Is the face turned the right side round
|
|
|
|
if (curF >= 0)
|
|
|
|
{
|
|
|
|
// Is the face on the boundary?
|
|
|
|
if (curF >= mesh_.nInternalFaces())
|
|
|
|
{
|
|
|
|
label curBPatch =
|
|
|
|
mesh_.boundaryMesh().whichPatch(curF);
|
|
|
|
|
|
|
|
if (!patchFields(curBPatch))
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
curBPatch,
|
|
|
|
fvsPatchField<Type>::New
|
|
|
|
(
|
|
|
|
mesh_.boundary()[curBPatch].type(),
|
|
|
|
mesh_.boundary()[curBPatch],
|
|
|
|
DimensionedField<Type, surfaceMesh>
|
|
|
|
::null()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the face
|
|
|
|
label curPatchFace =
|
|
|
|
mesh_.boundaryMesh()
|
|
|
|
[curBPatch].whichFace(curF);
|
|
|
|
|
|
|
|
patchFields[curBPatch][curPatchFace] =
|
|
|
|
curProcPatch[faceI];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Internal face
|
|
|
|
internalField[curF] = curProcPatch[faceI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
forAll (mesh_.boundary(), patchI)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// add empty patches
|
|
|
|
if
|
|
|
|
(
|
2010-09-22 18:13:13 +00:00
|
|
|
isType<emptyFvPatch>(mesh_.boundary()[patchI])
|
2010-05-12 13:27:55 +00:00
|
|
|
&& !patchFields(patchI)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
patchFields.set
|
|
|
|
(
|
|
|
|
patchI,
|
|
|
|
fvsPatchField<Type>::New
|
|
|
|
(
|
|
|
|
emptyFvsPatchField<Type>::typeName,
|
|
|
|
mesh_.boundary()[patchI],
|
|
|
|
DimensionedField<Type, surfaceMesh>::null()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now construct and write the field
|
|
|
|
// setting the internalField and patchFields
|
|
|
|
return tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
|
|
|
|
(
|
|
|
|
new GeometricField<Type, fvsPatchField, surfaceMesh>
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
fieldIoObject.name(),
|
|
|
|
mesh_.time().timeName(),
|
|
|
|
mesh_,
|
|
|
|
IOobject::NO_READ,
|
|
|
|
IOobject::NO_WRITE
|
|
|
|
),
|
|
|
|
mesh_,
|
|
|
|
procFields[0].dimensions(),
|
|
|
|
internalField,
|
|
|
|
patchFields
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
// Reconstruct and write all/selected volume fields
|
2010-05-12 13:27:55 +00:00
|
|
|
template<class Type>
|
|
|
|
void Foam::fvFieldReconstructor::reconstructFvVolumeFields
|
|
|
|
(
|
2010-09-22 18:13:13 +00:00
|
|
|
const IOobjectList& objects,
|
|
|
|
const HashSet<word>& selectedFields
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
const word& fieldClassName =
|
|
|
|
GeometricField<Type, fvPatchField, volMesh>::typeName;
|
|
|
|
|
|
|
|
IOobjectList fields = objects.lookupClass(fieldClassName);
|
|
|
|
|
|
|
|
if (fields.size())
|
|
|
|
{
|
|
|
|
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
|
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
forAllConstIter(IOobjectList, fields, fieldIter)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-09-22 18:13:13 +00:00
|
|
|
if
|
|
|
|
(
|
|
|
|
!selectedFields.size()
|
|
|
|
|| selectedFields.found(fieldIter()->name())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Info<< " " << fieldIter()->name() << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
reconstructFvVolumeField<Type>(*fieldIter())().write();
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
Info<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 01:05:24 +00:00
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
// Reconstruct and write all/selected surface fields
|
2010-05-12 13:27:55 +00:00
|
|
|
template<class Type>
|
|
|
|
void Foam::fvFieldReconstructor::reconstructFvSurfaceFields
|
|
|
|
(
|
2010-09-22 18:13:13 +00:00
|
|
|
const IOobjectList& objects,
|
|
|
|
const HashSet<word>& selectedFields
|
2010-05-12 13:27:55 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
const word& fieldClassName =
|
|
|
|
GeometricField<Type, fvsPatchField, surfaceMesh>::typeName;
|
|
|
|
|
|
|
|
IOobjectList fields = objects.lookupClass(fieldClassName);
|
|
|
|
|
|
|
|
if (fields.size())
|
|
|
|
{
|
|
|
|
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
|
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
forAllConstIter(IOobjectList, fields, fieldIter)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-09-22 18:13:13 +00:00
|
|
|
if
|
|
|
|
(
|
|
|
|
!selectedFields.size()
|
|
|
|
|| selectedFields.found(fieldIter()->name())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Info<< " " << fieldIter()->name() << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-09-22 18:13:13 +00:00
|
|
|
reconstructFvSurfaceField<Type>(*fieldIter())().write();
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
2011-02-19 01:05:24 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
Info<< endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|