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/)
-   -   How to set and read time-dependent source terms (http://www.cfd-online.com/Forums/openfoam-programming-development/107054-how-set-read-time-dependent-source-terms.html)

DeanM September 16, 2012 13:19

How to set and read time-dependent source terms
 
Dear Foamers,

I would like to read a time-dependent source term, which can be defined by a function in a file in the case directory and read from the solver itself.
So far I managed to set the source term using funkySetFields, but only as initial condition. My approach is the following: In createFields.H the field of the mass source is defined as follows:
Code:

     
        volScalarField massSource
        (
        IOobject
        (
            "massSource",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        ),
        mesh
        );

The equation to solve looks like
Code:

    fvScalarMatrix rhoEqn
    (
      fvm::ddt(rho)
    + some terms
    == massSource
    );
    rhoEqn.solve();

Finally the user should be able to define "massSource" with a mathematical expression as function of time and space in a file in the case directory. I tried to do it with funkySetFields, it works well for time 0, but I need it for all times. Example:
Code:

    massSource
    {
        field massS;
        expression    "sin(pi*time())*(pos().x+pos().y"; //arbitrary function
        //condition    "...";
    }

In conclusion: How can I define and read time-dependent source terms from the case directory?
Thank you for any ideas.
D.

ahmmed04 September 18, 2012 05:33

you can use the source term as a boundary condition, in that case you can easily use groovyBC.Or if you can access to the 'internalField' when creating source object, you might be able to do this.

marupio September 20, 2012 11:14

You could also use the equationReader extension. I'm working on a paper that will demonstrate this exact idea using it.

gschaider September 24, 2012 17:37

Quote:

Originally Posted by DeanM (Post 382024)
Dear Foamers,

I would like to read a time-dependent source term, which can be defined by a function in a file in the case directory and read from the solver itself.
So far I managed to set the source term using funkySetFields, but only as initial condition. My approach is the following: In createFields.H the field of the mass source is defined as follows:
Code:

     
        volScalarField massSource
        (
        IOobject
        (
            "massSource",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        ),
        mesh
        );

The equation to solve looks like
Code:

    fvScalarMatrix rhoEqn
    (
      fvm::ddt(rho)
    + some terms
    == massSource
    );
    rhoEqn.solve();

Finally the user should be able to define "massSource" with a mathematical expression as function of time and space in a file in the case directory. I tried to do it with funkySetFields, it works well for time 0, but I need it for all times. Example:
Code:

    massSource
    {
        field massS;
        expression    "sin(pi*time())*(pos().x+pos().y"; //arbitrary function
        //condition    "...";
    }

In conclusion: How can I define and read time-dependent source terms from the case directory?
Thank you for any ideas.
D.

In addition to the two other solutions given (equationReader and groovyBC) you can search the forum for expressionSource which comes with swak4Foam and does what you want (I've explained the usage in one of those threads ... you'll find it)


All times are GMT -4. The time now is 16:36.