Challenge

Week 5 Challenge- Creating a test case in OpenFOAM

Here, first I copied the cavity problem from $FOAM_TUTORIALS/incompressible/icoFoam into my run folder. Here from the icoFoam/cavity/cavity folder i just copied the constant folder and system folder into my run folder.

Then renamed the transportProperties file into thermalProperties fiile by usnig mv command as shown in following fig.

 Then inside the thermalProperties file i added Temperature term as T and assigned a value to it. And the text file is shown below.

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2306                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      thermalProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu              0.01;

T               200;

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

Then I created a C file called thermal.C and created an appropriate IOobject as 'ioDictObj' that reads the data inside the thermalProperties file, and assign the values to the scalar terms T and nu. And the thermal.C file code is given below.

#include "fvCFD.H" 


int main( int argc, char *argv[])
{
    Foam::argList::noBanner();
    Foam::argList args(argc,argv);

    Foam::Time runTime
        (
        Foam::Time::controlDictName,
        args.rootPath(), 
        args.caseName()
        );

    IOdictionary ioDictObj
    (
        IOobject
        (
            "thermalProperties",
            "constant",
            runTime,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
            )
            
    
    );
    // read and assign the "T" and "nu" variables as scalar
    scalar T = readScalar (ioDictObj.lookup("T"));
    scalar nu =readScalar (ioDictObj.lookup("nu"));
    Info << "T = " << T nu = " << nu << Foam::endl;
    return 0; 
}

  • Then the main function of the program contains command line arguments.
  • And the noBannes function used to print the results of the stimulation.
  • And the argListt functions takes the input arguments.
  • Then, defined the path of the controDIct file which is in the constant file folder to read the controlDict file.
  • Then created a IOdictionary named ioDictobj and assigned the thermalProperties file which is inside the constant folder.
  • Then, assigned the T and nu values of the ioDictobj to the scalar function of T and nu.
  • After, that printed the T and nu value.
  • To run this code by using wmake command it need a Make folder that contants files and options. So I just copies the Make folder from the icoFoam solver into the run folde as shown below.

    Then I did some changes in Make/files as shown below.

    thermal.C
    
    EXE = thermalread

    and Make/options as shown below.

    EXE_INC = \
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude
    
    EXE_LIBS = \
        -lfiniteVolume \
        -lmeshTools

    Then run the code by using wmake command ad the results are attached below.

    And by running ./thermalread command to read the EXE file, it results as follows,

    Your portfolio, next

    Ship work like this
    in your own course.

    Talk to a career counsellor

    Free 20-minute call. We'll map the right course to where you want to work.

    By submitting you agree to our Terms and Privacy Policy.