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 Members List Search Today's Posts Mark Forums Read

Like Tree18Likes
  • 2 Post By blebon
  • 4 Post By blebon
  • 1 Post By pibil1
  • 6 Post By blebon
  • 1 Post By pibil1
  • 3 Post By blebon
  • 1 Post By sourav90

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: 10
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
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: 10
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;
}
rarnaunot, Tanwk, sourav90 and 1 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: 5
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: 8
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: 5
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: 10
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

// ************************************************************************* //
hulli, tooran, rarnaunot and 3 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: 5
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: 10
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: 5
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: 13
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: 42
Rep Power: 4
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
New Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 21
Rep Power: 3
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: 4
Rep Power: 2
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: 10
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: 4
Rep Power: 2
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

Reply

Tags
function objects, strain rate

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
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 15:49.