CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Paraview & paraFoam

How to correctly show the result of #codeStream# internalField?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   May 7, 2017, 06:38
Exclamation How to correctly show the result of #codeStream# internalField?
  #1
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
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.
chengdi is offline   Reply With Quote

Old   May 7, 2017, 08:34
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 9,950
Blog Entries: 39
Rep Power: 108
wyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of light
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
    #};
__________________
wyldckat is offline   Reply With Quote

Old   May 8, 2017, 02:08
Default
  #3
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
Dear Bruno

Thank you so much for you reply!
chengdi is offline   Reply With Quote

Old   May 8, 2017, 02:18
Default
  #4
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
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?

Last edited by wyldckat; May 8, 2017 at 19:17. Reason: Added [CODE][/CODE] markers
chengdi is offline   Reply With Quote

Old   May 8, 2017, 04:44
Default
  #5
Senior Member
 
Join Date: Aug 2013
Posts: 272
Rep Power: 6
Antimony is on a distinguished road
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
Antimony is offline   Reply With Quote

Old   May 8, 2017, 19:19
Default
  #6
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 9,950
Blog Entries: 39
Rep Power: 108
wyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of lightwyldckat is a glorious beacon of light
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.
wyldckat is offline   Reply With Quote

Old   May 9, 2017, 02:51
Default
  #7
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
Dear Bruno

Thanks for your suggestion. I will try foamToVTK.
chengdi is offline   Reply With Quote

Old   May 18, 2017, 15:58
Default Implementing a new IOobject
  #8
New Member
 
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 14
Rep Power: 8
gtarang is on a distinguished road
Hi,
I am using OpenFOAM 4.1 for melting and solidification problem. I am following this thread Marangoni bc 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
gtarang is offline   Reply With Quote

Old   May 19, 2017, 23:47
Default
  #9
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
I think you can use post-processor to calculate grad(T)
chengdi is offline   Reply With Quote

Old   May 20, 2017, 00:54
Default
  #10
New Member
 
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 14
Rep Power: 8
gtarang is on a distinguished road
Will I be able to use "post process"ed grad(T) as volVectorField in boundaryConditionFvPatchField?
gtarang is offline   Reply With Quote

Old   May 20, 2017, 22:38
Default
  #11
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
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.
chengdi is offline   Reply With Quote

Old   May 21, 2017, 06:33
Default
  #12
New Member
 
Tarang
Join Date: Feb 2011
Location: Delhi, India
Posts: 14
Rep Power: 8
gtarang is on a distinguished road
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?
gtarang is offline   Reply With Quote

Old   June 12, 2017, 10:34
Default
  #13
Member
 
Di Cheng
Join Date: May 2010
Location: Beijing, China
Posts: 33
Rep Power: 9
chengdi is on a distinguished road
Quote:
Originally Posted by gtarang View Post
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.
chengdi is offline   Reply With Quote

Reply

Tags
codestream, openfoam, parafoam

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create the internalField with #codeStream chun OpenFOAM Running, Solving & CFD 3 May 6, 2017 10:35
Simulation won't show turbulence pete_87 OpenFOAM Running, Solving & CFD 4 June 25, 2014 11:35
Geometry show in Result Display ShFlow FLOW-3D 3 January 11, 2009 21:51


All times are GMT -4. The time now is 02:38.