CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Lookup transportproperties from BC (

michielm April 28, 2012 05:57

Lookup transportproperties from BC
I am currently adapting the dynamicAlphaContactAngle BC and I want to access transportProperties. I found online ( that the following piece of code should take care of that:

// Extract the dictionary from the database
const dictionary& transportProperties = db().lookupObject<IOdictionary>

// Exctract subdictionary from the main dictionary
dictionary mySubDict

// Extracting scalar value
dimensionedScalar myScalar(mySubDict.lookup("myScalar"));

However, if I compile the library I get the following error message:

/fhome/OpenFOAM/OpenFOAM-1.7.1/src/OpenFOAM/lnInclude/objectRegistryTemplates.C: In member
function `const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const
[with Type = Foam::IOdictionary]':newDynAngleFvPatchScalarField.C:153:  instantiated from here
error: cannot dynamic_cast `(const Foam::Time*)((const Foam::objectRegistry*)this)->Foam::objectRegistry::time_'
(of type `const struct Foam::Time*') to type `const class Foam::objectRegistry*' (source is a pointer to incomplete type)
make: *** [Make/linux64GccDPOpt/newDynAngleFvPatchScalarField.o] Error 1

I don't really understand the error message. Does anyone know what could be the problem here?

alberto April 29, 2012 01:07

Hi Michiel,

I have the code compiling in one of the boundary conditions I implemented (posted below as example). I think the error is somewhere else


    const dictionary& transportProperties = db().lookupObject<IOdictionary>

    const dictionary& kineticTheoryProperties = db().lookupObject<IOdictionary>

    dictionary phaseaDictionary

    dimensionedScalar rhoa(phaseaDictionary.lookup("rho"));

Could you post your code so that who reads can look at it?


michielm April 29, 2012 03:11

Hi Alberto,
Thanks for the quick response.
If I comment out this piece of code, the library compiles as it should (and can be used with interFoam). So maybe there is something earlier in my code that has a weird interaction with the lookup piece?
Anyway, the rest of the member functions section (which is the only part I touched), is added below:


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

    const fvPatchVectorField& Up,
    const fvsPatchVectorField& nHat
) const
    if (uTheta_ < SMALL)
        return tmp<scalarField>(new scalarField(size(), theta0_));

    const vectorField nf(patch().nf());

    // Calculated the component of the velocity parallel to the wall
    vectorField Uwall(Up.patchInternalField() - Up);
    Uwall -= (nf & Uwall)*nf;

    // Find the direction of the interface parallel to the wall
    vectorField nWall(nHat - (nf & nHat)*nf);

    // Normalise nWall
    nWall /= (mag(nWall) + SMALL);

    // Calculate Uwall resolved normal to the interface parallel to
    // the interface
    scalarField uwall(nWall & Uwall);

    // MM: Define result as a new 0 scalarField to fill with the new theta later on
    scalarField& result = *new scalarField(uwall.size(),scalar(0));

    // MM: IMPORTANT: theta0_ is in degrees! Therefore: define pi and
    //              use that to recalculate theta0_
    scalar pi(4.*atan(1.)) ;
    scalar theta0_rad(theta0_/180.0*pi);

152 //MM: trying to access transport properties for the value of nu
153 const dictionary& transportProperties = db().lookupObject<IOdictionary>("transportProperties");

155 // Exctract subdictionary from the main dictionary
156 dictionary mySubDict
157 (
158    transportProperties.subDict("phase1")
159 );

161 // Extracting scalar value
162 dimensionedScalar myScalar(mySubDict.lookup("nu"));

164 Info << "this should be nu:" << myScalar << endl;

    //MM: loop over all uwall[i], because power of scalarField is not allowed
    // i checked with Matlab that the implementation yields the correct numerical answers
        result[i] = 180.0/pi*pow(max(pow(theta0_rad,3.0)-40.6098*uwall[i],0),1./3.);

    //MM: The original equation
    // return theta0_ + (thetaA_ - thetaR_)*tanh(uwall/uTheta_);
        //MM: Return of the new calculation
    return result;

I have indicated the line numbers in my code, according to the error message the error is in line 153.

Is there any change that it is a version issue?! I'm using OF-1.7.1 (as you might have seen already in the error message)


alberto April 29, 2012 03:53

I modified the BC in ~/OpenFOAM/OpenFOAM-2.1.x/src/transportModels/twoPhaseInterfaceProperties/alphaContactAngle/dynamicAlphaContactAngle/ including your exact lines of code, and it compiles. I am not sure what's going on in your code.

michielm April 29, 2012 06:48

Thanks for trying that!

Since the newDynContactAngle was a separately compiled library (copied from the dynamicAlphaContactAngle) I decided to try putting the piece of code directly in the dynamicAlphaContactAngle.C file and recompile it. Just to see whether I messed up when copying and recompiling the new library.

Probably I didn't, because I get the same error message again. So either my openfoam installation has some error somewhere, or there is a difference between 1.7.1 and 2.1.x that causes the problem.

I think I'll switch to 2.1.x. In both cases I mention above I have to recompile OpenFOAM so I might as well. I haven't done much custom coding yet so working with the newest version will help me in the future anyway.

Thanks again for the help, it's much appreciated!

All times are GMT -4. The time now is 04:38.