CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] How to correctly show the result of #codeStream# internalField? (https://www.cfd-online.com/Forums/paraview/187463-how-correctly-show-result-codestream-internalfield.html)

chengdi May 7, 2017 06:38

How to correctly show the result of #codeStream# internalField?
 
Hi, everyone

I just used codeStream to generate some initial condtion and codedFixedValue to generate some boundary condtion. The codedFixedValue BC can be correctly executed and loaded using paraFoam (I am using OF1612+ in docker), however, the codeStream initial condition can be correctly interpreted and executed but cannot be loaded in paraFoam.


I was running the forwardStep with following "0/U" file
Code:

/*--------------------------------*- C++ -*----------------------------------*\

| =========                |                                                |

| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |

|  \\    /  O peration    | Version:  plus                                  |

|  \\  /    A nd          | Web:      www.OpenFOAM.com                      |

|    \\/    M anipulation  |                                                |

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

FoamFile

{

    version    2.0;

    format      ascii;

    class      volVectorField;

    object      U;

}

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



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



//internalField  uniform (3 0 0);



internalField  #codeStream

{

    code

    #{

        const IOdictionary& d = static_cast<const IOdictionary&>(dict);

        const fvMesh& mesh = refCast<const fvMesh>(d.db());

       

        vectorField T(mesh.nCells());



        const vectorField& CC = mesh.C(); //cell center

       

        forAll(CC,cellI)

        {

           

            //spatial coordinates, type: scalar

                scalar x = CC[cellI].x();

                scalar y = CC[cellI].y();

                scalar z = CC[cellI].z();

               

                T[cellI] = vector(3+0.2*sin(10*x),0,0);

        }

               

        //void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const

        T.writeEntry("", os);

    #};



    //! Optional:

    codeInclude

    #{

        #include "fvCFD.H"

    #};





    //! Optional:

    codeOptions

    #{

        -I$(LIB_SRC)/finiteVolume/lnInclude \

        -I$(LIB_SRC)/meshTools/lnInclude

    #};



    //! libs:

    codeLibs

    #{

        -lmeshTools

    #};

};



boundaryField

{



    inlet

    {

        type            codedMixed;

        refValue        uniform (3 0 0); //default value

        refGradient    uniform (0 0 0); //default value

        valueFraction  uniform 1;

        redirectType    linearOscillatingBC; //name of new BC type

        code

        #{

        const vectorField& Cf = patch().Cf(); // get face center coordinate;

       

        scalar ymax = max(Cf&vector(0,1,0)); // `&` is dot product

        scalar ymin = min(Cf&vector(0,1,0));

        // Info<<"ymax="<<ymax<<",ymin="<<ymin<<nl;

       

        vectorField& rvf = this->refValue();

        vectorField& rgf = this->refGrad();

        scalarField& vf = this->valueFraction();

       

        //temporal coordinate, type: scalar

        scalar t =this->db().time().value(); // get time

        //Oscillating parameters

        scalar omega = 5;

        scalar A = 0.2;

        scalar tt = (1+A*sin(omega*t)); // temporal term, separated

       

        forAll(Cf,faceI)

        {

                //spatial coordinates, type: scalar

                //scalar x = Cf[faceI].x();

                scalar y = Cf[faceI].y();

                //scalar z = Cf[faceI].z();

                rvf[faceI] = vector(((y-ymin)/(ymax-ymin)+2.5)*tt,0.0,0.0);

                rgf[faceI] = Zero;

                vf[faceI] = 1.0;

        }



        #};

       

        //I do not know why I need to add those things

        //codeInclude

        //#{

        //    #include "fvCFD.H"

        //#};

       

        //codeOptions

        //#{

        //    -I$(LIB_SRC)/finiteVolume/lnInclude

        //#};

    }



    outlet

    {

        type            inletOutlet;

        inletValue      uniform (3 0 0);

        value          uniform (3 0 0);

    }



    bottom

    {

        type            symmetryPlane;

    }



    top

    {

        type            symmetryPlane;

    }



    obstacle

    {

        type            slip;

    }



    defaultFaces

    {

        type            empty;

    }

}



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

And here is the output of crashing paraFoam when I try to load the data.
Code:

Created temporary 'forwardStepMod3.OpenFOAM'
Using #codeStream at line 21 in file "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U"
Using #codeStream with "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so"
Invoking wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f
wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f


--> FOAM FATAL IO ERROR:
Failed loading library "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so"
Did you add all libraries to the 'libs' entry in system/controlDict?

file: /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U from line 17 to line 17.

    From function static void (* Foam::functionEntries::codeStream::getFunction(const Foam::dictionary&, const Foam::dictionary&))(Foam::Ostream&, const Foam::dictionary&)
    in file db/dictionary/functionEntries/codeStream/codeStream.C at line 309.

FOAM exiting

I also tried to add "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665 a90f.so" to my system/controlDict 's libs entry. Here is the output:

Code:

Created temporary 'forwardStepMod3.OpenFOAM'
--> FOAM Warning :
    From function void* Foam::dlOpen(const Foam::fileName&, bool)
    in file POSIX.C at line 1244
    dlopen error : /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so: undefined symbol: _ZTIN4Foam6fvMeshE
--> FOAM Warning :
    From function bool Foam::dlLibraryTable::open(const Foam::fileName&, bool)
    in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 101
    could not load "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so"
Using #codeStream at line 21 in file "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U"
Using #codeStream with "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so"
Invoking wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f
wmake libso /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/_ba5ce8457724532859ca03bd0612f92a5665a90f


--> FOAM FATAL IO ERROR:
Failed loading library "/home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_ba5ce8457724532859ca03bd0612f92a5665a90f.so"
Did you add all libraries to the 'libs' entry in system/controlDict?

file: /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/0/U from line 17 to line 17.

    From function static void (* Foam::functionEntries::codeStream::getFunction(const Foam::dictionary&, const Foam::dictionary&))(Foam::Ostream&, const Foam::dictionary&)
    in file db/dictionary/functionEntries/codeStream/codeStream.C at line 309.

FOAM exiting

I thought "_ZTIN4Foam6fvMeshE" must be something important. However, there is only one result from Google and I cannot see any related information in it.

wyldckat May 7, 2017 08:34

Quick answer: You have this:
Code:

    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude
    #};



    //! libs:
    codeLibs
    #{
        -lmeshTools
    #};

Notice that in the first block here you mention "finiteVolume", but in the "codeLibs" block you don't mention it. This isn't a problem when using the solver, because the solver already has this library loaded in. Therefore, you need to update the second block to this:
Code:

    //! libs:
    codeLibs
    #{
        -lmeshTools \
        -lfiniteVolume
    #};


chengdi May 8, 2017 02:08

Dear Bruno

Thank you so much for you reply!

chengdi May 8, 2017 02:18

Hi Bruno,

I just tried to use "paraview" rather than "paraFoam" to post-process the result after time "0".

However, the "U" field cannot be read and here is the errors:


Code:

ERROR: In /home/buzz2/pawan/OpenFOAM/ThirdParty-1606_plus/ParaView-5.0.1/VTK/IO/Geometry/vtkOpenFOAMReader.cxx, line 6497
vtkOpenFOAMReaderPrivate (0x40ace10): Error reading line 16332 of /home/di/OpenFOAM/di-v1612+/run/forwardStepMod3/8/U: Unsupported directive {

And here is content in "8/U"

Code:

internalField  nonuniform List<vector>
16128
(
(2.877288422651 -3.144469067245e-05 0)
...
)
;
        name            linearOscillatingBC;
        code            #{
        const vectorField& Cf = patch().Cf(); // get face center coordinate;

        scalar ymax = max(Cf&vector(0,1,0)); // `&` is dot product
        scalar ymin = min(Cf&vector(0,1,0));
        // Info<<"ymax="<<ymax<<",ymin="<<ymin<<nl;

        vectorField& rvf = this->refValue();
        vectorField& rgf = this->refGrad();
        scalarField& vf = this->valueFraction();

        //temporal coordinate, type: scalar
        scalar t =this->db().time().value(); // get time
        //Oscillating parameters
        scalar omega = 5;
        scalar A = 0.2;
        scalar tt = (1+A*sin(omega*t)); // temporal term, separated

        forAll(Cf,faceI)
        {
                //spatial coordinates, type: scalar
                //scalar x = Cf[faceI].x();
                scalar y = Cf[faceI].y();
                //scalar z = Cf[faceI].z();
                rvf[faceI] = vector(((y-ymin)/(ymax-ymin)+2.5)*tt,0.0,0.0);
                rgf[faceI] = Zero;
                vf[faceI] = 1.0;
        }

        #};
    }
    outlet
    {
...

Is there any way to solve this problem?

Antimony May 8, 2017 04:44

Hi,

AFAIK, there isn't a very straightforward way to do this.

What I do is to open up the result file and modify the type from 'coded...' to 'fixedValue'. OF seems to write the values in any case (usually in the line/lines right below type) and so making this change allows Paraview to understand and display the velocity.

Hope this helps.

Cheers,
Antimony

wyldckat May 8, 2017 19:19

Quick answer: If the file extension ".OpenFOAM" is not used and instead the built-in reader with ".foam" is used instead, then it will not work. You could try with ParaView 5.3, but I haven't tested it yet.

The only other solution is to use foamToVTK and then open the VTK files in ParaView.

chengdi May 9, 2017 02:51

Dear Bruno

Thanks for your suggestion. I will try foamToVTK.

gtarang May 18, 2017 15:58

Implementing a new IOobject
 
Hi,
I am using OpenFOAM 4.1 for melting and solidification problem. I am following this thread https://www.cfd-online.com/Forums/op...angoni-bc.html for writing marangoni BC. The boundary condition uses an IOobject of volVectorField gradT. The thread suggest putting IOobject in solver. I want to know the possibility of calculating gradT from controlDict using functionObjects or codeStream.

I have written the controlDict in this way

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  4.1                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application    buoyantPimpleFoam;

startFrom      startTime;

startTime      0;

stopAt          endTime;

endTime        30.0;

deltaT          1.0;

writeControl    adjustableRunTime;

writeInterval  10;

purgeWrite      0;

writeFormat    ascii;

writePrecision  8;

writeCompression off;

timeFormat      general;

timePrecision  10;

runTimeModifiable yes;

adjustTimeStep  yes;

libs
(
    "libmyBoundaryConditions.so"
    "libOpenFOAM.so"
);
/*
maxCo          0.25;

maxDeltaT      1;
maxAlphaCo      1;
*/

    #codeStream
    {
        code
        #{
            const IOdictionary& d = static_cast<const IOdictionary&>(dict);
            const fvMesh& mesh = refCast<const fvMesh>(d.db());
            volVectorField gradT
            (
                IOobject
                (
                    "gradT",
                    runTime.timeName(),
                    mesh,
                    IOobject::READ_IF_PRESENT,
                    IOobject::AUTO_WRITE
                ),
                fvc::grad(T)
            );

        #};
        /*codeInclude
        #{
            #include "fvCFD.H"
        #};*/
        codeOptions
        #{
            -I$(LIB_SRC)/finiteVolume/lnInclude \
            -I$(LIB_SRC)/meshTools/lnInclude \
        #};
        codeLibs
        #{
            -lmeshTools
        #};
    }


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

