twoPhaseSystem.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) 2013-2018 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "twoPhaseSystem.H"
29 #include "dragModel.H"
30 #include "virtualMassModel.H"
31 
32 #include "MULES.H"
33 #include "subCycle.H"
34 #include "UniformField.H"
35 
36 #include "fvcDdt.H"
37 #include "fvcDiv.H"
38 #include "fvcSnGrad.H"
39 #include "fvcFlux.H"
40 #include "fvcSup.H"
41 
42 #include "fvmDdt.H"
43 #include "fvmLaplacian.H"
44 #include "fvmSup.H"
45 
46 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50  defineTypeNameAndDebug(twoPhaseSystem, 0);
51  defineRunTimeSelectionTable(twoPhaseSystem, dictionary);
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const fvMesh& mesh
60 )
61 :
63  phase1_(phaseModels_[0]),
64  phase2_(phaseModels_[1])
65 {
66  phase2_.volScalarField::operator=(scalar(1) - phase1_);
67 
68  volScalarField& alpha1 = phase1_;
69  mesh.setFluxRequired(alpha1.name());
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
80 
83 {
84  return sigma
85  (
87  );
88 }
89 
90 
93 {
94  return Kd
95  (
97  );
98 }
99 
100 
103 {
104  return Kdf
105  (
107  );
108 }
109 
110 
113 {
114  return Vm
115  (
117  );
118 }
119 
120 
122 {
123  const Time& runTime = mesh_.time();
124 
125  volScalarField& alpha1 = phase1_;
126  volScalarField& alpha2 = phase2_;
127 
128  const dictionary& alphaControls = mesh_.solverDict(alpha1.name());
129 
130  label nAlphaSubCycles(alphaControls.get<label>("nAlphaSubCycles"));
131  label nAlphaCorr(alphaControls.get<label>("nAlphaCorr"));
132 
133  bool LTS = fv::localEulerDdt::enabled(mesh_);
134 
135  word alphaScheme("div(phi," + alpha1.name() + ')');
136  word alpharScheme("div(phir," + alpha1.name() + ')');
137 
138  const surfaceScalarField& phi1 = phase1_.phi();
139  const surfaceScalarField& phi2 = phase2_.phi();
140 
141  // Construct the dilatation rate source term
143 
144  if (phase1_.divU().valid() && phase2_.divU().valid())
145  {
146  tdgdt =
147  (
148  alpha2()
149  *phase1_.divU()()()
150  - alpha1()
151  *phase2_.divU()()()
152  );
153  }
154  else if (phase1_.divU().valid())
155  {
156  tdgdt =
157  (
158  alpha2()
159  *phase1_.divU()()()
160  );
161  }
162  else if (phase2_.divU().valid())
163  {
164  tdgdt =
165  (
166  - alpha1()
167  *phase2_.divU()()()
168  );
169  }
170 
172 
173  surfaceScalarField phir("phir", phi1 - phi2);
174 
175  tmp<surfaceScalarField> alphaDbyA;
176  if (DByAfs().found(phase1_.name()) && DByAfs().found(phase2_.name()))
177  {
178  surfaceScalarField DbyA
179  (
180  *DByAfs()[phase1_.name()] + *DByAfs()[phase2_.name()]
181  );
182 
183  alphaDbyA =
184  fvc::interpolate(max(alpha1, scalar(0)))
185  *fvc::interpolate(max(alpha2, scalar(0)))
186  *DbyA;
187 
188  phir += DbyA*fvc::snGrad(alpha1, "bounded")*mesh_.magSf();
189  }
190 
191  for (int acorr=0; acorr<nAlphaCorr; acorr++)
192  {
194  (
195  IOobject
196  (
197  "Sp",
198  runTime.timeName(),
199  mesh_
200  ),
201  mesh_,
203  );
204 
206  (
207  IOobject
208  (
209  "Su",
210  runTime.timeName(),
211  mesh_
212  ),
213  // Divergence term is handled explicitly to be
214  // consistent with the explicit transport solution
215  fvc::div(phi_)*min(alpha1, scalar(1))
216  );
217 
218  if (tdgdt.valid())
219  {
220  scalarField& dgdt = tdgdt.ref();
221 
222  forAll(dgdt, celli)
223  {
224  if (dgdt[celli] > 0.0)
225  {
226  Sp[celli] -= dgdt[celli]/max(1 - alpha1[celli], 1e-4);
227  Su[celli] += dgdt[celli]/max(1 - alpha1[celli], 1e-4);
228  }
229  else if (dgdt[celli] < 0.0)
230  {
231  Sp[celli] += dgdt[celli]/max(alpha1[celli], 1e-4);
232  }
233  }
234  }
235 
237  (
238  fvc::flux
239  (
240  phi_,
241  alpha1,
242  alphaScheme
243  )
244  + fvc::flux
245  (
246  -fvc::flux(-phir, scalar(1) - alpha1, alpharScheme),
247  alpha1,
249  )
250  );
251 
252  phase1_.correctInflowOutflow(alphaPhi1);
253 
254  if (nAlphaSubCycles > 1)
255  {
256  tmp<volScalarField> trSubDeltaT;
257 
258  if (LTS)
259  {
260  trSubDeltaT =
262  }
263 
264  for
265  (
267  !(++alphaSubCycle).end();
268  )
269  {
271 
273  (
275  alpha1,
276  phi_,
277  alphaPhi10,
278  (alphaSubCycle.index()*Sp)(),
279  (Su - (alphaSubCycle.index() - 1)*Sp*alpha1)(),
280  UniformField<scalar>(phase1_.alphaMax()),
281  zeroField()
282  );
283 
284  if (alphaSubCycle.index() == 1)
285  {
286  phase1_.alphaPhiRef() = alphaPhi10;
287  }
288  else
289  {
290  phase1_.alphaPhiRef() += alphaPhi10;
291  }
292  }
293 
294  phase1_.alphaPhiRef() /= nAlphaSubCycles;
295  }
296  else
297  {
299  (
301  alpha1,
302  phi_,
303  alphaPhi1,
304  Sp,
305  Su,
306  UniformField<scalar>(phase1_.alphaMax()),
307  zeroField()
308  );
309 
310  phase1_.alphaPhiRef() = alphaPhi1;
311  }
312 
313  if (alphaDbyA.valid())
314  {
315  fvScalarMatrix alpha1Eqn
316  (
318  - fvm::laplacian(alphaDbyA(), alpha1, "bounded")
319  );
320 
321  alpha1Eqn.relax();
322  alpha1Eqn.solve();
323 
324  phase1_.alphaPhiRef() += alpha1Eqn.flux();
325  }
326 
327  phase1_.alphaRhoPhiRef() =
328  fvc::interpolate(phase1_.rho())*phase1_.alphaPhi();
329 
330  phase2_.alphaPhiRef() = phi_ - phase1_.alphaPhi();
331  phase2_.correctInflowOutflow(phase2_.alphaPhiRef());
332  phase2_.alphaRhoPhiRef() =
333  fvc::interpolate(phase2_.rho())*phase2_.alphaPhi();
334 
335  Info<< alpha1.name() << " volume fraction = "
336  << alpha1.weightedAverage(mesh_.V()).value()
337  << " Min(alpha1) = " << min(alpha1).value()
338  << " Max(alpha1) = " << max(alpha1).value()
339  << endl;
340 
341  // Ensure the phase-fractions are bounded
342  alpha1.clip(0, 1);
343 
344  // Update the phase-fraction of the other phase
345  alpha2 = scalar(1) - alpha1;
346  }
347 }
348 
349 
350 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:47
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::twoPhaseSystem::sigma
tmp< volScalarField > sigma() const
Return the surface tension coefficient.
Definition: twoPhaseSystem.C:82
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::MULES::explicitSolve
void explicitSolve(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiPsi, const SpType &Sp, const SuType &Su)
Definition: MULESTemplates.C:40
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::localEulerDdt::localRSubDeltaT
static tmp< volScalarField > localRSubDeltaT(const fvMesh &mesh, const label nAlphaSubCycles)
Calculate and return the reciprocal of the local sub-cycling.
Definition: localEulerDdt.C:72
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
twoPhaseSystem.H
alpha2
const volScalarField & alpha2
Definition: setRegionFluidFields.H:9
subCycle.H
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
phi1
surfaceScalarField & phi1
Definition: setRegionFluidFields.H:12
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
fvcSnGrad.H
Calculate the snGrad of the given volField.
Foam::vtk::Tools::zeroField
vtkSmartPointer< vtkFloatArray > zeroField(const word &name, const label size)
Create named field initialized to zero.
Definition: foamVtkToolsTemplates.C:258
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:764
Sp
zeroField Sp
Definition: alphaSuSp.H:2
Foam::geometricOneField
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
Definition: geometricOneField.H:54
fvcDiv.H
Calculate the divergence of the given field.
Foam::fvc::div
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
fvcSup.H
Calculate the field for explicit evaluation of implicit and explicit sources.
alpha1
const volScalarField & alpha1
Definition: setRegionFluidFields.H:8
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::GeometricField::clip
void clip(const dimensioned< MinMax< Type >> &range)
Clip the field to be bounded within the specified range.
Definition: GeometricField.C:1123
nAlphaSubCycles
label nAlphaSubCycles(alphaControls.get< label >("nAlphaSubCycles"))
alpharScheme
word alpharScheme("div(phirb,alpha)")
phi2
surfaceScalarField & phi2
Definition: setRegionFluidFields.H:16
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::fv::localEulerDdt::enabled
static bool enabled(const fvMesh &mesh)
Return true if LTS is enabled.
Definition: localEulerDdt.C:39
Su
zeroField Su
Definition: alphaSuSp.H:1
nAlphaCorr
label nAlphaCorr(alphaControls.get< label >("nAlphaCorr"))
Foam::UniformField
A class representing the concept of a uniform field which stores only the single value and providing ...
Definition: UniformField.H:49
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
phir
surfaceScalarField phir(fvc::flux(UdmModel.Udm()))
Foam::label
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:62
Foam::twoPhaseSystem::Vm
tmp< volScalarField > Vm() const
Return the virtual mass coefficient.
Definition: twoPhaseSystem.C:112
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fvm::laplacian
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:48
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fvMatrix::relax
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
Definition: fvMatrix.C:574
fvmLaplacian.H
Calculate the matrix for the laplacian of the field.
Foam::twoPhaseSystem::Kdf
tmp< surfaceScalarField > Kdf() const
Return the face drag coefficient.
Definition: twoPhaseSystem.C:102
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::phasePairKey
Definition: phasePairKey.H:59
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Kd
const volScalarField Kd(fluid.Kd())
Foam::twoPhaseSystem::solve
virtual void solve()
Solve for the phase fractions.
Definition: twoPhaseSystem.C:121
phase2
phaseModel & phase2
Definition: setRegionFluidFields.H:6
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
LTS
bool LTS
Definition: createRDeltaT.H:1
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:115
Foam::twoPhaseSystem::twoPhaseSystem
twoPhaseSystem(const fvMesh &)
Construct from fvMesh.
Definition: twoPhaseSystem.C:58
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
alphaPhi1
const surfaceScalarField & alphaPhi1
Definition: setRegionFluidFields.H:13
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fvc::interpolate
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.
fvmSup.H
Calculate the matrix for implicit and explicit sources.
Kdf
const surfaceScalarField Kdf("Kdf", fluid.Kdf())
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:909
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::fvm::ddt
tmp< fvMatrix< Type > > ddt(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvmDdt.C:48
fvcFlux.H
Calculate the face-flux of the given field.
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::fvMatrix::solve
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Definition: fvMatrixSolve.C:298
fvcDdt.H
Calculate the first temporal derivative.
Foam::twoPhaseSystem::~twoPhaseSystem
virtual ~twoPhaseSystem()
Destructor.
Definition: twoPhaseSystem.C:75
Foam::fvc::ddt
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:47
Foam::phaseSystem
Class to represent a system of phases and model interfacial transfers between them.
Definition: phaseSystem.H:69
sigma
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
phase1
phaseModel & phase1
Definition: setRegionFluidFields.H:5
Foam::tmp::valid
bool valid() const noexcept
Definition: tmpI.H:206
Foam::fvc::flux
tmp< surfaceScalarField > flux(const volVectorField &vvf)
Return the face-flux field obtained from the given volVectorField.
Definition: fvcFlux.C:34
Foam::twoPhaseSystem::Kd
tmp< volScalarField > Kd() const
Return the drag coefficient.
Definition: twoPhaseSystem.C:92
Foam::GeometricField< scalar, fvPatchField, volMesh >
MULES.H
MULES: Multidimensional universal limiter for explicit solution.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
alphaPhi10
surfaceScalarField alphaPhi10(alphaPhi10Header, phi *fvc::interpolate(alpha1))
Foam::fvMatrix::flux
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > flux() const
Return the face-flux field from the matrix.
Definition: fvMatrix.C:927
UniformField.H
fvmDdt.H
Calulate the matrix for the first temporal derivative.
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::subCycle
Perform a subCycleTime on a field.
Definition: subCycle.H:108
alphaControls
const dictionary & alphaControls
Definition: alphaControls.H:1