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

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

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By MartinB

Reply
 
LinkBack Thread Tools Display Modes
Old   April 26, 2011, 08:50
Default How to modify kinematic viscosity "nu" within the time loop?
  #1
New Member
 
Join Date: Mar 2011
Posts: 9
Rep Power: 6
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, 09:41
Default
  #2
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 252
Rep Power: 11
MartinB is on a distinguished road
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
MartinB is offline   Reply With Quote

Old   April 26, 2011, 14:01
Default
  #3
Senior Member
 
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 252
Rep Power: 11
MartinB is on a distinguished road
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
wyldckat likes this.
MartinB is offline   Reply With Quote

Old   April 28, 2011, 03:51
Default
  #4
New Member
 
Join Date: Mar 2011
Posts: 9
Rep Power: 6
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: 4
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

Reply

Tags
runtime modifiable, transportproperties

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the viscosity model mpml OpenFOAM Running, Solving & CFD 4 October 13, 2010 07:44
Questions about Cross-Arrhenius and Cross-WLF viscosity model awacs OpenFOAM Running, Solving & CFD 4 August 13, 2009 06:56
kinematic viscosity at diff temperatures,pressures Mecobio Main CFD Forum 0 November 7, 2005 13:55
Physical Reason for stability of Implicit Schemes? radhakrishnan Main CFD Forum 25 December 7, 2000 16:25
unsteady calcs in FLUENT Sanjay Padhiar Main CFD Forum 1 March 31, 1999 12:32


All times are GMT -4. The time now is 03:59.