Merge commit 'OpenCFD/master' into olesenm

This commit is contained in:
Mark Olesen
2009-03-05 11:00:34 +01:00
8 changed files with 383 additions and 120 deletions

View File

@ -319,6 +319,7 @@ int vtkPV3FoamReader::RequestData
<< output->GetNumberOfBlocks() << " blocks\n"; << output->GetNumberOfBlocks() << " blocks\n";
} }
#ifdef EXPERIMENTAL_TIME_CACHING #ifdef EXPERIMENTAL_TIME_CACHING
bool needsUpdate = false; bool needsUpdate = false;
@ -373,6 +374,9 @@ int vtkPV3FoamReader::RequestData
#endif #endif
// Do any cleanup on the Foam side
foamData_->CleanUp();
return 1; return 1;
} }

View File

@ -492,11 +492,15 @@ void Foam::vtkPV3Foam::Update
convertLagrangianFields(lagrangianOutput); convertLagrangianFields(lagrangianOutput);
reader_->UpdateProgress(0.95); reader_->UpdateProgress(0.95);
meshChanged_ = fieldsChanged_ = false;
}
void Foam::vtkPV3Foam::CleanUp()
{
// reclaim some memory // reclaim some memory
reduceMemory(); reduceMemory();
reader_->UpdateProgress(1.0); reader_->UpdateProgress(1.0);
meshChanged_ = fieldsChanged_ = false;
} }

View File

@ -700,6 +700,9 @@ public:
vtkMultiBlockDataSet* lagrangianOutput vtkMultiBlockDataSet* lagrangianOutput
); );
//- Clean any storage
void CleanUp();
//- Allocate and return a list of selected times //- Allocate and return a list of selected times
// returns the count via the parameter // returns the count via the parameter
double* findTimes(int& nTimeSteps); double* findTimes(int& nTimeSteps);

View File

