|
[Sponsors] |
March 8, 2016, 07:16 |
nuEff()()[patchI] and nuEff()
|
#1 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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.91743e-310 2.3774e-316 4.24399e-314 2.34004e-316 8.3003e-321 4.74303e-322 . . . 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
__________________
Keep foaming, Tobias Holzmann |
|
March 8, 2016, 08:22 |
|
#2 |
Senior Member
|
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, 08:41 |
|
#3 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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
__________________
Keep foaming, Tobias Holzmann |
|
March 8, 2016, 09:04 |
|
#4 |
Senior Member
|
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, 09:17 |
|
#6 | |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Quote:
Code:
Return the effective viscosity on patch.
__________________
Keep foaming, Tobias Holzmann |
||
March 8, 2016, 09:31 |
|
#7 |
Senior Member
|
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 09:37. Reason: rephrasing |
|
March 8, 2016, 09:56 |
|
#8 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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/OpenFOAM-2.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/OpenFOAM-2.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' [-Wunused-variable] const scalarField& nuEff2(turbModel.nuEff(patchI)); ^
__________________
Keep foaming, Tobias Holzmann |
|
March 8, 2016, 10:47 |
|
#9 |
Senior Member
|
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, 11:58 |
|
#10 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Hi,
I will try it tomorrow but today I tried it with boundaryField() without success. Maybe I made a simple mistake. Thanks in advance.
__________________
Keep foaming, Tobias Holzmann |
|
March 11, 2016, 07:08 |
|
#11 |
Senior Member
Join Date: Oct 2013
Posts: 397
Rep Power: 18 |
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, 07:29 |
|
#12 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Hey,
thanks for the hint. At last the code has to be: Code:
nuEff = turbModel.nuEff()().boundaryField()[patchI];
__________________
Keep foaming, Tobias Holzmann |
|
March 11, 2016, 18:16 |
strange things explained
|
#13 |
Member
Thomas Boucheres
Join Date: May 2013
Posts: 41
Rep Power: 12 |
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, 19:32 |
|
#14 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
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,
__________________
Keep foaming, Tobias Holzmann |
|
March 12, 2016, 15:30 |
|
#15 |
Member
Thomas Boucheres
Join Date: May 2013
Posts: 41
Rep Power: 12 |
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. " |
|
October 26, 2017, 08:10 |
|
#16 | |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15 |
Quote:
I have a problem with nuEff() because as you said it creates list with size zero. How to force nuEff() to create a list of mesh size?
__________________
best regards pblasiak |
||
October 26, 2017, 08:45 |
|
#17 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15 |
Basically I overriden nu() to return my volScalarField.
And Now I get the error in nuEff() = this->nut() + this->nu() that nut() returns zero size list and nu() returns the size equal to e.g. 1400 So the sizes are not equal during summation. So I am wondering how to force nut() to return the same list size as nu()??
__________________
best regards pblasiak |
|
October 27, 2017, 03:40 |
|
#18 |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15 |
Hi
In the RASModel.H we have a function nuEff() Code:
//- Return the effective viscosity virtual tmp<volScalarField> nuEff() const { return tmp<volScalarField> ( new volScalarField ( IOobject::groupName("nuEff", this->U_.group()), this->nut() + this->nu() ) ); } Code:
Foam::tmp<Foam::volScalarField> nu() { return tmp<volScalarField>(dynamicVisc/density); } When in the UEqn.H I have a code Code:
turbulence->divDevReff() How can I change the code to nut() returns also mesh size list?
__________________
best regards pblasiak |
|
November 4, 2017, 05:06 |
|
#19 | |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15 |
Quote:
I found how to solve the problem. I had something like this Code:
Foam::tmp<Foam::volScalarField> Foam::viscosityModels::Helium::calcNu() { volScalarField nu ( IOobject ( "nuLocal", U_.time().timeName(), U_.db(), IOobject::NO_READ, IOobject::NO_WRITE ), eta_/rho_ ); return nu; } Code:
Selecting incompressible transport model Helium #0 Foam::error::printStack(Foam::Ostream&) at ~/OpenFOAM/OpenFOAM-v1606+/src/OSspecific/POSIX/printStack.C:218 #1 Foam::sigSegv::sigHandler(int) at ~/OpenFOAM/OpenFOAM-v1606+/src/OSspecific/POSIX/signals/sigSegv.C:56 #2 ? in "/lib/x86_64-linux-gnu/libc.so.6" #3 Foam::List<double>::List(Foam::List<double>&, bool) at ~/OpenFOAM/OpenFOAM-v1606+/src/OpenFOAM/lnInclude/List.C:166 #4 Foam::Field<double>::Field(Foam::Field<double>&, bool) at ~/OpenFOAM/OpenFOAM-v1606+/src/OpenFOAM/lnInclude/Field.C:223 #5 Foam::DimensionedField<double, Foam::volMesh>::DimensionedField(Foam::IOobject const&, Foam::DimensionedField<double, Foam::volMesh>&, bool) at ~/OpenFOAM/OpenFOAM-v1606+/src/OpenFOAM/lnInclude/DimensionedField.C:203 (discriminator 2) #6 Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject const&, Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > const&) at ~/OpenFOAM/OpenFOAM-v1606+/src/OpenFOAM/lnInclude/GeometricField.C:498 #7 Foam::viscosityModels::Helium::Helium(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ~/OpenFOAM/przemek-v1606+/src/transportModels/incompressible/viscosityModels/Helium/Helium.C:276 (discriminator 86) #8 Foam::viscosityModel::adddictionaryConstructorToTable<Foam::viscosityModels::Helium>::New(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ~/OpenFOAM/przemek-v1606+/src/transportModels/incompressible/lnInclude/viscosityModel.H:96 (discriminator 2) #9 Foam::viscosityModel::New(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ~/OpenFOAM/OpenFOAM-v1606+/src/transportModels/incompressible/viscosityModels/viscosityModel/viscosityModelNew.C:58 #10 Foam::singlePhaseTransportModel::singlePhaseTransportModel(Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ~/OpenFOAM/OpenFOAM-v1606+/src/transportModels/incompressible/singlePhaseTransportModel/singlePhaseTransportModel.C:50 (discriminator 12) #11 ? at ~/OpenFOAM/OpenFOAM-v1606+/applications/solvers/heatTransfer/buoyantBoussinesqPimpleFoam/../buoyantBoussinesqSimpleFoam/readTransportProperties.H:7 #12 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #13 ? at ??:? Segmentation fault (core dumped) When I changed the nuCalc() function like this: Code:
Foam::tmp<Foam::volScalarField> Foam::viscosityModels::Helium::calcNu() { volScalarField nu ( IOobject ( "nuLocal", U_.time().timeName(), U_.db(), IOobject::NO_READ, IOobject::NO_WRITE ), eta_/rho_ ); return max ( nuMin_, min ( nuMax_, nu ) ); } Can anybody explain why this second solution works and the first doesn't?
__________________
best regards pblasiak |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calculating divDevReff | jposunz | OpenFOAM Running, Solving & CFD | 82 | June 12, 2022 14:01 |
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 12:57 |