CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Writing a solver - heat equation - Solution diverges (http://www.cfd-online.com/Forums/openfoam-programming-development/112496-writing-solver-heat-equation-solution-diverges.html)

DheepanPillai January 30, 2013 01:28

Writing a solver - heat equation - Solution diverges
 
Hi,

I'm new to CFD and OpenFOAM. I was able to write a solver for 1-D heat equation with and without source and run it easily. The numerical solution matched with analytical solution. But when Convection is included in the code, it diverges, and temperature becomes infinity.
Code:

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

#include "fvCFD.H"
#include "simpleControl.H"

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

int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"

    simpleControl simple(mesh);

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

    Info<< "\nCalculating temperature distribution\n" << endl;

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        while (simple.correctNonOrthogonal())
        {
            solve  //Solves thermal diffusion in a solid with convective heat transfer along its length
            (
              fvm::laplacian(T) - n* (T-Tatm) //where n = hP/kA
            );
        }

        #include "write.H"

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}


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

Mesh is just a 1 m long rod with 5 elements. Tried different number of nodes and different time steps. Still diverges. :confused: I tried upwind and central differencing for laplacian.

fumiya February 1, 2013 22:09

Hi,

You might want to try the following:

Code:

solve
(
    fvm::laplacian(T) - fvm::Sp(n, T) + n * Tatm
);

Fumiya


All times are GMT -4. The time now is 03:33.