@ -91,7 +91,7 @@ bool Foam::IOobject::readHeader(Istream& is)
<< "First token could not be read or is not the keyword 'FoamFile'" << "First token could not be read or is not the keyword 'FoamFile'"
<< nl << nl << "Check header is of the form:" << nl << endl; << nl << nl << "Check header is of the form:" << nl << endl;
writeHeader(Info); writeHeader(SeriousError);
return false; return false;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,11 +29,265 @@ License
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "fvMatrices.H" #include "fvMatrices.H"
#include "PackedList.H"
#include "syncTools.H" #include "syncTools.H"
#include "faceSet.H" #include "faceSet.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::MRFZone::setMRFFaces
(
labelList& faceType,
const labelList& excludedPatchIDs
)
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
// Knock out coupled patches
forAll(patches, patchi)
{
if (patches[patchi].coupled())
{
const polyPatch& pp = patches[patchi];
forAll(pp, j)
{
label faceI = pp.start()+j;
if (faceType[faceI] == 1)
{
faceType[faceI] = 2;
}
}
}
}
// All explicitly provided exclusions
forAll(excludedPatchIDs, i)
{
const polyPatch& pp = patches[excludedPatchIDs[i]];
forAll(pp, j)
{
label faceI = pp.start()+j;
if (faceType[faceI] == 1)
{
faceType[faceI] = 2;
}
}
}
// Collect into lists per patch.
internalFaces_.setSize(mesh_.nFaces());
label nInternal = 0;
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
if (faceType[faceI] == 1)
{
internalFaces_[nInternal++] = faceI;
}
}
internalFaces_.setSize(nInternal);
labelList nIncludedFaces(patches.size(), 0);
labelList nExcludedFaces(patches.size(), 0);
forAll(patches, patchi)
{
const polyPatch& pp = patches[patchi];
forAll(pp, patchFacei)
{
label faceI = pp.start()+patchFacei;
if (faceType[faceI] == 1)
{
nIncludedFaces[patchi]++;
}
else if (faceType[faceI] == 2)
{
nExcludedFaces[patchi]++;
}
}
}
includedFaces_.setSize(patches.size());
excludedFaces_.setSize(patches.size());
forAll(nIncludedFaces, patchi)
{
includedFaces_[patchi].setSize(nIncludedFaces[patchi]);
excludedFaces_[patchi].setSize(nExcludedFaces[patchi]);
}
nIncludedFaces = 0;
nExcludedFaces = 0;
forAll(patches, patchi)
{
const polyPatch& pp = patches[patchi];
forAll(pp, patchFacei)
{
label faceI = pp.start()+patchFacei;
if (faceType[faceI] == 1)
{
includedFaces_[patchi][nIncludedFaces[patchi]++] = patchFacei;
}
else if (faceType[faceI] == 2)
{
excludedFaces_[patchi][nExcludedFaces[patchi]++] = patchFacei;
}
}
}
//if (debug)
//{
// faceSet internalFaces(mesh_, "internalFaces", internalFaces_);
// Pout<< "Writing internal faces in MRF zone to faceSet "
// << internalFaces.name() << endl;
// internalFaces.write();
//}
//{
// faceSet MRFFaces(mesh_, "includedFaces", 100);
// forAll(includedFaces_, patchi)
// {
// forAll(includedFaces_[patchi], i)
// {
// label patchFacei = includedFaces_[patchi][i];
// MRFFaces.insert(patches[patchi].start()+patchFacei);
// }
// }
// Pout<< "Writing patch faces in MRF zone to faceSet "
// << MRFFaces.name() << endl;
// MRFFaces.write();
//}
//{
// faceSet excludedFaces(mesh_, "excludedFaces", 100);
// forAll(excludedFaces_, patchi)
// {
// forAll(excludedFaces_[patchi], i)
// {
// label patchFacei = excludedFaces_[patchi][i];
// excludedFaces.insert(patches[patchi].start()+patchFacei);
// }
// }
// Pout<< "Writing faces in MRF zone with special handling to faceSet "
// << excludedFaces.name() << endl;
// excludedFaces.write();
//}
}
void Foam::MRFZone::setMRFFaces()
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
// Type per face:
// 0:not in zone
// 1:moving with frame
// 2:other
labelList faceType(mesh_.nFaces(), 0);
bool faceZoneFound = (faceZoneID_ != -1);
reduce(faceZoneFound, orOp<bool>());
if (faceZoneFound)
{
// Explicitly provided faces.
if (faceZoneID_ != -1)
{
const labelList& zoneFaces = mesh_.faceZones()[faceZoneID_];
forAll(zoneFaces, i)
{
faceType[zoneFaces[i]] = 1;
}
if (allPatchesMove_)
{
// Explicitly provided patches that do not move
setMRFFaces(faceType, patchLabels_);
}
else
{
setMRFFaces(faceType, labelList(0));
}
}
}
else
{
// Determine faces in cell zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// (without constructing cells)
const labelList& own = mesh_.faceOwner();
const labelList& nei = mesh_.faceNeighbour();
// Cells in zone
boolList zoneCell(mesh_.nCells(), false);
if (cellZoneID_ != -1)
{
const labelList& cellLabels = mesh_.cellZones()[cellZoneID_];
forAll(cellLabels, i)
{
zoneCell[cellLabels[i]] = true;
}
}
label nZoneFaces = 0;
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
if (zoneCell[own[faceI]] || zoneCell[nei[faceI]])
{
faceType[faceI] = 1;
nZoneFaces++;
}
}
forAll(patches, patchI)
{
const polyPatch& pp = patches[patchI];
if (!isA<emptyPolyPatch>(pp))
{
forAll(pp, i)
{
label faceI = pp.start()+i;
if (zoneCell[own[faceI]])
{
faceType[faceI] = 1;
nZoneFaces++;
}
}
}
}
syncTools::syncFaceList(mesh_, faceType, maxEqOp<label>(), false);
Info<< nl
<< "MRFZone " << name_ << " : did not find a faceZone; using "
<< returnReduce(nZoneFaces, sumOp<label>())
<< " faces from the cellZone instead." << endl;
if (allPatchesMove_)
{
// Explicitly provided excluded patches
setMRFFaces(faceType, patchLabels_);
}
else
{
setMRFFaces(faceType, labelList(0));
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is) Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
@ -43,8 +297,13 @@ Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
dict_(is), dict_(is),
cellZoneID_(mesh_.cellZones().findZoneID(name_)), cellZoneID_(mesh_.cellZones().findZoneID(name_)),
faceZoneID_(mesh_.faceZones().findZoneID(name_)), faceZoneID_(mesh_.faceZones().findZoneID(name_)),
outsideFaces_(0), allPatchesMove_(dict_.found("nonRotatingPatches")),
patchNames_(dict_.lookup("patches")), patchNames_
(
allPatchesMove_
? dict_.lookup("nonRotatingPatches")
: dict_.lookup("patches")
),
origin_(dict_.lookup("origin")), origin_(dict_.lookup("origin")),
axis_(dict_.lookup("axis")), axis_(dict_.lookup("axis")),
omega_(dict_.lookup("omega")), omega_(dict_.lookup("omega")),
@ -55,83 +314,6 @@ Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
axis_ = axis_/mag(axis_); axis_ = axis_/mag(axis_);
Omega_ = omega_*axis_; Omega_ = omega_*axis_;
bool cellZoneFound = (cellZoneID_ != -1);
reduce(cellZoneFound, orOp<bool>());
if (!cellZoneFound)
{
FatalErrorIn
(
"Foam::MRFZone::MRFZone(const fvMesh& , const dictionary&)"
) << "cannot find MRF cellZone " << name_
<< exit(FatalError);
}
bool faceZoneFound = (faceZoneID_ != -1);
reduce(faceZoneFound, orOp<bool>());
if (!faceZoneFound)
{
// Determine faces in cell zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// (does not construct cells)
const labelList& own = mesh_.faceOwner();
const labelList& nei = mesh_.faceNeighbour();
// Cells in zone
PackedBoolList zoneCell(mesh_.nCells());
if (cellZoneID_ != -1)
{
const labelList& cellLabels = mesh_.cellZones()[cellZoneID_];
forAll(cellLabels, i)
{
zoneCell[cellLabels[i]] = 1u;
}
}
// Faces in zone
PackedBoolList zoneFacesSet(mesh_.nFaces());
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
if
(
zoneCell.get(own[faceI]) == 1u
|| zoneCell.get(nei[faceI]) == 1u
)
{
zoneFacesSet[faceI] = 1u;
}
}
syncTools::syncFaceList(mesh_, zoneFacesSet, orEqOp<unsigned int>());
// Transfer to labelList
label n = zoneFacesSet.count();
outsideFaces_.setSize(n);
n = 0;
forAll(zoneFacesSet, faceI)
{
if (zoneFacesSet.get(faceI) == 1u)
{
outsideFaces_[n++] = faceI;
}
}
Info<< nl
<< "MRFZone " << name_ << " : did not find a faceZone; using "
<< returnReduce(outsideFaces_.size(), sumOp<label>())
<< " faces internal to cellZone instead." << endl;
// Flag use of outsideFaces
faceZoneID_ = -2;
}
patchLabels_.setSize(patchNames_.size()); patchLabels_.setSize(patchNames_.size());
forAll(patchNames_, i) forAll(patchNames_, i)
@ -142,11 +324,26 @@ Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
{ {
FatalErrorIn FatalErrorIn
( (
"Foam::MRFZone::MRFZone(const fvMesh& , const dictionary&)" "Foam::MRFZone::MRFZone(const fvMesh&, Istream&)"
) << "cannot find MRF patch " << patchNames_[i] ) << "cannot find MRF patch " << patchNames_[i]
<< exit(FatalError); << exit(FatalError);
} }
} }
bool cellZoneFound = (cellZoneID_ != -1);
reduce(cellZoneFound, orOp<bool>());
if (!cellZoneFound)
{
FatalErrorIn
(
"Foam::MRFZone::MRFZone(const fvMesh&, Istream&)"
) << "cannot find MRF cellZone " << name_
<< exit(FatalError);
}
setMRFFaces();
} }
@ -174,48 +371,42 @@ void Foam::MRFZone::addCoriolis(fvVectorMatrix& UEqn) const
void Foam::MRFZone::relativeFlux(surfaceScalarField& phi) const void Foam::MRFZone::relativeFlux(surfaceScalarField& phi) const
{ {
if (faceZoneID_ == -1)
{
return;
}
const surfaceVectorField& Cf = mesh_.Cf(); const surfaceVectorField& Cf = mesh_.Cf();
const surfaceVectorField& Sf = mesh_.Sf(); const surfaceVectorField& Sf = mesh_.Sf();
const vector& origin = origin_.value(); const vector& origin = origin_.value();
const vector& Omega = Omega_.value(); const vector& Omega = Omega_.value();
// Use either zone faces or outsideFaces_ // Internal faces
const labelList& faces = forAll(internalFaces_, i)
(
faceZoneID_ == -2
? outsideFaces_
: mesh_.faceZones()[faceZoneID_]
);
forAll(faces, i)
{ {
label facei = faces[i]; label facei = internalFaces_[i];
phi[facei] -= (Omega ^ (Cf[facei] - origin)) & Sf[facei];
}
if (facei < mesh_.nInternalFaces()) // Included patches
forAll(includedFaces_, patchi)
{
forAll(includedFaces_[patchi], i)
{ {
phi[facei] -= (Omega ^ (Cf[facei] - origin)) & Sf[facei]; label patchFacei = includedFaces_[patchi][i];
phi.boundaryField()[patchi][patchFacei] = 0.0;
} }
else }
// Excluded patches
forAll(excludedFaces_, patchi)
{
forAll(excludedFaces_[patchi], i)
{ {
label patchi = mesh_.boundaryMesh().whichPatch(facei); label patchFacei = excludedFaces_[patchi][i];
label patchFacei = mesh_.boundaryMesh()[patchi].whichFace(facei);
phi.boundaryField()[patchi][patchFacei] -= phi.boundaryField()[patchi][patchFacei] -=
(Omega ^ (Cf.boundaryField()[patchi][patchFacei] - origin)) (Omega ^ (Cf.boundaryField()[patchi][patchFacei] - origin))
& Sf.boundaryField()[patchi][patchFacei]; & Sf.boundaryField()[patchi][patchFacei];
} }
} }
forAll(patchLabels_, i)
{
phi.boundaryField()[patchLabels_[i]] = 0.0;
}
} }
@ -224,10 +415,21 @@ void Foam::MRFZone::correctBoundaryVelocity(volVectorField& U) const
const vector& origin = origin_.value(); const vector& origin = origin_.value();
const vector& Omega = Omega_.value(); const vector& Omega = Omega_.value();
forAll(patchLabels_, i) // Included patches
forAll(includedFaces_, patchi)
{ {
U.boundaryField()[patchLabels_[i]] == const vectorField& patchC = mesh_.Cf().boundaryField()[patchi];
(Omega ^ (mesh_.Cf().boundaryField()[patchLabels_[i]] - origin));
vectorField pfld(U.boundaryField()[patchi]);
forAll(includedFaces_[patchi], i)
{
label patchFacei = includedFaces_[patchi][i];
pfld[patchFacei] = (Omega ^ (patchC[patchFacei] - origin));
}
U.boundaryField()[patchi] == pfld;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -75,16 +75,24 @@ class MRFZone
label cellZoneID_; label cellZoneID_;
//- label of face zone with faces on outside of cell zone. //- label of face zone with faces on outside of cell zone.
// If -2 determines outside faces itself
label faceZoneID_; label faceZoneID_;
//- outside faces (only if faceZoneID = -2) //- Do patches move with frame (true) or are explicitly provided (false,
labelList outsideFaces_; // old behaviour)
Switch allPatchesMove_;
const wordList patchNames_; const wordList patchNames_;
labelList patchLabels_; labelList patchLabels_;
//- Internal faces that are part of MRF
labelList internalFaces_;
//- Outside faces (per patch) that move with the MRF
labelListList includedFaces_;
//- Excluded faces (per patch) that do not move with the MRF
labelListList excludedFaces_;
const dimensionedVector origin_; const dimensionedVector origin_;
dimensionedVector axis_; dimensionedVector axis_;
const dimensionedScalar omega_; const dimensionedScalar omega_;
@ -93,6 +101,17 @@ class MRFZone
// Private Member Functions // Private Member Functions
//- Divide faces in frame according to patch
void setMRFFaces
(
labelList& faceType,
const labelList& excludedPatchIDs
);
//- Divide faces in frame according to patch
void setMRFFaces();
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
MRFZone(const MRFZone&); MRFZone(const MRFZone&);
@ -136,6 +155,13 @@ public:
// Member Functions // Member Functions
//- Update the mesh corresponding to given map
void updateMesh(const mapPolyMesh& mpm)
{
// Only updates face addressing
setMRFFaces();
}
//- Add the Coriolis force contribution to the momentum equation //- Add the Coriolis force contribution to the momentum equation
void addCoriolis(fvVectorMatrix& UEqn) const; void addCoriolis(fvVectorMatrix& UEqn) const;

View File

@ -31,6 +31,7 @@ License
#include "slicedVolFields.H" #include "slicedVolFields.H"
#include "slicedSurfaceFields.H" #include "slicedSurfaceFields.H"
#include "SubField.H" #include "SubField.H"
#include "cyclicFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -146,6 +147,27 @@ void fvMesh::makeC() const
cellCentres(), cellCentres(),
faceCentres() faceCentres()
); );
// Need to correct for cyclics transformation since absolute quantity.
// Ok on processor patches since hold opposite cell centre (no
// transformation)
slicedVolVectorField& C = *CPtr_;
forAll(C.boundaryField(), patchi)
{
if (isA<cyclicFvPatchVectorField>(C.boundaryField()[patchi]))
{
// Note: cyclic is not slice but proper field
C.boundaryField()[patchi] == static_cast<const vectorField&>
(
static_cast<const List<vector>&>
(
boundary_[patchi].patchSlice(faceCentres())
)
);
}
}
} }

View File

@ -19,7 +19,9 @@ FoamFile
( (
rotor rotor
{ {
patches (rotor); // Fixed patches (by default they 'move' with the MRF zone)
nonRotatingPatches ();
origin origin [0 1 0 0 0 0 0] (0 0 0); origin origin [0 1 0 0 0 0 0] (0 0 0);
axis axis [0 0 0 0 0 0 0] (0 0 1); axis axis [0 0 0 0 0 0 0] (0 0 1);
omega omega [0 0 -1 0 0 0 0] 104.72; omega omega [0 0 -1 0 0 0 0] 104.72;