CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Error arising from Energy Equation (https://www.cfd-online.com/Forums/openfoam-programming-development/183869-error-arising-energy-equation.html)

faab February 15, 2017 13:15

Error arising from Energy Equation
 
Dear FOAMers,

I have posted this in the section dedicated to Running, Solving and CFD, however as I am not getting any answer I imagine maybe this was the wrong forum to address.

I am actually working on a compressible solver (density based) that I created using the pre-existing chtMultiRegionFoam solver. As stated in the title, I get (see hereunder) an error when solving for the following energy equation:
fvScalarMatrix EEqn
(
fvm::ddt(rho, he) + fvm::div(phi, he)
+ fvc::ddt(rho, K) + fvc::div(phi, K)
==
fvm::laplacian(kEff, T)
+ HS
);
HS is just a volumetric source term, and kEff is the effective conductivity.
he is the internal energy (I compute it using an external Fortran code)
while K is set as being: const volScalarField& K = 0.5 * (U & U);

#0 Foam::error: rintStack(Foam::Ostream&) at ??:?
#1 Foam::sigSegv::sigHandler(int) at ??:?
#2
at sigaction.c:?
#3 memcpy at interp.c:?
#4 std::string::append(std::string const&) in "/home/faabid/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.1/lib64/libstdc++.so.6"
#5 std::basic_string<char, std::char_traits<char>, std::allocator<char> > std: perator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) at ~/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.1/include/c++/4.8.1/bits/basic_string.h:2370
#6
at ~/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvcDiv.C:240 (discriminator 2)
#7
at ~/OpenFOAM/OpenFOAM-2.3.0/applications/solvers/heatTransfer/CompressibleHeSolver/./fluid/EEqn.H:24 (discriminator 1)
#8 __libc_start_main at ??:?
#9
at ??:?
Segmentation fault (core dumped)

Where fluid/EEqn.H:24 corresponds to:
+ fvc::ddt(rho, K) + fvc::div(phi, K)
I also remind that K is set to: const volScalarField& K = 0.5*magSqr(U);

Could anyone please help me ??

Thank you !!

alexeym February 15, 2017 16:46

Hi,

Why K is const reference (why not create just a copy of 0.5*(U & U) using constructor from tmp as volScalarField K(0.5*(U & U))? Are you sure, object it is referencing is not destroyed before construction of energy equation?

faab February 16, 2017 09:23

Hi Alexey,

First of all, thank you very much for your attention and help!
I did modified the way I construct and call K and you were right to point this out because the error seems now corrected. However, I am getting an error from the energy term "he" and it is the following:

Code:

FOAM FATAL ERROR:

    valueInternalCoeffs cannot be called for a calculatedFvPatchField
    on patch outsidewalls of field he in file "/home/faabid/OpenFOAM/faabid_cases/testCase/mine/CompressibleSolver/0/hell_channel/he"
    You are probably trying to solve for a field with a default boundary condition.

    From function calculatedFvPatchField<Type>::valueInternalCoeffs(const tmp<scalarField>&) const
    in file fields/fvPatchFields/basic/calculated/calculatedFvPatchField.C at line 154.

FOAM exiting

The "he" term is defined in my code as:

Code:

volScalarField& he = heFluids[i];
heFluids.set
        (
            i,
            new volScalarField
            (
                IOobject
                (
                    "he",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                fluidRegions[i],
                dimensionedScalar
                (
                    "he",
                    dimensionSet(1,2,-2,0,0,0,0),
                    scalar(1990.4)
                )
            )
        );

And computed using an external Fortran code, from the thermodynamic properties rho, T and P at every time step. Also in the fvSchemes dictionnary I defined:

Code:

divSchemes
{
    default        none;

    div(phi,U)      Gauss upwind;
    div(rho,he)      Gauss upwind;
    div(phi,he)      Gauss upwind;
    //div((p*U))        Gauss linear;
    div(phi,(0.5*magSqr(U)))      Gauss linear;
    grad(T)            Gauss linear;
}

And he is itself defined in the initial folder 0/ as:
Code:

dimensions      [1 2 -2 0 0 0 0];

internalField  uniform 1990.4;

boundaryField
{
    FrontAndBack
    {
        type            empty;
    }
    outsidewalls
    {
        type            gradientEnergy;
        gradient        uniform 0;
    }
    hell_channel_to_solid2
    {
        type            mixedEnergy;
        refValue        uniform 0;
        refGradient    uniform 0;
        valueFraction  uniform 0;
        value          $internalField;
    }
    hell_channel_to_solid1
    {
        type            mixedEnergy;
        refValue        uniform 0;
        refGradient    uniform 0;
        valueFraction  uniform 0;
        value          $internalField;
    }
}

Would you or anyone have a suggestion to get past this error ?
Once again thank you for your time and support, it's much appreciated!

alexeym February 16, 2017 09:35

Hi,

Default constructor of volScalarField (which is just typedef over GeometricField, http://cpp.openfoam.org/v4/a00931.ht...0d8f8a5fec0dc8) sets calculated type for all boundary conditions, hence the error. The easies ways if to add to your constructor "zeroGradient", so he field has zero gradient BCs everywhere.

Code:

heFluids.set(
  i,
  new volScalarField(
    IOobject("he", runTime.timeName(), fluidRegions[i], IOobject::MUST_READ,
            IOobject::AUTO_WRITE),
    fluidRegions[i],
    dimensionedScalar("he", dimEnergy, 1990.4),
    "zeroGradient"));

Strictly speaking, you need to set real BCs for he, which correspond to your problem.

faab February 16, 2017 10:36

Hi Alexey,

I understand, I did not know about that, thanks a lot for the tip. I will try that as soon as I get my hands back on the code and will keep you posted. Thanks again for your valuable help !

faab February 17, 2017 06:27

Hi again,

The solution you provided did the job, now I've got to figure out why the solution for "he" diverges and makes the solver crash after a few time steps. But you were of great help, thanks a lot for everything Alexey !

Faab


All times are GMT -4. The time now is 07:01.