CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Read a new variable from a solver to turbulence model (https://www.cfd-online.com/Forums/openfoam-programming-development/153788-read-new-variable-solver-turbulence-model.html)

Clarkyan June 3, 2015 13:23

Read a new variable from a solver to turbulence model
 
Dear Foamers,

I've added the equation of state in the pisoFoam solver, now the rho is a function of temperature and salinity. The solver works well and the rho can be updated at every time step.

rho==1000;
rho==(rho/1000*(999.842594+6.793952e-2*T-(9.095290e-3*pow(T,2))+(1.001685e-4*pow(T,3))-(1.120083e-6*pow(T,4))+(6.536336e-9*pow(T,5))+S*(8.24493e-1-4.0899e-3*T+(7.6438e-5*pow(T,2))-(8.2467e-7*pow(T,3))+(5.3875e-9*pow(T,4)))+(pow(S,1.5))*(-5.72466e-3+1.0227e-4*T-1.6546e-6*pow(T,2))+S*(4.8314e-4)));

Currently I'm trying to add this rho into the incompressible kEpsilon turbulence model,

rho_
(
IOobject
(
"rho",
runTime_.timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
mesh_
),


however the model just reads the initial rho instead of the updated rho, I find it hard to read a new variable from a solver to a turbulence model. Can anybody drop a hint? Thanks in advance.

Regards,
Clark

kebsiali June 3, 2015 13:40

Hi,

What you need is the lookup command
it is mainly used for this stuff (fetch a variable from the solver into a model in the library)

You can see a simple example in the following link:
http://www.tfd.chalmers.se/~hani/kur...nFoam%20v2.pdf

page 11
where he needed the variable T to go into his viscosity model using:
const volScalarField& T= U_.mesh().lookupObject<volScalarField>("T");

Hope that helps

Clarkyan June 4, 2015 08:28

Hi Ali,

Thanks, I believe it's a good way, however, I haven't figured out where to put it in the incompressible kEpsilon model.

I have written the following one:

const volScalarField& rho= U_.mesh().lookupObject<volScalarField>("rho");

If I put it before the "namespace", an error called "'volScalarField' does not name a type" shows up, as expected.

If I put it after the "namespace" but before "Constructors", an error called "‘U_’ was not declared in this scope" shows up;

If I put it within the "kEpsilon::kEpsilon" and after "const word& modelName,", an error called "‘prototype for ‘Foam::incompressible::RASModels::kEpsilon::kEpsil on(const volVectorField&, const surfaceScalarField&, Foam::transportModel&, const Foam::word&, const Foam::word&, const volScalarField&)’ does not match any in class ‘Foam::incompressible::RASModels::kEpsilon’" shows up;

If I put it after the "Constructors" but before "Member Function", the error called "‘U_’ was not declared in this scope" shows up again;

If I put it within the "void kEpsilonGGDH::correct()", an error called "‘ invalid initialization of reference of type ‘const volScalarField&" shows up.

Any help is appreciated. Thanks
Clark


kebsiali June 4, 2015 08:55

im not 100% sure
but i would see it should go in:


tmp<fvVectorMatrix> kEpsilon::divDevRhoReff
(
const volScalarField& rho, put me here
volVectorField& U
) const
{
volScalarField muEff("muEff", rho*nuEff());

return
(
- fvm::laplacian(muEff, U)
- fvc::div(muEff*dev(T(fvc::grad(U))))
);
}

Clarkyan June 4, 2015 11:20

Hi Ali,

Thank you for your help! It works very well now!
Finally I put it within "void kEpsilon::correct()"

Thanks again,
Clark


All times are GMT -4. The time now is 16:11.