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

Custom function object

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 26, 2024, 04:38
Default Custom function object
  #1
Member
 
Giorgio
Join Date: Mar 2023
Posts: 57
Rep Power: 3
giorgianig is on a distinguished road
Dear all,

I am using Openfoam 2312. I am trying to develop a custom function object that compute a linear combination of an area average (at runtime). Seems complicated but it is just computing something like

Output = (0.9-Area_average)/(0.9-0.5)

where Area_average can be computed with the function object "surfaceFieldValue".

In other words, I want to apply an expression to the output of a function object before printing.

I know that I could compile a new function object but I guess there is a simpler approach? Moreover I need it for just one test case.

Thanks in advance

Last edited by giorgianig; November 26, 2024 at 06:43.
giorgianig is offline   Reply With Quote

Old   November 26, 2024, 07:24
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,255
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Hello Giorgio,

It looks like a job for the exprField function object!
https://doc.openfoam.com/2312/tools/...eld/exprField/

Cheers,
Yan
Yann is offline   Reply With Quote

Old   November 26, 2024, 08:18
Default
  #3
Member
 
Giorgio
Join Date: Mar 2023
Posts: 57
Rep Power: 3
giorgianig is on a distinguished road
Quote:
Originally Posted by Yann View Post
Hello Giorgio,

It looks like a job for the exprField function object!
https://doc.openfoam.com/2312/tools/...eld/exprField/

Cheers,
Yan
Thank you for your reply Yann. I don't see how to make an average using the exprField function object. Maybe I have to make the average using the surfaceFieldValue object and use the result in exprField?
giorgianig is offline   Reply With Quote

Old   November 27, 2024, 05:59
Default
  #4
Member
 
Giorgio
Join Date: Mar 2023
Posts: 57
Rep Power: 3
giorgianig is on a distinguished road
It seems that function objects create fields that can be stored for later use. From the documentation:

"Many function objects create fields that can be stored for later use. To avoid potential name clashes in the database, the useNamePrefix entry can be used to prepend the name of the function object to the name of the output field, e.g. applied to a fieldAverage function object, a velocity mean field could be named fieldAverage1:UMean."

It is not clear which function objects are able to do so, and how to practically do it. I wrote a first function object:

HTML Code:
cuttingPlane001
{
    type            surfaceFieldValue;
    libs            (fieldFunctionObjects);
    enabled         yes;
    writeControl    timeStep;
    writeInterval   1; 
    writeFields     no;
    writeToFile     no;

    //interpolationScheme cellPoint;
    regionType      sampledSurface;
    name            z-0.01;
    sampledSurfaceDict
    {
            type                    cuttingPlane;
            planeType               pointAndNormal;
            pointAndNormalDict
            {
                    basePoint       (0 0 0.01);  
                    normalVector    (0 0 1);
            }
            source cells; // sample cells or boundaryFaces
            interpolate true;
    }
    operation       areaAverage;
    fields          ( alpha.SA );
    result ctp001;

}
and another to use the result cpt001

HTML Code:
expr001
{
	type exprField;
	libs            (fieldFunctionObjects);
	name expr001;
	expression "(0.9-ctp001)/0.4";
	dimensions      [   ];
}
I am calling them in controlDict

HTML Code:
functions
{
    #include "cuttingPlane001"
    #include "expr001"
}
but I get:

HTML Code:
--> FOAM FATAL IO ERROR: (openfoam-2312 patch=240220) 
Entry 'field' not found in dictionary 
"/home/giorgio/tutorials/combustion/reactingFoam/RAS/TEST_liquid/lockExchange/system/controlDict/functions/expr001" 
file: system/controlDict/functions/expr001 at line 10 to 14.
giorgianig is offline   Reply With Quote

Old   November 28, 2024, 13:32
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,255
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Hello Giorgio,

Quote:
Originally Posted by giorgianig View Post
It seems that function objects create fields that can be stored for later use.
Yes, this was indeed my initial idea when I mentioned exprField.

However, I did not pay enough attention to the details: surfaceFieldValue will output a single value rather than a field, and I think exprField needs a field to work with.

It would need to have a closer look, but surfaceFieldValue does not seem to store anything to the object registry in order to be used afterward in another function object.
There is an inherited writeFields switch, but it does not seem to do anything here.
Yann is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Error in enabling the python wrapper Jinn SU2 Installation 2 April 23, 2022 14:52
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
Custom field function object from wallHeatFlux HorstvanGrass OpenFOAM Post-Processing 1 August 3, 2021 13:28
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 06:42
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 10:56


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