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

How to obtain fluid shear stress (not only wall shear stress) in openFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By sourav90

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 12, 2020, 15:33
Default How to obtain fluid shear stress (not only wall shear stress) in openFOAM
  #1
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7
sourav90 is on a distinguished road
Dear All,

I want to calculate/visualise shear stress inside the fluid domain. I came through wallShearStress utility but as you know, it only calculates the shear stress at the wall.

My model is very simple: a long pipe, with a non-Newtonian fluid simulated at a certain pressure difference between the inlet and the outlet, solved using simpleFoam.

Surprisingly, I found no relevant documentation, although there is plenty of discussion regarding the shear stress at the wall. I came through this helpful post, which enabled me to calculate shear strain in the fluid domain but finding it hard to adopt the approach to obtain shear stress.

Function object for strain rate tensor?

I tried with the approach mentioned there, by making files named fluidShearStressSM.C etc. At the wmake stage it throws a lot of errors such as :

Code:
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam7/src/finiteVolume/lnInclude -I/opt/openfoam7/src/meshTools/lnInclude -I/opt/openfoam7/src/lagrangian/basic/lnInclude -I/opt/openfoam7/src/fileFormats/lnInclude -I/opt/openfoam7/src/sampling/lnInclude -I/opt/openfoam7/src/surfMesh/lnInclude -I/opt/openfoam7/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam7/src/thermophysicalModels/solidThermo/lnInclude -I/opt/openfoam7/src/transportModels -I/opt/openfoam7/src/transportModels/compressible/lnInclude -I/opt/openfoam7/src/TurbulenceModels/turbulenceModels/lnInclude -I/opt/openfoam7/src/TurbulenceModels/incompressible/lnInclude -I/opt/openfoam7/src/TurbulenceModels/compressible/lnInclude -IlnInclude -I. -I/opt/openfoam7/src/OpenFOAM/lnInclude -I/opt/openfoam7/src/OSspecific/POSIX/lnInclude   -fPIC -c fluidShearStressSM/fluidShearStressSM.C -o /opt/openfoam7/platforms/linux64GccDPInt32Opt/src/functionObjects/field/fluidShearStressSM/fluidShearStressSM.o
fluidShearStressSM/fluidShearStressSM.C: In member function ‘virtual bool Foam::functionObjects::fluidShearStressSM::calc()’:
fluidShearStressSM/fluidShearStressSM.C:65:13: error: expected primary-expression before ‘const’
   65 |             const volTensorField& gradU = fvc::grad(U);
      |             ^~~~~
fluidShearStressSM/fluidShearStressSM.C:68:43: error: ‘mu’ was not declared in this scope
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                           ^~
fluidShearStressSM/fluidShearStressSM.C:68:49: error: ‘gradU’ was not declared in this scope
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                                 ^~~~~
fluidShearStressSM/fluidShearStressSM.C:69:9: error: expected primary-expression before ‘)’ token
   69 |         );
      |         ^
