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

How to modify kinematic viscosity "nu" within the time loop?

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 1 Post By MartinB
  • 5 Post By MartinB
  • 1 Post By suman91

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2011, 09:50
Default How to modify kinematic viscosity "nu" within the time loop?
  #1
New Member
 
Join Date: Mar 2011
Posts: 9
Rep Power: 15
taner is on a distinguished road
Dear all,

kinematic viscosity "nu" can be modified during the runtime by changing its value in the "transportProperties" dictionary.
Is there a simple way to change its value within the time loop?
I would like to define it as a function of time/iterations in a SIMPLE solver to improve convergence like:

while (runTime.loop())
{

if ( current_time <= some_fixed_time )
{
nu = nu_desired * ( some_fixed_time / current_time );
}
else
{
nu = nu_desired;
}

...

}

so that it reaches to the desired value after some fixed time. I would appreciate any proposal to implement it in an elegant way.

Thanks in advance
Taner.
taner is offline   Reply With Quote

Old   April 26, 2011, 10:41
Default
  #2
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22
MartinB will become famous soon enough
Hi Taner,

I propose to modify one of the existing viscosity models. You can find them in OpenFOAM-xxx/src/transportModels/incompressible/viscosityModels/.

Add some new values to the constant/transportProperties file, for example nu_start, nu_desired and some_fixed_time. Read these values into your new viscosity model class and adjust the current nu in dependency of the current time step.

This approach should work directly for simpleFoam or nonNewtonianIcoFoam and every other solver that uses non newtonian material models.

Martin
amuzeshi likes this.
MartinB is offline   Reply With Quote

Old   April 26, 2011, 15:01
Default
  #3
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22
MartinB will become famous soon enough
Well, here is a quick implementation. I changed the algorithm a little bit so that it runs more smoothly with my test case.

First, the "constant/transportProperties" file:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  1.6                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

transportModel  approachingNu;

approachingNuCoeffs
{
    nu_desired             nu_desired [ 0 2 -1 0 0 0 0 ] 1e-06;
    nu_start                  nu_start [ 0 2 -1 0 0 0 0 ] 1.0;
    some_fixed_time   some_fixed_time [ 0 0 1 0 0 0 0 ] 200;
}

// ************************************************************************* //
Here is the header file "approachingNu.H", written and roughly tested for OpenFOAM-1.6-ext:
Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright held by original author
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Class
    Foam::viscosityModels::approachingNu

Description
    A material model which is approaching the desired viscosity nu_desired,
    starting from nu_start.

    A blended algorithm is:
    if (current_time < some_fixed_time_)
    {
        scalar alpha = current_time / some_fixed_time;
        return (alpha * nu_desired_ + (1 - alpha) * nu_start_);
    }
    else
    {
        return nu_desired_;
    }

    However this one behaves better in my tests:
    if (current_time < some_fixed_time_)
    {
        scalar alpha = (nu_start * 1000 / nu_desired) ^ (1/some_fixed_time)
        return (nu_start / (alpha ^ current_time)) + nu_desired;
    }
    else
    {
        return nu_desired_;
    }
    

SourceFiles
    approachingNu.C

\*---------------------------------------------------------------------------*/

#ifndef approachingNu_H
#define approachingNu_H

