CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Adding transonic option to compressibleMultiphaseInterFoam

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 5, 2024, 09:10
Default Adding transonic option to compressibleMultiphaseInterFoam
  #1
New Member
 
Nicoḷ Badodi
Join Date: Mar 2020
Posts: 19
Rep Power: 6
NBad is on a distinguished road
Hi everyone!

I am trying to simulate the high pressure injection of water into a vessel full of molten metal. My end goal would be to implement both phase change and a sonic model to simulate flashing of water when it its injected into the vessel. To do so, I am modyfying compressibleMultiphaseInterFoam (OF2212) to handle the sonic condition and phase change.

To achieve this, since I am no master of C++ I just looked into compressibleInterFoam and built from there.

I run into trouble when trying to implement the sonic condition into compressibleMultiphaseInterFoam. To do so, I added a branch in the code that modifies the pressure equation utilizing the one implemented into compressibleInterFoam.

What I came up with is the following pEqn:

Code:
{
    volScalarField rAU("rAU", 1.0/UEqn.A());
    surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU));
    volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh));
    surfaceScalarField phiHbyA
    (
        "phiHbyA",
        fvc::flux(HbyA)
        + fvc::interpolate(rho*rAU)*fvc::ddtCorr(U, phi)
    //    + fvc::interpolate(rho*rAU)*fvc::ddtCorr(U, Uf)              //
    );

    surfaceScalarField phig
    (
        (
            mixture.surfaceTensionForce()
          - ghf*fvc::snGrad(rho)
        )*rAUf*mesh.magSf()
    );

    phiHbyA += phig;

    // Update the pressure BCs to ensure flux consistency
    constrainPressure(p_rgh, U, phiHbyA, rAUf);

    // Make the fluxes relative to the mesh motion                                      //
    fvc::makeRelative(phiHbyA, U);                                                      //

    PtrList<fvScalarMatrix> p_rghEqnComps(mixture.phases().size());

    label phasei = 0;                                                                   //
    if (pimple.transonic())
    {
        Info<< "Transonic equation construction" << endl;
        phasei = 0; 
        forAllConstIters(mixture.phases(), phase)
        {
            const rhoThermo& thermo = phase().thermo();
            const volScalarField& rho = thermo.rho()();

            surfaceScalarField phid("phid", fvc::interpolate(thermo.psi())*phi);
            surfaceScalarField rhof(fvc::interpolate(rho));  
            surfaceScalarField alphaPhi(phi*fvc::interpolate(phase()));
            
            p_rghEqnComps.set
            (
                phasei,
                (
                    pos(phase())
                    *(
                        (
                            fvc::ddt(phase(), rho) + fvc::div(alphaPhi*rhof)
                        )/rho
                        - fvc::ddt(phase()) - fvc::div(alphaPhi)
                        + (phase()/rho)
                        *correction
                        (
                            thermo.psi()*fvm::ddt(p_rgh)
                            + fvm::div(phid, p_rgh) - fvm::Sp(fvc::div(phid), p_rgh)
                        )
                    )
                ).ptr()
            );

            ++phasei;
        }
    }
    else
    {
        Info<< "Subsonic equation construction" << endl;
        phasei = 0; 
        forAllConstIters(mixture.phases(), phase)
        {
            const rhoThermo& thermo = phase().thermo();
            const volScalarField& rho = thermo.rho()();

            p_rghEqnComps.set
            (
                phasei,
                (
                    fvc::ddt(rho) + thermo.psi()*correction(fvm::ddt(p_rgh))
                    + fvc::div(phi, rho) - fvc::Sp(fvc::div(phi), rho)
                ).ptr()
            );

            ++phasei;
        }
    }
    // Cache p_rgh prior to solve for density update
    volScalarField p_rgh_0(p_rgh);

    while (pimple.correctNonOrthogonal())
    {
        Info<< "Incompressible matrix creation" << endl;
        fvScalarMatrix p_rghEqnIncomp
        (
            fvc::div(phiHbyA)
          - fvm::laplacian(rAUf, p_rgh)
        );

        tmp<fvScalarMatrix> p_rghEqnComp;

        phasei = 0;
        Info<< "Compressible matrix creation" << endl;
        forAllConstIters(mixture.phases(), phase)
        {
            tmp<fvScalarMatrix> hmm
            (
                (max(phase(), scalar(0))/phase().thermo().rho())
               *p_rghEqnComps[phasei]
            );

            if (phasei == 0)
            {
                Info<< "Base matrix" << endl;
                p_rghEqnComp = hmm;
            }
            else
            {
                Info<< "Other phases" << endl;
                p_rghEqnComp.ref() += hmm;
            }

            ++phasei;
        }
        
        Info<< "Solving the equations" << endl;
        solve
        (
            p_rghEqnComp
          + p_rghEqnIncomp,
            mesh.solver(p_rgh.select(pimple.finalInnerIter()))
        );

        Info<< "Final nonortho iteration" << endl;
        if (pimple.finalNonOrthogonalIter())
        {
            phasei = 0;
            for (phaseModel& phase : mixture.phases())
            {
                phase.dgdt() =
                    pos0(phase)
                  *(p_rghEqnComps[phasei] & p_rgh)/phase.thermo().rho();

                ++phasei;
            }

            phi = phiHbyA + p_rghEqnIncomp.flux();

            U = HbyA
              + rAU*fvc::reconstruct((phig + p_rghEqnIncomp.flux())/rAUf);
            U.correctBoundaryConditions();
        }
    }

    {                                                                               //
        Uf = fvc::interpolate(U);                                                   //
        surfaceVectorField n(mesh.Sf()/mesh.magSf());                               //
        Uf += n*(fvc::absolute(phi, U)/mesh.magSf() - (n & Uf));                    //
    }                                                                               //

    p = max(p_rgh + mixture.rho()*gh, pMin);

    // Update densities from change in p_rgh
    mixture.correctRho(p_rgh - p_rgh_0);
    rho = mixture.rho();

    // Correct p_rgh for consistency with p and the updated densities
    p_rgh = p - rho*gh;
    p_rgh.correctBoundaryConditions();

    K = 0.5*magSqr(U);

    Info<< "max(U) " << max(mag(U)).value() << endl;
    Info<< "min(p_rgh) " << min(p_rgh).value() << endl;
}
the structure of the equation is equal to the one implemented in compressibleInterFoam, modified to utilize the field of multiphaseCompressibleInterFoam. The non-sonic branch was left untouched and it works fine.

When executing the sonic branch instead, the solver is able to create the equation set, however, when building the matrices I get the error:

Code:
[3] --> FOAM FATAL ERROR: (openfoam-2212 patch=230612)
[3] Incompatible dimensions for operation
    [p_rgh[-1 3 -1 0 0 0 0] ] + [p_rgh[0 0 -1 0 0 0 0] ]
[3] 
[3]     From void Foam::checkMethod(const Foam::fvMatrix<Type>&, const Foam::fvMatrix<Type>&, const char*) [with Type = double]
[3]     in file /usr/lib/openfoam/openfoam2212/src/finiteVolume/lnInclude/fvMatrix.C at line 1915.
[3] 
FOAM parallel run aborting
I am aware that probably the error is caused by the term
Code:
- fvc::ddt(phase()) - fvc::div(alphaPhi)
, but after many hours of tests I can't really figure it out.

Any help would be appreciated!
NBad is offline   Reply With Quote

Old   September 6, 2024, 02:51
Default Solved
  #2
New Member
 
Nicoḷ Badodi
Join Date: Mar 2020
Posts: 19
Rep Power: 6
NBad is on a distinguished road
I had just implemented the equation wrong, the right one is:

Code:
                    fvc::ddt(rho) + 
                    correction
                    (
                        thermo.psi()*fvm::ddt(p_rgh) 
                        + fvm::div(phid, p_rgh) 
                        - fvc::Sp(fvc::div(phi), rho)
                    )
                    + fvc::div(phi, rho)
NBad is offline   Reply With Quote

Reply

Tags
compressible, multiphase, transonic


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the height of the stream in the free channel kevinmccartin CFX 12 October 13, 2022 22:43
Domain Reference Pressure and mass flow inlet boundary AdidaKK CFX 75 August 20, 2018 06:37
Simulation of a single bubble with a VOF-method Suzzn CFX 21 January 29, 2018 01:58
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 08:00
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 13:02


All times are GMT -4. The time now is 21:39.