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

Update Viscosity in every time step

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mAlletto

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 22, 2021, 16:48
Default Update Viscosity in every time step
  #1
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Hi Foamers,

For an incompressible flow case using a solver based on pimpleFoam, i am trying to update kinematic viscosity (nu()) as a function of temperature. (OpenFOAM version v1806)

I created a solver called ExpLaw using powerLaw as a reference.

# Code:

Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::ExpLaw::calcNu() const
{
const volScalarField& T = U_.mesh().lookupObject<volScalarField>("T");

return k_*exp(-n_*(T - Talpha_));
}

#

The model compiles and works in the first time step, where viscosity is being calculated using this new model. However, the model then doesn't update and shows the same values.

Now, when i stop the simulation and restart it from the last recorded time step, the expLaw is accessed and it calculates the new viscosity values at the first time step. After that, in the consecutive time steps, it again does not update the viscosity.

I have looked at a lot of different threads on this forum and spent days to solve this problem but cannot find a way to update the viscosity at each time step based on changes in the temperature field.

Please help me solve this issue.
i will really appreciate the help.

Thanks in advance.

Best,
HH
user_HH is offline   Reply With Quote

Old   August 24, 2021, 03:12
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Did you check if the function is called every time step or not? you can do this by outputting something on the screen.


From the only function you send it is impossible to judge what may be the reason of the behavior of your viscosity model
mAlletto is offline   Reply With Quote

Old   August 24, 2021, 08:37
Default
  #3
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Michael,

@mAlletto
Thank you so much for you response. Appreciate you taking the time to help me.

I output the values of viscosity using turbulence->nu() and that is how I realized that the values of viscosity are not being updated.
I also used a print statement in the function ("entered loop") as you will see in the attached ExpLaw. I only see this print statement on screen at the beginning of the simulation and NOT in every time-step.

1. Are transport properties and viscosityModel called in every time-step or just at the beginning of the simulation?
2. Is there a way to call them in every time step?
3. How can i call the calcNu() function in my runtime loop? Currently, it is using this only in the first time step to calculate the initial nu().

I am attaching the code for ExpLaw for your reference. It is exactly same as the powerLaw except the return value which is now based on an exponential function.

Please help me understand how the viscosityModel is called during the simulation and how can it be called at the beginning of each time step to update viscosity based on updated temperature.

Thanks in advance.

Best,
HH
Attached Files
File Type: c ExpLaw.C (3.1 KB, 12 views)
File Type: h ExpLaw.H (3.4 KB, 8 views)
user_HH is offline   Reply With Quote

Old   August 27, 2021, 08:08
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Did you have a look at this tutorial: compressible/rhoSimpleFoam/squareBendLiqNoNewtonian/constant/turbulenceProperties


how looks your turbulenceProperties file like?
mAlletto is offline   Reply With Quote

Old   August 27, 2021, 08:29
Default
  #5
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
To answer your questions:


TransprotProperties are evaluated at the beginning of the simulation for incompressbile solvers.



In the com version you have also viscosity models in $FOAM_SRC/TurbulenceModels/turbulenceModels/laminar/generalizedNewtonian/generalizedNewtonianViscosityModels


this are updated evey time step in the turbulence.correct() function
mAlletto is offline   Reply With Quote

Old   August 27, 2021, 14:21
Default
  #6
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Michael,

Thank you for your response.

Thanks for pointing me to this tutorial case. I haven't come across this in the past. I just checked my tutorial folder for v1806 and did not find it there. However, i did find it online. I will look at it in detail and try to replicate that for my model.

On a side note, i did try another tutorial case and made many setting changes to realize that the nu was not changing and nut was changing when turbulence model was on. Is this how it is because no model was defined for nu in turbulenceProperties file?

Extremely thankful for your help.
This helps me a lot and gives me a direction to tackle my viscosity issue.

I will try to make changes as per your recommendation and let you know how it goes.

Thanks,
HH
user_HH is offline   Reply With Quote

Old   August 27, 2021, 14:44
Default
  #7
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Michael,

My turbulenProperties file is simple:

#

FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object turbulenceProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType laminar;

#

Thanks,
HH
user_HH is offline   Reply With Quote

Old   August 27, 2021, 14:48
Default
  #8
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Ok. Yes the tutorial is actually from OF2012. Maybe you should modify the turbulence property according to the tutorial
mAlletto is offline   Reply With Quote

Old   August 27, 2021, 14:52
Default
  #9
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Michael,

I will do so.
I will first try to modify just the turbulenceProperties file.


I wonder if the same works for incompressible flows, as the tutorial is for compressible flows.

Thanks,
HH
user_HH is offline   Reply With Quote

Old   August 29, 2021, 12:35
Default Update
  #10
New Member
 
HH
Join Date: Apr 2019
Posts: 17
Rep Power: 7
user_HH is on a distinguished road
Michael,

I tried following the execution of the code and made a few changes to the solver.
I realized that this is the statement that calls viscosity model at the start of the simulation: singlePhaseTransportModel laminarTransport(U, phi);

So i used this to call the viscosity model in every time step.

I also has to updatd one portion in ExpLaw.H. I commented return nu_; and instead wrote: return calcNu() to call the function that calculated the nu based on temperature (calcNu() function is in ExpLaw.C file)

# Code

//- Return the laminar viscosity
virtual tmp<volScalarField> nu() const
{
return calcNu();
//return nu_;
}

#

These changes worked.
Now i am able to update viscosity in every time step.

Thanks so much for your help.

Best,
HH

Last edited by user_HH; August 29, 2021 at 15:46.
user_HH is offline   Reply With Quote

Old   August 29, 2021, 13:18
Default
  #11
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Nice you found a solution
user_HH likes this.
mAlletto is offline   Reply With Quote

Reply


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
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 04:13
Setting up Lid driven Cavity Benchmark with 1M cells for multiple cores puneet336 OpenFOAM Running, Solving & CFD 11 April 7, 2019 00:58
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 13:40
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 00:01
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07


All times are GMT -4. The time now is 18:16.