twoPhaseMixtureEThermo.C 13 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2016 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //

Foam::twoPhaseMixtureEThermo::twoPhaseMixtureEThermo
(
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
    basicThermo(U.mesh(),  word::null),
    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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
            heBoundaryTypes()
        )
    ),

    TSat_
    (
        "TSat",
        dimTemperature,
        basicThermo::lookup("TSat")
    ),

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

{
    // Initialise e
    init();
}

122

123
124
125
126
127
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

Foam::twoPhaseMixtureEThermo::~twoPhaseMixtureEThermo()
{}

128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// * * * * * * * * * * * * * * * 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();
}


150
151
152
153
154
155
156
Foam::word Foam::twoPhaseMixtureEThermo::thermoName() const
{
    NotImplemented;
    return word::null;
}


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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)
    {
        label celli = cells[i];
        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
214
    const label patchi
215
216
) const
{
Andrew Heather's avatar
Andrew Heather committed
217
218
    const scalarField& alpha1p = alpha1().boundaryField()[patchi];
    const scalarField& alpha2p = alpha2().boundaryField()[patchi];
219

Andrew Heather's avatar
Andrew Heather committed
220
    const scalarField& Tp = T_.boundaryField()[patchi];
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

    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())
    );
}


240
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::hc() const
241
242
243
{
    const fvMesh& mesh = this->T_.mesh();

244
    return tmp<volScalarField>::New
245
    (
246
        IOobject
247
        (
248
249
            "hc",
            mesh.time().timeName(),
250
            mesh,
251
252
253
254
255
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("hc", Hf2() - Hf1())
256
257
258
259
260
261
262
263
264
265
266
267
268
    );
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::THE
(
    const scalarField& h,
    const scalarField& p,
    const scalarField& T0,      // starting temperature
    const labelList& cells
) const
{
    NotImplemented;
269
    return nullptr;
270
271
272
273
274
275
276
277
278
279
280
281
}


Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::THE
(
    const scalarField& h,
    const scalarField& p,
    const scalarField& T0,      // starting temperature
    const label patchi
) const
{
    NotImplemented;
282
    return nullptr;
283
284
285
}


286
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cp() const
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
314
315
316
317
318
319
320
321
322
323
324
{
    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()
    );
}


325
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::rho() const
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

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


344
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::rho
345
346
347
348
349
350
351
352
353
354
355
356
357
(
    const label patchi
) const
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

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

    return
    (
358
        alpha1p*rho1().value() + (scalar(1) - alpha1p)*rho2().value()
359
360
361
362
    );
}


363
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cv() const
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

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


381
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::Cv
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
(
    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()
    );
}


402
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::gamma() const
403
404
405
{
    return tmp<volScalarField>
    (
406
        (alpha1_*Cp1() + alpha2_*Cp2())/(alpha1_*Cv1() + alpha2_*Cv2())
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    );
}


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


425
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::Cpv() const
426
427
428
429
430
431
432
433
434
435
{
     // 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
436
    const label patchi
437
438
) const
{
439
    // This is an e thermo (Cpv = Cv)
Andrew Heather's avatar
Andrew Heather committed
440
    return Cv(p, T, patchi);
441
442
443
}


444
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::CpByCpv() const
445
{
446
447
    NotImplemented;
    return nullptr;
448
449
450
}


451
452
453
454
455
456
457
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::W() const
{
    NotImplemented;
    return nullptr;
}


458
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::CpByCpv
459
460
461
462
463
464
(
    const scalarField& p,
    const scalarField& T,
    const label patchi
) const
{
465
466
    NotImplemented;
    return nullptr;
467
468
469
}


470
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::kappa() const
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

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


488
489
490
491
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::kappa
(
    const label patchi
) const
492
493
494
495
496
497
498
499
500
501
502
503
{
    const volScalarField limitedAlpha1
    (
        min(max(alpha1_, scalar(0)), scalar(1))
    );

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

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


504
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::kappaEff
505
506
507
508
509
510
511
512
513
514
(
    const volScalarField& kappat
) const
{
    tmp<Foam::volScalarField> kappaEff(kappa() + kappat);
    kappaEff.ref().rename("kappaEff");
    return kappaEff;
}


515
Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::kappaEff
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
(
    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;

}


534
Foam::tmp<Foam::volScalarField> Foam::twoPhaseMixtureEThermo::alphaEff
535
536
537
538
539
540
541
542
543
544
545
546
(
    const volScalarField& alphat
) const
{
    const volScalarField rho
    (
        alpha1_*rho1() + (1.0 - alpha1_)*rho2()
    );

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

547
548

Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::alphaEff
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
(
    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;
}

579

580
581
582
583
584
585
586
587
588
589
590
591
592
593
bool Foam::twoPhaseMixtureEThermo::read()
{
    if (basicThermo::read() && thermoIncompressibleTwoPhaseMixture::read())
    {
        basicThermo::lookup("pDivU") >> pDivU_;
        basicThermo::lookup("TSat") >> TSat_;
        return true;
    }
    else
    {
        return false;
    }
}

594

595
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //