CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

time dependent gravity based on codeStream OF v18

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By Ali Blues
  • 1 Post By alexeym
  • 1 Post By tonnykz

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2019, 09:24
Default time dependent gravity based on codeStream OF v18
  #1
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 11
Ali Blues is on a distinguished road
Hi all,
I'm trying to use the codeStream to have a time dependent gravity. But can't make it work. I get the following compilation error: (I'm using openfoam v18)

Code:
Reading g
Using #codeStream at line 19 in file "/home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/constant/g"
Using #codeStream with "/home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_daf99d91d91255ca8bb76a32c6753335187daeae.so"
Creating new library in "dynamicCode/_daf99d91d91255ca8bb76a32c6753335187daeae/platforms/linux64GccDPInt32Opt/lib/libcodeStream_daf99d91d91255ca8bb76a32c6753335187daeae.so"
Invoking wmake libso /home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/dynamicCode/_daf99d91d91255ca8bb76a32c6753335187daeae
wmake libso /home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/dynamicCode/_daf99d91d91255ca8bb76a32c6753335187daeae
    ln: ./lnInclude
    dep: codeStreamTemplate.C
    Ctoo: codeStreamTemplate.C
/home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/constant/g.#codeStream:0:10: fatal error: fvCFD.H: No such file or directory
compilation terminated.
/home/mme/OpenFOAM/OpenFOAM-v1812/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/codeStreamTemplate.o' failed
make: *** [Make/linux64GccDPInt32Opt/codeStreamTemplate.o] Error 1


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/_daf99d91d91255ca8bb76a32c6753335187daeae/platforms/linux64GccDPInt32Opt/lib/libcodeStream_daf99d91d91255ca8bb76a32c6753335187daeae.so"


file: /home/mme/OpenFOAM/mme-v1812/run/tutorial/gravityTime/constant/g

    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 215.

FOAM exiting

Here is the file for gravity "g" that I'm trying to modify at run-time. For now I just have a constant value just to make sure things are already working ...


Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       uniformDimensionedVectorField;
    location    "constant";
    object      g;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -2 0 0 0 0];
value           #codeStream
{
  codeInclude
  #{
    #include "fvCFD.H"
    #include <cmath>
    #include <iostream>
  #};

  code
  #{
    const scalar gravity=9.81;
    scalar t = this->db().time().value();
    vector gravityVector = vector (0,0, gravity);
    gravity.writeEntry("", os);

  #};
};
So I would appreciate your help on this.
Best
Ali
Ali Blues is offline   Reply With Quote

Old   April 26, 2019, 10:54
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

To compile your fragment, you can add codeOptions section as shown in the example here: https://cpp.openfoam.org/v6/classFoa...odeStream.html.

But I would suggest to use coded fvOption (based on buoyancyForce fvOption) instead. uniformDimensionedVectorField is not supposed to be time dependent.
alexeym is offline   Reply With Quote

Old   May 6, 2019, 09:30
Default time dependent gravity based on codeStream OF v18
  #3
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 11
Ali Blues is on a distinguished road
Thanks Alexey for the reply.
Here is the updated code:
Code:
dimensions      [0 1 -2 0 0 0 0];
value           #codeStream
{

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

  codeInclude
  #{
    #include "fvCFD.H"
    // #include <cmath>
    // #include <iostream>
  #};

  code
  #{
    const  scalar gravity=9.81;  
    scalar t = d.db().time().value();
    vector gravityVector = vector (0,0, gravity);
    gravity.writeEntry("", os);
  #};

};
I also had to add " -I$(LIB_SRC)/meshTools/lnInclude" to the Code Options. I yet get another error:




Code:
Using #codeStream at line 19 in file "/home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/constant/g"
Using #codeStream with "/home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_2f2c559a762c6d5171aca347a50dcdcf31a28a70.so"
Creating new library in "dynamicCode/_2f2c559a762c6d5171aca347a50dcdcf31a28a70/platforms/linux64GccDPInt32Opt/lib/libcodeStream_2f2c559a762c6d5171aca347a50dcdcf31a28a70.so"
Invoking wmake libso /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_2f2c559a762c6d5171aca347a50dcdcf31a28a70
wmake libso /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_2f2c559a762c6d5171aca347a50dcdcf31a28a70
Make/linux64GccDPInt32Opt/options:61: *** missing separator.  Stop.
Make/linux64GccDPInt32Opt/options:61: *** missing separator.  Stop.
wmake error: file 'Make/linux64GccDPInt32Opt/sourceFiles' could not be created in /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_2f2c559a762c6d5171aca347a50dcdcf31a28a70


