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-2021 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 = 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().timeName(),
94  mesh,
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 
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 ) 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 // ************************************************************************* //
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
virtual bool writeData(Ostream &os) const
Write.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool read()
Read object.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(rho0+psi *p, rhoMin);# 1 "/home/ubuntu/OpenFOAM-10/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=max(min((rho - rholSat)/(rhovSat - rholSat), scalar(1)), scalar(0));alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:68
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
fvMesh & mesh
label fieldIndex(const label index) const
Return label index.
Definition: porosityModel.C:66
void adjustNegativeResistance(dimensionedVector &resist)
Adjust negative resistance values to be multiplier of max value.
Definition: porosityModel.C:40
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:1060
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
A class for handling words, derived from string.
Definition: word.H:59
const Type & value() const
Return const reference to value.
static const word null
An empty word.
Definition: word.H:77
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void transformModelData()
Transform the model data wrt mesh changes.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
virtual ~porosityModel()
Destructor.
static autoPtr< coordinateSystem > New(const objectRegistry &obr, const dictionary &dict)
Select constructed from dictionary and objectRegistry.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
void correctBoundaryConditions()
Correct boundary field.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
messageStream Info
Field< vector > vectorField
Specialisation of Field<T> for vector.
A class for managing temporary objects.
Definition: PtrList.H:53
virtual void addResistance(fvVectorMatrix &UEqn)
Add resistance.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Top level model for porosity models.
Definition: porosityModel.H:54
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864