CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   coded functionObjects behaving not as expected (https://www.cfd-online.com/Forums/openfoam/231192-coded-functionobjects-behaving-not-expected.html)

alexfells October 26, 2020 08:21

coded functionObjects behaving not as expected
 
Hi everyone,

I've been experimenting with coded functionObjects in OpenFOAM v7 and have noticed some unusual behaviour, specifically regarding accessing the mesh.

I created the following coded functionObject, loosely based on the example outlined in the guide:

https://cpp.openfoam.org/v7/classFoa...ionObject.html

Code:


functions
{
test
    {
        type                      coded;
        libs                      ("libutilityFunctionObjects.so");
        name                      holdUp;
        codeWrite
        #{
        Info << "Things that go at the start of the functionObject go here." << endl;

        const volVectorField& U = mesh().lookupObject<volVectorField>("U");

        Info << "Things that go at the end of the functionObject go here." << endl;

        #};
    }

}

Where I received the following error:

Code:


/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    | Website:  https://openfoam.org
    \\  /    A nd          | Version:  7
    \\/    M anipulation  |
\*---------------------------------------------------------------------------*/
Build  : 7-5e743dcea67c
Exec  : postProcess
Date  : Oct 26 2020
Time  : 13:15:42
Host  : "login2.arc4.leeds.ac.uk"
PID    : 70703
I/O    : uncollated
Case  : /nobackup/pm11af/2D/codedFunctionObject
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 60

Using dynamicCode for functionObject test at line 71 in "/nobackup/pm11af/2D/codedFunctionObject/system/controlDict.functions.test"
Creating new library in "dynamicCode/holdUp/platforms/linux64GccDPInt32Opt/lib/libholdUp_3fd58367d4a7b3404ee8e36178d034265336b936.so"
Invoking "wmake -s libso /nobackup/pm11af/2D/codedFunctionObject/dynamicCode/holdUp"
wmake libso /nobackup/pm11af/2D/codedFunctionObject/dynamicCode/holdUp
    ln: ./lnInclude
    wmkdep: functionObjectTemplate.C
    Ctoo: functionObjectTemplate.C
/nobackup/pm11af/2D/codedFunctionObject/system/controlDict.functions.test: In member function ‘virtual bool Foam::holdUpFunctionObject::write()’:
/nobackup/pm11af/2D/codedFunctionObject/system/controlDict.functions.test:78:31: warning: unused variable ‘U’ [-Wunused-variable]
    ld: /nobackup/pm11af/2D/codedFunctionObject/dynamicCode/holdUp/../platforms/linux64GccDPInt32Opt/lib/libholdUp_3fd58367d4a7b3404ee8e36178d034265336b936.so
Time = 60

Reading fields:


Executing functionObjects
Things that go at the start of the functionObject go here.
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigSegv::sigHandler(int) at ??:?
#2  ? in "/lib64/libc.so.6"
#3  __dynamic_cast in "/apps/developers/compilers/gnu/6.3.0/1/default/lib64/libstdc++.so.6"
#4  Foam::holdUpFunctionObject::mesh() const at ~/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/typeInfo.H:110
#5  Foam::holdUpFunctionObject::write() at system/controlDict.functions.test:78
#6  Foam::functionObjectList::execute() at ??:?
#7  ? at ??:?
#8  ? at ??:?
#9  __libc_start_main in "/lib64/libc.so.6"
#10  ? at ??:?
Segmentation fault

I've had some playing around using different variations of code that apparently work including this one:
From line 4 of the error, it seems to me that the mesh object doesn't exist. Any idea how I can get this to work? I would expect mesh to be accessible from a functionObject. I've tested this on two machines both belonging to my university and the error is reproducible.

Kind regards,

Alex

olesen October 27, 2020 14:17

It usually makes sense to use old school "printf" debugging to verify that your code and assumptions are correct. For example, check with foundObject if the field is there. Print out the toc() from the registry to see which objects really are there etc.

JNSN October 28, 2020 03:58

I think the fields are not loaded, as you do this via postProcess tool. I am not quite familiar with the post-processing CLI, but some ideas (not tested):
Code:

postProcess -fields "(U)" -func yourCodedFunction
or

Code:

interSimplePimpleWhateverFoamSolver -postProcess -func yourCodedFunction

Hope this helps,
Jan


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