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

make custom functionObject available with postProcess

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Shibi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 15, 2021, 08:57
Default make custom functionObject available with postProcess
  #1
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Hello to all,

I would like to know how to make a custom functionObject available via the postProcess utility in OpenFOAM from ESI (v2012).

As an example, I have duplicated the writeCellCentres functionObject and renamed it as myWriteCellCentres. Did the same inside the .H and .C files.

Prepared a Make folder with (copied from OpenFOAM-v2012/src/functionObjects/field):

files
Code:
myWriteCellCentres.C

LIB = $(FOAM_USER_LIBBIN)/libmyFunctionObjects
options

Code:
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/fileFormats/lnInclude \
    -I$(LIB_SRC)/surfMesh/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude \
    -I$(LIB_SRC)/lagrangian/basic/lnInclude \
    -I$(LIB_SRC)/lagrangian/distributionModels/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/compressible/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
    -I$(LIB_SRC)/transportModels/compressible/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/solidThermo/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
    -I$(LIB_SRC)/fvAgglomerationMethods/pairPatchAgglomeration/lnInclude

LIB_LIBS = \
    -lfiniteVolume \
    -lfileFormats \
    -lsurfMesh \
    -lmeshTools \
    -lsampling \
    -llagrangian \
    -ldistributionModels \
    -lfluidThermophysicalModels \
    -lsolidThermo \
    -lincompressibleTransportModels \
    -lturbulenceModels \
    -lcompressibleTransportModels \
    -lincompressibleTurbulenceModels \
    -lcompressibleTurbulenceModels \
    -lchemistryModel \
    -lreactionThermophysicalModels \
    -lpairPatchAgglomeration
In the controlDict I have:
Code:
functions
{

    writeBoundaryCells1
    {
        // Mandatory entries (unmodifiable)
        type            myWriteCellCentres;
        libs            (libmyFunctionObjects.so);
    }
}
The functionObject work as expected.


When I try to execute it with the postProcess utility with:

Code:
postProcess -func myWriteCellCentres -lib myFunctionObjects
I get:

Code:
--> FOAM Warning : 
    From static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, Foam::HashSet<Foam::wordRe>&, const Foam::word&)
    in file db/functionObjects/functionObjectList/functionObjectList.C at line 336
     Cannot find functionObject file myWriteCellCentres

What is the correct way of calling a custom functionObject with postProcess?
Mars409 likes this.
Shibi is offline   Reply With Quote

Old   July 17, 2021, 15:44
Default
  #2
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Anyone can give a hand with this issue?
Shibi is offline   Reply With Quote

Old   July 19, 2021, 01:14
Default
  #3
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 16
ybapat is on a distinguished road
You can try by including your compiled library in libs entry in controlDict file. This will load your library while running the case and your functionObject should be then available for postProcess utility.

-Yogesh
ybapat is offline   Reply With Quote

Old   July 19, 2021, 04:21
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Shibi View Post
Anyone can give a hand with this issue?
Try calling postprocces with your function "writeBoundaryCells1" instead. Probably don't need the - lib argument since it is already mentioned in the dictionary.
The function execution is by your function name, not by the type of functionObject.
olesen is offline   Reply With Quote

Old   July 19, 2021, 05:51
Default
  #5
Member
 
Join Date: Mar 2021
Posts: 39
Rep Power: 5
trailer is on a distinguished road
Quote:
Originally Posted by olesen View Post
Try calling postprocces with your function "writeBoundaryCells1" instead. Probably don't need the - lib argument since it is already mentioned in the dictionary.
The function execution is by your function name, not by the type of functionObject.

Hello Mr. Olesen,

I had no luck with that.


I know you have a very busy schedule but I will attach the case with the functionObject in case your are interested in having a look.

test.zip
trailer is offline   Reply With Quote

Old   October 4, 2023, 03:55
Default Same issue here
  #6
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
Hi there. I'm facing the same issue. I use the primer openfoam.



I've compilated my custom function object with


Code:
LIB = $(FOAM_USER_LIBBIN)/libcalcul_surface_faceFunctionObject
I put this in my controlDict :

Code:
functions
{  

    calc_SF
    {
        type            calcul_surface_face;
        libs ("libcalcul_surface_faceFunctionObject.so");

        executeControl  writeTime;
        writeControl    writeTime;
    }
}
And when doing postProcess -func calcul_surface_face I get the following error:


Code:
--> FOAM Warning : 
    From static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, Foam::HashSet<Foam::wordRe>&, const Foam::word&)
    in file db/functionObjects/functionObjectList/functionObjectList.C at line 290
    Cannot find functionObject file calcul_surface_face
Can any one give insights ?
__________________
« Debugging is what CFD is about. 5 minutes to modify your code, 5 months to find why it does not work anymore. »
Voulet is offline   Reply With Quote

Old   October 5, 2023, 19:40
Default
  #7
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
try with the foamLibrary utility if your library can even load properly. If it does load then did you also remember to register the function in your code as well?
olesen is offline   Reply With Quote

Old   October 5, 2023, 23:56
Default
  #8
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
Hello Olesen. Thanks for your message. I'm sad because it seems that I'm not enough skilled to fully understand it.

