twoPhaseMixtureEThermo.C 12.8 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "twoPhaseMixtureEThermo.H"

#include "zeroGradientFvPatchFields.H"
#include "fixedEnergyFvPatchScalarField.H"
#include "gradientEnergyFvPatchScalarField.H"
#include "mixedEnergyFvPatchScalarField.H"
#include "twoPhaseMixtureEThermo.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineTypeNameAndDebug(twoPhaseMixtureEThermo, 0);
}

// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //

void Foam::twoPhaseMixtureEThermo::eBoundaryCorrection(volScalarField& h)
{
45
    volScalarField::Boundary& hbf = h.boundaryFieldRef();
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

    forAll(hbf, patchi)
    {
        if (isA<gradientEnergyFvPatchScalarField>(hbf[patchi]))
        {
            refCast<gradientEnergyFvPatchScalarField>(hbf[patchi]).gradient()
                = hbf[patchi].fvPatchField::snGrad();
        }
        else if (isA<mixedEnergyFvPatchScalarField>(hbf[patchi]))
        {
            refCast<mixedEnergyFvPatchScalarField>(hbf[patchi]).refGrad()
                = hbf[patchi].fvPatchField::snGrad();
        }
    }
}

62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void Foam::twoPhaseMixtureEThermo::init()
{
    const volScalarField alpha1Rho1(alpha1()*rho1());
    const volScalarField alpha2Rho2(alpha2()*rho2());

    e_ =
        (
            (T_ - TSat_)*(alpha1Rho1*Cv1() + alpha2Rho2*Cv2())
          + (alpha1Rho1*Hf1() + alpha2Rho2*Hf2())
        )
       /(alpha1Rho1 + alpha2Rho2);

    e_.correctBoundaryConditions();
}

78

79
80
81
82
83
84
85
86
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //

