porosityModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "porosityModel.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(porosityModel, 0);
34  defineRunTimeSelectionTable(porosityModel, mesh);
35 }
36 
37 
38 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
39 
41 {
42  scalar maxCmpt = max(0, cmptMax(resist.value()));
43 
44  if (maxCmpt < 0)
45  {
47  << "Negative resistances are invalid, resistance = " << resist
48  << exit(FatalError);
49  }
50  else
51  {
52  vector& val = resist.value();
53  for (label cmpt = 0; cmpt < vector::nComponents; cmpt++)
54  {
55  if (val[cmpt] < 0)
56  {
57  val[cmpt] *= -maxCmpt;
58  }
59  }
60  }
61 }
62 
63 
65 {
66  label index = 0;
67  if (!coordSys_.R().uniform())
68  {
69  index = i;
70  }
71  return index;
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76 
78 (
79  const word& name,
80  const word& modelType,
81  const fvMesh& mesh,
82  const dictionary& dict,
83  const word& cellZoneName
84 )
85 :
87  (
88  IOobject
89  (
90  name,
91  mesh.time().timeName(),
92  mesh,
95  )
96  ),
97  name_(name),
98  mesh_(mesh),
99  dict_(dict),
100  coeffs_(dict.subDict(modelType + "Coeffs")),
101  active_(true),
102  zoneName_(cellZoneName),
103  cellZoneIDs_(),
104  coordSys_(coordinateSystem::New(mesh, coeffs_))
105 {
106  if (zoneName_ == word::null)
107  {
108  dict.lookup("active") >> active_;
109  dict_.lookup("cellZone") >> zoneName_;
110  }
111 
112  cellZoneIDs_ = mesh_.cellZones().findIndices(zoneName_);
113 
114  Info<< " creating porous zone: " << zoneName_ << endl;
115 
116  bool foundZone = !cellZoneIDs_.empty();
117  reduce(foundZone, orOp<bool>());
118 
119  if (!foundZone && Pstream::master())
120  {
122  << "cannot find porous cellZone " << zoneName_
123  << exit(FatalError);
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129 
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
137 {
138  if (!mesh_.upToDatePoints(*this))
139  {
140  calcTransformModelData();
141 
142  // set model up-to-date wrt points
143  mesh_.setUpToDatePoints(*this);
144  }
145 }
146 
147 
148 Foam::tmp<Foam::vectorField> Foam::porosityModel::porosityModel::force
149 (
150  const volVectorField& U,
151  const volScalarField& rho,
152  const volScalarField& mu
153 )
154 {
155  transformModelData();
156 
157  tmp<vectorField> tforce(new vectorField(U.size(), vector::zero));
158 
159  if (!cellZoneIDs_.empty())
160  {
161  this->calcForce(U, rho, mu, tforce());
162  }
163 
164  return tforce;
165 }
166 
167 
169 {
170  if (cellZoneIDs_.empty())
171  {
172  return;
173  }
174 
175  transformModelData();
176  this->correct(UEqn);
177 }
178 
179 
181 (
183  const volScalarField& rho,
184  const volScalarField& mu
185 )
186 {
187  if (cellZoneIDs_.empty())
188  {
189  return;
190  }
191 
192  transformModelData();
193  this->correct(UEqn, rho, mu);
194 }
195 
196 
198 (
199  const fvVectorMatrix& UEqn,
200  volTensorField& AU,
201  bool correctAUprocBC
202 )
203 {
204  if (cellZoneIDs_.empty())
205  {
206  return;
207  }
208 
209  transformModelData();
210  this->correct(UEqn, AU);
211 
212  if (correctAUprocBC)
213  {
214  // Correct the boundary conditions of the tensorial diagonal to ensure
215  // processor boundaries are correctly handled when AU^-1 is interpolated
216  // for the pressure equation.
218  }
219 }
220 
221 
223 {
224  return true;
225 }
226 
227 
229 {
230  active_ = readBool(dict.lookup("active"));
231  coeffs_ = dict.subDict(type() + "Coeffs");
232  dict.lookup("cellZone") >> zoneName_;
233  cellZoneIDs_ = mesh_.cellZones().findIndices(zoneName_);
234 
235  return true;
236 }
237 
238 
239 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::porosityModel::~porosityModel
virtual ~porosityModel()
Destructor.
Definition: porosityModel.C:130
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::constant::physicoChemical::mu
const dimensionedScalar mu
Atomic mass unit.
Definition: createFields.H:13
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:171
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
porosityModel.H
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
U
U
Definition: pEqn.H:46
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:49
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:224
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::porosityModel::transformModelData
virtual void transformModelData()
Transform the model data wrt mesh changes.
Definition: porosityModel.C:136
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::orOp
Definition: ops.H:178
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::Info
messageStream Info
correct
fvOptions correct(rho)
UEqn
tmp< fvVectorMatrix > UEqn(fvm::div(phi, U)+MRF.DDt(U)+turbulence->divDevReff(U)==fvOptions(U))
Foam::porosityModel::adjustNegativeResistance
void adjustNegativeResistance(dimensionedVector &resist)
Adjust negative resistance values to be multiplier of max value.
Definition: porosityModel.C:40
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:885
rho
rho
Definition: pEqn.H:3
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::porosityModel::writeData
virtual bool writeData(Ostream &os) const
Write.
Definition: porosityModel.C:222
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Vector< scalar >
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::porosityModel::fieldIndex
label fieldIndex(const label index) const
Return label index.
Definition: porosityModel.C:64
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::porosityModel::porosityModel
porosityModel(const porosityModel &)
Disallow default bitwise copy construct.
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::porosityModel::addResistance
virtual void addResistance(fvVectorMatrix &UEqn)
Add resistance.
Definition: porosityModel.C:168
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(const objectRegistry &obr, const dictionary &dict)
Select constructed from dictionary and objectRegistry.
Definition: coordinateSystemNew.C:32
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47