CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

coded functionObjects behaving not as expected

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 26, 2020, 09:21
Default coded functionObjects behaving not as expected
  #1
New Member
 
Alex Fells
Join Date: Sep 2019
Posts: 5
Rep Power: 7
alexfells is on a distinguished road
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

Last edited by alexfells; October 26, 2020 at 11:02. Reason: Provided additional info.
alexfells is offline   Reply With Quote

Old   October 27, 2020, 15:17
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen is offline   Reply With Quote

Old   October 28, 2020, 04:58
Default
  #3
Senior Member
 
JNSN's Avatar
 
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 143
Rep Power: 20
JNSN is on a distinguished road
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
JNSN is offline   Reply With Quote

Reply

Tags
codedfunctionobject, functionobject


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error compiling modified applications yvyan OpenFOAM Programming & Development 21 March 1, 2016 05:53
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 07:42
POSDAT problem piotka STAR-CD 4 June 12, 2009 09:43
wmake compiling Problem with OF1.5 openTom OpenFOAM Installation 4 May 3, 2009 15:44
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 14:27.