Commit 6a03ebdd authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: support keyType for porousZones

- allows a regex to collect several cellZones.
  For example,
  (
      "cat1?(Back|Front)*"
      {
          coordinateSystem    system_10;
          porosity    0.781;
          ...
      }
  )
parent 48696bdb
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,6 +27,7 @@ License
#include "fvMesh.H"
#include "fvMatrices.H"
#include "geometricOneField.H"
#include "stringListOps.H"
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
......@@ -62,15 +63,15 @@ void Foam::porousZone::adjustNegativeResistance(dimensionedVector& resist)
Foam::porousZone::porousZone
(
const word& name,
const keyType& key,
const fvMesh& mesh,
const dictionary& dict
)
:
name_(name),
key_(key),
mesh_(mesh),
dict_(dict),
cellZoneID_(mesh_.cellZones().findZoneID(name)),
cellZoneIds_(0),
coordSys_(dict, mesh),
porosity_(1),
intensity_(0),
......@@ -80,9 +81,27 @@ Foam::porousZone::porousZone
D_("D", dimensionSet(0, -2, 0, 0, 0), tensor::zero),
F_("F", dimensionSet(0, -1, 0, 0, 0), tensor::zero)
{
Info<< "Creating porous zone: " << name_ << endl;
Info<< "Creating porous zone: " << key_ << endl;
bool foundZone = (cellZoneID_ != -1);
if (key_.isPattern())
{
cellZoneIds_ = findStrings
(
key_,
mesh_.cellZones().names()
);
}
else
{
const label zoneId = mesh_.cellZones().findZoneID(key_);
if (zoneId != -1)
{
cellZoneIds_.setSize(1);
cellZoneIds_[0] = zoneId;
}
}
bool foundZone = !cellZoneIds_.empty();
reduce(foundZone, orOp<bool>());
if (!foundZone && Pstream::master())
......@@ -90,8 +109,8 @@ Foam::porousZone::porousZone
FatalErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)"
) << "cannot find porous cellZone " << name_
"(const keyType&, const fvMesh&, const dictionary&)"
) << "cannot find porous cellZone " << key_
<< exit(FatalError);
}
......@@ -106,7 +125,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
)
<< "out-of-range porosity value " << porosity_
......@@ -123,7 +142,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
)
<< "out-of-range turbulent intensity value " << intensity_
......@@ -140,7 +159,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
)
<< "out-of-range turbulent length scale " << mixingLength_
......@@ -169,7 +188,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
) << "incorrect dimensions for d: " << d.dimensions()
<< " should be " << D_.dimensions()
......@@ -192,7 +211,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
) << "incorrect dimensions for f: " << f.dimensions()
<< " should be " << F_.dimensions()
......@@ -220,7 +239,7 @@ Foam::porousZone::porousZone
FatalIOErrorIn
(
"Foam::porousZone::porousZone"
"(const fvMesh&, const word&, const dictionary&)",
"(const keyType&, const fvMesh&, const dictionary&)",
dict_
) << "neither powerLaw (C0/C1) "
"nor Darcy-Forchheimer law (d/f) specified"
......@@ -239,7 +258,7 @@ Foam::porousZone::porousZone
void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
{
if (cellZoneID_ == -1)
if (cellZoneIds_.empty())
{
return;
}
......@@ -250,7 +269,6 @@ void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
compressible = true;
}
const labelList& cells = mesh_.cellZones()[cellZoneID_];
const scalarField& V = mesh_.V();
scalarField& Udiag = UEqn.diag();
vectorField& Usource = UEqn.source();
......@@ -263,7 +281,6 @@ void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
addPowerLawResistance
(
Udiag,
cells,
V,
mesh_.lookupObject<volScalarField>("rho"),
U
......@@ -274,7 +291,6 @@ void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
addPowerLawResistance
(
Udiag,
cells,
V,
geometricOneField(),
U
......@@ -293,7 +309,6 @@ void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
(
Udiag,
Usource,
cells,
V,
mesh_.lookupObject<volScalarField>("rho"),
mesh_.lookupObject<volScalarField>("mu"),
......@@ -306,7 +321,6 @@ void Foam::porousZone::addResistance(fvVectorMatrix& UEqn) const
(
Udiag,
Usource,
cells,
V,
geometricOneField(),
mesh_.lookupObject<volScalarField>("nu"),
......@@ -324,7 +338,7 @@ void Foam::porousZone::addResistance
bool correctAUprocBC
) const
{
if (cellZoneID_ == -1)
if (cellZoneIds_.empty())
{
return;
}
......@@ -335,7 +349,6 @@ void Foam::porousZone::addResistance
compressible = true;
}
const labelList& cells = mesh_.cellZones()[cellZoneID_];
const vectorField& U = UEqn.psi();
if (C0_ > VSMALL)
......@@ -345,7 +358,6 @@ void Foam::porousZone::addResistance
addPowerLawResistance
(
AU,
cells,
mesh_.lookupObject<volScalarField>("rho"),
U
);
......@@ -355,7 +367,6 @@ void Foam::porousZone::addResistance
addPowerLawResistance
(
AU,
cells,
geometricOneField(),
U
);
......@@ -372,7 +383,6 @@ void Foam::porousZone::addResistance
addViscousInertialResistance
(
AU,
cells,
mesh_.lookupObject<volScalarField>("rho"),
mesh_.lookupObject<volScalarField>("mu"),
U
......@@ -383,7 +393,6 @@ void Foam::porousZone::addResistance
addViscousInertialResistance
(
AU,
cells,
geometricOneField(),
mesh_.lookupObject<volScalarField>("nu"),
U
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -110,8 +110,8 @@ class porousZone
{
// Private data
//- Name of this zone
word name_;
//- Name of this zone, or a regular expression
keyType key_;
//- Reference to the finite volume mesh this zone is part of
const fvMesh& mesh_;
......@@ -119,8 +119,8 @@ class porousZone
//- Dictionary containing the parameters
dictionary dict_;
//- Cell zone ID
label cellZoneID_;
//- Cell zone Ids
labelList cellZoneIds_;
//- Coordinate system used for the zone (Cartesian)
coordinateSystem coordSys_;
......@@ -159,7 +159,6 @@ class porousZone
void addPowerLawResistance
(
scalarField& Udiag,
const labelList& cells,
const scalarField& V,
const RhoFieldType& rho,
const vectorField& U
......@@ -171,7 +170,6 @@ class porousZone
(
scalarField& Udiag,
vectorField& Usource,
const labelList& cells,
const scalarField& V,
const RhoFieldType& rho,
const scalarField& mu,
......@@ -184,7 +182,6 @@ class porousZone
void addPowerLawResistance
(
tensorField& AU,
const labelList& cells,
const RhoFieldType& rho,
const vectorField& U
) const;
......@@ -194,7 +191,6 @@ class porousZone
void addViscousInertialResistance
(
tensorField& AU,
const labelList& cells,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
......@@ -213,7 +209,7 @@ public:
// Constructors
//- Construct from components
porousZone(const word& name, const fvMesh&, const dictionary&);
porousZone(const keyType& key, const fvMesh&, const dictionary&);
//- Return clone
autoPtr<porousZone> clone() const
......@@ -237,10 +233,10 @@ public:
autoPtr<porousZone> operator()(Istream& is) const
{
word name(is);
keyType key(is);
dictionary dict(is);
return autoPtr<porousZone>(new porousZone(name, mesh_, dict));
return autoPtr<porousZone>(new porousZone(key, mesh_, dict));
}
};
......@@ -255,9 +251,9 @@ public:
// Access
//- cellZone name
const word& zoneName() const
const keyType& zoneName() const
{
return name_;
return key_;
}
//- Return mesh
......@@ -266,10 +262,10 @@ public:
return mesh_;
}
//- cellZone number
label zoneId() const
//- cellZone numbers
const labelList& zoneIds() const
{
return cellZoneID_;
return cellZoneIds_;
}
//- dictionary values used for the porousZone
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -33,12 +33,15 @@ void Foam::porousZone::modifyDdt(fvMatrix<Type>& m) const
{
if (porosity_ < 1)
{
const labelList& cells = mesh_.cellZones()[cellZoneID_];
forAll(cells, i)
forAll(cellZoneIds_, zoneI)
{
m.diag()[cells[i]] *= porosity_;
m.source()[cells[i]] *= porosity_;
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
m.diag()[cells[i]] *= porosity_;
m.source()[cells[i]] *= porosity_;
}
}
}
}
......@@ -48,7 +51,6 @@ template<class RhoFieldType>
void Foam::porousZone::addPowerLawResistance
(
scalarField& Udiag,
const labelList& cells,
const scalarField& V,
const RhoFieldType& rho,
const vectorField& U
......@@ -57,10 +59,15 @@ void Foam::porousZone::addPowerLawResistance
const scalar C0 = C0_;
const scalar C1m1b2 = (C1_ - 1.0)/2.0;
forAll(cells, i)
forAll(cellZoneIds_, zoneI)
{
Udiag[cells[i]] +=
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
Udiag[cells[i]] +=
V[cells[i]]*rho[cells[i]]*C0*pow(magSqr(U[cells[i]]), C1m1b2);
}
}
}
......@@ -70,7 +77,6 @@ void Foam::porousZone::addViscousInertialResistance
(
scalarField& Udiag,
vectorField& Usource,
const labelList& cells,
const scalarField& V,
const RhoFieldType& rho,
const scalarField& mu,
......@@ -80,14 +86,21 @@ void Foam::porousZone::addViscousInertialResistance
const tensor& D = D_.value();
const tensor& F = F_.value();
forAll(cells, i)
forAll(cellZoneIds_, zoneI)
{
tensor dragCoeff = mu[cells[i]]*D + (rho[cells[i]]*mag(U[cells[i]]))*F;
scalar isoDragCoeff = tr(dragCoeff);
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
const tensor dragCoeff = mu[cells[i]]*D
+ (rho[cells[i]]*mag(U[cells[i]]))*F;
Udiag[cells[i]] += V[cells[i]]*isoDragCoeff;
Usource[cells[i]] -=
V[cells[i]]*((dragCoeff - I*isoDragCoeff) & U[cells[i]]);
const scalar isoDragCoeff = tr(dragCoeff);
Udiag[cells[i]] += V[cells[i]]*isoDragCoeff;
Usource[cells[i]] -=
V[cells[i]]*((dragCoeff - I*isoDragCoeff) & U[cells[i]]);
}
}
}
......@@ -96,7 +109,6 @@ template<class RhoFieldType>
void Foam::porousZone::addPowerLawResistance
(
tensorField& AU,
const labelList& cells,
const RhoFieldType& rho,
const vectorField& U
) const
......@@ -104,10 +116,15 @@ void Foam::porousZone::addPowerLawResistance
const scalar C0 = C0_;
const scalar C1m1b2 = (C1_ - 1.0)/2.0;
forAll(cells, i)
forAll(cellZoneIds_, zoneI)
{
AU[cells[i]] = AU[cells[i]]
+ I*(rho[cells[i]]*C0*pow(magSqr(U[cells[i]]), C1m1b2));
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
AU[cells[i]] = AU[cells[i]]
+ I*(rho[cells[i]]*C0*pow(magSqr(U[cells[i]]), C1m1b2));
}
}
}
......@@ -116,7 +133,6 @@ template<class RhoFieldType>
void Foam::porousZone::addViscousInertialResistance
(
tensorField& AU,
const labelList& cells,
const RhoFieldType& rho,
const scalarField& mu,
const vectorField& U
......@@ -125,9 +141,14 @@ void Foam::porousZone::addViscousInertialResistance
const tensor& D = D_.value();
const tensor& F = F_.value();
forAll(cells, i)
forAll(cellZoneIds_, zoneI)
{
AU[cells[i]] += mu[cells[i]]*D + (rho[cells[i]]*mag(U[cells[i]]))*F;
const labelList& cells = mesh_.cellZones()[cellZoneIds_[zoneI]];
forAll(cells, i)
{
AU[cells[i]] += mu[cells[i]]*D + (rho[cells[i]]*mag(U[cells[i]]))*F;
}
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -32,12 +32,12 @@ License
Foam::thermalPorousZone::thermalPorousZone
(
const word& name,
const keyType& key,
const fvMesh& mesh,
const dictionary& dict
)
:
porousZone(name, mesh, dict),
porousZone(key, mesh, dict),
T_("T", dimTemperature, -GREAT)
{
if (const dictionary* dictPtr = dict.subDictPtr("thermalModel"))
......@@ -53,11 +53,7 @@ Foam::thermalPorousZone::thermalPorousZone
FatalIOErrorIn
(
"thermalPorousZone::thermalPorousZone"
"("
"const word& name, "
"const fvMesh& mesh, "
"const dictionary& dict"
")",
"(const keyType&, const fvMesh&, const dictionary&)",
*dictPtr
) << "thermalModel " << thermalModel << " is not supported" << nl
<< " Supported thermalModels are: fixedTemperature"
......@@ -76,23 +72,28 @@ void Foam::thermalPorousZone::addEnthalpySource
fvScalarMatrix& hEqn
) const
{
if (zoneId() == -1 || T_.value() < 0.0)
const labelList& zones = this->zoneIds();
if (zones.empty() || T_.value() < 0.0)
{
return;
}
const labelList& cells = mesh().cellZones()[zoneId()];
const scalarField& V = mesh().V();
scalarField& hDiag = hEqn.diag();
scalarField& hSource = hEqn.source();
scalarField hZone = thermo.h(scalarField(cells.size(), T_.value()), cells);
scalar rate = 1e6;
// TODO: generalize for non-fixedTemperature methods
const scalar rate = 1e6;
forAll(cells, i)
forAll(zones, zoneI)
{
hDiag[cells[i]] += rate*V[cells[i]]*rho[cells[i]];
hSource[cells[i]] += rate*V[cells[i]]*rho[cells[i]]*hZone[i];
const labelList& cells = mesh().cellZones()[zones[zoneI]];
forAll(cells, i)
{
hDiag[cells[i]] += rate*V[cells[i]]*rho[cells[i]];
hSource[cells[i]] += rate*V[cells[i]]*rho[cells[i]]*T_.value();
}
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -33,7 +33,6 @@ See Also
SourceFiles
thermalPorousZone.C
thermalPorousZoneTemplates.C
\*---------------------------------------------------------------------------*/
......@@ -76,7 +75,7 @@ public:
// Constructors
//- Construct from components
thermalPorousZone(const word& name, const fvMesh&, const dictionary&);
thermalPorousZone(const keyType& key, const fvMesh&, const dictionary&);
//- Return clone
autoPtr<thermalPorousZone> clone() const
......@@ -101,12 +100,12 @@ public:
autoPtr<thermalPorousZone> operator()(Istream& is) const
{
word name(is);
keyType key(is);
dictionary dict(is);
return autoPtr<thermalPorousZone>
(
new thermalPorousZone(name, mesh_, dict)
new thermalPorousZone(key, mesh_, dict)
);
}
};
......@@ -149,12 +148,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
//# include "thermalPorousZoneTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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.