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

Function object for strain rate tensor?

Register Blogs Community New Posts Updated Threads Search

Like Tree25Likes
  • 3 Post By blebon
  • 5 Post By blebon
  • 1 Post By pibil1
  • 9 Post By blebon
  • 1 Post By pibil1
  • 3 Post By blebon
  • 1 Post By sourav90
  • 2 Post By Tobermory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 9, 2017, 07:47
Default Function object for strain rate tensor?
  #1
Member
 
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13
blebon is on a distinguished road
Dear Foamers,

Is there a way of outputting the strain rate using function objects?

The strainRate is already calculated in viscosityModel:

Code:
Foam::tmp<Foam::volScalarField> Foam::viscosityModel::strainRate() const
{
    return sqrt(2.0)*mag(symm(fvc::grad(U_)));
}
I would like to output this field from a calculated case with -postProcess.

Thanks
kiski, y_jiang and ahparvin like this.
blebon is offline   Reply With Quote

Old   August 9, 2017, 08:35
Default Just created a new function object
  #2
Member
 
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13
blebon is on a distinguished road
Never mind, found a solution and posting it if anyone interested in the future. Just create a new function object to recalculate the strain rate. Copy the vorticity fn object and rename strainRate, change the curl include line to #include "fvcGrad.H" and edit the calc function as follows:

Code:
bool Foam::functionObjects::strainRate::calc()
{
    if (foundObject<volVectorField>(fieldName_))
    {
        return store
        (
            resultName_,
            sqrt(2.0)*mag(symm(fvc::grad(lookupObject<volVectorField>(fieldName_))))
        );
    }
    else
    {
        return false;
    }

    return true;
}
hulli, rarnaunot, Tanwk and 2 others like this.
blebon is offline   Reply With Quote

Old   September 1, 2017, 18:38
Smile How to achieve
  #3
New Member
 
Join Date: Aug 2017
Posts: 28
Rep Power: 8
pibil1 is on a distinguished road
Hello blebon,

Thanks Can you help me on how to implement this please?, I have copied /opt/openfoam4/src/functionObjects/field/vorticity to /opt/openfoam4/src/functionObjects/field/strainRate. Then replaced everything that says vorticity to strainRate in both strainRate.H and strainRate.C. Then added #include "fvcGrad.H" in strainRate.H and rewrote the calc funcion.

Please help I get this error

--> FOAM Warning :
From function bool Foam::dictionary::add(Foam::entry*, bool)
in file db/dictionary/dictionary.C at line 807
Reading ""
attempt to add entry functions which already exists in dictionary ""
--> FOAM Warning :
From function static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, Foam::HashSet<>&, const Foam::word&)
in file db/functionObjects/functionObjectList/functionObjectList.C at line 245
Cannot find functionObject file strainRate
sourav90 likes this.
pibil1 is offline   Reply With Quote

Old   September 1, 2017, 18:50
Default
  #4
Member
 
Yousef
Join Date: Feb 2015
Posts: 40
Rep Power: 11
ykanani is on a distinguished road
Quote:
Originally Posted by pibil1 View Post
Hello blebon,

Thanks Can you help me on how to implement this please?, I have copied /opt/openfoam4/src/functionObjects/field/vorticity to /opt/openfoam4/src/functionObjects/field/strainRate. Then replaced everything that says vorticity to strainRate in both strainRate.H and strainRate.C. Then added #include "fvcGrad.H" in strainRate.H and rewrote the calc funcion.

Please help I get this error

--> FOAM Warning :
From function bool Foam::dictionary::add(Foam::entry*, bool)
in file db/dictionary/dictionary.C at line 807
Reading ""
attempt to add entry functions which already exists in dictionary ""
--> FOAM Warning :
From function static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, Foam::HashSet<>&, const Foam::word&)
in file db/functionObjects/functionObjectList/functionObjectList.C at line 245
Cannot find functionObject file strainRate
Hi, I believe adding the strainRate file under the /opt/openfoam4/etc/caseDicts/postProcessing/fields/ will solve your second warning.
Just copy the vorticity file under that folder and rename it to strainRate. Then modify the file content accordingly. Hope this helps.

Regards,
ykanani is offline   Reply With Quote

Old   September 2, 2017, 12:15
Default
  #5
New Member
 
Join Date: Aug 2017
Posts: 28
Rep Power: 8
pibil1 is on a distinguished road
Hi Ikanani,

I already had done that, can you help me please? I got this error:

