Skip to content

pressure functionObject in v1906 does not calculate total pressure coefficient (fix attached)

In v1906, the pressure function object uses a new "mode" specification. The documentation is not up yet, but from the source code it looks like the options are: static, total, isentropic, staticCoeff, totalCoeff.

The block of code below correctly handles the difference between static and total pressure, and when I calculate these, the values are correct.

However, when the mode is totalCoeff or staticCoeff, the output of both is the same: staticCoeff (i.e., the default in the switch below). I think the switch needs some kind of "startswith" logic.

To fix this, I have replaced this switch case with an if statement similar to the one used for the coeff logic and resultName logic. After compiling and running, I am getting proper values for totalCoeff. I've attached the modified file.

pressure.C

Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::calcPressure
(
    const volScalarField& p,
    const tmp<volScalarField>& tp
) const
{
    switch (mode_)
    {
        case TOTAL:
        {
            return
                tp
              + dimensionedScalar("pRef", dimPressure, pRef_)
              + rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
        }
        case ISENTROPIC:
        {
            const basicThermo* thermoPtr =
                p.mesh().lookupObjectPtr<basicThermo>(basicThermo::dictName);

            if (!thermoPtr)
            {
                FatalErrorInFunction
                    << "Isentropic pressure calculation requires a "
                    << "thermodynamics package"
                    << exit(FatalError);
            }

            const volScalarField gamma(thermoPtr->gamma());
            const volScalarField Mb
            (
                mag(lookupObject<volVectorField>(UName_))
               /sqrt(gamma*tp.ref()/thermoPtr->rho())
            );

            return tp()*(pow(1 + (gamma - 1)/2*sqr(Mb), gamma/(gamma - 1)));
        }
        default:
        {
            return
                tp
              + dimensionedScalar("pRef", dimPressure, pRef_);
        }
    }
}
Edited by Aaron