CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Update Viscosity in every time step (https://www.cfd-online.com/Forums/openfoam-programming-development/238080-update-viscosity-every-time-step.html)

user_HH August 22, 2021 16:48

Update Viscosity in every time step
 
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

mAlletto August 24, 2021 03:12

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

user_HH August 24, 2021 08:37

2 Attachment(s)
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

mAlletto August 27, 2021 08:08

Did you have a look at this tutorial: compressible/rhoSimpleFoam/squareBendLiqNoNewtonian/constant/turbulenceProperties


how looks your turbulenceProperties file like?

mAlletto August 27, 2021 08:29

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

user_HH August 27, 2021 14:21

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 August 27, 2021 14:44

Michael,

My turbulenProperties file is simple:

#

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

simulationType laminar;

#

Thanks,
HH

mAlletto August 27, 2021 14:48

Ok. Yes the tutorial is actually from OF2012. Maybe you should modify the turbulence property according to the tutorial

user_HH August 27, 2021 14:52

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 August 29, 2021 12:35

Update
 
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

mAlletto August 29, 2021 13:18

Nice you found a solution


All times are GMT -4. The time now is 09:04.