--> FOAM Warning :
From function bool Foam::functionObjectList::read()
in file db/functionObjects/functionObjectList/functionObjectList.C at line 671
Caught FatalError
--> FOAM FATAL ERROR:
Unknown function type strainRate

Valid functions are :

39
(
CourantNo
Lambda2
MachNo
PecletNo
Q
blendingFactor
components
div
enstrophy
fieldAverage
fieldCoordinateSystemTransform
fieldMinMax
fieldValueDelta
flowType
grad
histogram
mag
magSqr
nearWallFields
patchProbes
pressure
probes
processorField
psiReactionThermoMoleFractions
randomise
readFields
regionSizeDistribution
rhoReactionThermoMoleFractions
sets
streamLine
surfaceInterpolate
surfaceRegion
surfaces
turbulenceFields
volRegion
vorticity
wallBoundedStreamLine
wallShearStress
yPlus
)
pibil1 is offline   Reply With Quote

Old   September 4, 2017, 09:15
Default
  #6
Member
 
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13
blebon is on a distinguished road
Hi pibil1,

Sorry for the late reply. My additions to the standard code are:

In /etc/caseDicts/postProcessing/fields

file strainRate with contents:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Web:      www.OpenFOAM.org
     \\/     M anipulation  |
-------------------------------------------------------------------------------
Description
    Calculates the strainRate field.

\*---------------------------------------------------------------------------*/

type            strainRate;
libs            ("libfieldFunctionObjects.so");

field           U;

executeControl  writeTime;
writeControl    writeTime;

// ************************************************************************* //
In $FOAM_SRC/functionObjects

Modify field/Make/files to add

Code:
strainRate/strainRate.C
just below vorticity/vorticity.C (might be what you are missing?)

Added a folder field/strainRate with contents

strainRate.C

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2014-2016 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "strainRate.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(strainRate, 0);

    addToRunTimeSelectionTable
    (
        functionObject,
        strainRate,
        dictionary
    );
}
}


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

bool Foam::functionObjects::strainRate::calc()
{
    if (foundObject<volVectorField>(fieldName_))
    {
        return store
        (
            resultName_,
            sqrt(2.0)*mag(symm(fvc::grad(lookupObject<volVectorField>(fieldName_))))
        );
    }
    else
    {
        return false;
    }

    return true;
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::functionObjects::strainRate::strainRate
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    fieldExpression(name, runTime, dict, "U")
{
    setResultName(typeName, "U");
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::functionObjects::strainRate::~strainRate()
{}


// ************************************************************************* //
strainRate.H

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2014-2016 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::functionObjects::strainRate

Group
    grpFieldFunctionObjects

Description
    This function object calculates the strain rate.

See also
    Foam::functionObjects::fieldExpression
    Foam::functionObjects::fvMeshFunctionObject

SourceFiles
    strainRate.C

\*---------------------------------------------------------------------------*/

#ifndef functionObjects_strainRate_H
#define functionObjects_strainRate_H

#include "fieldExpression.H"

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

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                          Class strainRate Declaration
\*---------------------------------------------------------------------------*/

class strainRate
:
    public fieldExpression
{
    // Private Member Functions

        //- Calculate the strainRate field and return true if successful
        virtual bool calc();


public:

    //- Runtime type information
    TypeName("strainRate");


    // Constructors

        //- Construct from Time and dictionary
        strainRate
        (
            const word& name,
            const Time& runTime,
            const dictionary& dict
        );


    //- Destructor
    virtual ~strainRate();
};


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

} // End namespace functionObjects
} // End namespace Foam

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

#endif

// ************************************************************************* //
Maff, hulli, GodotMisogi and 6 others like this.
blebon is offline   Reply With Quote

Old   September 4, 2017, 19:01
Default
  #7
New Member
 
Join Date: Aug 2017
Posts: 28
Rep Power: 8
pibil1 is on a distinguished road
Thanks a lot blebon, do I have to compile or make something? because after following step by step your guide I get this error in OpenFOAM 4.1

--> FOAM Warning :
From function bool Foam::dictionary::add(Foam::entry*, bool)
in file db/dictionary/dictionary.C at line 807
Reading "" from line 13 to line 19
attempt to add entry functions which already exists in dictionary ""
--> FOAM Warning :
From function bool Foam::functionObjectList::read()
in file db/functionObjects/functionObjectList/functionObjectList.C at line 671
Caught FatalError
--> FOAM FATAL ERROR:
Unknown function type strainRate

Valid functions are :

