MartinB |
April 26, 2011 14:01 |
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
|