Commit 1b421e65 authored by andy's avatar andy
Browse files

ENH: Added new refactored porosity models functionality

parent 6e3ff884
......@@ -365,8 +365,12 @@ $(solutionControl)/simpleControl/simpleControl.C
$(solutionControl)/pimpleControl/pimpleControl.C
porousMedia = $(general)/porousMedia
$(porousMedia)/porousZone.C
$(porousMedia)/porousZones.C
$(porousMedia)/porosityModel/porosityModel/porosityModel.C
$(porousMedia)/porosityModel/porosityModel/porosityModelNew.C
$(porousMedia)/porosityModel/porosityModel/porosityModelList.C
$(porousMedia)/porosityModel/porosityModel/IOporosityModelList.C
$(porousMedia)/porosityModel/DarcyForchheimer/DarcyForchheimer.C
$(porousMedia)/porosityModel/powerLaw/powerLaw.C
MRF = $(general)/MRF
$(MRF)/MRFZone.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 "addToRunTimeSelectionTable.H"
#include "DarcyForchheimer.H"
#include "geometricOneField.H"
#include "fvMatrices.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace porosityModels
{
defineTypeNameAndDebug(DarcyForchheimer, 0);
addToRunTimeSelectionTable(porosityModel, DarcyForchheimer, mesh);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::porosityModels::DarcyForchheimer::DarcyForchheimer
(
const word& name,
const word& modelType,
const fvMesh& mesh,
const dictionary& dict
)
:
porosityModel(name, modelType, mesh, dict),
coordSys_(coeffs_, mesh),
D_("D", dimless/sqr(dimLength), tensor::zero),
F_("F", dimless/dimLength, tensor::zero),
rhoName_(coeffs_.lookupOrDefault<word>("rho", "rho")),
muName_(coeffs_.lookupOrDefault<word>("mu", "mu")),
nuName_(coeffs_.lookupOrDefault<word>("nu", "nu"))
{
// local-to-global transformation tensor
const tensor& E = coordSys_.R();
dimensionedVector d(coeffs_.lookup("d"));
if (D_.dimensions() != d.dimensions())
{
FatalIOErrorIn
(
"Foam::porosityModels::DarcyForchheimer::DarcyForchheimer"
"("
"const dictionary&, "
"const coordinateSystem&, "
"const keyType&"
")",
coeffs_
) << "incorrect dimensions for d: " << d.dimensions()
<< " should be " << D_.dimensions()
<< exit(FatalIOError);
}
adjustNegativeResistance(d);
D_.value().xx() = d.value().x();
D_.value().yy() = d.value().y();
D_.value().zz() = d.value().z();
D_.value() = (E & D_ & E.T()).value();
dimensionedVector f(coeffs_.lookup("f"));
if (F_.dimensions() != f.dimensions())
{
FatalIOErrorIn
(
"Foam::porosityModels::DarcyForchheimer::DarcyForchheimer"
"("
"const dictionary&, "
"const coordinateSystem&, "
"const keyType&"
")",
coeffs_
) << "incorrect dimensions for f: " << f.dimensions()
<< " should be " << F_.dimensions()
<< exit(FatalIOError);
}
adjustNegativeResistance(f);
// leading 0.5 is from 1/2*rho
F_.value().xx() = 0.5*f.value().x();
F_.value().yy() = 0.5*f.value().y();
F_.value().zz() = 0.5*f.value().z();
F_.value() = (E & F_ & E.T()).value();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::porosityModels::DarcyForchheimer::~DarcyForchheimer()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::porosityModels::DarcyForchheimer::correct
(
fvVectorMatrix& UEqn
) const
{
const vectorField& U = UEqn.psi();
const scalarField& V = mesh_.V();
scalarField& Udiag = UEqn.diag();
vectorField& Usource = UEqn.source();
if (UEqn.dimensions() == dimForce)
{
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);
const volScalarField& mu =
mesh_.lookupObject<volScalarField>(muName_);
apply(Udiag, Usource, V, rho, mu, U);
}
else
{
const volScalarField& nu =
mesh_.lookupObject<volScalarField>(nuName_);
apply(Udiag, Usource, V, geometricOneField(), nu, U);
}
}
void Foam::porosityModels::DarcyForchheimer::correct
(
fvVectorMatrix& UEqn,
const volScalarField& rho,
const volScalarField& mu
) const
{
const vectorField& U = UEqn.psi();
const scalarField& V = mesh_.V();
scalarField& Udiag = UEqn.diag();
vectorField& Usource = UEqn.source();
apply(Udiag, Usource, V, rho, mu, U);
}
void Foam::porosityModels::DarcyForchheimer::correct
(
const fvVectorMatrix& UEqn,
volTensorField& AU
) const
{
const vectorField& U = UEqn.psi();
if (UEqn.dimensions() == dimForce)
{
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);
const volScalarField& mu =
mesh_.lookupObject<volScalarField>(muName_);
apply(AU, rho, mu, U);
}
else
{
const volScalarField& nu =
mesh_.lookupObject<volScalarField>(nuName_);
apply(AU, geometricOneField(), nu, U);
}
}
void Foam::porosityModels::DarcyForchheimer::writeData(Ostream& os) const
{
os << indent << name_ << endl;
dict_.write(os);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::DarcyForchheimer
Description
Darcy-Forchheimer law porosity model, given by:
\f[
S = - (\mu d + \frac{\rho |U|}{2} f) U
\f]
where
\vartable
d | Darcy coefficient [1/m2]
f | Forchheimer coefficient [1/m]
\endvartable
Since negative Darcy/Forchheimer parameters are invalid, they can be used
to specify a multiplier (of the max component).
The orientation of the porous region is defined with the same notation as
a co-ordinate system, but only a Cartesian co-ordinate system is valid.
SourceFiles
DarcyForchheimer.C
\*---------------------------------------------------------------------------*/
#ifndef DarcyForchheimer_H
#define DarcyForchheimer_H
#include "porosityModel.H"
#include "coordinateSystem.H"
#include "dimensionedTensor.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace porosityModels
{
/*---------------------------------------------------------------------------*\
Class DarcyForchheimer Declaration
\*---------------------------------------------------------------------------*/
class DarcyForchheimer
:
public porosityModel
{
private:
// Private data
//- Local co-ordinate system
coordinateSystem coordSys_;
//- Darcy coefficient [1/m2]
dimensionedTensor D_;
//- Forchheimer coefficient [1/m]
dimensionedTensor F_;
//- Name of density field
word rhoName_;
//- Name of dynamic viscosity field
word muName_;
//- Name of kinematic viscosity field
word nuName_;
// Private Member Functions
//- Apply
template<class RhoFieldType>
void apply
(
scalarField& Udiag,
vectorField& Usource,
const scalarField& V,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
) const;
//- Apply
template<class RhoFieldType>
void apply
(
tensorField& AU,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
) const;
//- Disallow default bitwise copy construct
DarcyForchheimer(const DarcyForchheimer&);
//- Disallow default bitwise assignment
void operator=(const DarcyForchheimer&);
public:
//- Runtime type information
TypeName("DarcyForchheimer");
//- Constructor
DarcyForchheimer
(
const word& name,
const word& modelType,
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~DarcyForchheimer();
// Member Functions
//- Add resistance
virtual void correct(fvVectorMatrix& UEqn) const;
//- Add resistance
virtual void correct
(
fvVectorMatrix& UEqn,
const volScalarField& rho,
const volScalarField& mu
) const;
//- Add resistance
virtual void correct
(
const fvVectorMatrix& UEqn,
volTensorField& AU
) const;
// I-O
//- Write
void writeData(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace porosityModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "DarcyForchheimerTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class RhoFieldType>
void Foam::porosityModels::DarcyForchheimer::apply
(
scalarField& Udiag,
vectorField& Usource,
const scalarField& V,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
) const
{
const tensor& D = D_.value();
const tensor& F = F_.value();
forAll(cellZoneIds_, zoneI)
{
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
const label cellI = cells[i];
const tensor Cd = mu[cellI]*D + (rho[cellI]*mag(U[cellI]))*F;
const scalar isoCd = tr(Cd);
Udiag[cellI] += V[cellI]*isoCd;
Usource[cellI] -= V[cellI]*((Cd - I*isoCd) & U[cellI]);
}
}
}
template<class RhoFieldType>
void Foam::porosityModels::DarcyForchheimer::apply
(
tensorField& AU,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
) const
{
const tensor& D = D_.value();
const tensor& F = F_.value();
forAll(cellZoneIds_, zoneI)
{
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
const label cellI = cells[i];
AU[cellI] += mu[cellI]*D + (rho[cellI]*mag(U[cellI]))*F;
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "IOporosityModelList.H"
#include "fvMesh.H"
#include "Time.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::IOobject Foam::IOporosityModelList::createIOobject
(
const fvMesh& mesh
) const
{
IOobject io
(
"porosityProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (io.headerOk())
{
Info<< "Creating porosity model list from " << io.name() << nl << endl;
io.readOpt() = IOobject::MUST_READ_IF_MODIFIED;
return io;
}
else
{
Info<< "No porosity models present" << nl << endl;
io.readOpt() = IOobject::NO_READ;
return io;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::IOporosityModelList::IOporosityModelList
(
const fvMesh& mesh
)
:
IOdictionary(createIOobject(mesh)),
porosityModelList(mesh, *this)
{}
bool Foam::IOporosityModelList::read()
{
if (regIOobject::read())
{
porosityModelList::read(*this);
return true;
}
else
{
return false;
}
}
// ************************************************************************* //