CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Time dependent properties (http://www.cfd-online.com/Forums/openfoam-solving/87909-time-dependent-properties.html)

mrangitschdowcom May 2, 2011 12:06

Time dependent properties
 
Hi all,
I need to implement a time dependent viscosity -- my fluid viscosity increases as time advances. I can't convince the viscosity models to access the run time (says runTime is out of scope). I'm not a good c++ programmer, does anyone have some guidance on how to implement something like this?

Thanks in advance!

Mike Rangitsch

MartinB May 2, 2011 12:11

Hi Michael,

you might have a look to my proposal in this thread:
http://www.cfd-online.com/Forums/ope...time-loop.html

There is access to the current time step...

Martin

MartinB May 3, 2011 08:13

Hi Mike,

just out of curiosity, could post your viscosity model? It just came to my mind that not the run time is the important feature for your viscosity model, but the residential time in your fluid domain... this would imply to calculate an aging process of the fluid. Since "old" fluid near an outlet would get another viscosity than "fresh" fluid from an inlet...

Martin

mrangitschdowcom May 9, 2011 10:21

Time dependent viscosity....
 
Hi Martin,
Sorry for the delay. Unfortunately I can't share the viscosity model (customer says no). You're right, it is about the age of the fluid. The viscosity behavior changes as it ages.
I'd like one more piece of advice, though. I'd like to save the viscosity and shearRate fields during the calculations and then use the previous iterations' values to under-relax the viscosity I put into the main iteration loop. I can create a field (viscosity_old), but I can't figure out how to access it from the viscosity calculation code (again, it complains about not being in scope). I'm also not sure where to put the read/write of the viscosity values. If I do it before the PISO loop (in interFoam), at least it seems to read in the viscosity values I specify (but won't write the shearRate field), if I put it just before the runtime.Write statement it fails...


Any suggestions?

MartinB May 10, 2011 05:22

Hi Mike,

this is how I would start:

- Adding residential time as a volScalarField to interFoam. So in createFields.H you add
Code:

    // check if age exists
    switch ageExist(false);
    IOobject ageHeader
    (
        "age",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ
    );

    volScalarField* age;

    if (ageHeader.headerOk())
    {
        ageExist = true;
        Info<< "Reading field age\n" << endl;

        age = new volScalarField
        (
            IOobject
            (
                "age",
                runTime.timeName(),
                mesh,
                IOobject::MUST_READ,
                IOobject::AUTO_WRITE
            ),
            mesh
        );
    }

A new field with name "age" in your time folder must be inserted, i.e. "0/age". Boundary condition for inlet is fixedValue 0, rest of the patches get zeroGradient.

A transport equation for the residential time must be solved, for example after UEqn.H:
Code:

if (ageExists)
{
        fvScalarMatrix ageEqn
        (
                        fvm::ddt(*age)
                        + fvm::div(phi, *age)
                        - fvm::laplacian(turbulence->nuEff(), *age)
                        ==
                        dimensionedScalar("ageSource", *age.dimensions()*dimensionSet(0,0,-1,0,0), runTime.deltaT().value())
                        //dimensionedScalar("ageSource", (*age).dimensions()*dimensionSet(0,0,-1,0,0), 1) // steady state
        );

        ageEqn.solve();
}

Then derive your new viscosity model from one of the existing transportModels. Add the new coefficients to the yourNewTransportModel.H file, and read the values for them in the read() method of yourNewTransportModel.C. In the calcNu() method you have access to the time field with
Code:

    const volScalarField& residenceTime = U_.mesh().lookupObject<volScalarField>("age");
To write the fields of interest, make a new file "write.H" and call it like this
Code:

    if (runTime.outputTime())
#      include "write.H"

just before the runTime.write() call of interFoam.

The file "write.H" can look like this:
Code:

{
                volScalarField shearRate
                (
                                IOobject
                                (
                                                "shearRate",
                                                runTime.timeName(),
                                                mesh,
                                                IOobject::NO_READ,
                                                IOobject::AUTO_WRITE
                                ),
                                mag(fvc::grad(U))
                );
                shearRate.write();

                volScalarField strainRate
                (
                                IOobject
                                (
                                                "strainRate",
                                                runTime.timeName(),
                                                mesh,
                                                IOobject::NO_READ,
                                                IOobject::AUTO_WRITE
                                ),
                                Foam::sqrt(2.0)*mag(symm(fvc::grad(U)))
                );
                strainRate.write();

        volScalarField nu
        (
                        IOobject
                        (
                                        "nu",
                                        runTime.timeName(),
                                        mesh,
                                        IOobject::NO_READ,
                                        IOobject::AUTO_WRITE
                        ),
                        twoPhaseProperties.nu()
        );
        nu.write();
}

Depending on your version of OpenFOAM the definition of strainRate, which is used in the transportModels for shear thinning models, varies. Therefor to verify your implementation you should check your exact definition of strainRate.

I would not do an underrelaxation of the viscosity. It doesn't seems useful for me for a PISO algorithm, it seems to be even wrong... so you don't need an viscosity_old field, I suppose.

If you do need it for some other reasons, you can define in createFields.H at the end of the file:
Code:

        volScalarField viscosity_old
        (
                        IOobject
                        (
                                        "visco_old",
                                        runTime.timeName(),
                                        mesh,
                                        IOobject::NO_READ,
                                        IOobject::AUTO_WRITE
                        ),
                        twoPhaseProperties.nu()
        );

and update it before calling twoPhaseProperties.correct(); in interFoam.C with
Code:

visco_old == twoPhaseProperties.nu();
Well, these hints are not tested, so use with care!

Martin


All times are GMT -4. The time now is 20:36.