CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Adding a new temperature dependent viscositymodel? (http://www.cfd-online.com/Forums/openfoam-programming-development/75819-adding-new-temperature-dependent-viscositymodel.html)

dgadensg May 6, 2010 03:56

Adding a new temperature dependent viscositymodel?
 
Hi Foamers.

I am currently trying to implement a new viscosity model that is dependent on temperature. I can see that a few others in this forum has succesfully implemented the CrossWLF model, but i have not yet seen how they have done it.

My problem is how to read the volScalarField T that i have for temperature, created in createFields.H and calculated with a temperature equation.

Whenever i do this, it messes up in several classes, because the viscositymodel suddenly have an extra parameter T besides U and phi.

Does anyone have a way to get around this? or maybe even a working code to do this?

// Dan

dgadensg May 8, 2010 12:30

Solved
 
Hi again.

There is no need to answer, as i have just solved this issue. However, i did in a somewhat alternative way, by adding the volScalarField T to all my transportmodels. It works, but it is not the most elegant solution :).

// Dan

johannes May 12, 2010 17:53

Hi Dan,

I came across your thread just recently so I missed answering in time... :)

A few months ago I was in the same situation, searching for a CrossWLF viscosity model for OpenFOAM. Since I couldn't find any working code snippets floating around on the forum, I tried to implement it myself.

I don't know exactly if everything is implementet correctly, since I encountered some serious stability problems with increasing viscosity and VOF solvers.

However, maybe at least I can provide you with a 'more elegant' solution for your problem.

Assuming you already added volScalarField T to your CrossWLF class, you should be able to read it during the viscosity correction calcNu() using

Code:

const volScalarField& T = U_.mesh().lookupObject<volScalarField>("T");
Back then I lacked a suitable test case for validating the CrossWLF model, which was one of the reasons I stopped testing. Have you already found one?

Best regards,
Johannes

dgadensg May 13, 2010 02:32

Hi Johannes.

Thanks you for your answer. The code for accessing "T" in the models class you've provided is definetly more elegant, as iv'e implemented it by adding "volScalarField T" to all the constructors in the transportmodels.

As for the testcase, i am validating my implementation against the article: S. Radl, T. Tritthart, J.G. Khinast: "A Novel Design for hot-melt extrusion pelletizers", brought in Chemical Engineering Science, by Elsevier. In this article they have also use OpenFOAM, and they have shown the development of flow and temperature through a capillary die hole.

Note that I have not implemented the CrossWLF model, but instead added an exponential term to the powerLawModel.

Best Regards,
Dan

l_r_mcglashan May 13, 2010 06:39

Is that really more elegant though? If you're looking for better programming practice then it is surely preferable to pass temperature through the constructor, as opposed to looking the temperature up in the object registry. Or you could just pass it through a new member function when you want to evaluate a new viscosity.

dgadensg May 13, 2010 07:32

Well, i see your point, but passing it through the constructor is in my opinion only an elegant solution if it done consistenly throughout the code, which requires a respectible amount of work. This will also result in the volScalarField T being added to many classes, without ever being used.

I am sure that you could pass it through a new member function, but being on the "beginner"-level in OpenFOAM, this will take me a considerable amount of time to do.

// Dan

l_r_mcglashan May 13, 2010 07:53

I would have a look at how the thermophysical models are implemented, in particular how the basic/psiThermo and basic/rhoThermo inherit from basicThermo.

Obviously, it may not be worth the effort, but it may be quite satisfying to try!

wendywu May 19, 2010 04:58

problem with adding a viscosityModel
 
Hi, foamers,