Kindly suggest me how can I calculate gradT.

--
Tarang

chengdi May 19, 2017 23:47

I think you can use post-processor to calculate grad(T)

gtarang May 20, 2017 00:54

Will I be able to use "post process"ed grad(T) as volVectorField in boundaryConditionFvPatchField?

chengdi May 20, 2017 22:38

sorry, I misunderstood your purpose.

As far as I know. #codeStream is just used to generate some "TEXT" in the controlDict or other text-based configuration file for OpenFOAM. If you want to use some volVectorField grad(T) in your BC. you must modify your solver.

gtarang May 21, 2017 06:33

Thanks chengdi. I have modified my solver to calculate gradT. One thing about the #codestream in controlDict I want to ask is that where in the execution flow process the code is executed?

chengdi June 12, 2017 10:34

Quote:

Originally Posted by gtarang (Post 649708)
Thanks chengdi. I have modified my solver to calculate gradT. One thing about the #codestream in controlDict I want to ask is that where in the execution flow process the code is executed?

I think #codeStream is just used to generate texts.

You may understand it like this:

When the foam app read the controlDict, what your app actually read is the text generated by your #codeStream at the start of the dict-entry-reading.

gaza September 7, 2017 10:08

Hi
I use codeStream BC for U
I tried to access time as you posted in https://www.cfd-online.com/Forums/op...tml#post647952

