CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Changing viscosity in interFoam (https://www.cfd-online.com/Forums/openfoam-solving/149915-changing-viscosity-interfoam.html)

ThomasV March 11, 2015 04:14

Changing viscosity in interFoam
 
Hi!

I want to use interFoam and change the viscosity depending on the temperature. I already included the temperature transport and a method for interpolating the respective viscosity values based on some actually measured data. I'm now struggling to get access to the viscosity field / understanding how all of this works...

1.)
The viscosity is calculated via the incompressibleTwoPhaseMixture model. There a volScalarField "nu_" is created but it's protected so I cannot change it via my solver's code...

2.)
I had a look at the velocity / pressure solver itself to see where the viscosity is passed on to the solver so I could like clone the internally calculated viscosity field in order to pass on an altered version to the actual velocity equations. I would have expected to see it in the momentum equation but for U there's just this:

Code:

    fvVectorMatrix UEqn
    (
        fvm::ddt(rho, U)
      + fvm::div(rhoPhi, U)
      + turbulence->divDevRhoReff(rho, U)
    );

    UEqn.relax();

    if (pimple.momentumPredictor())
    {
        solve
        (
            UEqn
        ==
            fvc::reconstruct
            (
                (
                    fvc::interpolate(interface.sigmaK())*fvc::snGrad(alpha1)
                  - ghf*fvc::snGrad(rho)
                  - fvc::snGrad(p_rgh)
                ) * mesh.magSf()
            )
        );
    }

So at which point in the solver's code does the viscosity play a role and how can I get access to the viscosity field in order to change it?

kebsiali March 11, 2015 09:55

hello

I'm also interested in doing this ( I have to. )
I think, if you are not going to use any turbulence model (laminar case)
then you could just exchange the line
+ turbulence->divDevRhoReff(rho, U)
with one like in icoFoam
where you will have to go to createFields.H and create you nu1 nu2 and nu
and make it calculated like rho (averaging).
However it might prove not effective (its just an idea i came up with to try)
in case you find another solution i'm very interested in knowing how

and i think that the slover uses the nu as calculated in
incompressibleTwoPhaseMixture.C
by calling
twoPhaseProperties.correct();

ybapat March 11, 2015 23:45

Hello Thomas,

You can write your own viscosity model as in src/transportModels/viscosityModel. Here you can find different viscosity models are implemented.

Regards,
-Yogesh

ThomasV March 12, 2015 02:47

Hi!

Thanks for your suggestions. Writing a viscosity model of my own might be a solution but after quite a struggle to get a boundary condition of mine to work I want to avoid writing more template code plus it usually costs quite some time to understand how those models are supposed to work. But maybe I should have a look at this again - perhaps OpenFOAM surprises me for once by giving a straightforward process for integrating something new... ;)

Right now I'm trying to implement a "dirty trick". I just copied the entire transport model sources to my solver in order to compile all of this as a custom library. I then added a function which passes on a pointer to the nu_ volScalarField. In my solver I know use the pointer to simply overwrite nu_ with a field of my own. This seems to work so far but recently I just did some tests without the U and p calculations so I still have to check that it won't become overwritten by something. There also seems to be a bug in my interpolation code I have to fix first...

If none of all this will work I guess I'll try kebsiali's approach. So the viscosity is implemented via the turbulence model?

olivierG March 12, 2015 04:45

hello,

This has already been done ...
check http://www.tfd.chalmers.se/~hani/kur...nFoam%20v2.pdf

Regards,
olivier

ThomasV March 12, 2015 06:43

Thanks - that's a nice source. Way more easy than my approach... ;)


All times are GMT -4. The time now is 17:00.