Yes foamHasLibrary -detail libcalcul_surface_faceFunctionObject.so do returns me the lib.

What do you mean by register the function ? I put TypeName("calcul_surface_face"); inside the header of my class declaraction if this is what you means.


Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/

#ifndef functionObjects_calcul_surface_face_H
#define functionObjects_calcul_surface_face_H

#include "fvMeshFunctionObject.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                       Class calcul_surface_face Declaration
\*---------------------------------------------------------------------------*/

class calcul_surface_face
:
    public fvMeshFunctionObject
{
public:

    //- Runtime type information
    TypeName("calcul_surface_face");


    // Constructors

        //- Construct from Time and dictionary
        calcul_surface_face
        (
            const word& name,
            const Time& runTime,
            const dictionary& dict
        );

        //- No copy construct
        calcul_surface_face(const calcul_surface_face&) = delete;

        //- No copy assignment
        void operator=(const calcul_surface_face&) = delete;


    //- Destructor
    virtual ~calcul_surface_face() = default;


    // Member Functions

        //- Read the cell-volume data
        virtual bool read(const dictionary&);

        //- Do nothing
        virtual bool execute();

        //- Write the cell-volume fields
        virtual bool write();
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace functionObjects
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
__________________
« Debugging is what CFD is about. 5 minutes to modify your code, 5 months to find why it does not work anymore. »

Last edited by Voulet; October 6, 2023 at 05:52.
Voulet is offline   Reply With Quote

Old   October 6, 2023, 05:36
Default
  #9
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Voulet View Post
Hello Olesen. Thanks for your message. I'm sad because it seems that I'm not enough skilled to fully understand it.

Yes foamHasLibrary -detail libcalcul_surface_faceFunctionObject.so do returns me the lib.

What do you mean by register the function ? I put TypeName("calcul_surface_face"); inside the header of my class declaraction if this is what you means.
You need something like this (but of course with your own function):

Code:

#include "addToRunTimeSelectionTable.H" 

namespace Foam 
{ 
namespace functionObjects 
{ 
    defineTypeNameAndDebug(grad, 0); 
    addToRunTimeSelectionTable(functionObject, grad, dictionary); 
} 
} 
olesen is offline   Reply With Quote

Old   October 6, 2023, 05:50
Default
  #10
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
Yes I have it :


Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2016 OpenFOAM Foundation
    Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "calcul_surface_face.H"
#include "surfaceFields.H"
#include "fvMesh.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(calcul_surface_face, 0);
    addToRunTimeSelectionTable(functionObject, calcul_surface_face, dictionary);
}
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::functionObjects::calcul_surface_face::calcul_surface_face
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    fvMeshFunctionObject(name, runTime, dict)
{
    read(dict);
}


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

bool Foam::functionObjects::calcul_surface_face::read(const dictionary& dict)
{
    return fvMeshFunctionObject::read(dict);
}


bool Foam::functionObjects::calcul_surface_face::execute()
{
    return true;
}


bool Foam::functionObjects::calcul_surface_face::write()
{
    surfaceVectorField Sf
    (
        IOobject
        (   
            mesh_.Sf().name(),
            time_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::NO_WRITE,
            IOobject::NO_REGISTER
        ),
        mesh_,
        Zero
    );

    Sf.ref() = mesh_.Sf();

    // Without correctBoundaryConditions() - boundary faces have zero volume

    Log << type() << " " << name() << " write:" << nl
        << "    writing cell-face area field Sf" 
        << " to " << time_.timeName() << endl;

    Sf.write();

    return true;
}


// ************************************************************************* //
__________________
« Debugging is what CFD is about. 5 minutes to modify your code, 5 months to find why it does not work anymore. »
Voulet is offline   Reply With Quote

Old   October 6, 2023, 06:05
Default
  #11
Member
 
Join Date: Jun 2019
Posts: 41
Rep Power: 7
Voulet is on a distinguished road
In fact when I run it on a tutorial case with one of the following comand :

postProcess -func calcul_surface_face
or
postProcess

it does works !

But the openfoam case I wanted to treat was an old case which was run with openfoam8. With this case : (using ofv23 and the objectFunction compiled with ofv23)

postProcess -func calcul_surface_face doesn't find the function
or
postProcess works

This is quite strange but I suppose my issue is solved.
Thanks Olesen
__________________
« Debugging is what CFD is about. 5 minutes to modify your code, 5 months to find why it does not work anymore. »
Voulet is offline   Reply With Quote

Reply


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
postProcess functionality in openFOAM 4 bullmut OpenFOAM Post-Processing 23 July 21, 2017 10:11
OF-4.x: Multiple Inheritance of a functionObject A_Pete OpenFOAM Programming & Development 1 September 21, 2016 11:01
[OpenFOAM.org] Compile OF 2.3 on Mac OS X .... the patch gschaider OpenFOAM Installation 225 August 25, 2015 20:43
Create registered object at runtime using a functionObject CedricVH OpenFOAM Programming & Development 21 November 28, 2012 06:04
a way to make lots of money quick and easy no lies Dob Main CFD Forum 0 October 10, 2006 17:45


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