However I got error "error: invalid use of ‘this’ in non-member function"
in the line scalar t = this->db().time().value();

My U file is
Code:

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

internalField  uniform (16 0 0);

boundaryField
{
    WALL
    {
        type            fixedValue;
        value            #codeStream
        {
            codeInclude
            #{
                #include "fvCFD.H";
            #};

            codeOptions
            #{
                -I$(LIB_SRC)/finiteVolume/lnInclude \
                -I$(LIB_SRC)/meshTools/lnInclude
            #};

            codeLibs
            #{
                -lmeshTools \
                -lfiniteVolume
            #};

            code
            #{
                const IOdictionary& d = static_cast<const IOdictionary&>
                (
                    dict.parent().parent()
                );

                const fvMesh& mesh = refCast<const fvMesh>(d.db());
                const label id = mesh.boundary().findPatchID("WALL");
                const fvPatch& patch = mesh.boundary()[id];
               
                vectorField U(patch.size(), vector(0, 0, 0));

                scalar t = this->db().time().value();

                forAll(U,i)
                {
                    U[i] = vector(1, 0., 0.);
                }

                U.writeEntry("", os);
            #};
        };
    }

Do you know what is wrong?

rarnaunot July 4, 2018 09:14

Hi Foamers,

I got the same error as you:
Quote:

Originally Posted by gaza (Post 663550)
Hi
I use codeStream BC for U
I tried to access time as you posted in https://www.cfd-online.com/Forums/op...tml#post647952

However I got error "error: invalid use of ‘this’ in non-member function"
in the line scalar t = this->db().time().value();

My U file is
Code:

.
.
.
.
                scalar t = this->db().time().value();
.
.
.
.

Do you know what is wrong?

How did you solve this error?

Thanks!

gaza July 5, 2018 08:34

Hi
I did not solve this. I used codedFixedValue instead of fixedValue.

rarnaunot July 5, 2018 10:18

:confused: I'm not really into the difference between codedFixedValue and fixedValue. But i am initializing a IC so I use: internalField #codeStream

Quote:

Originally Posted by gaza (Post 698282)
Hi
I did not solve this. I used codedFixedValue instead of fixedValue.


gaza July 5, 2018 13:04

you can find basic info here
https://www.openfoam.com/documentati...xed-value.html


or search on the forum

Ali Amarloo September 21, 2018 08:41

Quote:

Originally Posted by gaza (Post 663550)
Hi
I use codeStream BC for U
I tried to access time as you posted in https://www.cfd-online.com/Forums/op...tml#post647952

However I got error "error: invalid use of ‘this’ in non-member function"
in the line scalar t = this->db().time().value();

My U file is
Code:

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

internalField  uniform (16 0 0);

boundaryField
{
    WALL
    {
        type            fixedValue;
        value            #codeStream
        {
            codeInclude
            #{
                #include "fvCFD.H";
            #};

            codeOptions
            #{
                -I$(LIB_SRC)/finiteVolume/lnInclude \
                -I$(LIB_SRC)/meshTools/lnInclude
            #};

            codeLibs
            #{
                -lmeshTools \
                -lfiniteVolume
            #};

            code
            #{
                const IOdictionary& d = static_cast<const IOdictionary&>
                (
                    dict.parent().parent()
                );

                const fvMesh& mesh = refCast<const fvMesh>(d.db());
                const label id = mesh.boundary().findPatchID("WALL");
                const fvPatch& patch = mesh.boundary()[id];
               
                vectorField U(patch.size(), vector(0, 0, 0));

                scalar t = this->db().time().value();

                forAll(U,i)
                {
                    U[i] = vector(1, 0., 0.);
                }

                U.writeEntry("", os);
            #};
        };
    }

Do you know what is wrong?

I have the same problem
It seems that by "scalar t = this->db().time().value(); " we can access time just for codedFixedvalue
Does anybody know how can I access time (of simulation) in "codeStream"?

gaza September 21, 2018 14:25

change
Code:

fixedValue
into
Code:

codedFixedValue


All times are GMT -4. The time now is 23:04.