Commit 41d98c2d authored by andy's avatar andy
Browse files

ENH: Updated MRF functionality

parent afcd601a
......@@ -379,7 +379,8 @@ $(porosity)/fixedCoeff/fixedCoeff.C
MRF = $(general)/MRF
$(MRF)/MRFZone.C
$(MRF)/MRFZones.C
$(MRF)/MRFZoneList.C
$(MRF)/IOMRFZoneList.C
SRF = $(general)/SRF
$(SRF)/SRFModel/SRFModel/SRFModel.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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/>.
\*---------------------------------------------------------------------------*/
#include "IOMRFZoneList.H"
#include "fvMesh.H"
#include "Time.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::IOobject Foam::IOMRFZoneList::createIOobject
(
const fvMesh& mesh
) const
{
IOobject io
(
"MRFProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (io.headerOk())
{
Info<< "Creating MRF zone list from " << io.name() << endl;
io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
return io;
}
else
{
Info<< "No MRF models present" << nl << endl;
io.readOpt() = IOobject::NO_READ;
return io;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IOMRFZoneList::IOMRFZoneList
(
const fvMesh& mesh
)
:
IOdictionary(createIOobject(mesh)),
MRFZoneList(mesh, *this)
{}
bool Foam::IOMRFZoneList::read()
{
if (regIOobject::read())
{
MRFZoneList::read(*this);
return true;
}
else
{
return false;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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::IOMRFZoneList
Description
List of MRF zones with IO functionality
SourceFiles
IOMRFZoneList.C
\*---------------------------------------------------------------------------*/
#ifndef IOMRFZoneList_H
#define IOMRFZoneList_H
#include "IOdictionary.H"
#include "MRFZoneList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class IOMRFZoneList Declaration
\*---------------------------------------------------------------------------*/
class IOMRFZoneList
:
public IOdictionary,
public MRFZoneList
{
private:
// Private Member Functions
//- Create IO object if dictionary is present
IOobject createIOobject(const fvMesh& mesh) const;
//- Disallow default bitwise copy construct
IOMRFZoneList(const IOMRFZoneList&);
//- Disallow default bitwise assignment
void operator=(const IOMRFZoneList&);
public:
// Constructors
//- Construct from mesh
IOMRFZoneList(const fvMesh& mesh);
//- Destructor
virtual ~IOMRFZoneList()
{}
// Member Functions
//- Read dictionary
virtual bool read();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -32,7 +32,6 @@ License
#include "faceSet.H"
#include "geometricOneField.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::MRFZone, 0);
......@@ -144,7 +143,7 @@ void Foam::MRFZone::setMRFFaces()
forAll(pp, patchFacei)
{
label faceI = pp.start()+patchFacei;
label faceI = pp.start() + patchFacei;
if (faceType[faceI] == 1)
{
......@@ -173,7 +172,7 @@ void Foam::MRFZone::setMRFFaces()
forAll(pp, patchFacei)
{
label faceI = pp.start()+patchFacei;
label faceI = pp.start() + patchFacei;
if (faceType[faceI] == 1)
{
......@@ -228,64 +227,71 @@ void Foam::MRFZone::setMRFFaces()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is)
Foam::MRFZone::MRFZone
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
)
:
mesh_(mesh),
name_(is),
dict_(is),
cellZoneID_(mesh_.cellZones().findZoneID(name_)),
name_(name),
coeffs_(dict),
active_(readBool(coeffs_.lookup("active"))),
cellZoneName_(coeffs_.lookup("cellZone")),
cellZoneID_(mesh_.cellZones().findZoneID(cellZoneName_)),
excludedPatchNames_
(
dict_.lookupOrDefault("nonRotatingPatches", wordList(0))
coeffs_.lookupOrDefault("nonRotatingPatches", wordList(0))
),
origin_(dict_.lookup("origin")),
axis_(dict_.lookup("axis")),
omega_(DataEntry<scalar>::New("omega", dict_))
origin_(coeffs_.lookup("origin")),
axis_(coeffs_.lookup("axis")),
omega_(DataEntry<scalar>::New("omega", coeffs_))
{
if (dict_.found("patches"))
if (!active_)
{
WarningIn("MRFZone(const fvMesh&, Istream&)")
<< "Ignoring entry 'patches'\n"
<< " By default all patches within the rotating region rotate.\n"
<< " Optionally supply excluded patches "
<< "using 'nonRotatingPatches'."
<< endl;
cellZoneID_ = -1;
}
else
{
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
axis_ = axis_/mag(axis_);
axis_ = axis_/mag(axis_);
excludedPatchLabels_.setSize(excludedPatchNames_.size());
excludedPatchLabels_.setSize(excludedPatchNames_.size());
forAll(excludedPatchNames_, i)
{
excludedPatchLabels_[i] =
patches.findPatchID(excludedPatchNames_[i]);
forAll(excludedPatchNames_, i)
{
excludedPatchLabels_[i] = patches.findPatchID(excludedPatchNames_[i]);
if (excludedPatchLabels_[i] == -1)
{
FatalErrorIn
(
"MRFZone(const word&, const fvMesh&, const dictionary&)"
)
<< "cannot find MRF patch " << excludedPatchNames_[i]
<< exit(FatalError);
}
}
bool cellZoneFound = (cellZoneID_ != -1);
reduce(cellZoneFound, orOp<bool>());
if (excludedPatchLabels_[i] == -1)
if (!cellZoneFound)
{
FatalErrorIn
(
"Foam::MRFZone::MRFZone(const fvMesh&, Istream&)"
) << "cannot find MRF patch " << excludedPatchNames_[i]
"MRFZone(const word&, const fvMesh&, const dictionary&)"
)
<< "cannot find MRF cellZone " << cellZoneName_
<< 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();
}
setMRFFaces();
}
......@@ -497,24 +503,37 @@ void Foam::MRFZone::correctBoundaryVelocity(volVectorField& U) const
}
Foam::Ostream& Foam::operator<<(Ostream& os, const MRFZone& MRF)
void Foam::MRFZone::writeData(Ostream& os) const
{
os << indent << nl;
os.write(MRF.name_) << nl;
os << nl;
os.write(name_) << nl;
os << token::BEGIN_BLOCK << incrIndent << nl;
os.writeKeyword("origin") << MRF.origin_ << token::END_STATEMENT << nl;
os.writeKeyword("axis") << MRF.axis_ << token::END_STATEMENT << nl;
MRF.omega_->writeData(os);
os.writeKeyword("active") << active_ << token::END_STATEMENT << nl;
os.writeKeyword("cellZone") << cellZoneName_ << token::END_STATEMENT << nl;
os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
os.writeKeyword("axis") << axis_ << token::END_STATEMENT << nl;
omega_->writeData(os);
if (MRF.excludedPatchNames_.size())
if (excludedPatchNames_.size())
{
os.writeKeyword("nonRotatingPatches") << MRF.excludedPatchNames_
os.writeKeyword("nonRotatingPatches") << excludedPatchNames_
<< token::END_STATEMENT << nl;
}
os << decrIndent << token::END_BLOCK << nl;
}
return os;
bool Foam::MRFZone::read(const dictionary& dict)
{
coeffs_ = dict;
active_ = readBool(coeffs_.lookup("active"));
coeffs_.lookup("cellZone") >> cellZoneName_;
cellZoneID_ = mesh_.cellZones().findZoneID(cellZoneName_);
return true;
}
// ************************************************************************* //
......@@ -67,12 +67,22 @@ class MRFZone
{
// Private data
//- Reference to the mesh database
const fvMesh& mesh_;
//- Name of the MRF region model
const word name_;
const dictionary dict_;
//- Coefficients dictionary
dictionary coeffs_;
//- MRF region active flag
bool active_;
//- Name of cell zone
word cellZoneName_;
//- Cell zone ID
label cellZoneID_;
const wordList excludedPatchNames_;
......@@ -133,8 +143,8 @@ public:
// Constructors
//- Construct from fvMesh and Istream
MRFZone(const fvMesh& mesh, Istream& is);
//- Construct from fvMesh
MRFZone(const word& name, const fvMesh& mesh, const dictionary& dict);
//- Return clone
autoPtr<MRFZone> clone() const
......@@ -143,79 +153,73 @@ public:
return autoPtr<MRFZone>(NULL);
}
//- Return a pointer to a new MRFZone created on freestore
// from Istream
class iNew
{
const fvMesh& mesh_;
public:
// Member Functions
iNew(const fvMesh& mesh)
:
mesh_(mesh)
{}
// Access
autoPtr<MRFZone> operator()(Istream& is) const
{
return autoPtr<MRFZone>(new MRFZone(mesh_, is));
}
};
//- Return const access to the porosity model name
inline const word& name() const;
//- Return const access to the porosity active flag
inline bool active() const;
// Member Functions
//- Update the mesh corresponding to given map
void updateMesh(const mapPolyMesh& mpm)
{
// Only updates face addressing
setMRFFaces();
}
// Evaluation
//- Add the Coriolis force contribution to the acceleration field
void addCoriolis(const volVectorField& U, volVectorField& ddtU) const;
//- 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
void addCoriolis(fvVectorMatrix& UEqn) const;
//- Add the Coriolis force contribution to the acceleration field
void addCoriolis(const volVectorField& U, volVectorField& ddtU) const;
//- Add the Coriolis force contribution to the momentum equation
void addCoriolis(const volScalarField& rho, fvVectorMatrix& UEqn) const;
//- Add the Coriolis force contribution to the momentum equation
void addCoriolis(fvVectorMatrix& UEqn) const;
//- Make the given absolute velocity relative within the MRF region
void relativeVelocity(volVectorField& U) const;
//- Add the Coriolis force contribution to the momentum equation
void addCoriolis(const volScalarField& rho, fvVectorMatrix& UEqn) const;
//- Make the given relative velocity absolute within the MRF region
void absoluteVelocity(volVectorField& U) const;
//- Make the given absolute velocity relative within the MRF region
void relativeVelocity(volVectorField& U) const;
//- Make the given absolute flux relative within the MRF region
void relativeFlux(surfaceScalarField& phi) const;
//- Make the given relative velocity absolute within the MRF region
void absoluteVelocity(volVectorField& U) const;
//- Make the given absolute mass-flux relative within the MRF region
void relativeFlux
(
const surfaceScalarField& rho,
surfaceScalarField& phi
) const;
//- Make the given absolute flux relative within the MRF region
void relativeFlux(surfaceScalarField& phi) const;
//- Make the given relative flux absolute within the MRF region
void absoluteFlux(surfaceScalarField& phi) const;
//- Make the given absolute mass-flux relative within the MRF region
void relativeFlux
(
const surfaceScalarField& rho,
surfaceScalarField& phi
) const;
//- Make the given relative mass-flux absolute within the MRF region
void absoluteFlux
(
const surfaceScalarField& rho,
surfaceScalarField& phi
) const;
//- Make the given relative flux absolute within the MRF region
void absoluteFlux(surfaceScalarField& phi) const;
//- Correct the boundary velocity for the roation of the MRF region
void correctBoundaryVelocity(volVectorField& U) const;
//- Make the given relative mass-flux absolute within the MRF region
void absoluteFlux
(
const surfaceScalarField& rho,
surfaceScalarField& phi
) const;
//- Correct the boundary velocity for the roation of the MRF region
void correctBoundaryVelocity(volVectorField& U) const;
// IOstream operator
friend Ostream& operator<<(Ostream& os, const MRFZone& MRF);
// I-O
//- Write
void writeData(Ostream& os) const;
//- Read MRF dictionary
bool read(const dictionary& dict);
};
......@@ -231,6 +235,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "MRFZoneI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 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/>.
\*---------------------------------------------------------------------------*/
inline const Foam::word& Foam::MRFZone::name() const
{
return name_;
}
inline bool Foam::MRFZone::active() const
{
return active_;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -23,59 +23,109 @@ License
\*---------------------------------------------------------------------------*/
#include "MRFZones.H"
#include "Time.H"
#include "fvMesh.H"
#include "MRFZoneList.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //