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/)
-   -   Access turbulence model in coded functionobjectlibs (https://www.cfd-online.com/Forums/openfoam-programming-development/104518-access-turbulence-model-coded-functionobjectlibs.html)

eelcovv July 11, 2012 11:23

Access turbulence model in coded functionobjectlibs
 
Dear foamers,

I have been using function object libs now for a while to be able to do some extra coding at run time without modifying the solver.

Now I want to create a code snipped which calculates the RMS value of the solution matrix being solved, so you can access the accuracy of the solution.

My code snipped would look like

Code:



errorAnalysis
{
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType average;
    outputControl timeStep;
    code
    #{
      const volVectorField&      U=mesh().lookupObject<volVectorField>("U");
      const surfaceScalarField& phi=mesh().lookupObject<surfaceScalarField>("phi");
      const volScalarField&      p=mesh().lookupObject<volScalarField>("p");



fvVectorMatrix residualMatrix
        (
                fvm::ddt(U)
            +  fvm::div(phi, U) 
            +  turbulence->divDevReff(U)
            +  fvc::grad(p)
        );

        Info << "RMS residualMatrix: " << Foam::sqrt(gSumMag(magSqr(residualMatrix.residual()))) << nl  ;


    #};
}

This piece of code works if I put it in the solver, but in the coded functionobject libs I do not know how to access the turbulence pointer using the lookupObject. Would somebode know how to access the divDevReff in code snipped dynamically linked at the case level ?

Regards

Eelco

eelcovv July 12, 2012 10:46

work-around
 
As a work around in order to access the turbulence->divDevReff from the dynamically linked function object I found the following.

Code:

errorAnalysis
{
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType average;
    outputControl timeStep;
    code
    #{

      const volVectorField&      U=mesh().lookupObject<volVectorField>("U");
      const surfaceScalarField&  phi=mesh().lookupObject<surfaceScalarField>("phi");
      const volScalarField&      p=mesh().lookupObject<volScalarField>("p");
      const volScalarField&      nuSgs=U.db().lookupObject<volScalarField>("nuSgs");
      const dictionary& transportProperties = U.db().lookupObject<IOdictionary>
      (
        "transportProperties"
      );
      const dimensionedScalar&  nu(transportProperties.lookup("nu"));

      fvVectorMatrix residualMatrix
        (
              fvm::ddt(U)
            + fvm::div(phi, U)
            - fvm::laplacian(nu+nuSgs, U) - fvc::div((nu+nuSgs)*dev(T(fvc::grad(U))))
            + fvc::grad(p)
        );

      Info << "RMS residualMatrix: " << Foam::sqrt(gSumMag(magSqr(residualMatrix.residual()))) << nl  ;
    #};
}

It works, but is rather ugly. I prefer to replace the line fvc::div((nu+nuSgs)*dev(T(fvc::grad(U)))) with turbulence-> value. Does anybody has a hint?

newOFuser August 12, 2012 00:18

Hello

Is the 'type coded' option available in OF 1.7.1? I get an error: Unknown function type coded
Is there a way to implement it in OF 1.7.1?

Thanks!
ak

GerhardHolzinger March 7, 2013 06:54

The coded functionObjects seem to be only available in OpenFOAM 2.0+

See this release notes:

http://www.cfd-online.com/Forums/ope...unction+object

liquidspoon August 22, 2013 12:03

Hi Eelcovv,

Did you ever have any more success trying to access the turbulence data from coded function objects? I was trying to do something similar, and found the obr() function. This returns a reference to the object registry, which lists the turbulence model, and can supposedly return a reference to it. However, I kept getting errors when I tried to get at the turbulence model through the lookupObject function, but kept getting errors (type incompressible::turbulenceModel not found, foundObject method not valid), and wasn't sure how to link in the required libraries.

anishtain4 December 6, 2016 21:01

Can anyone please advise how to access turbulenceModel in a coded functionObject?
obr() which is mentioned is the same as mesh() but it only has a reference to turbulence dictionary, not the object itself! I need to access epsilon of an LES simulation which cannot be found through lookupObject. I looked into the file and to calculate it directly I still need k which is the subgridscale kinetic energy in an LES simulation.

hismother December 1, 2018 18:43

Quote:

Originally Posted by anishtain4 (Post 628567)
Can anyone please advise how to access turbulenceModel in a coded functionObject?
obr() which is mentioned is the same as mesh() but it only has a reference to turbulence dictionary, not the object itself! I need to access epsilon of an LES simulation which cannot be found through lookupObject. I looked into the file and to calculate it directly I still need k which is the subgridscale kinetic energy in an LES simulation.

i am having the same problem. anyone has the solution???

thank you.


All times are GMT -4. The time now is 01:22.