#include "viscosityModel.H"
#include "dimensionedScalar.H"
#include "volFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace viscosityModels
{

/*---------------------------------------------------------------------------*\
                           Class approachingNu Declaration
\*---------------------------------------------------------------------------*/

class approachingNu
:
    public viscosityModel
{
    // Private data

        dictionary approachingNuCoeffs_;

        dimensionedScalar nu_desired_;
        dimensionedScalar nu_start_;
        dimensionedScalar some_fixed_time_;

        volScalarField nu_;


    // Private Member Functions

        //- Calculate and return the laminar viscosity
        tmp<volScalarField> calcNu() const;


public:

    //- Runtime type information
    TypeName("approachingNu");


    // Constructors

        //- construct from components
        approachingNu
        (
            const word& name,
            const dictionary& viscosityProperties,
            const volVectorField& U,
            const surfaceScalarField& phi
        );


    // Destructor

        ~approachingNu()
        {}


    // Member Functions

        //- Return the laminar viscosity
        const volScalarField& nu() const
        {
            return nu_;
        }

        //- Correct the laminar viscosity
        void correct()
        {
            nu_ = calcNu();
        }

        //- Read transportProperties dictionary
        bool read(const dictionary& viscosityProperties);
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace viscosityModels
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
And the "approachingNu.C" file:
Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright held by original author
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*---------------------------------------------------------------------------*/

#include "approachingNu.H"
#include "addToRunTimeSelectionTable.H"
#include "surfaceFields.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace viscosityModels
{
    defineTypeNameAndDebug(approachingNu, 0);
    addToRunTimeSelectionTable
    (
        viscosityModel,
        approachingNu,
        dictionary
    );
}
}


// * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
/* this is the linear blended algorithm... however I do prefer the alternative algorithm below
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::approachingNu::calcNu() const
{
    scalar current_time((U_.time()).value());
    Info << "current_time = " << current_time << endl;
    Info << "some_fixed_time_ = " << some_fixed_time_.value() << endl;

    if (current_time < some_fixed_time_.value())
    {
        scalar alpha = current_time / some_fixed_time_.value();
        Info << "alpha = " << alpha << ", nu = " << (alpha * nu_desired_ + (1 - alpha) * nu_start_) << endl;
        return
        (
            strainRate() * dimensionedScalar("dummy",nu_desired_.dimensions()*dimTime,0.0) // dummy for adding strainRate dependend model
            + (alpha * nu_desired_ + (1 - alpha) * nu_start_)
        );
    }
    else
    {
        Info << "nu = " << nu_desired_ << endl;
        return
        (
            strainRate() * dimensionedScalar("dummy",nu_desired_.dimensions()*dimTime,0.0) // dummy for adding strainRate dependend model
            + nu_desired_
        );
    }
}
*/
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::approachingNu::calcNu() const
{
    scalar current_time((U_.time()).value());
    //Info << "current_time = " << current_time << endl;
    //Info << "some_fixed_time_ = " << some_fixed_time_.value() << endl;

    if (current_time < some_fixed_time_.value())
    {
        scalar alpha = pow((nu_start_.value()*1000/nu_desired_.value()), (1/some_fixed_time_.value()));
        //Info << "alpha = " << alpha << ", nu = " << (nu_start_ / (pow(alpha, current_time))) + nu_desired_ << endl;
        return
        (
            strainRate() * dimensionedScalar("dummy",nu_desired_.dimensions()*dimTime,0.0) // dummy for adding strainRate dependend model
            + (nu_start_ / (pow(alpha, current_time))) + nu_desired_ 
        );
    }
    else
    {
        //Info << "nu = " << nu_desired_ << endl;
        return
        (
            strainRate() * dimensionedScalar("dummy",nu_desired_.dimensions()*dimTime,0.0) // dummy for adding strainRate dependend model
            + nu_desired_
        );
    }
}

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::viscosityModels::approachingNu::approachingNu
(
    const word& name,
    const dictionary& viscosityProperties,
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
    viscosityModel(name, viscosityProperties, U, phi),
    approachingNuCoeffs_(viscosityProperties.subDict(typeName + "Coeffs")),
    nu_desired_(approachingNuCoeffs_.lookup("nu_desired")),
    nu_start_(approachingNuCoeffs_.lookup("nu_start")),
    some_fixed_time_(approachingNuCoeffs_.lookup("some_fixed_time")),
    
    nu_
    (
        IOobject
        (
            "nu",
            U_.time().timeName(),
            U_.db(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        calcNu()
    )
{}


// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //

bool Foam::viscosityModels::approachingNu::read
(
    const dictionary& viscosityProperties
)
{
    viscosityModel::read(viscosityProperties);

    approachingNuCoeffs_ = viscosityProperties.subDict(typeName + "Coeffs");

    approachingNuCoeffs_.lookup("nu_desired") >> nu_desired_;
    approachingNuCoeffs_.lookup("nu_start") >> nu_start_;
    approachingNuCoeffs_.lookup("some_fixed_time") >> some_fixed_time_;

    return true;
}


// ************************************************************************* //
For non-Extend OpenFOAM versions it should be
Code:
tmp<volScalarField> nu() const
in line 126 instead, but I didn't test it with these versions...

Martin
MartinB is offline   Reply With Quote

Old   April 28, 2011, 04:51
Default
  #4
New Member
 
Join Date: Mar 2011
Posts: 9
Rep Power: 15
taner is on a distinguished road
Hi Martin,
I appreciated your quick and accurate support very much.
The model that you implemented works well for the non-extended, official OpenFOAM 1.7.1.
Best regards,
Taner.
taner is offline   Reply With Quote

Old   January 8, 2013, 04:12
Default
  #5
New Member
 
Hossein Yahyazadeh
Join Date: Oct 2012
Posts: 9
Rep Power: 14
hossein_y62 is on a distinguished road
Hi every body,

I need to change the power law in the OpenFOAM-xxx/src/transportModels/incompressible/viscosityModels/ directory. How can I do that?

the default power law model defines nuMax and nuMin, as I set them to 100000 and 0 respectively, the run time will increase dramatically. I have to notice that I am using interFoam Solver.

It would be very appreciated if someone could help me,

Thanx
hossein_y62 is offline   Reply With Quote

Old   September 20, 2016, 20:04
Default Cannot access nu value
  #6
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 12
suman91 is on a distinguished road
Hi,

Since this thread talks about kinematic viscosity and changing its value, am posting my doubt here. I am running a flow over backward facing step using LES model and pisoFoam. I can't seem to access the kinematic viscosity by referring to it as "nu";

I tried to just print the value to see if I have access to it:

Code:
Info<<"laminar viscosity is"<<nu;
I get the error : " nu was not declared in this scope"

Please suggest where I am going wrong. I am using OpenFOAM 2.4.0
suman91 is offline   Reply With Quote

Old   October 13, 2016, 11:30
Default
  #7
Member
 
Sebastian W.
Join Date: Nov 2012
Location: Saxony, Germany
Posts: 43
Rep Power: 14
nero235 is on a distinguished road
Send a message via ICQ to nero235
You're calling the wrong function. The function name is
Code:
nu()
See:
Code:
singlePhaseTransportModel.H
.

Best, Sebastian
nero235 is offline   Reply With Quote

Old   October 26, 2016, 10:19
Default
  #8
Member
 
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 12
suman91 is on a distinguished road
Hi Sebastian,

Thanks for the reply. Really appreciate it. Sorry was not able to reply to this before. I should have posted an update. So, I was able to access the viscosity values in the following manner:

Code:
volScalarField viscosity = laminarTransport.nu();
Another way I was able to access it was through the turbulence object

Code:
volScalarField viscosity = turbulence->nu();
Thanks again.
Suman
amolrajan likes this.
suman91 is offline   Reply With Quote

Reply

Tags
runtime modifiable, transportproperties


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
Physical Reason for stability of Implicit Schemes? radhakrishnan Main CFD Forum 26 October 3, 2023 23:05
How to modify the viscosity model mpml OpenFOAM Running, Solving & CFD 4 October 13, 2010 08:44
Questions about Cross-Arrhenius and Cross-WLF viscosity model awacs OpenFOAM Running, Solving & CFD 4 August 13, 2009 07:56
kinematic viscosity at diff temperatures,pressures Mecobio Main CFD Forum 0 November 7, 2005 13:55
unsteady calcs in FLUENT Sanjay Padhiar Main CFD Forum 1 March 31, 1999 13:32


All times are GMT -4. The time now is 23:32.