/*---------------------------------------------------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | Multiphase Code Repository by HZDR
  ======   //   ||  || ===//   | Website: https://doi.org/10.14278/rodare.767
  ||  ||  //    ||  // || \\   | License: GPL-3.0-or-later
  ==  == ====== ====   ==  ==  |
-------------------------------------------------------------------------------
License
    This file is part of the Multiphase Code Repository by HZDR.

    Copyright (C) 2025 by Helmholtz-Zentrum Dresden-Rossendorf e.V. (HZDR),
    Website: https://hzdr.de

    Multiphase Code Repository by HZDR is based on the free software for
    computational fluid dynamics (CFD) from the OpenFOAM Foundation.
    Copyright (C) 2025 by OpenFOAM Foundation, Website: https://openfoam.org

    If you are interested in which files are original OpenFOAM Foundation
    files, which OpenFOAM Foundation files were modified, and which files were
    newly created, see FILES.md.

    Multiphase Code Repository by HZDR 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.

    Multiphase Code Repository by HZDR 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 the Multiphase Code Repository by HZDR. If not, see
    <http://www.gnu.org/licenses/>.

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

#include "segregatedPhaseInterface.H"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ Begin Code Repository ~~~~~~~~~~~~~~~~~~~~~~~~~//
#include "resolvedInterfaceSystem.H"
#include "fvcGrad.H"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End Code Repository ~~~~~~~~~~~~~~~~~~~~~~~~~~//
#include "addToRunTimeSelectionTable.H"

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

namespace Foam
{
    bool segregatedPhaseInterfaceAddedHeadSeparator =
        phaseInterface::addHeadSeparator(segregatedPhaseInterface::separator());

    bool segregatedPhaseInterfaceAddedOldSeparatorToSeparator =
        phaseInterface::addOldSeparatorToSeparator
        (
            "and",
            segregatedPhaseInterface::separator()
        );
}

namespace Foam
{
    defineTypeNameAndDebugWithName
    (
        segregatedPhaseInterface,
        separatorsToTypeName({separator()}).c_str(),
        0
    );
    addToRunTimeSelectionTable(phaseInterface, segregatedPhaseInterface, word);
}


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

bool Foam::segregatedPhaseInterface::same
(
    const phaseInterface& interface,
    bool strict
) const
{
    return
        (!strict || isType<segregatedPhaseInterface>(interface))
     && phaseInterface::same(interface, false);
}


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

Foam::segregatedPhaseInterface::segregatedPhaseInterface
(
    const phaseModel& phase1,
    const phaseModel& phase2
)
:
    phaseInterface(phase1, phase2)
{}


Foam::segregatedPhaseInterface::segregatedPhaseInterface
(
    const phaseSystem& fluid,
    const word& name
)
:
    phaseInterface(fluid, name)
{}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::segregatedPhaseInterface::~segregatedPhaseInterface()
{}


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

Foam::word Foam::segregatedPhaseInterface::name() const
{
    return phase1().name() + '_' + separator() + '_' + phase2().name();
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~ Begin Code Repository ~~~~~~~~~~~~~~~~~~~~~~~~~//
Foam::tmp<Foam::volScalarField>
Foam::segregatedPhaseInterface::Ai() const
{
    const volScalarField gradPhase1(mag(fvc::grad(phase1())));
    const volScalarField gradPhase2(mag(fvc::grad(phase2())));

    return
        2.0*gradPhase1*gradPhase2/(gradPhase1 + gradPhase2 + fluid().deltaN());
}


Foam::tmp<Foam::volVectorField>
Foam::segregatedPhaseInterface::gradAlpha() const
{
    return fluid().resolvedInterface().gradAlpha(phase1(), phase2());
}


Foam::tmp<Foam::surfaceScalarField>
Foam::segregatedPhaseInterface::gradAlphaf() const
{
    return fluid().resolvedInterface().gradAlphaf(phase1(), phase2());
}


Foam::tmp<Foam::volVectorField>
Foam::segregatedPhaseInterface::nHat() const
{
    return fluid().resolvedInterface().nHat(phase1(), phase2());
}


Foam::tmp<Foam::surfaceVectorField>
Foam::segregatedPhaseInterface::nHatfv() const
{
    return fluid().resolvedInterface().nHatfv(phase1(), phase2());
}


Foam::tmp<Foam::surfaceScalarField>
Foam::segregatedPhaseInterface::nHatf() const
{
    return fluid().resolvedInterface().nHatf(phase1(), phase2());
}


const Foam::volVectorField& Foam::segregatedPhaseInterface::gradAlphaI() const
{
    const phaseInterfaceKey key(phase1(), phase2());

    return fluid().resolvedInterface().gradAlphaI(key);
}


const Foam::volVectorField& Foam::segregatedPhaseInterface::UrI() const
{
    const phaseInterfaceKey key(phase1(), phase2());

    return fluid().resolvedInterface().UrI(key);
}


const Foam::volScalarField& Foam::segregatedPhaseInterface::tauI() const
{
    const phaseInterfaceKey key(phase1(), phase2());

    return fluid().resolvedInterface().tauI(key);
}


Foam::tmp<Foam::volScalarField> Foam::segregatedPhaseInterface::K() const
{
    return fluid().resolvedInterface().K(*this);
}


const Foam::volScalarField&
Foam::segregatedPhaseInterface::underResolution() const
{
    const phaseInterfaceKey key(phase1(), phase2());

    return fluid().resolvedInterface().underResolution(key);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End Code Repository ~~~~~~~~~~~~~~~~~~~~~~~~~~//


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