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/)
-   -   OpenFOAM basic integration (http://www.cfd-online.com/Forums/openfoam-programming-development/132646-openfoam-basic-integration.html)

maybee April 3, 2014 15:33

OpenFOAM basic integration
 
Hi,

does OpenFOAM provide basic integral methods?

If I provide a mathematical function and the lower and upper limits of integration is there a OpenFOAM method to calculate the integral or do I have to use third party code?

greetings
maybee

sharonyue April 9, 2014 00:06

Check this out:http://www.cfd-online.com/Forums/ope...-integral.html

By Christian Butcher's hint, I am gonna try Remberg method. You can find Remberg's code somewhere else.

Best,

maybee April 9, 2014 05:02

hi,

thx, but I ve already used another library for basic numerical integration. :) I am not sure if I am allowed link it here (?).

manju819 April 10, 2014 09:21

Hi Maybee
 
Its availble in OpenFOAM no need of third party soft

In the "/opt/openfoam222/applications/test/dataEntry" in the dataEntry.C you can find about the integration with the upper and lower limits. You can make that dataEntry.C by copying it to run folder.

Regards,
Manjunath

sharonyue April 10, 2014 20:15

Quote:

Originally Posted by manju819 (Post 485227)
Its availble in OpenFOAM no need of third party soft

In the "/opt/openfoam222/applications/test/dataEntry" in the dataEntry.C you can find about the integration with the upper and lower limits. You can make that dataEntry.C by copying it to run folder.

Regards,
Manjunath

Thanks bro, This Test-DataEntry.C can calculate integration. But when I run this Test-DateEntry.C it failed. So I just make it very simple:

Code:


#include "fvCFD.H"
#include "DataEntry.H"
#include "IOdictionary.H"

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

int main(int argc, char *argv[])
{
#  include "setRootCase.H"
#  include "createTime.H"
#  include "createMesh.H"

    IOdictionary dataEntryProperties
    (
        IOobject
        (
            "dataEntryProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );

    autoPtr<DataEntry<scalar> > dataEntry
    (
        DataEntry<scalar>::New
        (
            "dataEntry",
            dataEntryProperties
        )
    );

    scalar x0 = readScalar(dataEntryProperties.lookup("x0"));
    scalar x1 = readScalar(dataEntryProperties.lookup("x1"));

    Info<< "Integration" << nl
        << "    int(f(x)) lim(x0->x1) = " << dataEntry().integrate(x0, x1) << nl
        << endl;

    return 0;
}

While right now Im confused that where can I input my f(x), do you know? Thanks.

manju819 April 10, 2014 23:59

Hi sharonyue
 
Firstly it works like if we give x and y data, it interpolates linearly(default) or it uses cubic spline. So then by giving lower limit and upper limit it integrates over the limits and gives the data. This is how it works kk

Now coming to dataEntry....

you can see in dataEntryProperties


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

x0 0.5;//lower limit
x1 1;//Upper limit


dataEntry table (
(0 0)//(x1,y1) point
(10 1));(x2,y2) point


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


dataEntry().integrate(x0, x1) //This is area under the region

Iterpolates this data and gives the stright line and on integration gives area under the region....

Post your error i will look into that....

Regards
Manjunath


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