massTransferTemplates.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 
29 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const VolField<Type>& field
35 ) const
36 {
37  const label i = index(phaseNames(), field.group());
38 
39  const word otherFieldName =
40  IOobject::groupName(field.member(), phaseNames()[!i]);
41 
42  if (mesh().foundObject<VolField<Type>>(otherFieldName))
43  {
44  return mesh().lookupObject<VolField<Type>>(otherFieldName);
45  }
46  else
47  {
48  return NullObjectRef<VolField<Type>>();
49  }
50 }
51 
52 
53 template<class Type>
55 (
56  const VolField<Type>& field,
57  fvMatrix<Type>& eqn
58 ) const
59 {
61  << "field=" << field.name()
62  << ", eqnField=" << eqn.psi().name() << endl;
63 
64  // Volume-weighted mixture property equation
65  if (field.group() == word::null)
66  {
67  eqn -= fvm::SuSp((1/rho(0) - 1/rho(1))*mDot(), eqn.psi());
68  }
69  // Not recognised. Fail.
70  else
71  {
73  << "Cannot add a phase transfer for field " << field.name()
74  << exit(FatalError);
75  }
76 }
77 
78 
79 template<class Type>
81 (
82  const volScalarField& alphaOrRho,
83  const VolField<Type>& field,
84  fvMatrix<Type>& eqn
85 ) const
86 {
88  << "alphaOrRho=" << alphaOrRho.name()
89  << ", field=" << field.name()
90  << ", eqnField=" << eqn.psi().name() << endl;
91 
92  const label i = index(alphaNames(), alphaOrRho.name());
93 
94  // Incompressible property equation
95  if
96  (
97  i != -1
98  && i == index(phaseNames(), field.group())
99  )
100  {
101  // Try and lookup the corresponding field in the other phase
102  const VolField<Type>& otherField = this->otherField(field);
103 
104  // If a corresponding field exists then transfer its value
105  if (!isNull(otherField))
106  {
107  const volScalarField::Internal S(this->S(field.name())/rho(i));
108 
109  eqn += posPart(S)*otherField;
110 
111  if (&field == &eqn.psi())
112  {
113  eqn += fvm::Sp(negPart(S), eqn.psi());
114  }
115  else
116  {
117  eqn += negPart(S)*field;
118  }
119  }
120  // Otherwise, get the base class to create the source. This will
121  // require a field source specification.
122  else
123  {
124  fvMatrix<Type> rhoEqn(eqn.psi(), dimDensity*eqn.dimensions());
125 
126  fvSpecificSource::addSupType(alphaOrRho, field, rhoEqn);
127 
128  eqn += rhoEqn/rho(i);
129  }
130  }
131  // Mass-weighted mixture property equation
132  else if
133  (
134  alphaOrRho.group() == word::null
135  && alphaOrRho.dimensions() == dimDensity
136  && field.group() == word::null
137  )
138  {
139  // Nothing to do. Standard transport terms already represent the
140  // transfer. No source term is needed.
141  }
142  // Not recognised. Fail.
143  else
144  {
146  << "Cannot add a phase transfer for field " << field.name()
147  << exit(FatalError);
148  }
149 }
150 
151 
152 template<class Type>
154 (
155  const volScalarField& alpha,
156  const volScalarField& rho,
157  const VolField<Type>& field,
158  fvMatrix<Type>& eqn
159 ) const
160 {
162  << "alpha=" << alpha.name()
163  << ", rho=" << rho.name()
164  << ", field=" << field.name()
165  << ", eqnField=" << eqn.psi().name() << endl;
166 
167  const label i = index(alphaNames(), alpha.name());
168 
169  // Compressible property equation
170  if
171  (
172  i != -1
173  && i == index(rhoNames(), rho.name())
174  && i == index(phaseNames(), field.group())
175  )
176  {
177  // Try and lookup the corresponding field in the other phase
178  const VolField<Type>& otherField = this->otherField(field);
179 
180  // If a corresponding field exists then transfer its value
181  if (!isNull(otherField))
182  {
183  const volScalarField::Internal S(this->S(field.name()));
184 
185  eqn += posPart(S)*otherField;
186 
187  if (&field == &eqn.psi())
188  {
189  eqn += fvm::Sp(negPart(S), eqn.psi());
190  }
191  else
192  {
193  eqn += negPart(S)*field;
194  }
195  }
196  // Otherwise, get the base class to create the source. This will
197  // require a field source specification.
198  else
199  {
200  fvSpecificSource::addSupType(alpha, rho, field, eqn);
201  }
202  }
203  // Not recognised. Fail.
204  else
205  {
207  << "Cannot add a phase transfer for field " << field.name()
208  << exit(FatalError);
209  }
210 }
211 
212 
213 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
Generic GeometricField class.
static word member(const word &name)
Return member (name without the extension)
Definition: IOobject.C:149
static word group(const word &name)
Return group (extension part of name)
Definition: IOobject.C:134
const word & name() const
Return name.
Definition: IOobject.H:310
static word groupName(Name name, const word &group)
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
const dimensionSet & dimensions() const
Definition: fvMatrix.H:302
const fvMesh & mesh() const
Return const access to the mesh database.
Definition: fvModelI.H:53
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
void addSupType(const VolField< Type > &field, fvMatrix< Type > &eqn) const
Add a source term to an equation.
const Pair< word > & phaseNames() const
Return the names of the phases.
Definition: massTransferI.H:52
static label index(const Pair< word > &names, const word &name)
Get the index of the name in the given pair, or -1.
Definition: massTransferI.H:31
const VolField< Type > & otherField(const VolField< Type > &field) const
Return the corresponding field in the other phase, or a null.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#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.
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
#define DebugInFunction
Report an information message using Foam::Info.
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
tmp< fvMatrix< Type > > Sp(const volScalarField::Internal &, const VolField< Type > &)
tmp< fvMatrix< Type > > SuSp(const volScalarField::Internal &, const VolField< Type > &)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
dimensionedScalar negPart(const dimensionedScalar &ds)
const dimensionSet dimDensity
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:58
error FatalError
dimensionedScalar posPart(const dimensionedScalar &ds)