massTransfer.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) 2021-2024 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 "massTransfer.H"
27 #include "fvMatrices.H"
28 #include "physicalProperties.H"
30 
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace fv
36 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::fv::massTransfer::readCoeffs(const dictionary& dict)
45 {
46  if
47  (
48  phaseNames_ != lookupPhaseNames(dict)
49  || alphaNames_ != lookupPhaseFieldNames(dict, "alpha")
50  || rhoNames_ != lookupPhaseFieldNames(dict, "rho")
51  )
52  {
54  << "Cannot change the phases of a " << typeName << " model "
55  << "at run time" << exit(FatalIOError);
56  }
57 }
58 
59 
60 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
61 
63 (
64  const dictionary& dict
65 ) const
66 {
67  return dict.lookup<Pair<word>>("phases");
68 }
69 
70 
73 (
74  const dictionary& dict,
75  const word& name
76 ) const
77 {
78  return
79  dict.lookupOrDefault<Pair<word>>
80  (
81  name + "s",
83  (
84  IOobject::groupName(name, phaseNames_.first()),
85  IOobject::groupName(name, phaseNames_.second())
86  )
87  );
88 }
89 
90 
92 (
93  const label i
94 ) const
95 {
96  // Compressible case. Lookup the field.
97  if (mesh().foundObject<volScalarField::Internal>(rhoNames()[i]))
98  {
99  return mesh().lookupObject<volScalarField::Internal>(rhoNames()[i]);
100  }
101 
102  // Incompressible case. Read from the physical properties dictionary.
103  const word physicalPropertiesName =
104  IOobject::groupName(physicalProperties::typeName, phaseNames()[i]);
105 
106  if (mesh().foundObject<IOdictionary>(physicalPropertiesName))
107  {
109  mesh().lookupObject<IOdictionary>(physicalPropertiesName);
110 
111  if (physicalProperties.found("rho"))
112  {
113  return
115  (
116  rhoNames()[i],
117  mesh(),
119  );
120  }
121  }
122 
123  // Fail.
125  << "Could not determine the density " << rhoNames()[i]
126  << " for phase " << phaseNames()[i]
127  << exit(FatalError);
128  return tmp<volScalarField::Internal>(nullptr);
129 }
130 
131 
133 (
134  const volScalarField& alphaOrField,
135  fvMatrix<scalar>& eqn
136 ) const
137 {
139  << "alphaOrField=" << alphaOrField.name()
140  << ", eqnField=" << eqn.psi().name() << endl;
141 
142  const label i = index(alphaNames(), alphaOrField.name());
143 
144  // Incompressible continuity equation
145  if (i != -1)
146  {
147  eqn += S(alphaOrField.name())/rho(i);
148  }
149  // Not recognised. Fail.
150  else
151  {
152  addSupType<scalar>(alphaOrField, eqn);
153  }
154 }
155 
156 
158 (
159  const volScalarField& alphaOrRho,
160  const volScalarField& rhoOrField,
161  fvMatrix<scalar>& eqn
162 ) const
163 {
165  << "alphaOrRho=" << alphaOrRho.name()
166  << ", rhoOrField=" << rhoOrField.name()
167  << ", eqnField=" << eqn.psi().name() << endl;
168 
169  // Compressible continuity equation
170  if
171  (
172  index(alphaNames(), alphaOrRho.name()) != -1
173  && index(rhoNames(), rhoOrField.name()) != -1
174  )
175  {
176  eqn += S(alphaOrRho.name());
177  }
178  // Mixture property equation
179  else
180  {
181  addSupType<scalar>(alphaOrRho, rhoOrField, eqn);
182  }
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187 
189 (
190  const word& name,
191  const word& modelType,
192  const fvMesh& mesh,
193  const dictionary& dict
194 )
195 :
196  fvSpecificSource(name, modelType, mesh, dict),
197  phaseNames_(lookupPhaseNames(dict)),
198  alphaNames_(lookupPhaseFieldNames(dict, "alpha")),
199  rhoNames_(lookupPhaseFieldNames(dict, "rho"))
200 {
201  readCoeffs(coeffs(dict));
202 }
203 
204 
205 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
206 
207 bool Foam::fv::massTransfer::addsSupToField(const word& fieldName) const
208 {
209  const word group = IOobject::group(fieldName);
210 
211  return
212  group == word::null
213  || group == phaseNames_.first()
214  || group == phaseNames_.second();
215 }
216 
217 
219 Foam::fv::massTransfer::S(const word& fieldName) const
220 {
221  return sign(phaseNames(), IOobject::group(fieldName))*mDot();
222 }
223 
224 
226 {
228  << "eqnField=" << eqn.psi().name() << endl;
229 
231  << "Field-less mass transfers are not possible"
232  << exit(FatalError);
233 }
234 
235 
237 
238 
240 
241 
243 (
245  fv::massTransfer
246 );
247 
248 
250 {
252  {
253  readCoeffs(coeffs(dict));
254  return true;
255  }
256  else
257  {
258  return false;
259  }
260 }
261 
262 
263 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Mesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
Generic GeometricField class.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
word group() const
Return group (extension part of name)
Definition: IOobject.C:321
const word & name() const
Return name.
Definition: IOobject.H:307
static word groupName(Name name, const word &group)
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:539
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
VolField< Type > & psi()
Definition: fvMatrix.H:289
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
static const dictionary & coeffs(const word &modelType, const dictionary &)
Return the coefficients sub-dictionary for a given model type.
Definition: fvModelI.H:31
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvModel.C:200
Base class for sources which are specified as a specific value (e.g., mass flow rate per unit volume)...
Base class for mass transfers between phases.
Definition: massTransfer.H:55
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
const Pair< word > lookupPhaseNames(const dictionary &dict) const
Lookup the phase names.
Definition: massTransfer.C:63
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: massTransfer.C:249
tmp< volScalarField::Internal > rho(const label i) const
Return the density.
Definition: massTransfer.C:92
massTransfer(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from explicit source name and mesh.
Definition: massTransfer.C:189
const Pair< word > lookupPhaseFieldNames(const dictionary &dict, const word &name) const
Lookup the phase field names.
Definition: massTransfer.C:73
virtual void addSup(fvMatrix< scalar > &eqn) const
Add a source term to a field-less proxy equation.
Definition: massTransfer.C:225
virtual bool addsSupToField(const word &fieldName) const
Return true if the fvModel adds a source term to the given.
Definition: massTransfer.C:207
virtual tmp< DimensionedField< scalar, volMesh > > S(const word &fieldName) const
Return the source value.
Definition: massTransfer.C:219
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
A base class for physical properties.
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
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
A special matrix type and solver, designed for finite volume solutions of scalar equations.
#define IMPLEMENT_FV_MODEL_ADD_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:33
#define IMPLEMENT_FV_MODEL_ADD_ALPHA_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:71
#define IMPLEMENT_FV_MODEL_ADD_RHO_FIELD_SUP(Type, modelType)
Definition: fvModelM.H:51
#define DebugInFunction
Report an information message using Foam::Info.
const char *const group
Group name for atomic constants.
defineTypeNameAndDebug(bound, 0)
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensionedScalar sign(const dimensionedScalar &ds)
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:258
const dimensionSet dimDensity
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
labelList fv(nPoints)
dictionary dict