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

creating geometricField unknown Type in main(){}

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 6, 2012, 02:07
Default creating geometricField of unknown Type in main(){}
  #1
Member
 
Artem Shaklein
Join Date: Feb 2010
Location: Russia, Izhevsk
Posts: 43
Rep Power: 16
ARTem is on a distinguished road
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.

Last edited by ARTem; July 6, 2012 at 04:41. Reason: adding source code
ARTem is offline   Reply With Quote

Old   July 7, 2012, 18:11
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ARTem View Post
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)
gschaider is offline   Reply With Quote

Old   July 9, 2012, 02:10
Default
  #3
Member
 
Artem Shaklein
Join Date: Feb 2010
Location: Russia, Izhevsk
Posts: 43
Rep Power: 16
ARTem is on a distinguished road
gschaider, thank you for detailed explanation.
ARTem is offline   Reply With Quote

Reply


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
[Commercial meshers] Fluent3DMeshToFoam simvun OpenFOAM Meshing & Mesh Conversion 50 January 19, 2020 15:33
[CGNS] CGNS converters available mbeaudoin OpenFOAM Meshing & Mesh Conversion 137 December 14, 2018 04:20
Segmentation Fault in fluent3DMeshToFoam cwang5 OpenFOAM Bugs 23 April 13, 2011 15:37
turbulent jet simulation antonio_ing OpenFOAM Running, Solving & CFD 5 September 16, 2010 02:31
rhoSimpleFoam claco OpenFOAM 7 April 20, 2010 04:32


All times are GMT -4. The time now is 15:14.