|
[Sponsors] |
Function object for strain rate tensor? |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 ![]() |
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_))); } Thanks |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 ![]() |
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; } |
|
![]() |
![]() |
![]() |
![]() |
#3 |
New Member
Join Date: Aug 2017
Posts: 28
Rep Power: 9 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#4 | |
Member
Yousef
Join Date: Feb 2015
Posts: 40
Rep Power: 11 ![]() |
Quote:
Just copy the vorticity file under that folder and rename it to strainRate. Then modify the file content accordingly. Hope this helps. Regards, |
||
![]() |
![]() |
![]() |
![]() |
#5 |
New Member
Join Date: Aug 2017
Posts: 28
Rep Power: 9 ![]() |
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 ) |
|
![]() |
![]() |
![]() |
![]() |
#6 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 ![]() |
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; // ************************************************************************* // Modify field/Make/files to add Code:
strainRate/strainRate.C 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() {} // ************************************************************************* // 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 // ************************************************************************* // |
|
![]() |
![]() |
![]() |
![]() |
#7 |
New Member
Join Date: Aug 2017
Posts: 28
Rep Power: 9 ![]() |
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 ) |
|
![]() |
![]() |
![]() |
![]() |
#8 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 ![]() |
Yes, run wmake in $FOAM_SRC/functionObjects/field
|
|
![]() |
![]() |
![]() |
![]() |
#9 |
New Member
Join Date: Aug 2017
Posts: 28
Rep Power: 9 ![]() |
Thank you blebon, you were very helpful
|
|
![]() |
![]() |
![]() |
![]() |
#10 |
Senior Member
Elham
Join Date: Oct 2009
Posts: 184
Rep Power: 16 ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#11 | |
Member
Join Date: Sep 2018
Posts: 53
Rep Power: 7 ![]() |
Quote:
![]() ![]() ![]() ![]() |
||
![]() |
![]() |
![]() |
![]() |
#12 |
Member
Sourav Mandal
Join Date: Jul 2019
Posts: 55
Rep Power: 7 ![]() |
For the people who are wondering why it takes so long, try to use:
Code:
wmake -j 16 HTML Code:
https://www.cfd-online.com/Forums/openfoam-installation/57543-openfoam-14-parallel-build.html |
|
![]() |
![]() |
![]() |
![]() |
#13 | |
New Member
Join Date: Dec 2020
Posts: 9
Rep Power: 5 ![]() |
Quote:
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 |
||
![]() |
![]() |
![]() |
![]() |
#14 |
Member
Bruno Lebon
Join Date: Dec 2012
Posts: 33
Rep Power: 13 ![]() |
Did you put the strainRate dictionary file in the system directory?
|
|
![]() |
![]() |
![]() |
![]() |
#15 |
New Member
Join Date: Dec 2020
Posts: 9
Rep Power: 5 ![]() |
||
![]() |
![]() |
![]() |
![]() |
#16 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 51 ![]() ![]() ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#17 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 711
Rep Power: 14 ![]() |
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.:
![]() but in others (eg Fluent manual for the realizable k-eps model) it will simply be the norm: ![]() 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, ![]() ![]() where ![]() ![]() with all the other components being zero. The norm of this tensor is therefore: ![]() And so to recover the strain rate we need to introduce the sqrt(2) factor: ![]() 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. |
|
![]() |
![]() |
![]() |
![]() |
#18 |
Senior Member
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 12 ![]() |
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.
__________________
The OpenFOAM community is the biggest contributor to OpenFOAM: User guide/Wiki-1/Wiki-2/Code guide/Code Wiki/Journal Nilsson/Guerrero/Holzinger/Holzmann/Nagy/Santos/Nozaki/Jasak/Primer Governance Bugs/Features: OpenFOAM (ESI-OpenCFD-Trademark) Bugs/Features: FOAM-Extend (Wikki-FSB) Bugs: OpenFOAM.org How to create a MWE New: Forkable OpenFOAM mirror |
|
![]() |
![]() |
![]() |
![]() |
#19 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 711
Rep Power: 14 ![]() |
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
![]() |
|
![]() |
![]() |
![]() |
Tags |
function objects, strain rate |
|
|
![]() |
||||
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 |