--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/_2f2c559a762c6d5171aca347a50dcdcf31a28a70/platforms/linux64GccDPInt32Opt/lib/libcodeStream_2f2c559a762c6d5171aca347a50dcdcf31a28a70.so"


file: /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/constant/g

    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 215.

FOAM exiting
Would you know where does the error stem from.

I looked at the floating object tutorial ( multiphase/interFoam/RAS/floatingObject/constant/dynamicMeshDict.sixDoF) in which only the diagTensor library is included. So if I simplify the problem by just calling vector.H, it works.


Code:
dimensions      [0 1 -2 0 0 0 0];
value           #codeStream
{

  codeInclude
  #{
    #include "vector.H"

  #};

  code
  #{
    const  scalar gravity=9.81;  
     vector gravityVector = vector (0,0, gravity);
    os << gravityVector;
  #};

};
I don't know why as soon as I include the fvCFD library things go wrong during compilation ...

Also thanks for your suggestion regarding the buoyancyForce fvOption, but I was wondering whether there is a restriction regarding time dependence on the uniformDimensionedVectorField. I found a similar example here:
https://www.youtube.com/watch?v=Zgnk6jSK_YM

In the description they mention the following : " a time varying gravity vector was implemented using codeStream." . So I'm assuming this should be possible?


Thanks
Ali
Ali Blues is offline   Reply With Quote

Old   May 6, 2019, 12:09
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Since codeOptions part goes to Makefile, you should join multiple files with continuation symbol:

Code:
    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude
    #};
or put options onto a single line:

Code:
    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/meshTools/lnInclude
    #};
You can use codeStream in MANY places. In the comment for the video they never state, start variable gravitational acceleration vector was implemented using codeStream in the constant/g file.
alexeym is offline   Reply With Quote

Old   May 7, 2019, 08:48
Default time dependent gravity based on codeStream OF v18
  #5
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 11
Ali Blues is on a distinguished road
Hi,
Thanks for the reply and your time. I made the correction you mentioned and it works. However if I make the gravity time dependent:

