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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2024-2026 OpenFOAM Foundation
     \\/     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 "wallBoiling.H"

#include "multiphaseEuler.H"

#include "fluidThermophysicalTransportModel.H"

#include "partitioningModel.H"
#include "nucleationSiteModel.H"
#include "departureDiameterModel.H"
#include "departureFrequencyModel.H"

#include "alphatPhaseChangeWallFunctionFvPatchScalarField.H"
#include "alphatJayatillekeWallFunctionFvPatchScalarField.H"
#include "wallBoilingPhaseChangeRateFvPatchScalarField.H"
#include "zeroGradientFvPatchFields.H"

#include "addToRunTimeSelectionTable.H"

/*---------------------------------------------------------------------------*\
                Class wallBoiling::laggedProperties Declaration
\*---------------------------------------------------------------------------*/

struct Foam::fv::wallBoiling::laggedProperties
{
    //- Typedef to shorten the name of the Jayatilleke wall function
    typedef
        compressible::alphatJayatillekeWallFunctionFvPatchScalarField
        alphatJayatillekeWallFunction;

    //- Wall function field
    const wallBoiling& model;

    //- Patch index
    const label patchi;

    //- Liquid volume fraction
    const scalarField& alphaLiquid;

    //- Vapour volume fraction
    const scalarField& alphaVapour;

    //- Liquid thermophysical transport model
    const fluidThermophysicalTransportModel& ttmLiquid;

    //- Vapour thermophysical transport model
    const fluidThermophysicalTransportModel& ttmVapour;

    //- Liquid convective turbulent thermal diffusivity
    const scalarField alphatConvLiquid;

    //- Phase convective turbulent thermal diffusivity
    const scalarField alphatConvVapour;

    //- Patch area by neighbouring cell volume ratio
    const scalarField AbyV;

    //- Liquid density
    private: const tmp<scalarField> trhoLiquid;
    public: const scalarField& rhoLiquid;

    //- Vapour density
    private: const tmp<scalarField> trhoVapour;
    public: const scalarField& rhoVapour;

    //- Liquid heat capacity
    const scalarField& CpLiquid;

    //- Liquid laminar kinematic viscosity
    private: const tmp<scalarField> tnuLiquid;
    public: const scalarField& nuLiquid;

    //- Liquid laminar thermal diffusivity
    const scalarField kappaByCpLiquid;

    //- Liquid viscosity wall function
    const nutWallFunctionFvPatchScalarField& nutLiquid;

    //- Dimensionless wall distance
    const scalarField yPlusLiquid;

    //- Smoothing function
    const scalarField P;

    //- Cell temperature
    const scalarField TcLiquid;

    //- Saturation temperature
    const scalarField Tsat;

    //- Latent heat
    const scalarField L;

    //- Patch
    inline const fvPatch& patch() const
    {
        return model.mesh().boundary()[patchi];
    }

    //- Constructor
    laggedProperties
    (
        const wallBoiling& model,
        const label patchi
    )
    :
        model(model),
        patchi(patchi),
        alphaLiquid(model.liquid_.boundaryField()[patchi]),
        alphaVapour(model.vapour_.boundaryField()[patchi]),
        ttmLiquid
        (
            model.mesh().lookupType<fluidThermophysicalTransportModel>
            (
                model.liquid_.name()
            )
        ),
        ttmVapour
        (
            model.mesh().lookupType<fluidThermophysicalTransportModel>
            (
                model.vapour_.name()
            )
        ),
        alphatConvLiquid
        (
            alphatJayatillekeWallFunction::alphat(ttmLiquid, model.Prt_, patchi)
        ),
        alphatConvVapour
        (
            alphatJayatillekeWallFunction::alphat(ttmVapour, model.Prt_, patchi)
        ),
        AbyV
        (
            patch().magSf()
           /scalarField
            (
                patch().mesh().V(),
                patch().faceCells()
            )
        ),
        trhoLiquid(model.liquid_.thermo().rho(patchi)),
        rhoLiquid(trhoLiquid()),
        trhoVapour(model.vapour_.thermo().rho(patchi)),
        rhoVapour(trhoVapour()),
        CpLiquid(model.liquid_.thermo().Cp().boundaryField()[patchi]),
        tnuLiquid(model.liquid_.fluidThermo().nu(patchi)),
        nuLiquid(tnuLiquid()),
        kappaByCpLiquid
        (
            model.liquid_.thermo().kappa().boundaryField()[patchi]/CpLiquid
        ),
        nutLiquid
        (
            nutWallFunctionFvPatchScalarField::nutw
            (
                ttmLiquid.momentumTransport(),
                patchi
            )
        ),
        yPlusLiquid
        (
            pow025(nutLiquid.Cmu())
           *sqrt(ttmLiquid.momentumTransport().k()().boundaryField()[patchi])
           *ttmLiquid.momentumTransport().yb()[patchi]
           /nuLiquid
        ),
        P
        (
            alphatJayatillekeWallFunction::P
            (
                rhoLiquid*nuLiquid/kappaByCpLiquid/model.Prt_
            )
        ),
        TcLiquid
        (
            model.liquid_.thermo().T().boundaryField()[patchi]
           .patchInternalField()
        ),
        Tsat
        (
            model.Tsat_->value
            (
                model.liquid_.fluidThermo().p().boundaryField()[patchi]
            )
        ),
        L
        (
            model.L
            (
                patchi,
                model.liquid_.thermo().T().boundaryField()[patchi]
            )
        )
    {}
};


// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //

namespace Foam
{
namespace fv
{
    defineTypeNameAndDebug(wallBoiling, 0);
    addToRunTimeSelectionTable(fvModel, wallBoiling, dictionary);
}
}


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

void Foam::fv::wallBoiling::readCoeffs(const dictionary& dict)
{
    reReadSpecie(dict);

    Tsat_.reset
    (
        Function1<scalar>::New
        (
            "saturationTemperature",
            {dimPressure, dimTemperature},
            dict
        ).ptr()
    );

    partitioningModel_.reset
    (
        wallBoilingModels::partitioningModel::New
        (
            dict.subDict("partitioningModel")
        ).ptr()
    );

    nucleationSiteModel_.reset
    (
        wallBoilingModels::nucleationSiteModel::New
        (
            dict.subDict("nucleationSiteModel")
        ).ptr()
    );

    departureDiameterModel_.reset
    (
        wallBoilingModels::departureDiameterModel::New
        (
            dict.subDict("departureDiameterModel")
        ).ptr()
    );

    departureFrequencyModel_.reset
    (
        wallBoilingModels::departureFrequencyModel::New
        (
            dict.subDict("departureFrequencyModel")
        ).ptr()
    );

    tolerance_ =
        dict.lookupOrDefault<scalar>("tolerance", units::unitless, rootSmall);

    liquidTemperatureWallFunction_ =
        dict.lookupOrDefault<Switch>("useLiquidTemperatureWallFunction", true);

    Prt_ = dict.lookupOrDefault<scalar>("Prt", dimless, 0.85);

    bubbleWaitingTimeRatio_ =
        dict.lookupOrDefault<scalar>("bubbleWaitingTimeRatio", dimless, 0.8);
}


const Foam::fvPatchScalarField&
Foam::fv::wallBoiling::getLiquidTemperaturePatchField
(
    const laggedProperties& lagProps,
    scalarField& isFixed,
    scalarField& h,
    scalarField& hTaPlusQa
) const
{
    isFixed.setSize(lagProps.patch().size());
    h.setSize(lagProps.patch().size());
    hTaPlusQa.setSize(lagProps.patch().size());

    const fvPatchScalarField& T =
        liquid_.thermo().T().boundaryField()[lagProps.patchi];

    const fvPatchScalarField& alphat =
        alphatLiquid_.boundaryField()[lagProps.patchi];

    if (isA<fixedValueFvPatchScalarField>(T))
    {
        isFixed = 1;
        h = rootVGreat;
        hTaPlusQa = rootVGreat*T;
    }
    else if (isA<zeroGradientFvPatchScalarField>(T))
    {
        isFixed = 0;
        h = 0;
        hTaPlusQa = 0;
    }
    else if (isA<fixedGradientFvPatchScalarField>(T))
    {
        const fixedGradientFvPatchScalarField& Tfg =
            refCast<const fixedGradientFvPatchScalarField>(T);

        isFixed = 0;
        h = 0;
        hTaPlusQa = alphat*lagProps.CpLiquid*Tfg.gradient();
    }
    else if (isA<mixedFvPatchScalarField>(T))
    {
        const mixedFvPatchScalarField& Tm =
            refCast<const mixedFvPatchScalarField>(T);

        isFixed = pos(Tm.valueFraction() - 1 + rootSmall);
        h =
            Tm.valueFraction()
           /max(1 - Tm.valueFraction(), rootVSmall)
           *alphat
           *lagProps.CpLiquid
           *lagProps.patch().deltaCoeffs();
        hTaPlusQa =
            h*Tm.refValue()
          + alphat*lagProps.CpLiquid*Tm.refGrad();
    }
    else
    {
        FatalErrorInFunction
            << "Temperature boundary condition type not recognised"
            << exit(FatalError);
    }

    return T;
}