39
(
CourantNo
Lambda2
MachNo
PecletNo
Q
blendingFactor
components
div
enstrophy
fieldAverage
fieldCoordinateSystemTransform
fieldMinMax
fieldValueDelta
flowType
grad
histogram
mag
magSqr
nearWallFields
patchProbes
pressure
probes
processorField
psiReactionThermoMoleFractions
randomise
readFields
regionSizeDistribution
rhoReactionThermoMoleFractions
sets
streamLine
surfaceInterpolate
surfaceRegion
surfaces
turbulenceFields
volRegion
vorticity
wallBoundedStreamLine
wallShearStress
yPlus
)
sourav90 likes this.
pibil1 is offline   Reply With Quote

Old   September 5, 2017, 03:25
Default
  #8
Member
 
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13
blebon is on a distinguished road
Yes, run wmake in $FOAM_SRC/functionObjects/field
hulli, pibil1 and sourav90 like this.
blebon is offline   Reply With Quote

Old   September 5, 2017, 12:04
Smile
  #9
New Member
 
Join Date: Aug 2017
Posts: 28
Rep Power: 8
pibil1 is on a distinguished road
Thank you blebon, you were very helpful
pibil1 is offline   Reply With Quote

Old   March 8, 2019, 01:26
Default
  #10
Senior Member
 
Elham
Join Date: Oct 2009
Posts: 184
Rep Power: 16
Elham is on a distinguished road
Quote:
Originally Posted by pibil1 View Post
Thank you blebon, you were very helpful
Hi everybody,


Can I have the stress tensor with postprocessing directly?

I have used foalCalc to have the gradU. The resul is a tensor of 9 elements. I do not know which argument is the Uij and Uji to find the strain tensor then. Anyone knows?



Regards,
Elham
Elham is offline   Reply With Quote

Old   April 26, 2019, 12:36
Default
  #11
Member
 
Join Date: Sep 2018
Posts: 53
Rep Power: 7
tecmul is on a distinguished road
Quote:
Originally Posted by Elham View Post
Hi everybody,


Can I have the stress tensor with postprocessing directly?

I have used foalCalc to have the gradU. The resul is a tensor of 9 elements. I do not know which argument is the Uij and Uji to find the strain tensor then. Anyone knows?



Regards,
Elham
The gradient tensor that gradU outputs is \partial{u_j}/\partial{x_i}. So the first element, grad_0 is \partial{u}/\partial{x}, grad_2 is \partial{w}/\partial{x} and grad_3 is \partial{u}/\partial{y}.
tecmul is offline   Reply With Quote

Old   August 9, 2020, 05:57
Default Parallel building makes it much faster
  #12
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 6
sourav90 is on a distinguished road
Quote:
Originally Posted by blebon View Post
Yes, run wmake in $FOAM_SRC/functionObjects/field
For the people who are wondering why it takes so long, try to use:

Code:
wmake -j 16
where `16` is the number of processor cores available in your machine. As noted from here:
HTML Code:
https://www.cfd-online.com/Forums/openfoam-installation/57543-openfoam-14-parallel-build.html
hulli likes this.
sourav90 is offline   Reply With Quote

Old   March 4, 2021, 05:32
Default
  #13
New Member
 
Join Date: Dec 2020
Posts: 9
Rep Power: 5
ahparvin is on a distinguished road
Quote:
Originally Posted by pibil1 View Post
Thanks a lot blebon, do I have to compile or make something? because after following step by step your guide I get this error in OpenFOAM 4.1

--> FOAM Warning :
From function bool Foam::dictionary::add(Foam::entry*, bool)
in file db/dictionary/dictionary.C at line 807
Reading "" from line 13 to line 19
attempt to add entry functions which already exists in dictionary ""
--> FOAM Warning :
From function bool Foam::functionObjectList::read()
in file db/functionObjects/functionObjectList/functionObjectList.C at line 671
Caught FatalError
--> FOAM FATAL ERROR:
Unknown function type strainRate

Valid functions are :

39
(
CourantNo
Lambda2
MachNo
PecletNo
Q
blendingFactor
components
div
enstrophy
fieldAverage
fieldCoordinateSystemTransform
fieldMinMax
fieldValueDelta
flowType
grad
histogram
mag
magSqr
nearWallFields
patchProbes
pressure
probes
processorField
psiReactionThermoMoleFractions
randomise
readFields
regionSizeDistribution
rhoReactionThermoMoleFractions
sets
streamLine
surfaceInterpolate
surfaceRegion
surfaces
turbulenceFields
volRegion
vorticity
wallBoundedStreamLine
wallShearStress
yPlus
)
Hey pibil1

Thank you! I did all steps, The function apparently is running on all time steps, but I can not find any outputs.

