|
[Sponsors] |
How to modify kinematic viscosity "nu" within the time loop? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 26, 2011, 09:50 |
How to modify kinematic viscosity "nu" within the time loop?
|
#1 |
New Member
Join Date: Mar 2011
Posts: 9
Rep Power: 15 |
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. |
|
April 26, 2011, 10:41 |
|
#2 |
Senior Member
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22 |
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 |
|
April 26, 2011, 15:01 |
|
#3 |
Senior Member
Martin
Join Date: Oct 2009
Location: Aachen, Germany
Posts: 255
Rep Power: 22 |
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; } // ************************************************************************* // 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 // ************************************************************************* // 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; } // ************************************************************************* // Code:
tmp<volScalarField> nu() const Martin |
|
April 28, 2011, 04:51 |
|
#4 |
New Member
Join Date: Mar 2011
Posts: 9
Rep Power: 15 |
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. |
|
January 8, 2013, 04:12 |
|
#5 |
New Member
Hossein Yahyazadeh
Join Date: Oct 2012
Posts: 9
Rep Power: 14 |
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 |
|
September 20, 2016, 20:04 |
Cannot access nu value
|
#6 |
Member
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 12 |
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; Please suggest where I am going wrong. I am using OpenFOAM 2.4.0 |
|
October 13, 2016, 11:30 |
|
#7 |
Member
|
You're calling the wrong function. The function name is
Code:
nu() Code:
singlePhaseTransportModel.H Best, Sebastian |
|
October 26, 2016, 10:19 |
|
#8 |
Member
Suman Chakraborty
Join Date: Sep 2014
Location: Mumbai, India
Posts: 42
Rep Power: 12 |
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(); Code:
volScalarField viscosity = turbulence->nu(); Suman |
|
Tags |
runtime modifiable, transportproperties |
|
|
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 |