Foam::tmp<Foam::scalarField> Foam::fv::wallBoiling::calcBoiling
(
    const laggedProperties& lagProps,
    const scalarField& TLiquid,
    const scalarField& wetFraction,
    scalarField& dDeparture,
    scalarField& fDeparture,
    scalarField& nucleationSiteDensity,
    scalarField& qQuenching,
    scalarField& qEvaporative,
    scalarField& mDot
) const
{
    using constant::mathematical::pi;

    scalarField Tl;
    if (!liquidTemperatureWallFunction_)
    {
        Tl = lagProps.TcLiquid;
    }
    else
    {
        // Liquid temperature at y+=250 is estimated from the logarithmic
        // thermal wall function of Koncar, Krepper & Egorov (2005)
        const scalarField TyPlus250
        (
            Prt_
           *(
                log(lagProps.nutLiquid.E()*250)
               /lagProps.nutLiquid.kappa()
              + lagProps.P
           )
        );

        const scalarField TyPlus
        (
            Prt_
           *(
                log
                (
                    lagProps.nutLiquid.E()
                   *max(lagProps.yPlusLiquid, scalar(11))
                )
               /lagProps.nutLiquid.kappa()
              + lagProps.P
            )
        );

        Tl = TLiquid - (TyPlus250/TyPlus)*(TLiquid - lagProps.TcLiquid);
    }

    // Bubble departure diameter
    dDeparture =
        departureDiameterModel_->dDeparture
        (
            liquid_,
            vapour_,
            lagProps.patchi,
            Tl,
            lagProps.Tsat,
            lagProps.L
        );

    // Bubble departure frequency
    fDeparture =
        departureFrequencyModel_->fDeparture
        (
            liquid_,
            vapour_,
            lagProps.patchi,
            Tl,
            lagProps.Tsat,
            lagProps.L,
            dDeparture
        );

    // Nucleation site density
    nucleationSiteDensity =
        nucleationSiteModel_->nucleationSiteDensity
        (
            liquid_,
            vapour_,
            lagProps.patchi,
            Tl,
            lagProps.Tsat,
            lagProps.L,
            dDeparture,
            fDeparture
        );

    // Del Valle & Kenning (1985)
    const scalarField Ja
    (
        lagProps.rhoLiquid
       *lagProps.CpLiquid
       *max(lagProps.Tsat - Tl, scalar(0))
       /(lagProps.rhoVapour*lagProps.L)
    );

    const scalarField Al
    (
        wetFraction*4.8*exp(min(-Ja/80, log(vGreat)))
    );

    scalarField A2
    (
        min(pi*sqr(dDeparture)*nucleationSiteDensity*Al/4, scalar(1))
    );
    const scalarField A1(max(1 - A2, scalar(1e-4)));
    scalarField A2E
    (
        min(pi*sqr(dDeparture)*nucleationSiteDensity*Al/4, scalar(5))
    );

    // Volumetric mass source in the near wall cell due to the
    // wall boiling
    mDot = (1.0/6.0)*A2E*dDeparture*lagProps.rhoVapour*fDeparture*lagProps.AbyV;

    // Quenching heat transfer coefficient
    const scalarField hQ
    (
        2*lagProps.kappaByCpLiquid*lagProps.CpLiquid*fDeparture
       *sqrt
        (
            bubbleWaitingTimeRatio_
           /max(fDeparture, small)
           /(pi*lagProps.kappaByCpLiquid/lagProps.rhoLiquid)
        )
    );

    // Quenching heat flux
    qQuenching = A2*hQ*max(TLiquid - Tl, scalar(0));

    // Evaporation heat flux
    qEvaporative = mDot*lagProps.L/lagProps.AbyV;

    // Return total sum of convective, quenching and evaporative heat fluxes
    const scalarField gradT
    (
        lagProps.patch().deltaCoeffs()
       *max(TLiquid - lagProps.TcLiquid, small*lagProps.TcLiquid)
    );
    return
        A1*lagProps.alphatConvLiquid*lagProps.CpLiquid*gradT
      + qQuenching
      + qEvaporative;
}


