porosityModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2022 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 {
35 }
36 
37 
38 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
39 
41 {
42  scalar maxCmpt = cmptMax(resist.value());
43 
44  if (maxCmpt < 0)
45  {
47  << "Cannot have all resistances set to negative, resistance = "
48  << resist
49  << exit(FatalError);
50  }
51  else
52  {
53  maxCmpt = max(0, maxCmpt);
54  vector& val = resist.value();
55  for (label cmpt = 0; cmpt < vector::nComponents; cmpt++)
56  {
57  if (val[cmpt] < 0)
58  {
59  val[cmpt] *= -maxCmpt;
60  }
61  }
62  }
63 }
64 
65 
67 {
68  label index = 0;
69  if (!coordSys_.R().uniform())
70  {
71  index = i;
72  }
73  return index;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 Foam::porosityModel::porosityModel
80 (
81  const word& name,
82  const word& modelType,
83  const fvMesh& mesh,
84  const dictionary& dict,
85  const word& cellZoneName
86 )
87 :
89  (
90  IOobject
91  (
92  name,
93  mesh.time().name(),
94  mesh,
95  IOobject::NO_READ,
96  IOobject::NO_WRITE
97  )
98  ),
99  name_(name),
100  mesh_(mesh),
101  dict_(dict),
102  coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
103  zoneName_(cellZoneName),
104  cellZoneIDs_(),
105  coordSys_(coordinateSystem::New(mesh, coeffs_))
106 {
107  if (zoneName_ == word::null)
108  {
109  dict_.lookup("cellZone") >> zoneName_;
110  }
111 
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 ) const
154 {
155  const_cast<porosityModel&>(*this).transformModelData();
156 
157  tmp<vectorField> tforce(new vectorField(U.size(), Zero));
158 
159  if (!cellZoneIDs_.empty())
160  {
161  this->calcForce(U, rho, mu, tforce.ref());
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 (
182  const fvVectorMatrix& UEqn,
183  volTensorField& AU,
184  bool correctAUprocBC
185 )
186 {
187  if (cellZoneIDs_.empty())
188  {
189  return;
190  }
191 
192  transformModelData();
193  this->correct(UEqn, AU);
194 
195  if (correctAUprocBC)
196  {
197  // Correct the boundary conditions of the tensorial diagonal to ensure
198  // processor boundaries are correctly handled when AU^-1 is interpolated
199  // for the pressure equation.
201  }
202 }
203 
204 
206 {
207  return true;
208 }
209 
210 
212 {
213  coeffs_ = dict.optionalSubDict(type() + "Coeffs");
214 
215  dict.lookup("cellZone") >> zoneName_;
216  cellZoneIDs_ = mesh_.cellZones().findIndices(zoneName_);
217 
218  return true;
219 }
220 
221 
222 // ************************************************************************* //
Generic GeometricField class.
void correctBoundaryConditions()
Correct boundary field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
labelList findIndices(const wordRe &) const
Return zone indices for all matches.
Definition: MeshZones.C:273
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
Base class for other coordinate system specifications.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:860
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:1076
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:451
Top level model for porosity models.
Definition: porosityModel.H:57
virtual void addResistance(fvVectorMatrix &UEqn)
Add resistance.
const fvMesh & mesh_
Reference to the mesh database.
Definition: porosityModel.H:75
virtual ~porosityModel()
Destructor.
virtual bool writeData(Ostream &os) const
Write.
virtual void transformModelData()
Transform the model data wrt mesh changes.
const dictionary dict_
Dictionary used for model construction.
Definition: porosityModel.H:78
wordRe zoneName_
Name(s) of cell-zone.
Definition: porosityModel.H:84
void adjustNegativeResistance(dimensionedVector &resist)
Adjust negative resistance values to be multiplier of max value.
Definition: porosityModel.C:40
labelList cellZoneIDs_
Cell zone IDs.
Definition: porosityModel.H:87
virtual bool read()
Inherit read from regIOobject.
label fieldIndex(const label index) const
Return label index.
Definition: porosityModel.C:66
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
fvVectorMatrix & UEqn
Definition: UEqn.H:11
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
U
Definition: pEqn.H:72
void correct(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiCorr, const SpType &Sp, const SuType &Su)
const dimensionedScalar mu
Atomic mass unit.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict