
[Sponsors] 
March 8, 2016, 08:16 
nuEff()()[patchI] and nuEff()

#1 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Dear all,
I have a simple question about the following. In the fixedShearStress BC we find this: Code:
const label patchI = patch().index(); const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>(phiName_); scalarField nuEff; if (phi.dimensions() == dimVelocity*dimArea) { const incompressible::turbulenceModel& turbModel = db().lookupObject<incompressible::turbulenceModel> ( "turbulenceModel" ); nuEff = turbModel.nuEff()()[patchI]; } At least nuEff is empty: Code:
nuEff 0() Code:
Info<< turbModel.nuEff() << endl; If I use this one, that is exactly the same, I get some complete different values: Code:
scalarField nuEff2(turbModel.nuEff()()[patch().index()]); Info<< "nuEff2: " << nuEff2 << endl; Result: nuEff2 124 (boundary has 500 faces) ( 6.91743e310 2.3774e316 4.24399e314 2.34004e316 8.3003e321 4.74303e322 . . . Code:
Info<< "nueff: " << turbModel.nuEff()()[patchI] << endl; Result: nueff: 124.601 Code:
scalarField nuEff2(turbModel.nuEff()()[patch().index()]); nuEff = turbModel.nuEff()()[patchI]; At least the BC will fail because we use nuEff to divide: Code:
operator==(tauHat*(tauHat & (tau0_*(1.0/(ry*nuEff)) + Uc))); Finally, if we output the turbModel.nuEff() we get the correct values: Code:
. . . movingWall { type calculated; value nonuniform List<scalar> 500 ( 0.285685 0.285685 0.285685 0.285685 0.285685 0.285685 0.285685 0.285685 . . . I also made a bug report now because it seems really strange. http://openfoam.org/mantisbt/view.php?id=2020
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 8, 2016, 09:22 

#2 
Senior Member
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,423
Rep Power: 25 
Hi,
Maybe I am missing something but, turbulenceModel::nuEff() returns tmp<volScalarField>, so nuEff()() (http://foam.sourceforge.net/docs/cpp...2d975c8876d3d6) is volScalarField and nuEff()()[index] should be scalar. Yet there is turbulenceModel::nuEff(label patchI), which returns viscosity on a patch. Could you post whole code snippet (so it could be compiled and tested)? 

March 8, 2016, 09:41 

#3 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Hey Bruno,
thanks for the reference about ()() ... here is the link to the file. If you are correct and ()()[patchI] returns a scalar, why we use a scalarField nuEff than and can you tell me what scalar is returned? Mean value of the patch or sth. like that? http://www.openfoam.com/documentatio...36_source.html
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 8, 2016, 10:04 

#4 
Senior Member
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,423
Rep Power: 25 
Hi,
Not quite Bruno, but OK Do you talk about line 112 of fixedShearStressFvPatchVectorField.C? It uses turbulenceModel::nuEff(label patchI), which returns tmp<scalarField> (http://www.openfoam.com/documentatio...4f85f6644d2d6a). 

March 8, 2016, 10:14 

#5 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Aaa its version 3.0 Here it the file I was talking about...
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 8, 2016, 10:17 

#6  
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Quote:
Code:
Return the effective viscosity on patch.
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 8, 2016, 10:31 

#7 
Senior Member
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,423
Rep Power: 25 
You have scalarField with the size of the patch and it is has scalar for each face value.
Though BC uses this  turbModel.nuEff()()[patchI]  strange construction, turbulenceModel class has nuEff(label patchI) method even in 2.3.1. Last edited by alexeym; March 8, 2016 at 10:37. Reason: rephrasing 

March 8, 2016, 10:56 

#8 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Hi,
Henry changed it: https://github.com/OpenFOAM/OpenFOAM...1fe57e8a140c7c For 3.0.x it is working now but for 2.3.1 I get an error if I use the code you (or henry) mentioned: Code:
fixedShearStress/fixedShearStressFvPatchVectorField.C: In member function 'virtual void Foam::fixedShearStressFvPatchVectorField::updateCoeffs()': fixedShearStress/fixedShearStressFvPatchVectorField.C:136:55: error: no matching function for call to 'Foam::incompressible::turbulenceModel::nuEff(const label&) const' const scalarField& nuEff2(turbModel.nuEff(patchI)); ^ fixedShearStress/fixedShearStressFvPatchVectorField.C:136:55: note: candidate is: In file included from fixedShearStress/fixedShearStressFvPatchVectorField.C:31:0: /home/shorty/OpenFOAM/OpenFOAM2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H:199:37: note: virtual Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::incompressible::turbulenceModel::nuEff() const virtual tmp<volScalarField> nuEff() const = 0; ^ /home/shorty/OpenFOAM/OpenFOAM2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H:199:37: note: candidate expects 0 arguments, 1 provided fixedShearStress/fixedShearStressFvPatchVectorField.C:136:26: warning: unused variable 'nuEff2' [Wunusedvariable] const scalarField& nuEff2(turbModel.nuEff(patchI)); ^
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 8, 2016, 11:47 

#9 
Senior Member
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,423
Rep Power: 25 
Hi,
Even in 2.3.1 there are two types of turbulence models ones in src/turbulenceModels and another in src/TurbulenceModels (surprise, surprise). First type does not have nuEff(const label), second type has it and for RASModel it is implemented as: Code:
// Return the effective viscosity on patch virtual tmp<scalarField> nuEff(const label patchi) const { return this>nut(patchi) + this>nu(patchi); } Code:
// Return the laminar viscosity for patch tmp<scalarField> nu(const label patchi) const { return nu_.boundaryField()[patchi]; } Code:
// Return the turbulence viscosity on patch virtual tmp<scalarField> nut(const label patchi) const { return nut_.boundaryField()[patchi]; } Code:
nuEff = turbModel.nuEff()()[patchI] Code:
scalarField nuEff(turbModel.nuEff().boundaryField()[patchI]); Code:
transport().nu(patchI) Code:
scalarField nuEff(transport().nu(patchI) + nut().boundaryField()[patchI]); 

March 8, 2016, 12:58 

#10 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Hi,
I will try it tomorrow but today I tried it with boundaryField() without success. Maybe I made a simple mistake. Thanks in advance.
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 11, 2016, 08:08 

#11 
Senior Member
Join Date: Oct 2013
Posts: 369
Rep Power: 6 
I think there might also be problems with memory management. You receive a tmp<volScalarField> without storing it, and only access the boundary. I had a similar issue before and for me it helped to initialize a copy of the volScalarField before accessing the patch values like this:
volScalarField copy(turb>nuEff()); Afterwards you can use the boundaries of the copied field without worrying about the scope of the classes contained in the temporary object. In my case I even regarded it as a bug or atleast a design error. 

March 11, 2016, 08:29 

#12 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Hey,
thanks for the hint. At last the code has to be: Code:
nuEff = turbModel.nuEff()().boundaryField()[patchI];
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 11, 2016, 19:16 
strange things explained

#13 
Member
Thomas Boucheres
Join Date: May 2013
Posts: 37
Rep Power: 5 
Hello Tobi.
First thanks for your tuto and videos. Good job which could help some people and help OF to be more widely used than it is For your problem described here, Alexeym gave you good answer (using turbModel.nuEf()().boundaryField()[patchI]). To complete the post, I can give you some answers to the "strange" things you have mentioned in your first post. All things are related to the fact that turbModel.nuEff()()[patchI] (which is clearly a bug) is a scalar as mentioned by alexeym. A) What happens is the following: scalarField nuEff > create a scalarField of size 0 nuEff = turbModel.nuEff()()[patchI] > it is the UList<Type>:perator =(Type& v) (with Type=scalar) which assign all values of the List to v. But do nothing here since nuEff is of size 0! So nuEff is still empty list and Info << nuEff gives 0(). B) Other thing: your "scalarField nuEff2(turbmodel.nuEff()()[patchI])"... In fact, you try to construct a scalarField with a constructor scalarField (scalar& v) But this constructor doesn't exist... You have scalarField(label i, scalar v) (build a scalarField of size i and all values equal v) but clearly it is not this one you use. In fact, you use the base constructor scalarField(label i) which construct a scalarField of size i and no prescribed values (so compiler dependant / something like VSMALL for most compilers). And what is your i? The integer part of the scalar turbModel.nuEff()()[patchI] (124 for your example). These things explain what you have seen. 

March 11, 2016, 20:32 

#14 
Senior Member
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,519
Blog Entries: 6
Rep Power: 26 
Dear Thomas,
thanks for completing the topic and the feedback to my webpage. I am familiar with c++ but the error reported here was from a collegue in the german openfoam forum, that I just investigated during other investigations (: So at last I wanted to report you the bug, learn new things (thanks to you and Alexeym) but I did not investigate into the code deeply and of course I am not a FOAM  code expert (what function will return what or what is doing that). Its good that there are people like you that will clear the questions. So just one question. If I will create my scalarField nuEff with the size of the real field (lets say 200), and use Code:
nuEff = turbModel.nuEff()()[patchI] Nice dreams,
__________________
Best regards, Tobias Holzmann Some interesting OpenFOAM tutorials, publications and videos on www.Holzmanncfd.de OpenFOAM Beginners should check out the new wiki on wiki.openfoam.com A list of some active OpenFOAM contributers can be found »here« A book about the basics of »Mathematics, Numerics, Derivations and OpenFOAM« can be found on www.Holzmanncfd.de 

March 12, 2016, 16:30 

#15 
Member
Thomas Boucheres
Join Date: May 2013
Posts: 37
Rep Power: 5 
Well if you write:
" scalarField nuEff(200) // create a scalarField with size 200 (not yet inialized here) .... nuEff = turbModel.nuEff()()[patchI] // assign all values of the scalarField as equal to the scalar on the right; comes from UList:perator =(scalar &v); doesn't change the size of the container as said in th previous post " at end, all the 200 values of the nuEff list will be equal to the same scalar value turbModel.nuEff()()[patchI]. It takes sense from informatic point of view but it is clearly not what you want I think. You should prefer the scalarField nuEff being equal to the scalarField turbModel.nuEff()().boundaryField()[patchI]. For this, you must use alexeym correct expression: " scalarField nuEff // create zero sized List (size doesn't matter here  see later) nuEff = turbModel.nuEff()().boundaryField()[patchI] // it is the UList:perator =(UList& f) function. This function resizes the calling list (nuEff here) to the size of the called one (f in the prototype / turbModel..... in the example  this is why the instanciation of nuEff as a zero sized list doesn't matter) and equals the values. " 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Calculating divDevReff  jposunz  OpenFOAM Running, Solving & CFD  46  August 18, 2016 06:35 
Add new nuEff() law to simpleFoam  T.D.  OpenFOAM Running, Solving & CFD  2  July 16, 2015 07:27 
Calculate and display eddy viscosity  ceyrows  OpenFOAM Running, Solving & CFD  4  February 16, 2009 13:57 