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
|