I am adding a viscosityModel into OF. I set up a folder named myViscosityModel into viscosityModels folder, looks like PowerLaw. Surely I set up myViscosityModel.C
and myViscosityModel.H. when I finished these I compile it with command "wmake libso".
there comes an error in the results:
"myViscosityModelCoeffs_lookup" was not declared in this scope.
the myViscosityModel.C file is as follows:
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "myViscosityModel.H"
#include "addToRunTimeSelectionTable.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace viscosityModels
{ defineTypeNameAndDebug(myViscosityModel, 0);
addToRunTimeSelectionTable
(
viscosityModel,
myViscosityModel,
dictionary
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::myViscosityModel::calcNu() const
{ //shearrate
//- in your class, we can obtain the temperature. The only possible way is looking up "T" through objectRgistry.
const volScalarField & T=U_.db().lookupObject<volScalarField>("T");


volScalarField shearrate=max(minshearrate_,sqrt(2.0*((symm(fvc::g rad(U_))) && (symm(fvc::grad(U_))))/3.0)); //锟斤拷锟斤拷锟截凤拷锟斤拷U原锟斤拷没锟斤拷锟铰伙拷锟斤拷
volScalarField Z=shearrate*(exp(deltaH_/(R_*T)));
return asinh(pow(Z/A_,1.0/n_))/(3*beta_*shearrate)/rho_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::viscosityModels::myViscosityModel::myViscosi tyModel
(
const word& name,
const dictionary& viscosityProperties,
const volVectorField& U_, //锟斤拷锟斤拷锟截凤拷锟斤拷U原锟斤拷没锟斤拷锟铰伙拷锟斤拷
const surfaceScalarField& phi
)
: viscosityModel(name, viscosityProperties, U_, phi), //锟斤拷锟斤拷锟截凤拷锟斤拷U原锟斤拷没锟斤拷锟铰伙拷锟斤拷
myViscosityModelCoeffs_(viscosityProperties.subDic t(typeName + "Coeffs")), //********what is this for???
rho_(myViscosityModelCoeffs_.lookup("rho")),
R_(myViscosityModelCoeffs_.lookup("R")),
A_(myViscosityModelCoeffs_.lookup("A")),
beta_(myViscosityModelCoeffs_.lookup("beta")),
deltaH_(myViscosityModelCoeffs_.lookup("deltaH")),
n_(myViscosityModelCoeffs_.lookup("n")),
minshearrate_(myViscosityModelCoeffs_.lookup("mins hearrate")),
nu_
(
IOobject
( name,
U_.time().timeName(), //锟斤拷锟斤拷锟截凤拷锟斤拷U原锟斤拷没锟斤拷锟铰伙拷锟斤拷
U_.db(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
calcNu()
)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::viscosityModels::myViscosityModel::read
( const dictionary& viscosityProperties
)
{
viscosityModel::read(viscosityProperties);
myViscosityModelCoeffs_ = viscosityProperties.subDict(typeName + "Coeffs");
myViscosityModelCoeffs_.lookup("rho") >> rho_;
myViscosityModelCoeffs_.lookup("R") >> R_;
myViscosityModelCoeffs_.lookup("A") >> A_;
myViscosityModelCoeffs_.lookup("beta") >> beta_;
myViscosityModelCoeffs_.lookup("deltaH") >> deltaH_;
myViscosityModelCoeffs_.lookup("n") >> n_;
myViscosityModelCoeffs_lookup("minshearrate")>>min shearrate_;
return true;
}
// ************************************************** ********************* //

the error is located at the last line: myViscosityModelCoeffs_lookup)"minshearrate")>>min shearrate_;

Anybody knows the reason? Thanks in advance.

Wendy

wendywu May 19, 2010 05:00

myviscosityModel.H
 
here is the File "myViscosityModel.H"
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
Class
Foam::viscosityModels::myViscosityModel
Description
Standard viscoPlastic non-Newtonian viscosity model.
SourceFiles
myViscosityModel.C
\*---------------------------------------------------------------------------*/
#ifndef myViscosityModel_H
#define myViscosityModel_H
#include "viscosityModel.H"
#include "dimensionedScalar.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{ namespace viscosityModels
{
/*---------------------------------------------------------------------------*\
Class myViscosityModel Declaration
\*---------------------------------------------------------------------------*/
class myViscosityModel
: public viscosityModel
{
// Private data
dictionary myViscosityModelCoeffs_;
// dimensionedScalar k_;
// dimensionedScalar n_;
// dimensionedScalar nuMin_;
// dimensionedScalar nuMax_;
// volScalarField shearrate_;
// volScalarField Z_;
dimensionedScalar rho_;
dimensionedScalar R_;
dimensionedScalar A_;
dimensionedScalar beta_;
dimensionedScalar deltaH_;
dimensionedScalar n_;
volScalarField nu_;
dimensionedScalar minshearrate_;
// Private Member Functions
//- Calculate and return the laminar viscosity
tmp<volScalarField> calcNu() const;
public:
//- Runtime type information
TypeName("myViscosityModel");
// Constructors
//- Construct from components
myViscosityModel
(
const word& name,
const dictionary& viscosityProperties,
const volVectorField& U,
const surfaceScalarField& phi
);
// Destructor
~myViscosityModel()
{}
// Member Functions
//- Return the laminar viscosity
tmp<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
// ************************************************** *********************** //

Thanks,

Wendy

l_r_mcglashan May 19, 2010 05:04

Quote:

Originally Posted by wendywu (Post 259420)
{
viscosityModel::read(viscosityProperties);
myViscosityModelCoeffs_ = viscosityProperties.subDict(typeName + "Coeffs");
myViscosityModelCoeffs_.lookup("rho") >> rho_;
myViscosityModelCoeffs_.lookup("R") >> R_;
myViscosityModelCoeffs_.lookup("A") >> A_;
myViscosityModelCoeffs_.lookup("beta") >> beta_;
myViscosityModelCoeffs_.lookup("deltaH") >> deltaH_;
myViscosityModelCoeffs_.lookup("n") >> n_;
myViscosityModelCoeffs_lookup("minshearrate")>>min shearrate_;
return true;
}
// ************************************************** ********************* //

the error is located at the last line: myViscosityModelCoeffs_lookup)"minshearrate")>>min shearrate_;

Anybody knows the reason? Thanks in advance.

Wendy

You forgot the dot in that line:

myViscosityModelCoeffs_.lookup("minshearrate")>>mi nshearrate_;

You should also start another thread as this doesn't really relate to what was being discussed earlier.

wendywu May 22, 2010 05:47

Laurence,

Thank you so much. Sorry for being so careless.:o

Wendy


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