CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Lookup autoPtr from fvMesh (https://www.cfd-online.com/Forums/openfoam/84156-lookup-autoptr-fvmesh.html)

Misha January 21, 2011 09:04

Lookup autoPtr from fvMesh
 
Dear openFOAM'ers

I am trying to access to the turbulence properties from a class where I have access to the mesh.

That is, in createFields.H I have:

singlePhaseTransportModel laminarTransport(U, phi);
autoPtr<incompressible::RASModel> turbulence
(
incompressible::RASModel::New(U, phi, laminarTransport)
);

And I would now like to access the pointer named "turbulence" from another class.

I thought it would be possible to access it in the way a dictionary can be accessed in another class, where the mesh has been passed and named mesh_:
dictionary transport = mesh_.lookupObject<IOdictionary>("transportPropert ies");

So what I need might be something like:
autoPtr<incompressible::RASModel> turbulence = mesh_.lookupObject<incompressible::RASModel>("turb ulence");

The expression above is of course not consistent, so I would appreciate any help or comments on how to access such a pointer from the objectRegistry!

Best regards
Misha

deepsterblue January 21, 2011 09:43

It appears that RASModel is derived from IOdictionary, which means that any turbulence model can be accessed by looking for it's typeName (like "kEpsilon", for instance). The (object).names() member function should give you a list of all objects currently registered with the mesh.

Also, any particular reason why you're looking for an autoPtr? Wouldn't a const reference to the object do the trick?

Misha January 24, 2011 06:20

Thank you for your answer!

I see that my pointer is not listed in mesh.names(), so I guess I cannot access it that way.

I want to be able to solve my equations using a member function in my new class;

Code:


void new_class::solveEqn()
{
volScalarField& U = const_cast<volScalarField&>(mesh_.lookupObject<volScalarField>("U"));
surfaceScalarField& phi = const_cast<surfaceScalarField&>(mesh_.lookupObject<surfaceScalarField>("phi"));
volScalarField& p = const_cast<volScalarField&>(mesh_.lookupObject<volScalarField>("p"));
{
// (.... Standard SIMPLE code)
 
tmp<fvVectorMatrix> UEqn
(
fvm::div(phi, U)
+ turbulence->divDevReff(U)
);
 
// (.... Standard SIMPLE code)
}
}

Having defined my autoPtr "turbulence" together with the fields U, phi, p in the createFields.H file I now want to access it in the member function of my class new_class as sketched above. So, I can figure out how to look up the fields U, phi and p, but I do not know how to access "turbulence".

My approach to the problem may be wrong - if so, I would really appreciate your comments!

~ Misha


All times are GMT -4. The time now is 18:41.