Fickian.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 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 "Fickian.H"
27 #include "fvcDiv.H"
28 #include "fvcLaplacian.H"
29 #include "fvcSnGrad.H"
30 #include "fvmSup.H"
31 #include "surfaceInterpolate.H"
32 #include "Function2Evaluate.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 template<class BasicThermophysicalTransportModel>
43 (
44  const word& type,
45  const momentumTransportModel& momentumTransport,
46  const thermoModel& thermo
47 )
48 :
49  BasicThermophysicalTransportModel
50  (
51  type,
52  momentumTransport,
53  thermo
54  ),
55 
56  mixtureDiffusionCoefficients_(true),
57 
58  DFuncs_(this->thermo().composition().species().size()),
59 
60  DmFuncs_(this->thermo().composition().species().size()),
61 
62  DTFuncs_
63  (
64  this->coeffDict_.found("DT")
65  ? this->thermo().composition().species().size()
66  : 0
67  ),
68 
69  Dm_(this->thermo().composition().species().size())
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
75 template<class BasicThermophysicalTransportModel>
77 {
78  if
79  (
81  )
82  {
84  const speciesTable& species = composition.species();
85 
86  this->coeffDict_.lookup("mixtureDiffusionCoefficients")
87  >> mixtureDiffusionCoefficients_;
88 
89  if (mixtureDiffusionCoefficients_)
90  {
91  const dictionary& Ddict = this->coeffDict_.subDict("Dm");
92 
93  forAll(species, i)
94  {
95  DmFuncs_.set
96  (
97  i,
98  Function2<scalar>::New(species[i], Ddict).ptr()
99  );
100  }
101  }
102  else
103  {
104  const dictionary& Ddict = this->coeffDict_.subDict("D");
105 
106  // Read the array of specie binary mass diffusion coefficient
107  // functions
108  forAll(species, i)
109  {
110  DFuncs_[i].setSize(species.size());
111 
112  forAll(species, j)
113  {
114  if (j >= i)
115  {
116  const word nameij(species[i] + '-' + species[j]);
117  const word nameji(species[j] + '-' + species[i]);
118 
119  word Dname;
120 
121  if (Ddict.found(nameij) && Ddict.found(nameji))
122  {
123  if (i != j)
124  {
126  << "Binary mass diffusion coefficients "
127  "for Both " << nameij
128  << " and " << nameji << " provided, using "
129  << nameij << endl;
130  }
131 
132  Dname = nameij;
133  }
134  else if (Ddict.found(nameij))
135  {
136  Dname = nameij;
137  }
138  else if (Ddict.found(nameji))
139  {
140  Dname = nameji;
141  }
142  else
143  {
145  << "Binary mass diffusion coefficient for pair "
146  << nameij << " or " << nameji << " not provided"
147  << exit(FatalIOError);
148  }
149 
150  DFuncs_[i].set
151  (
152  j,
153  Function2<scalar>::New(Dname, Ddict).ptr()
154  );
155  }
156  }
157  }
158  }
159 
160  // Optionally read the List of specie Soret thermal diffusion
161  // coefficient functions
162  if (this->coeffDict_.found("DT"))
163  {
164  const dictionary& DTdict = this->coeffDict_.subDict("DT");
165 
166  forAll(species, i)
167  {
168  DTFuncs_.set
169  (
170  i,
171  Function2<scalar>::New(species[i], DTdict).ptr()
172  );
173  }
174  }
175 
176  return true;
177  }
178  else
179  {
180  return false;
181  }
182 }
183 
184 
185 template<class BasicThermophysicalTransportModel>
187 (
188  const volScalarField& Yi
189 ) const
190 {
192 
193  return volScalarField::New
194  (
195  "DEff",
196  this->momentumTransport().rho()
197  *Dm_[composition.index(Yi)]
198  );
199 }
200 
201 
202 template<class BasicThermophysicalTransportModel>
204 (
205  const volScalarField& Yi,
206  const label patchi
207 ) const
208 {
210 
211  return
212  this->momentumTransport().rho().boundaryField()[patchi]
213  *Dm_[composition.index(Yi)].boundaryField()[patchi];
214 }
215 
216 
217 template<class BasicThermophysicalTransportModel>
219 {
221  (
223  (
225  (
226  "q",
227  this->momentumTransport().alphaRhoPhi().group()
228  ),
229  -fvc::interpolate(this->alpha()*this->kappaEff())
230  *fvc::snGrad(this->thermo().T())
231  )
232  );
233 
235  const PtrList<volScalarField>& Y = composition.Y();
236 
237  if (Y.size())
238  {
239  surfaceScalarField sumJ
240  (
242  (
243  "sumJ",
244  Y[0].mesh(),
246  )
247  );
248 
249  surfaceScalarField sumJh
250  (
252  (
253  "sumJh",
254  Y[0].mesh(),
256  )
257  );
258 
259  forAll(Y, i)
260  {
261  if (i != composition.defaultSpecie())
262  {
263  const volScalarField hi
264  (
265  composition.Hs(i, this->thermo().p(), this->thermo().T())
266  );
267 
268  const surfaceScalarField ji(this->j(Y[i]));
269  sumJ += ji;
270 
271  sumJh += ji*fvc::interpolate(hi);
272  }
273  }
274 
275  {
276  const label i = composition.defaultSpecie();
277 
278  const volScalarField hi
279  (
280  composition.Hs(i, this->thermo().p(), this->thermo().T())
281  );
282 
283  sumJh -= sumJ*fvc::interpolate(hi);
284  }
285 
286  tmpq.ref() += sumJh;
287  }
288 
289  return tmpq;
290 }
291 
292 
293 template<class BasicThermophysicalTransportModel>
295 (
296  volScalarField& he
297 ) const
298 {
299  tmp<fvScalarMatrix> tmpDivq
300  (
301  fvm::Su
302  (
303  -fvc::laplacian(this->alpha()*this->kappaEff(), this->thermo().T()),
304  he
305  )
306  );
307 
309  const PtrList<volScalarField>& Y = composition.Y();
310 
311  tmpDivq.ref() -=
312  correction(fvm::laplacian(this->alpha()*this->alphaEff(), he));
313 
314  surfaceScalarField sumJ
315  (
317  (
318  "sumJ",
319  he.mesh(),
321  )
322  );
323 
324  surfaceScalarField sumJh
325  (
327  (
328  "sumJh",
329  he.mesh(),
330  dimensionedScalar(sumJ.dimensions()*he.dimensions(), 0)
331  )
332  );
333 
334  forAll(Y, i)
335  {
336  if (i != composition.defaultSpecie())
337  {
338  const volScalarField hi
339  (
340  composition.Hs(i, this->thermo().p(), this->thermo().T())
341  );
342 
343  const surfaceScalarField ji(this->j(Y[i]));
344  sumJ += ji;
345 
346  sumJh += ji*fvc::interpolate(hi);
347  }
348  }
349 
350  {
351  const label i = composition.defaultSpecie();
352 
353  const volScalarField hi
354  (
355  composition.Hs(i, this->thermo().p(), this->thermo().T())
356  );
357 
358  sumJh -= sumJ*fvc::interpolate(hi);
359  }
360 
361  tmpDivq.ref() += fvc::div(sumJh*he.mesh().magSf());
362 
363  return tmpDivq;
364 }
365 
366 
367 template<class BasicThermophysicalTransportModel>
369 (
370  const volScalarField& Yi
371 ) const
372 {
373  if (DTFuncs_.size())
374  {
376  const volScalarField& p = this->thermo().p();
377  const volScalarField& T = this->thermo().T();
378 
379  return
380  BasicThermophysicalTransportModel::j(Yi)
382  (
383  evaluate
384  (
385  DTFuncs_[composition.index(Yi)],
387  p,
388  T
389  )
390  )
392  }
393  else
394  {
395  return BasicThermophysicalTransportModel::j(Yi);
396  }
397 }
398 
399 
400 template<class BasicThermophysicalTransportModel>
402 (
403  volScalarField& Yi
404 ) const
405 {
406  if (DTFuncs_.size())
407  {
409  const volScalarField& p = this->thermo().p();
410  const volScalarField& T = this->thermo().T();
411 
412  return
413  BasicThermophysicalTransportModel::divj(Yi)
414  - fvc::div
415  (
417  (
418  evaluate
419  (
420  DTFuncs_[composition.index(Yi)],
422  p,
423  T
424  )
425  )
427  *T.mesh().magSf()
428  );
429  }
430  else
431  {
432  return BasicThermophysicalTransportModel::divj(Yi);
433  }
434 }
435 
436 
437 template<class BasicThermophysicalTransportModel>
439 {
441 
443  const PtrList<volScalarField>& Y = composition.Y();
444  const volScalarField& p = this->thermo().p();
445  const volScalarField& T = this->thermo().T();
446 
447  if (mixtureDiffusionCoefficients_)
448  {
449  forAll(Y, i)
450  {
451  Dm_.set(i, evaluate(DmFuncs_[i], dimViscosity, p, T));
452  }
453  }
454  else
455  {
456  const volScalarField Wm(this->thermo().W());
457  volScalarField sumXbyD
458  (
460  (
461  "sumXbyD",
462  T.mesh(),
464  )
465  );
466 
467  forAll(Dm_, i)
468  {
469  sumXbyD = Zero;
470 
471  forAll(Y, j)
472  {
473  if (j != i)
474  {
475  sumXbyD +=
476  Y[j]
477  /(
479  (
480  "Wj",
481  Wm.dimensions(),
482  composition.Wi(j)
483  )
484  *(
485  i < j
486  ? evaluate(DFuncs_[i][j], dimViscosity, p, T)
487  : evaluate(DFuncs_[j][i], dimViscosity, p, T)
488  )
489  );
490  }
491  }
492 
493  Dm_.set
494  (
495  i,
496  (
497  1/Wm
498  - Y[i]
499  /dimensionedScalar("Wi", Wm.dimensions(), composition.Wi(i))
500  )/max(sumXbyD, dimensionedScalar(sumXbyD.dimensions(), small))
501  );
502  }
503  }
504 }
505 
506 
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
508 
509 } // End namespace Foam
510 
511 // ************************************************************************* //
const char *const group
Group name for atomic constants.
const dimensionSet dimViscosity
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const dimensionSet dimArea
fluidReactionThermo & thermo
Definition: createFields.H:28
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
virtual tmp< fvScalarMatrix > divq(volScalarField &he) const
Return the source term for the energy equation.
Definition: Fickian.C:295
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
basicSpecieMixture & composition
virtual tmp< fvScalarMatrix > divj(volScalarField &Yi) const
Return the source term for the given specie mass-fraction equation.
Definition: Fickian.C:402
label index(const volScalarField &Yi) const
Return the specie index of the given mass-fraction field.
tmp< fvMatrix< Type > > Su(const DimensionedField< Type, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Internal &, const PtrList< fvPatchField< scalar >> &)
Return a temporary field constructed from name,.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
unityLewisFourier< laminarThermophysicalTransportModel > ::thermoModel thermoModel
Definition: Fickian.H:95
virtual scalar Wi(const label speciei) const =0
Molecular weight of the given specie [kg/kmol].
Calculate the snGrad of the given volField.
const dimensionSet dimless
virtual scalar rho(const label speciei, const scalar p, const scalar T) const =0
Density [kg/m^3].
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Specialisation of basicMixture for a mixture consisting of a number for molecular species...
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:45
virtual volScalarField & p()=0
Pressure [Pa].
virtual basicSpecieMixture & composition()=0
Return the composition of the multi-component mixture.
Fickian(const word &type, const momentumTransportModel &momentumTransport, const thermoModel &thermo)
Construct from a momentum transport model and a thermo model.
Definition: Fickian.C:43
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:982
virtual tmp< surfaceScalarField > q() const
Return the heat flux [W/m^2].
Definition: Fickian.C:218
const dimensionSet dimTime
const dimensionSet & dimensions() const
Return dimensions.
unityLewisFourier< laminarThermophysicalTransportModel > ::momentumTransportModel momentumTransportModel
Definition: Fickian.H:92
dynamicFvMesh & mesh
virtual tmp< volScalarField > DEff(const volScalarField &Yi) const
Effective mass diffusion coefficient.
Definition: Fickian.C:187
A class for handling words, derived from string.
Definition: word.H:59
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(rho0+psi *p, rhoMin);# 1 "/home/ubuntu/OpenFOAM-9/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
static word groupName(Name name, const word &group)
Calculate the laplacian of the given field.
virtual void correct()
Update the diffusion coefficients.
Definition: Fickian.C:438
static const zero Zero
Definition: zero.H:97
const dimensionSet dimDynamicViscosity
Calculate the divergence of the given field.
const Mesh & mesh() const
Return mesh.
virtual tmp< surfaceScalarField > j(const volScalarField &Yi) const
Return the specie flux for the given specie mass-fraction [kg/m^2/s].
Definition: Fickian.C:369
virtual bool read()
Read thermophysicalTransport dictionary.
Definition: Fickian.C:76
const dimensionSet dimEnergy
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const dimensionSet dimMass
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
virtual const volScalarField & T() const =0
Temperature [K].
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
A wordList with hashed indices for faster lookup by name.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:46
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
const scalarList W(::W(thermo))
PtrList< volScalarField > & Y
virtual scalar Hs(const label speciei, const scalar p, const scalar T) const =0
Sensible enthalpy [J/kg].
Run-time selectable function of two variables.
Definition: Function2.H:52
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
PtrList< volScalarField > & Y()
Return the mass-fraction fields.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Calculate the matrix for implicit and explicit sources.
Namespace for OpenFOAM.
const speciesTable & species() const
Return the table of species.
label defaultSpecie() const
Return the index of the default specie.
IOerror FatalIOError