Code:
dimensions      [0 1 -2 0 0 0 0];
value           #codeStream
{

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

 //libs needed to visualize BC in paraview
            codeLibs
            #{
            -lmeshTools \
            -lfiniteVolume
            #};


  codeInclude
  #{
   // #include "fvCFD.H"
    #include "fvCFD.H"
    
    #include <cmath>
    #include <iostream>
  #};

  code
  #{
    const  scalar gravity=9.81; 
    const IOdictionary& d = static_cast<const IOdictionary&>(dict); 
    scalar t = d.db().time().value();
    vector gravityVector = vector ((t<1.5) ? gravity : 0 ,0,gravity)     

    os <<  gravityVector; //gravityVector.writeEntry("", os);
  #};

};
this is the error i get:
Code:
Reading g
Using #codeStream at line 19 in file "/home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/constant/g"
Using #codeStream with "/home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_7b26292c40d786917a6d1a2dd698837bf4407965.so"
Creating new library in "dynamicCode/_7b26292c40d786917a6d1a2dd698837bf4407965/platforms/linux64GccDPInt32Opt/lib/libcodeStream_7b26292c40d786917a6d1a2dd698837bf4407965.so"
Invoking wmake libso /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_7b26292c40d786917a6d1a2dd698837bf4407965
wmake libso /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_7b26292c40d786917a6d1a2dd698837bf4407965
    ln: ./lnInclude
    dep: codeStreamTemplate.C
    Ctoo: codeStreamTemplate.C
    ld: /home/mme/OpenFOAM/mme-v1812/run/sloshingTankProject/tutorials/sloshingBox_gravityTime/dynamicCode/_7b26292c40d786917a6d1a2dd698837bf4407965/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_7b26292c40d786917a6d1a2dd698837bf4407965.so
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigSegv::sigHandler(int) at ??:?
#2  ? in /lib/x86_64-linux-gnu/libc.so.6
#3  codeStream_7b26292c40d786917a6d1a2dd698837bf4407965 at constant/g.#codeStream:4
#4  Foam::functionEntries::codeStream::execute(Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
#5  Foam::functionEntry::execute(Foam::word const&, Foam::dictionary const&, Foam::primitiveEntry&, Foam::Istream&) at ??:?
#6  Foam::primitiveEntry::acceptToken(Foam::token const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#7  Foam::primitiveEntry::read(Foam::dictionary const&, Foam::Istream&) at ??:?
#8  Foam::primitiveEntry::readEntry(Foam::dictionary const&, Foam::Istream&) at ??:?
#9  Foam::primitiveEntry::primitiveEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#10  Foam::entry::New(Foam::dictionary&, Foam::Istream&, Foam::entry::inputMode, int) at ??:?
#11  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#12  Foam::dictionary::dictionary(Foam::Istream&, bool) at ??:?
#13  Foam::UniformDimensionedField<Foam::Vector<double> >::readData(Foam::Istream&) in ~/OpenFOAM/OpenFOAM-v1812/platforms/linux64GccDPInt32Opt/bin/interFoam
#14  Foam::fileOperations::uncollatedFileOperation::read(Foam::regIOobject&, bool, Foam::IOstreamOption::streamFormat, Foam::word const&) const at ??:?
#15  Foam::regIOobject::readHeaderOk(Foam::IOstreamOption::streamFormat, Foam::word const&) at ??:?
#16  Foam::meshObjects::gravity::New(Foam::Time const&) in ~/OpenFOAM/OpenFOAM-v1812/platforms/linux64GccDPInt32Opt/bin/interFoam
#17  ? in ~/OpenFOAM/OpenFOAM-v1812/platforms/linux64GccDPInt32Opt/bin/interFoam
#18  __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
#19  ? in ~/OpenFOAM/OpenFOAM-v1812/platforms/linux64GccDPInt32Opt/bin/interFoam
Segmentation fault (core dumped)
If I'm not wrong it seems to complain about uniformDimensionedVectorField not accepting temporal modifications.What do you think? or is the error pointing to another thing (sorry I can't really follow the output)



Regarding fvOption , so either I have to make a new fvOption which as you mentioned the bouyantForce is the closest, or a codedSource. I think the following seems to be a good start (scroll to comment #10)

How to add a body force to a momentum equation


One last thing which might be trivial, but I don't see how codeStream would come into play in all this as I don't see any existing fvOptions which within the respective dictionary I can use codeStream ...


Best
Ali
tonnykz likes this.
Ali Blues is offline   Reply With Quote

Old   May 9, 2019, 16:50
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

sigSegv in fact is caused by access to Time object. It seems static cast gives you rather strange IOdictionary. If you use in the codeStream, for example

Code:
os << "(0 -9.81 0)";
everything works fine. And codeStream is evaluated only during creation of g object, i.e. only at the beginning of the simulation, it won't be executed during the simulation. So there will be no time-dependence of g value.

You can start with the example provided in message 10.

The easiest way to learn what Wolfdynamics meant by codeStream is to ask them directly, either through comment on Youtube, or through contact e-main on their web-site. One can call code inside codedFvOption configuration sections "codeStream".
tonnykz likes this.
alexeym is offline   Reply With Quote

Old   May 13, 2019, 18:06
Default
  #7
Member
 
Join Date: Oct 2016
Posts: 31
Rep Power: 10
tonnykz is on a distinguished road
Hello Ali Blues,
I am trying to implement same thing in of v1812. Have you solved the issue?
If yes, I would appreciate you sharing solution.
Best regards,
Tonnykz
joshmccraney likes this.
tonnykz is offline   Reply With Quote

Reply

Tags
codestream, time dependent gravity


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 06:49
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 12:08
Pressure inlet vs outlet position, transient, time dependent pressure and gravity silent2608 FLUENT 0 February 6, 2016 11:19
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 07:20
dynamic Mesh is faster than MRF???? sharonyue OpenFOAM Running, Solving & CFD 14 August 26, 2013 08:47


All times are GMT -4. The time now is 11:13.