fluidShearStressSM/fluidShearStressSM.C:68:35: warning: unused variable ‘tau’ [-Wunused-variable]
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                   ^~~
fluidShearStressSM/fluidShearStressSM.C: In constructor ‘Foam::functionObjects::fluidShearStressSM::fluidShearStressSM(const Foam::word&, const Foam::Time&, const Foam::dictionary&)’:
fluidShearStressSM/fluidShearStressSM.C:90:5: error: type ‘Foam::functionObjects::fvMeshFunctionObject’ is not a direct base of ‘Foam::functionObjects::fluidShearStressSM’
   90 |     fvMeshFunctionObject(name, runTime, dict),
      |     ^~~~~~~~~~~~~~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:91:5: error: class ‘Foam::functionObjects::fluidShearStressSM’ does not have any field named ‘logFiles’
   91 |     logFiles(obr_, name),
      |     ^~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:92:5: error: class ‘Foam::functionObjects::fluidShearStressSM’ does not have any field named ‘writeLocalObjects’
   92 |     writeLocalObjects(obr_, log),
      |     ^~~~~~~~~~~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:93:1: error: expected identifier before ‘{’ token
   93 | {
      | ^
fluidShearStressSM/fluidShearStressSM.C:93:1: error: no matching function for call to ‘Foam::functionObjects::fieldExpression::fieldExpression()’
In file included from fluidShearStressSM/fluidShearStressSM.H:42,
                 from fluidShearStressSM/fluidShearStressSM.C:26:
lnInclude/fieldExpression.H:88:9: note: candidate: ‘Foam::functionObjects::fieldExpression::fieldExpression(const Foam::word&, const Foam::Time&, const Foam::dictionary&, const Foam::word&, const Foam::word&)’
   88 |         fieldExpression
      |         ^~~~~~~~~~~~~~~
lnInclude/fieldExpression.H:88:9: note:   candidate expects 5 arguments, 0 provided
fluidShearStressSM/fluidShearStressSM.C:95:5: error: ‘resetName’ was not declared in this scope; did you mean ‘resultName_’?
   95 |     resetName(typeName);
      |     ^~~~~~~~~
      |     resultName_
fluidShearStressSM/fluidShearStressSM.C:96:5: error: ‘resetLocalObjectName’ was not declared in this scope
   96 |     resetLocalObjectName(typeName);
      |     ^~~~~~~~~~~~~~~~~~~~
make: *** [/opt/openfoam7/wmake/rules/General/transform:26: /opt/openfoam7/platforms/linux64GccDPInt32Opt/src/functionObjects/field/fluidShearStressSM/fluidShearStressSM.o] Error 1
I would like to have the code usable both as a runtime or a post-processing tool.

I am new to OpenFOAM & have no prior exposure to OOC++ coding. Any suggestion or pointers in the right direction would help me greatly in my research, with this nice open-source software.
sourav90 is offline   Reply With Quote

Old   July 13, 2020, 04:13
Default
  #2
Member
 
Join Date: Oct 2011
Posts: 56
Rep Power: 15
fanta is on a distinguished road
-Move to $FOAM_SRC/etc/caseDicts/postProcessing/fields
-make a copy of vorticity to strainRate, replace every occurance of vorticity with strainRate in the files
-Move to $FOAM_SRC/functionObjects/field/make. Edit "files", add strainRate/strainRate.C after vorticity
-copy the folder vorticity in $FOAM_SRC/functionObjects/field to strainRate
-replace vorticity with strainRate in the copied filenames
-in strainRate.C replace #fvcCurl.H with #fvcGrad.H, replace function calc() with

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

    return false;

For non-Newtonian Liquids this formula is generally wrong. I could not find a better approach, yet.
fanta is offline   Reply With Quote

Old   August 6, 2020, 14:41
Default
  #3
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7
sourav90 is on a distinguished road
Quote:
Originally Posted by fanta View Post

For non-Newtonian Liquids this formula is generally wrong. I could not find a better approach, yet.
Why is the formula generally wrong?

BTW, the problem I am facing isn't with implementing strain rate (it works as that link says), rather with the shear stress in the entire fluid domain. Sorry, if I wasn't clear enough...
sourav90 is offline   Reply With Quote

Old   August 6, 2020, 14:56
Default Using swak4FOAM, but shear stress & wall shear stress do not match
  #4
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7
sourav90 is on a distinguished road
I found a workaround while fiddling with Swak4Foam. He files or commands that I used are as follow:
  • Contents of `funkySetFieldsDict`, to be placed inside `system/`
Code:
FoamFile
{
    version         2.0;
    format          ascii;
    instance        "system";
    local           "";
    class           dictionary;
    object          funkySetFieldsDict;
}

expressions (
    setTau {
        field           Tau;
        create          true ;
        expression      "mag(grad(U))*nu";
    }
);
  • After the simulation was over, I ran
    Code:
    funkySetFields -time '500:3000'

The simulation is as such that the highest shear stress would be at the wall. So, I compare the maximum values of shear stress and wall shear stress (using the wallShearStress utility), it's hugely different. I am not sure now, which one is correct. Can anybody help me inferring where is the error?
Attached Images
File Type: png Alg340kPaBlunted3mm0.4mm4mm6mm_tau_WSS.png (9.8 KB, 100 views)
File Type: png Alg340kPaBlunted3mm0.4mm4mm6mm.png (19.7 KB, 86 views)
sourav90 is offline   Reply With Quote

Old   November 17, 2020, 16:32
Default
  #5
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 7
Bodo1993 is on a distinguished road
Hi Sourav,
I am wondering if you managed to get a way to extract the correct stress tensor from the openFoam simulations. Thanks.
Bodo1993 is offline   Reply With Quote

Old   December 10, 2020, 13:44
Smile Version 8 of OpenFOAM has natively implemented this
  #6
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7
sourav90 is on a distinguished road
Hello Bodo1993, if you haven't found it already there are two ways to achieve this.

First, with OpenFOAM version 8, you can just add these lines at the end of your controldict file:

Code:
functions
{
//https://www.openfoam.com/documentation/guides/latest/doc/guide-function-objects.html
    #includeFunc            shearStress;

}
Copying the commit notes from here https://github.com/OpenFOAM/OpenFOAM...ae08a224cc9d4b

Quote:
"MomentumTransportModels: Update of the TurbulenceModels library for a…
…ll flow types

providing the shear-stress term in the momentum equation for incompressible and
compressible Newtonian, non-Newtonian and visco-elastic laminar flow as well as
Reynolds averaged and large-eddy simulation of turbulent flow.

The general deviatoric shear-stress term provided by the MomentumTransportModels
library is named divDevTau for compressible flow and divDevSigma (sigma =
tau/rho) for incompressible flow, the spherical part of the shear-stress is
assumed to be either included in the pressure or handled separately. The
corresponding stress function sigma is also provided which in the case of
Reynolds stress closure returns the effective Reynolds stress (including the
laminar contribution) or for other Reynolds averaged or large-eddy turbulence
closures returns the modelled Reynolds stress or sub-grid stress respectively.
For visco-elastic flow the sigma function returns the effective total stress
including the visco-elastic and Newtonian contributions.

For thermal flow the heat-flux generated by thermal diffusion is now handled by
the separate ThermophysicalTransportModels library allowing independent run-time
selection of the heat-flux model.

During the development of the MomentumTransportModels library significant effort
has been put into rationalising the components and supporting libraries,
removing redundant code, updating names to provide a more logical, consistent
and extensible interface and aid further development and maintenance. All
solvers and tutorials have been updated correspondingly and backward
compatibility of the input dictionaries provided.

Henry G. Weller
CFD Direct Ltd."
Second, iff you are curious, have time & want to have fun, then you can implement this yourself, with the cue from here Function object for strain rate tensor? However, this leads to some naming issue with the recent versions, due to the changes described here https://github.com/OpenFOAM/OpenFOAM...6bca16c6020bfe. If anyone try this with the new versions & it works, it would be great if you share it
hulli and Teresa.Z like this.

Last edited by sourav90; December 10, 2020 at 13:46. Reason: update
sourav90 is offline   Reply With Quote

Old   February 13, 2022, 00:10
Default Encounter the same problem, find a solution
  #7
New Member
 
刘旭阳
Join Date: Feb 2022
Posts: 1
Rep Power: 0
Beta Liu is on a distinguished road
I have a similar problem, would you like to ask if it is solved? If solved, can you share the code for calculating fluid shear stress? I would be very grateful and happy to share it. Thanks!
Quote:
Originally Posted by sourav90 View Post
Dear All,

I want to calculate/visualise shear stress inside the fluid domain. I came through wallShearStress utility but as you know, it only calculates the shear stress at the wall.

My model is very simple: a long pipe, with a non-Newtonian fluid simulated at a certain pressure difference between the inlet and the outlet, solved using simpleFoam.

Surprisingly, I found no relevant documentation, although there is plenty of discussion regarding the shear stress at the wall. I came through this helpful post, which enabled me to calculate shear strain in the fluid domain but finding it hard to adopt the approach to obtain shear stress.

Function object for strain rate tensor?

I tried with the approach mentioned there, by making files named fluidShearStressSM.C etc. At the wmake stage it throws a lot of errors such as :

Code:
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam7/src/finiteVolume/lnInclude -I/opt/openfoam7/src/meshTools/lnInclude -I/opt/openfoam7/src/lagrangian/basic/lnInclude -I/opt/openfoam7/src/fileFormats/lnInclude -I/opt/openfoam7/src/sampling/lnInclude -I/opt/openfoam7/src/surfMesh/lnInclude -I/opt/openfoam7/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam7/src/thermophysicalModels/solidThermo/lnInclude -I/opt/openfoam7/src/transportModels -I/opt/openfoam7/src/transportModels/compressible/lnInclude -I/opt/openfoam7/src/TurbulenceModels/turbulenceModels/lnInclude -I/opt/openfoam7/src/TurbulenceModels/incompressible/lnInclude -I/opt/openfoam7/src/TurbulenceModels/compressible/lnInclude -IlnInclude -I. -I/opt/openfoam7/src/OpenFOAM/lnInclude -I/opt/openfoam7/src/OSspecific/POSIX/lnInclude   -fPIC -c fluidShearStressSM/fluidShearStressSM.C -o /opt/openfoam7/platforms/linux64GccDPInt32Opt/src/functionObjects/field/fluidShearStressSM/fluidShearStressSM.o
fluidShearStressSM/fluidShearStressSM.C: In member function ‘virtual bool Foam::functionObjects::fluidShearStressSM::calc()’:
fluidShearStressSM/fluidShearStressSM.C:65:13: error: expected primary-expression before ‘const’
   65 |             const volTensorField& gradU = fvc::grad(U);
      |             ^~~~~
fluidShearStressSM/fluidShearStressSM.C:68:43: error: ‘mu’ was not declared in this scope
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                           ^~
fluidShearStressSM/fluidShearStressSM.C:68:49: error: ‘gradU’ was not declared in this scope
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                                 ^~~~~
fluidShearStressSM/fluidShearStressSM.C:69:9: error: expected primary-expression before ‘)’ token
   69 |         );
      |         ^
fluidShearStressSM/fluidShearStressSM.C:68:35: warning: unused variable ‘tau’ [-Wunused-variable]
   68 |             const volTensorField& tau = - mu * (gradU + gradU.T());
      |                                   ^~~
fluidShearStressSM/fluidShearStressSM.C: In constructor ‘Foam::functionObjects::fluidShearStressSM::fluidShearStressSM(const Foam::word&, const Foam::Time&, const Foam::dictionary&)’:
fluidShearStressSM/fluidShearStressSM.C:90:5: error: type ‘Foam::functionObjects::fvMeshFunctionObject’ is not a direct base of ‘Foam::functionObjects::fluidShearStressSM’
   90 |     fvMeshFunctionObject(name, runTime, dict),
      |     ^~~~~~~~~~~~~~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:91:5: error: class ‘Foam::functionObjects::fluidShearStressSM’ does not have any field named ‘logFiles’
   91 |     logFiles(obr_, name),
      |     ^~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:92:5: error: class ‘Foam::functionObjects::fluidShearStressSM’ does not have any field named ‘writeLocalObjects’
   92 |     writeLocalObjects(obr_, log),
      |     ^~~~~~~~~~~~~~~~~
fluidShearStressSM/fluidShearStressSM.C:93:1: error: expected identifier before ‘{’ token
   93 | {
      | ^
fluidShearStressSM/fluidShearStressSM.C:93:1: error: no matching function for call to ‘Foam::functionObjects::fieldExpression::fieldExpression()’
In file included from fluidShearStressSM/fluidShearStressSM.H:42,
                 from fluidShearStressSM/fluidShearStressSM.C:26:
lnInclude/fieldExpression.H:88:9: note: candidate: ‘Foam::functionObjects::fieldExpression::fieldExpression(const Foam::word&, const Foam::Time&, const Foam::dictionary&, const Foam::word&, const Foam::word&)’
   88 |         fieldExpression
      |         ^~~~~~~~~~~~~~~
lnInclude/fieldExpression.H:88:9: note:   candidate expects 5 arguments, 0 provided
fluidShearStressSM/fluidShearStressSM.C:95:5: error: ‘resetName’ was not declared in this scope; did you mean ‘resultName_’?
   95 |     resetName(typeName);
      |     ^~~~~~~~~
      |     resultName_
fluidShearStressSM/fluidShearStressSM.C:96:5: error: ‘resetLocalObjectName’ was not declared in this scope
   96 |     resetLocalObjectName(typeName);
      |     ^~~~~~~~~~~~~~~~~~~~
make: *** [/opt/openfoam7/wmake/rules/General/transform:26: /opt/openfoam7/platforms/linux64GccDPInt32Opt/src/functionObjects/field/fluidShearStressSM/fluidShearStressSM.o] Error 1
I would like to have the code usable both as a runtime or a post-processing tool.

I am new to OpenFOAM & have no prior exposure to OOC++ coding. Any suggestion or pointers in the right direction would help me greatly in my research, with this nice open-source software.
Beta Liu is offline   Reply With Quote

Old   June 7, 2023, 07:26
Default
  #8
Member
 
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7
sourav90 is on a distinguished road
Quote:
Originally Posted by Beta Liu View Post
I have a similar problem, would you like to ask if it is solved? If solved, can you share the code for calculating fluid shear stress? I would be very grateful and happy to share it. Thanks!
Sorry for my late reply! My goal was to plot the shear stress in the entire domain -wallShearStress utility (functionObject) wasn't good for that. I used the OpenFOAM.org (version 6) back then. Later on OpenFOAM 7/8 provided shearStress utility, which served the purpose

You can find a minimal reproducible example (MRE), for the published paper with this work here: inSilicoE3DBP_model_MRE
sourav90 is offline   Reply With Quote

Old   June 27, 2023, 11:03
Default
  #9
New Member
 
Shanu
Join Date: Jun 2023
Posts: 3
Rep Power: 3
chaudhad is on a distinguished road
Hi Sourav and everyone,


I know this is an ancient post but I hope someone can find me a solution. I have been stuck for a very long time. I am actually doing LES and cannot figure out how to output wall shear stress during the simulation in openfoam. So I was trying to calculate the wall shear stress in Paraview using gradientOfUnstructuresDataSet and then extracting the surface and computing the surface normals and then doing the dot product of this gradient tensor with the surface normal vector and the dynamic viscosity to calculate the wall shear stress. But my gradient vectors are computed all zero on the wall. I don't know how to include the gradient at the cell centroid and not at the face of the wall cell. Any help will be highly appreciated.
chaudhad is offline   Reply With Quote

Reply

Tags
fluid shear stress, function objects, post procesing, programming, runtime processing


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
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
UDF for wall slipping HFLUENT Fluent UDF and Scheme Programming 0 April 27, 2011 13:03
Wall shear stress distributions en51nm STAR-CD 2 January 28, 2010 05:42
LES: mean wall shear stress Francois FLUENT 0 July 7, 2005 12:15
WALL SHEAR STRESS Min-Hua Wang CFX 0 April 3, 2002 18:40


All times are GMT -4. The time now is 13:00.