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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "porosityModel.H"
30 #include "volFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(porosityModel, 0);
37  defineRunTimeSelectionTable(porosityModel, mesh);
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 {
45  scalar maxCmpt = cmptMax(resist.value());
46 
47  if (maxCmpt < 0)
48  {
50  << "Cannot have all resistances set to negative, resistance = "
51  << resist
52  << exit(FatalError);
53  }
54  else
55  {
56  vector& val = resist.value();
57  for (label cmpt = 0; cmpt < vector::nComponents; cmpt++)
58  {
59  if (val[cmpt] < 0)
60  {
61  val[cmpt] *= -maxCmpt;
62  }
63  }
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
70 Foam::porosityModel::porosityModel
71 (
72  const word& name,
73  const word& modelType,
74  const fvMesh& mesh,
75  const dictionary& dict,
76  const word& cellZoneName
77 )
78 :
80  (
81  IOobject
82  (
83  name,
84  mesh.time().timeName(),
85  mesh,
88  )
89  ),
90  name_(name),
91  mesh_(mesh),
92  dict_(dict),
93  coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
94  active_(true),
95  zoneName_(cellZoneName),
96  cellZoneIDs_(),
97  csysPtr_
98  (
99  coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName_())
100  )
101 {
102  if (zoneName_.empty())
103  {
104  dict.readIfPresent("active", active_);
105  dict_.readEntry("cellZone", zoneName_);
106  }
107 
108  cellZoneIDs_ = mesh_.cellZones().indices(zoneName_);
109 
110  Info<< " creating porous zone: " << zoneName_ << endl;
111 
112  bool foundZone = !cellZoneIDs_.empty();
113  reduce(foundZone, orOp<bool>());
114 
115  if (!foundZone && Pstream::master())
116  {
118  << "cannot find porous cellZone " << zoneName_
119  << exit(FatalError);
120  }
121 
122  Info<< incrIndent << indent << csys() << decrIndent << endl;
123 
124  const pointField& points = mesh_.points();
125  const cellList& cells = mesh_.cells();
126  const faceList& faces = mesh_.faces();
127 
128  for (const label zonei : cellZoneIDs_)
129  {
130  const cellZone& cZone = mesh_.cellZones()[zonei];
131 
132  boundBox bb;
133 
134  for (const label celli : cZone)
135  {
136  const cell& c = cells[celli];
137  const pointField cellPoints(c.points(faces, points));
138 
139  for (const point& pt : cellPoints)
140  {
141  bb.add(csys().localPosition(pt));
142  }
143  }
144 
145  bb.reduce();
146 
147  Info<< " local bounds: " << bb.span() << nl << endl;
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 {
156  if (!mesh_.upToDatePoints(*this))
157  {
158  calcTransformModelData();
159 
160  // set model up-to-date wrt points
161  mesh_.setUpToDatePoints(*this);
162  }
163 }
164 
165 
166 Foam::tmp<Foam::vectorField> Foam::porosityModel::porosityModel::force
167 (
168  const volVectorField& U,
169  const volScalarField& rho,
170  const volScalarField& mu
171 )
172 {
173  transformModelData();
174 
175  tmp<vectorField> tforce(new vectorField(U.size(), Zero));
176 
177  if (!cellZoneIDs_.empty())
178  {
179  this->calcForce(U, rho, mu, tforce.ref());
180  }
181 
182  return tforce;
183 }
184 
185 
187 {
188  if (cellZoneIDs_.empty())
189  {
190  return;
191  }
192 
193  transformModelData();
194  this->correct(UEqn);
195 }
196 
197 
199 (
201  const volScalarField& rho,
202  const volScalarField& mu
203 )
204 {
205  if (cellZoneIDs_.empty())
206  {
207  return;
208  }
209 
210  transformModelData();
211  this->correct(UEqn, rho, mu);
212 }
213 
214 
216 (
217  const fvVectorMatrix& UEqn,
218  volTensorField& AU,
219  bool correctAUprocBC
220 )
221 {
222  if (cellZoneIDs_.empty())
223  {
224  return;
225  }
226 
227  transformModelData();
228  this->correct(UEqn, AU);
229 
230  if (correctAUprocBC)
231  {
232  // Correct the boundary conditions of the tensorial diagonal to ensure
233  // processor boundaries are correctly handled when AU^-1 is interpolated
234  // for the pressure equation.
236  }
237 }
238 
239 
241 {
242  return true;
243 }
244 
245 
247 {
248  dict.readIfPresent("active", active_);
249 
250  coeffs_ = dict.optionalSubDict(type() + "Coeffs");
251 
252  dict.readEntry("cellZone", zoneName_);
253  cellZoneIDs_ = mesh_.cellZones().indices(zoneName_);
254 
255  return true;
256 }
257 
258 
259 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::boundBox::reduce
void reduce()
Parallel reduction of min/max values.
Definition: boundBox.C:184
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::constant::physicoChemical::mu
const dimensionedScalar mu
Atomic mass unit.
Definition: createFieldRefs.H:4
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:191
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
porosityModel.H
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
rho
rho
Definition: readInitialConditions.H:88
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:62
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:253
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::porosityModel::transformModelData
virtual void transformModelData()
Transform the model data wrt mesh changes.
Definition: porosityModel.C:154
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
correct
fvOptions correct(rho)
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:84
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
Foam::porosityModel::adjustNegativeResistance
void adjustNegativeResistance(dimensionedVector &resist)
Adjust negative resistance values to be multiplier of max value.
Definition: porosityModel.C:43
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned< vector >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
Foam::indent
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:339
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::porosityModel::writeData
virtual bool writeData(Ostream &os) const
Write.
Definition: porosityModel.C:240
U
U
Definition: pEqn.H:72
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::List< cell >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::dictionary::optionalSubDict
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:577
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
UEqn
fvVectorMatrix & UEqn
Definition: UEqn.H:13
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::porosityModel::addResistance
virtual void addResistance(fvVectorMatrix &UEqn)
Add resistance.
Definition: porosityModel.C:186
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::orOp
Definition: ops.H:234
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101
Foam::boundBox::add
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191