I also have warning at the beginning...

Code:
Create time

Create mesh for time = 0

--> FOAM Warning : 
    From function static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, const Foam::string&, Foam::HashSet<>&, const Foam::word&)
    in file db/functionObjects/functionObjectList/functionObjectList.C at line 311
    Cannot find functionObject file strainRate
Time = 0

Reading fields:


Executing functionObjects
ahparvin is offline   Reply With Quote

Old   March 4, 2021, 05:41
Default
  #14
Member
 
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13
blebon is on a distinguished road
Did you put the strainRate dictionary file in the system directory?
blebon is offline   Reply With Quote

Old   March 4, 2021, 08:58
Default
  #15
New Member
 
Join Date: Dec 2020
Posts: 9
Rep Power: 5
ahparvin is on a distinguished road
Quote:
Originally Posted by blebon View Post
Did you put the strainRate dictionary file in the system directory?
Thanks for your quick reply!
No, how is that? should I make one?
ahparvin is offline   Reply With Quote

Old   June 13, 2021, 05:45
Default
  #16
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hey everybody,


can someone give the information regarding the square root of 2 in front of the equation mentioned in the first post? Based on my derivations (from my book) and here on cfd-online (Calculating divDevReff), I never saw this factor and I have no idea where this factor occurs. For me it seems that the calculation of the strain rate is only used for non-Newtonian fluids and is not related to Newtonian fluids
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   June 14, 2021, 06:14
Default
  #17
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
I understand your confusion here - in some sources (eg the Shih et al paper on the realizable k-epsilon model, StarCCM+ manual, CFX manual) you'll see the shear rate defined as sqrt(2) times the norm, i.e.:

\gamma = \sqrt{2 \mathbf{S}:\mathbf{S}}

but in others (eg Fluent manual for the realizable k-eps model) it will simply be the norm:

\tilde{S} = \sqrt{\mathbf{S}:\mathbf{S}}

The reason for the difference is just convention, I think. As I think someone else has said in one of the numerous posts on this subject, the sqrt(2) is introduced for compatibility with the 2D case. Let me explain. Consider a case of a simple shear flow, \partial U / \partial y, with all other velocity partial derivatives being zero. The shear stress is:

\tau= \mu \frac{\partial U}{\partial y} = \mu \gamma

where \gamma = \partial U/\partial y is the strain rate. Now, from the strain rate tensor, we have:

\mathbf{S}_{12} = \mathbf{S}_{21} = \frac{1}{2} \frac{\partial U}{\partial y}

with all the other components being zero. The norm of this tensor is therefore:

\sqrt{\mathbf{S}:\mathbf{S}} = \sqrt{\mathbf{S}_{12}^2 + \mathbf{S}_{21}^2} = \sqrt{2\mathbf{S}_{12}^2} =\frac{1}{\sqrt{2}} \frac{\partial U}{\partial y}

And so to recover the strain rate we need to introduce the sqrt(2) factor:

\gamma = \sqrt{2\mathbf{S}:\mathbf{S}} = \sqrt{4\mathbf{S}_{12}^2} = \frac{\partial U}{\partial y}

In other words, in this definition of the strain rate parameter, it is calculated from sqrt(2) times the norm of the strain tensor. Either convention is "correct" - it's just important to keep track of which one you are using.
HPE and ahparvin like this.
Tobermory is offline   Reply With Quote

Old   June 23, 2021, 17:12
Default
  #18
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
As far as I remember, the global confusion around sqrt(2) thereat stems from FLUENT's unconventional convention, which, for some reason, does not use the factor of 0.5 in the computation of the symmetric part of the gradient tensor, hence affecting the conventional factors in the expressions of the dependent variables, e.g. magnitude of shear rate, in unconventional ways.
HPE is offline   Reply With Quote

Old   June 24, 2021, 03:50
Default
  #19
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
Agreed - that's probably the main cause, although beware that some journal papers, eg the Shih one on the realizable k-epsilon model, will also use the expression without the root 2 (i.e. the \tilde{S}, above) for use in calculating other model parameters (though not to denote the shear rate, which should always have the root 2 I think) ... in fact the Shih paper uses both!
Tobermory is offline   Reply With Quote

Reply

Tags
function objects, strain rate


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
Mass Flow Rate Custom Field Function AJoubert FLUENT 2 March 23, 2013 08:50
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 14:11
Compilation errors in ThirdPartymallochoard feng_w OpenFOAM Installation 1 January 25, 2009 06:59
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 07:36


All times are GMT -4. The time now is 10:28.