CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

How to rename the field name in FunctionObject?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Michael@UW

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 21, 2024, 09:59
Default How to rename the field name in FunctionObject?
  #1
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
For example, I use wallShearStress function object first then use mag , then get the field like
Code:
mag(wallShearStress)
. How can I rename mag(wallShearStress) to mag_tau?

This is just an example. What I want is to control the output file name of the field obtained from FO. I know that U and p are created in the solver, but the fileds created in FO should be able to control by users.

Also, how can I manipulate these derived fields, for example, how to calculate mag(U)*mag(U)/2 + p (energy head)?
Michael@UW is offline   Reply With Quote

Old   February 21, 2024, 10:48
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,148
Rep Power: 27
Yann will become famous soon enough
Hello,

I don't know which OpenFOAM branch/version you are using, so I'll answer for the OpenCFD branch (openfoam.com).
I didn't check if it is also true on the foundation branch (openfoam.org).

You can use the parameter result to define your own variable name: https://doc.openfoam.com/2306/tools/...cts/field/mag/
This parameter seems to be inherited from the fieldExpression class, so it should also be available in the other function objects using this class.

The objects created by function objects are available in the database to be used in other function object, so you should be able to use the field computed by a function object in another function object.

Depending on what you need to do, you can also have a look at the exprField function object to directly define the expression you need to compute: https://doc.openfoam.com/2306/tools/...eld/exprField/

I hope this will help you to find the information your need,
Yann
Yann is offline   Reply With Quote

Old   February 21, 2024, 11:35
Default
  #3
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
Hi Yann,
Thank you so much for your help!

Quote:
Originally Posted by Yann View Post
Hello,

I don't know which OpenFOAM branch/version you are using, so I'll answer for the OpenCFD branch (openfoam.com). I didn't check if it is also true on the foundation branche (openfoam.org).
I use OpenFOAM v2306. Your methods work very well.

Quote:
Originally Posted by Yann View Post
You can use the parameter result to define your own variable name: https://doc.openfoam.com/2306/tools/...cts/field/mag/
This parameter seems to be inherited from the fieldExpression class, so it should also be available in the other function objects using this class.

Quote:
Originally Posted by Yann View Post
The objects created by function objects are available in the database to be used in other function object, so you should be able to use the field computed by a function object in another function object.
I tested, result keyword can rename the filed name mag(fieldName). This works for FO mag. I tried it for fieldAverage, but it seems it does not work.


Quote:
Originally Posted by Yann View Post
Depending on what you need to do, you can also have a look at the exprField function object to directly define the expression you need to compute: https://doc.openfoam.com/2306/tools/...eld/exprField/
exprField is a fantastic one. It actually can replace many functionObjects such as mag, add , and others. I'm playing with this one.
Yann likes this.
Michael@UW is offline   Reply With Quote

Old   February 21, 2024, 11:58
Default
  #4
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,148
Rep Power: 27
Yann will become famous soon enough
I'm glad it helped!

Quote:
Originally Posted by Michael@UW View Post
I tested, result keyword can rename the filed name mag(fieldName). This works for FO mag. I tried it for fieldAverage, but it seems it does not work.
I think this is because fieldAverage does not inherit from the fieldExpression class. It inherits from fieldAverageItem but it does not look like there is a way to define the field names there.
https://doc.openfoam.com/2306/tools/.../fieldAverage/

Cheers,
Yann
Yann is offline   Reply With Quote

Old   February 21, 2024, 12:20
Default
  #5
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
Basically, I want to calculate the time averaged shear stress and rename it to TAWSS. Here is my dict:

Code:
// step 1: get wall shear stress
	tau
	{
		type            wallShearStress;
		libs            (fieldFunctionObjects);

		patches         (wall); 
		writeControl        writeTime;
	}