Foam::twoPhaseMixtureEThermo::twoPhaseMixtureEThermo
(
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
87
    basicThermo(U.mesh(), word::null),
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    thermoIncompressibleTwoPhaseMixture(U, phi),

    e_
    (
        volScalarField
        (
            IOobject
            (
                "e",
                U.mesh().time().timeName(),
                U.mesh(),
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            U.mesh(),
103
            dimensionedScalar(dimEnergy/dimMass, Zero),
104
105
106
107
            heBoundaryTypes()
        )
    ),

108
    TSat_("TSat", dimTemperature, static_cast<const basicThermo&>(*this)),
109
110
111
112
113
114
115
116

    pDivU_(basicThermo::lookupOrDefault<Switch>("pDivU", true))

{
    // Initialise e
    init();
}

117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::twoPhaseMixtureEThermo::correct()
{
    incompressibleTwoPhaseMixture::correct();

    const volScalarField alpha1Rho1(alpha1()*rho1());
    const volScalarField alpha2Rho2(alpha2()*rho2());

    T_ =
        (
            (e_*(alpha1Rho1 + alpha2Rho2))
         -  (alpha1Rho1*Hf1() + alpha2Rho2*Hf2())
        )
       /(alpha1Rho1*Cv1() + alpha2Rho2*Cv2())
       + TSat_;

    T().correctBoundaryConditions();
}


139
140
141
142
143
144
145
Foam::word Foam::twoPhaseMixtureEThermo::thermoName() const
{
    NotImplemented;
    return word::null;
}


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::he
(
    const volScalarField& p,
    const volScalarField& T
) const
{
    const volScalarField alpha1Rho1(alpha1()*rho1());
    const volScalarField alpha2Rho2(alpha2()*rho2());

    return
    (
        (T - TSat_)*(alpha1Rho1*Cv1() + alpha2Rho2*Cv2())
        + (alpha1Rho1*Hf1() + alpha2Rho2*Hf2())
    )
    / (alpha1Rho1 + alpha2Rho2);
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::he
(
    const scalarField& p,
    const scalarField& T,
    const labelList& cells
) const
{
    tmp<scalarField> the(new scalarField(T.size()));
    scalarField& he = the.ref();

    const volScalarField alpha1Rho1(alpha1()*rho1());
    const volScalarField alpha2Rho2(alpha2()*rho2());

    forAll(T, i)
    {
179
        const label celli = cells[i];
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
        he[i] =
            (
                (T[i] - TSat_.value())
               *(
                   alpha1Rho1[celli]*Cv1().value()
                 + alpha2Rho2[celli]*Cv2().value()
                )
              + (
                    alpha1Rho1[celli]*Hf1().value()
                  + alpha2Rho2[celli]*Hf2().value()
                )
            )
            / (alpha1Rho1[celli] + alpha2Rho2[celli]);
    }

    return the;
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::he
(
    const scalarField& p,
    const scalarField& T,
Andrew Heather's avatar
Andrew Heather committed
203
    const label patchi
204
205
) const
{
Andrew Heather's avatar
Andrew Heather committed
206
207
    const scalarField& alpha1p = alpha1().boundaryField()[patchi];
    const scalarField& alpha2p = alpha2().boundaryField()[patchi];
208

Andrew Heather's avatar
Andrew Heather committed
209
    const scalarField& Tp = T_.boundaryField()[patchi];
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

    return
    (
        (
            (Tp - TSat_.value())
           *(
               alpha1p*rho1().value()*Cv1().value()
             + alpha2p*rho2().value()*Cv2().value()
            )
          + (
               alpha1p*rho1().value()*Hf1().value()
             + alpha2p*rho2().value()*Hf2().value()
            )
        )
        / (alpha1p*rho1().value() + alpha2p*rho2().value())
    );
}


229
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::hc() const
230
231
232
{
    const fvMesh& mesh = this->T_.mesh();

233
    return tmp<volScalarField>::New
234
    (
235
        IOobject
236
        (
237
238
            "hc",
            mesh.time().timeName(),
239
            mesh,
240
241
242
243
244
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("hc", Hf2() - Hf1())
245
246
247
248
249
250
251
252
253
254
255
256
257
    );
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::THE
(
    const scalarField& h,
    const scalarField& p,
    const scalarField& T0,      // starting temperature
    const labelList& cells
) const
{
    NotImplemented;
258
    return nullptr;
259
260
261
262
263
264
265
266
267
268
269
270
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::THE
(
    const scalarField& h,
    const scalarField& p,
    const scalarField& T0,      // starting temperature
    const label patchi
) const
{
    NotImplemented;
271
    return nullptr;
272
273
274
}


275
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cp() const
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    return tmp<volScalarField>
    (
        new volScalarField
        (
            "cp",
            limitedAlpha1*Cp1() + (scalar(1) - limitedAlpha1)*Cp2()
        )
    );
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::Cp
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    return
    (
        alpha1p*Cp1().value() + (scalar(1) - alpha1p)*Cp2().value()
    );
}


314
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::rho() const
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    return tmp<volScalarField>
    (
        new volScalarField
        (
            "rho",
            limitedAlpha1*rho1().value()
          + (scalar(1) - limitedAlpha1)*rho2().value()
        )
    );
}


333
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::rho
334
335
336
337
338
339
340
341
342
343
344
345
346
(
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    return
    (
347
        alpha1p*rho1().value() + (scalar(1) - alpha1p)*rho2().value()
348
349
350
351
    );
}


352
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cv() const
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    return tmp<volScalarField>
    (
        new volScalarField
        (
            "cv",
            limitedAlpha1*Cv1() + (scalar(1) - limitedAlpha1)*Cv2()
        )
    );
}


370
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::Cv
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    return
    (
        alpha1p*Cv1().value() + (scalar(1) - alpha1p)*Cv2().value()
    );
}


391
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::gamma() const
392
393
394
{
    return tmp<volScalarField>
    (
395
        (alpha1_*Cp1() + alpha2_*Cp2())/(alpha1_*Cv1() + alpha2_*Cv2())
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
    );
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::gamma
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
    return
    (
        gamma()().boundaryField()[patchi]
    );
}


414
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cpv() const
415
416
417
418
419
420
421
422
423
424
{
     // This is an e thermo (Cpv = Cv)
     return Cv();
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::Cpv
(
    const scalarField& p,
    const scalarField& T,
Andrew Heather's avatar
Andrew Heather committed
425
    const label patchi
426
427
) const
{
428
    // This is an e thermo (Cpv = Cv)
Andrew Heather's avatar
Andrew Heather committed
429
    return Cv(p, T, patchi);
430
431
432
}


433
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::CpByCpv() const
434
{
435
436
    NotImplemented;
    return nullptr;
437
438
439
}


440
441
442
443
444
445
446
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::W() const
{
    NotImplemented;
    return nullptr;
}


447
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::CpByCpv
448
449
450
451
452
453
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
454
455
    NotImplemented;
    return nullptr;
456
457
458
}


459
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::kappa() const
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    return tmp<volScalarField>
    (
        new volScalarField
        (
            "kappa",
            limitedAlpha1*kappa1() + (scalar(1) - limitedAlpha1)*kappa2()
        )
    );
}


477
478
479
480
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::kappa
(
    const label patchi
) const
481
482
483
484
485
486
487
488
489
490
491
492
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    return (alpha1p*kappa1().value() + (1 - alpha1p)*kappa2().value());
}


493
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::kappaEff
494
495
496
497
498
499
500
501
502
503
(
    const volScalarField& kappat
) const
{
    tmp<Foam::volScalarField> kappaEff(kappa() + kappat);
    kappaEff.ref().rename("kappaEff");
    return kappaEff;
}


504
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::kappaEff
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
(
    const scalarField& kappat,
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    return
        (alpha1p*kappa1().value() + (1 - alpha1p)*kappa2().value()) + kappat;

}


523
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::alphaEff
524
525
526
527
528
529
530
531
532
533
534
535
(
    const volScalarField& alphat
) const
{
    const volScalarField rho
    (
        alpha1_*rho1() + (1.0 - alpha1_)*rho2()
    );

    return (kappa()/Cp()/rho + alphat);
}

536
537

Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::alphaEff
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
(
    const scalarField& alphat,
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

    const scalarField& alpha1p = limitedAlpha1.boundaryField()[patchi];

    const scalarField rho
    (
        alpha1p*rho1().value() + (1.0 - alpha1p)*rho2().value()
    );

    const scalarField kappa
    (
        alpha1p*kappa1().value() + (1.0 - alpha1p)*kappa2().value()
    );

    const scalarField Cp
    (
        alpha1p*Cp1().value() + (1.0 - alpha1p)*Cp2().value()
    );

    return kappa/Cp/rho + alphat;
}

568

569
570
571
572
bool Foam::twoPhaseMixtureEThermo::read()
{
    if (basicThermo::read() && thermoIncompressibleTwoPhaseMixture::read())
    {
573
        basicThermo::readIfPresent("pDivU", pDivU_);
574
        basicThermo::readEntry("TSat", TSat_);
575
576
        return true;
    }
577
578

    return false;
579
580
}

581

582
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //