Skip to content

PC-SAFT quadrupolar with zero composition producing NaN #182

@svenpohl1991

Description

@svenpohl1991

Hey everyone,

When calling a PC-SAFT mixture with a quadrupolar component and calling the quadrupolar component with molefrac[i] = 0.0
the alphar function returns "NaN".

The causes lies in:

auto eval(const TTYPE& T, const RhoType& rho_A3, const EtaType& eta, const VecType& mole_fractions) const {
    auto alpha2 = get_alpha2QQ(T, rho_A3, eta, mole_fractions);
    auto alpha3 = get_alpha3QQ(T, rho_A3, eta, mole_fractions);
    -   auto alpha = forceeval(alpha2/(1.0-alpha3/alpha2)); // <-- problematic line
   +   auto alpha = (alpha2 == 0.0) ? 0.0 : forceeval(alpha2/(1.0 - alpha3/alpha2)); <-- suggested fix
    using alpha2_t = decltype(alpha2);
    using alpha3_t = decltype(alpha3);
    using alpha_t = decltype(alpha);
    struct QuadrupolarContributionTerms{
        alpha2_t alpha2;
        alpha3_t alpha3;
        alpha_t alpha;
    };
    return QuadrupolarContributionTerms{alpha2, alpha3, alpha};
}

If alpha2 and alpha3 are zero, we need the ternary to return just zero.

Sven

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions