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-2023 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_
104  (
105  cellZoneName != word::null
106  ? cellZoneName
107  : dict_.lookup<word>("cellZone")
108  ),
109  coordSys_(coordinateSystem::New(mesh, coeffs_))
110 {
111  Info<< " creating porous zone: " << zoneName_ << endl;
112 
113  if (mesh_.cellZones().findIndex(zoneName_) == -1)
114  {
116  << "cannot find porous cellZone " << zoneName_
117  << exit(FatalError);
118  }
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  if (!mesh_.upToDatePoints(*this))
133  {
134  calcTransformModelData();
135 
136  // set model up-to-date wrt points
137  mesh_.setUpToDatePoints(*this);
138  }
139 }
140 
141 
142 Foam::tmp<Foam::vectorField> Foam::porosityModel::porosityModel::force
143 (
144  const volVectorField& U,
145  const volScalarField& rho,
146  const volScalarField& mu
147 ) const
148 {
149  const_cast<porosityModel&>(*this).transformModelData();
150 
151  tmp<vectorField> tforce(new vectorField(U.size(), Zero));
152  this->calcForce(U, rho, mu, tforce.ref());
153 
154  return tforce;
155 }
156 
157 
159 {
160  transformModelData();
161  this->correct(UEqn);
162 }
163 
164 
166 (
167  const fvVectorMatrix& UEqn,
168  volTensorField& AU,
169  bool correctAUprocBC
170 )
171 {
172  transformModelData();
173  this->correct(UEqn, AU);
174 
175  if (correctAUprocBC)
176  {
177  // Correct the boundary conditions of the tensorial diagonal to
178  // ensure processor boundaries are correctly handled when AU^-1 is
179  // interpolated for the pressure equation.
181  }
182 }
183 
184 
186 {
187  return true;
188 }
189 
190 
192 {
193  coeffs_ = dict.optionalSubDict(type() + "Coeffs");
194 
195  dict.lookup("cellZone") >> zoneName_;
196 
197  return true;
198 }
199 
200 
201 // ************************************************************************* //
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
label findIndex(const word &key) const
Return the index of the given the key or -1 if not found.
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:105
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:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:921
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:99
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:452
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.
word zoneName_
Name of cellZone.
Definition: porosityModel.H:84
virtual bool writeData(Ostream &os) const
Write.
virtual void transformModelData()
Transform the model data wrt mesh changes.
void adjustNegativeResistance(dimensionedVector &resist)
Adjust negative resistance values to be multiplier of max value.
Definition: porosityModel.C:40
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
fvVectorMatrix & UEqn
Definition: UEqn.H:11
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
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
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