Foam::tmp<Foam::scalarField> Foam::fv::wallBoiling::calcBoiling
(
    const wallBoilingPhaseChangeRateFvPatchScalarField& mDot,
    const laggedProperties& lagProps,
    const scalarField& TLiquid
) const
{
    scalarField dDeparture(mDot.dDeparture_);
    scalarField fDeparture(mDot.fDeparture_);
    scalarField nucleationSiteDensity(mDot.nucleationSiteDensity_);
    scalarField qQuenching(mDot.qQuenching_);
    scalarField qEvaporative(mDot.qEvaporative_);
    scalarField mDotCopy(mDot);

    return
        calcBoiling
        (
            lagProps,
            TLiquid,
            mDot.wetFraction_,
            dDeparture,
            fDeparture,
            nucleationSiteDensity,
            qQuenching,
            qEvaporative,
            mDotCopy
        );
}


Foam::tmp<Foam::scalarField> Foam::fv::wallBoiling::evaluateBoiling
(
    wallBoilingPhaseChangeRateFvPatchScalarField& mDot,
    const laggedProperties& lagProps,
    const scalarField& TLiquid
) const
{
    return
        calcBoiling
        (
            lagProps,
            TLiquid,
            mDot.wetFraction_,
            mDot.dDeparture_,
            mDot.fDeparture_,
            mDot.nucleationSiteDensity_,
            mDot.qQuenching_,
            mDot.qEvaporative_,
            mDot
        );
}


