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/)
-   -   creating geometricField unknown Type in main(){} (http://www.cfd-online.com/Forums/openfoam-programming-development/104280-creating-geometricfield-unknown-type-main.html)

ARTem July 6, 2012 02:07

creating geometricField of unknown Type in main(){}
 
Hello, FOAM'er users!
I'd like to create post-proc time averaging utility, something like that (_http://www.cfd-online.com/Forums/openfoam-programming-development/70396-using-fieldaverage-library-average-postprocessing.html), but without using createField.H and etc. E.g. "average U" or "average p".
So, as base foamCalc utility was used. But, it seems to me, that I have to initialize averagedField of unknown type (<vector>, <scalar> etc.) right inside main function before starting cycle on stored time steps.

Code:

int main(int argc, char *argv[])
{
  // Reading information about field to be averaged
    IOobject fieldHeader
    (
        fieldName,
        ...
    );
    // Defining fieldType by some means
    fieldType averagedField
    (
        IOobject
        (
            "averaged" + fieldHeader.name(),
            ...
    // Averaging procedure
    forAll(timeDirs, timeI)
    {
        ...
    }
    ...
}

FoamCalc is to initialize geometricField, e.g. interpolateField, of unknown type. But, that can be done inside user function, called by cycle at each stored time step, using <template>. InterpolateField from old time steps isn't needed at new time step, so it can be initialized at each time step.

Code:

int main(int argc, char *argv[])
{
    forAll(timeDirs, timeI)
    {
        ...
        // template<class Type> void writeInterpolateField is called, where interpolationField is initialized, calculated, stored and destructed
        writeInterpolateField<scalar>(fieldHeader, mesh, processed);
        writeInterpolateField<vector>(fieldHeader, mesh, processed);
        writeInterpolateField<sphericalTensor>(fieldHeader, mesh, processed);
        ...
    }
    ...
}

Is it real to create geometricField of unknown type right inside main function? Or are there other ways to approach final goal?
Thank you very much for your attention.

gschaider July 7, 2012 18:11

Quote:

Originally Posted by ARTem (Post 370026)
Hello, FOAM'er users!
I'd like to create post-proc time averaging utility, something like that (_http://www.cfd-online.com/Forums/openfoam-programming-development/70396-using-fieldaverage-library-average-postprocessing.html), but without using createField.H and etc. E.g. "average U" or "average p".
So, as base foamCalc utility was used. But, it seems to me, that I have to initialize averagedField of unknown type (<vector>, <scalar> etc.) right inside main function before starting cycle on stored time steps.

Code:

int main(int argc, char *argv[])
{
  // Reading information about field to be averaged
    IOobject fieldHeader
    (
        fieldName,
        ...
    );
    // Defining fieldType by some means
    fieldType averagedField
    (
        IOobject
        (
            "averaged" + fieldHeader.name(),
            ...
    // Averaging procedure
    forAll(timeDirs, timeI)
    {
        ...
    }
    ...
}

FoamCalc is to initialize geometricField, e.g. interpolateField, of unknown type. But, that can be done inside user function, called by cycle at each stored time step, using <template>. InterpolateField from old time steps isn't needed at new time step, so it can be initialized at each time step.

Code:

int main(int argc, char *argv[])
{
    forAll(timeDirs, timeI)
    {
        ...
        // template<class Type> void writeInterpolateField is called, where interpolationField is initialized, calculated, stored and destructed
        writeInterpolateField<scalar>(fieldHeader, mesh, processed);
        writeInterpolateField<vector>(fieldHeader, mesh, processed);
        writeInterpolateField<sphericalTensor>(fieldHeader, mesh, processed);
        ...
    }
    ...
}

Is it real to create geometricField of unknown type right inside main function? Or are there other ways to approach final goal?
Thank you very much for your attention.

No you can't. All these fields are instantiations of GeometricField but have no common base-class except regIOobject (which you could use, but the resulting cast-orgies won't simplify the elegance of your code. If there was a better way the guys who wrote foamCalc would use it (they really know what they're doing)

ARTem July 9, 2012 02:10

gschaider, thank you for detailed explanation.


All times are GMT -4. The time now is 21:25.