// step 2: get the magnitude of wall shear stress and rename it to mag_tau
    magwallShearStress
    {
        type            mag;
        libs            (fieldFunctionObjects);

        // Mandatory (inherited) entries (runtime modifiable)
        field           wallShearStress;

        // Optional (inherited) entries
        result  mag_tau;  // rename mag(wallShearStress) to mag_tau
        region          region0;
        enabled         true;
        log             true;
        timeStart       0;
        timeEnd         1000;
        executeControl  timeStep;
        executeInterval 1;
        writeControl    timeStep;
        writeInterval   1;
        writeFields     true;
    }


// step 3: get the time averaged wall shear stress, we'll get the field named "mag_tauMean"
    mean_tau
    {
        type                fieldAverage;
        libs  ("libfieldFunctionObjects.so");
        timeStart           0;
        writeControl    timeStep;
        writeInterval   1;
        writeFields     no;
        fields
        (
            wallShearStress
            {   
                mean        on;
                prime2Mean  off;
                base        time;  // time average
           }
        );

    }

// step 4: manipulate mag_tauMean obtained in step 3. Here I only rename it but could do other thing.
    TAWSS1
    {
        type exprField;
        libs (fieldFunctionObjects);

        writeControl    timeStep;
        writeInterval   1;

        action new; // no, new(default), modify
        field TAWSS;
        readFields (mag_tauMean);

        autowrite true; //default: false
        store     true; //default: true  store on the object-registry
        // dimension [0 2 -2 0 0 0 0];
// note: mag_tauMean field looks good.
        expression "1000*mag_tauMean";
         // dimension [Pa];
    }
But step 4 failed, in the TAWSS file, the values are zero as follows and the dimension seems wrong no matter how I define it int the dict.

Code:
dimensions      [0 0 0 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    inlet
    {
        type            zeroGradient;
    }
    inlet2
    {
        type            zeroGradient;
    }
    outlet
    {
        type            zeroGradient;
    }
    wall
    {
        type            zeroGradient;
    }
    procBoundary0to1
    {
        type            processor;
        value           uniform 0;
    }
    procBoundary0to2
    {
        type            processor;
        value           uniform 0;
    }
    procBoundary0to3
    {
        type            processor;
        value           uniform 0;
    }
    procBoundary0to5
    {
        type            processor;
        value           uniform 0;
    }
}
Michael@UW is offline   Reply With Quote

Old   February 21, 2024, 12:21
Default
  #6
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
Quote:
Originally Posted by Yann View Post
I'm glad it helped!



I think this is because fieldAverage does not inherit from the fieldExpression class. It inherits from fieldAverageItem but it does not look like there is a way to define the field names there.
https://doc.openfoam.com/2306/tools/.../fieldAverage/

Cheers,
Yann
Yeah. It makes sense.
Michael@UW is offline   Reply With Quote

Old   February 22, 2024, 03:19
Default
  #7
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,148
Rep Power: 27
Yann will become famous soon enough
Quote:
Originally Posted by Michael@UW View Post
// step 3: get the time averaged wall shear stress, we'll get the field named "mag_tauMean"
Code:
    mean_tau
    {
        type                fieldAverage;
        libs  ("libfieldFunctionObjects.so");
        timeStart           0;
        writeControl    timeStep;
        writeInterval   1;
        writeFields     no;
        fields
        (
            wallShearStress
            {   
                mean        on;
                prime2Mean  off;
                base        time;  // time average
           }
        );

    }
I don't understand how you can get mag_tauMean on step 3 as you defined averaging for wallShearStress. You should get wallShearStressMean rather than mag_tauMean.
Yann 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
functionObject to process field from scalarTransport, field not found Tom Lauriks Main CFD Forum 6 April 29, 2020 11:25
Access to field which is evaluated at the moment Tobi OpenFOAM Programming & Development 6 April 19, 2017 13:09
[General] How to create an additional vector with {Field 4, Field 5, Field 6} Bombacar ParaView 1 August 15, 2015 18:05
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL AndoniBM OpenFOAM Running, Solving & CFD 2 March 25, 2015 18:44
how to rename a field defined from others fields ? Cyp OpenFOAM Programming & Development 2 April 26, 2012 11:32


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