void Foam::fv::wallBoiling::correctMDot() const
{
    Info<< type() << ": " << name() << endl << incrIndent;

    //- Reset the phase-change rates in all the near-wall cells
    forAll(mDot_.boundaryField(), patchi)
    {
        if (!isPatchActive(patchi)) continue;

        const labelUList& faceCells = mesh().boundary()[patchi].faceCells();
        forAll(faceCells, i)
        {
            mDot_[faceCells[i]] = scalar(0);
        }
    }

    // Loop the boiling patches, evaluate the model, and sum the phase change
    // rates into the adjacent cells
    forAll(mDot_.boundaryField(), patchi)
    {
        if (!isPatchActive(patchi)) continue;

        // Access the wall-boiling phase-change patch field for this patch
        wallBoilingPhaseChangeRateFvPatchScalarField& mDot = mDotPfRef(patchi);

        // Construct lagged properties
        const laggedProperties lagProps(*this, patchi);

        // Evaluate the wetted fraction
        mDot.wetFraction_ =
            partitioningModel_->wetFraction(lagProps.alphaLiquid);

        // Set the vapour turbulent thermal diffusivity
        mDot.alphatVapour_ =
            (1 - mDot.wetFraction_)
           /max(1 - lagProps.alphaLiquid, rootSmall)
           *lagProps.alphatConvVapour;

        // Get the temperature boundary condition and extract its
        // physical parameters
        scalarField TLiquidIsFixed, TLiquidH, TLiquidHTaPlusQa;
        const fvPatchScalarField& TLiquid =
            getLiquidTemperaturePatchField
            (
                lagProps,
                TLiquidIsFixed,
                TLiquidH,
                TLiquidHTaPlusQa
            );

        // Define the residual. This should be monotonic in T.
        auto R = [&](const scalarField& T)
        {
            return
                calcBoiling(mDot, lagProps, T)
              - TLiquidHTaPlusQa
              + TLiquidH*T;
        };

        // Solve using interval bisection. Boiling cannot occur below the
        // saturation temperature, so that is taken to be the lower bound. The
        // upper bound is harder to define. For now, take twice the current
        // superheat as the maximum. The solution is likely to be below this
        // value. If it is not, then the iteration will converge to this upper
        // limit, creating a new superheat of twice the current value.
        // Subsequent time-steps will then double this superheat again and
        // again until it does eventually bound the solution.
        mDot.boiling_ = neg(R(lagProps.Tsat));
        scalarField T0(lagProps.Tsat);
        scalarField T1
        (
            max
            (
                TLiquid + (TLiquid - lagProps.Tsat),
                lagProps.Tsat*(1 + sqrt(tolerance_))
            )
        );
        scalar e =
            gMax((1 - TLiquidIsFixed)*mDot.boiling_*(T1 - T0)/(T0 + T1));
        for (; e > tolerance_; e /= 2)
        {
            const scalarField Tm((T0 + T1)/2);
            const scalarField rM(R(Tm));
            T0 = pos(rM)*T0 + neg0(rM)*Tm;
            T1 = pos(rM)*Tm + neg0(rM)*T1;
        }
        const scalarField T
        (
            TLiquidIsFixed*TLiquid + (1 - TLiquidIsFixed)*(T0 + T1)/2
        );

        // Use solution to re-evaluate the boiling and set the thermal
        // diffusivity to recover the calculated heat flux
        const scalarField gradT
        (
            lagProps.patch().deltaCoeffs()
           *max(T - lagProps.TcLiquid, small*lagProps.TcLiquid)
        );

        const scalarField q(evaluateBoiling(mDot, lagProps, T));

        const scalarField alphatBoilingLiquid
        (
            q/lagProps.CpLiquid/gradT/max(lagProps.alphaLiquid, rootSmall)
        );

        mDot.alphatLiquid_=
            mDot.boiling_*alphatBoilingLiquid
          + (1 - mDot.boiling_)*lagProps.alphatConvLiquid;
        infoField
        (
            word("mDot[", mesh().boundary()[patchi].name(), "]"),
            dimensions::density/dimensions::time,
            mDot
        );

        // Sum the phase change rate into the internal field
        const labelUList& faceCells = mesh().boundary()[patchi].faceCells();
        forAll(faceCells, i)
        {
            mDot_[faceCells[i]] += mDot[i];
        }
    }

    Info<< decrIndent;
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::fv::wallBoiling::wallBoiling
(
    const word& name,
    const word& modelType,
    const fvMesh& mesh,
    const dictionary& dict
)
:
    wallPhaseChange
    (
        name,
        modelType,
        mesh,
        dict,
        readSpecie(coeffs(modelType, dict), false)
    ),
    nucleation(),
    liquid_(phases().first()),
    vapour_(phases().second()),
    alphatLiquid_(wallPhaseChange::alphats().first()),
    alphatVapour_(wallPhaseChange::alphats().second()),
    p_rgh_
    (
        mesh().lookupObject<solvers::multiphaseEuler>(solver::typeName).p_rgh
    ),
    tolerance_(NaN),
    liquidTemperatureWallFunction_(true),
    Prt_(NaN),
    bubbleWaitingTimeRatio_(NaN),
    Tsat_(nullptr),
    partitioningModel_(nullptr),
    nucleationSiteModel_(nullptr),
    departureDiameterModel_(nullptr),
    departureFrequencyModel_(nullptr),
    pressureEquationIndex_(-1),
    mDot_
    (
        IOobject
        (
            name + ":mDot",
            mesh.time().name(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar(dimensions::density/dimensions::time, scalar(0)),
        mDotBoundaryTypes
        (
            wallBoilingPhaseChangeRateFvPatchScalarField::typeName
        )
    )
{
    readCoeffs(coeffs(dict));
}


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

const Foam::scalarField& Foam::fv::wallBoiling::active
(
    const label patchi
) const
{
    return mDotPfRef(patchi).boiling_;
}


Foam::Pair<const Foam::scalarField&> Foam::fv::wallBoiling::alphats
(
    const label patchi
) const
{
    return
        Pair<const Foam::scalarField&>
        (
            mDotPfRef(patchi).alphatLiquid_,
            mDotPfRef(patchi).alphatVapour_
        );
}


Foam::tmp<Foam::volInternalScalarField>
Foam::fv::wallBoiling::Lfraction() const
{
    // Put all the latent heat into the liquid
    return
        volInternalScalarField::New
        (
            name() + ":Lfraction",
            mesh(),
            dimensionedScalar(dimless, scalar(0))
        );
}


Foam::tmp<Foam::volInternalScalarField>
Foam::fv::wallBoiling::d() const
{
    tmp<volScalarField> tdVapour = vapour_.d();
    const volInternalScalarField& dVapour = tdVapour();

    const volInternalScalarField mask
    (
        neg
        (
            mag(mDot_())
          - dimensionedScalar(dimensions::density/dimensions::time, rootVSmall)
        )
    );

    tmp<volInternalScalarField> td =
        volInternalScalarField::New(name() + ":d", mask*dVapour);
    volInternalScalarField& d = td.ref();

    forAll(mDot_.boundaryField(), patchi)
    {
        if (!isPatchActive(patchi)) continue;

        // Access the wall-boiling phase-change patch field for this patch
        const wallBoilingPhaseChangeRateFvPatchScalarField& mDot =
            mDotPf(patchi);

        // Average the diameter into the internal field
        const labelUList& faceCells = mesh().boundary()[patchi].faceCells();
        forAll(faceCells, i)
        {
            if (mask[faceCells[i]]) continue;

            d[faceCells[i]] += mDot.dDeparture_[i]*mDot[i]/mDot_[faceCells[i]];
        }
    }

    return td;
}


Foam::tmp<Foam::volInternalScalarField>
Foam::fv::wallBoiling::nDot() const
{
    tmp<volInternalScalarField> tnDot =
        volInternalScalarField::New
        (
            name() + ":nDot",
            mesh(),
            dimensionedScalar(inv(dimensions::time), scalar(0))
        );
    volInternalScalarField& nDot = tnDot.ref();

    forAll(mDot_.boundaryField(), patchi)
    {
        if (!isPatchActive(patchi)) continue;

        // Access the wall-boiling phase-change patch field for this patch
        const wallBoilingPhaseChangeRateFvPatchScalarField& mDot =
            mDotPf(patchi);

        // Sum the frequency into the internal field
        const labelUList& faceCells = mesh().boundary()[patchi].faceCells();
        forAll(faceCells, i)
        {
            nDot[faceCells[i]] += mDot.fDeparture_[i];
        }
    }

    return tnDot;
}


Foam::tmp<Foam::volInternalScalarField>
Foam::fv::wallBoiling::tau() const
{
    NotImplemented;
    return tmp<volInternalScalarField>(nullptr);
}


Foam::tmp<Foam::volInternalScalarField>
Foam::fv::wallBoiling::mDot() const
{
    return mDot_.internalField();
}


const Foam::wallBoilingPhaseChangeRateFvPatchScalarField&
Foam::fv::wallBoiling::mDotPf(const label patchi) const
{
    if (!isPatchActive(patchi))
    {
        FatalErrorInFunction
            << "Patch " << mesh().boundary()[patchi].name()
            << " is not boiling" << exit(FatalError);
    }

    return
        refCast<const wallBoilingPhaseChangeRateFvPatchScalarField>
        (
            mDot_.boundaryField()[patchi]
        );
}


Foam::wallBoilingPhaseChangeRateFvPatchScalarField&
Foam::fv::wallBoiling::mDotPfRef(const label patchi) const
{
    if (!isPatchActive(patchi))
    {
        FatalErrorInFunction
            << "Patch " << mesh().boundary()[patchi].name()
            << " is not boiling" << exit(FatalError);
    }

    return
        refCast<wallBoilingPhaseChangeRateFvPatchScalarField>
        (
            mDot_.boundaryFieldRef()[patchi]
        );
}


void Foam::fv::wallBoiling::addSup
(
    const volScalarField& alpha,
    const volScalarField& rho,
    fvMatrix<scalar>& eqn
) const
{
    // Pressure equation (i.e., continuity, linearised in the pressure)
    if
    (
        (&alpha == &liquid_ || &alpha == &vapour_)
     && (&rho == &liquid_.rho() || &rho == &vapour_.rho())
     && &eqn.psi() == &p_rgh_
    )
    {
        // Ensure that the source is up-to date if this is the first call in
        // the current phase loop
        if (pressureEquationIndex_ % 2 == 0) correctMDot();
        pressureEquationIndex_ ++;
    }

    // Let the base class add the actual source
    massTransfer::addSup(alpha, rho, eqn);
}


void Foam::fv::wallBoiling::correct()
{
    // Reset the p_rgh equation solution counter
    pressureEquationIndex_ = 0;

    // Correct the total phase change rate
    correctMDot();
}


bool Foam::fv::wallBoiling::read(const dictionary& dict)
{
    if (phaseChange::read(dict))
    {
        readCoeffs(coeffs(dict));
        return true;
    }
    else
    {
        return false;
    }
}


// ************************************************************************* //