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

Custom field function object from wallHeatFlux

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 3, 2021, 13:27
Default Custom field function object from wallHeatFlux
  #1
Member
 
Horst van Gras
Join Date: Oct 2018
Posts: 45
Rep Power: 8
HorstvanGrass is on a distinguished road
Hi,
I want to calculate the Nusselt number at the walls and I wand to implement this in a postprocess field function. My problem is similar to making a custom functionObject but does not solve my problem.


My approach using OpenFoam-v2012


cp wallHeatFlux from src/functionObjects/field/wallHeatFlux/ to a local dir.
Adapt the Make dir


files
Code:
NusseltNum/NusseltNum.C
LIB = $(FOAM_USER_LIBBIN)/libCustom
options
Code:
XE_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
~
Changed every pattern wallHeatFlux to NusseltNum

NusseltNum.H
Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2016-2017 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/>.

Class
    Foam::functionObjects::NusseltNum

Group
    grpForcesFunctionObjects

Description
    Computes the wall-heat flux at selected wall patches.

    \table
      Operand        | Type              | Location
      input          | -                 | -
      output file    | dat               <!--
                 --> | $FOAM_CASE/postProcessing/\<FO\>/\<time\>/\<field\>
      output field   | volScalarField (only boundaryField) <!--
                 --> | $FOAM_CASE/\<time\>/\<outField\>
    \endtable

Usage
    Minimal example by using \c system/controlDict.functions:
    \verbatim
    NusseltNum1
    {
        // Mandatory entries (unmodifiable)
        type        NusseltNum;
        libs        (fieldFunctionObjects);

        // Optional entries (runtime modifiable)
        patches     (<patch1> ... <patchN>); // (wall1 "(wall2|wall3)");
        qr          qr;

        // Optional (inherited) entries
        ...
    }
    \endverbatim

    where the entries mean:
    \table
      Property     | Description                           | Type | Req'd | Dflt
      type         | Type name: NusseltNum               | word |  yes  | -
      libs         | Library name: fieldFunctionObjects    | word |  yes  | -
      patches    | Names of operand patches   | wordList | no | all wall patches
      qr         | Name of radiative heat flux field       | word | no | qr
    \endtable

    The inherited entries are elaborated in:
     - \link functionObject.H \endlink
     - \link writeFile.H \endlink

    Minimal example by using the \c postProcess utility:
    \verbatim
        <solver> -postProcess -func NusseltNum
    \endverbatim

See also
    - Foam::functionObject
    - Foam::functionObjects::fvMeshFunctionObject
    - Foam::functionObjects::writeFile
    - ExtendedCodeGuide::functionObjects::field::NusseltNum

SourceFiles
    NusseltNum.C

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

#ifndef functionObjects_NusseltNum_H
#define functionObjects_NusseltNum_H

#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "volFieldsFwd.H"
#include "HashSet.H"

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

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                       Class NusseltNum Declaration
\*---------------------------------------------------------------------------*/

class NusseltNum
:
    public fvMeshFunctionObject,
    public writeFile
{
protected:

    // Protected Data

        //- Optional list of wall patches to process
        labelHashSet patchSet_;

        //- Name of radiative heat flux name
        word qrName_;


    // Protected Member Functions

        //- File header information
        virtual void writeFileHeader(Ostream& os) const;

        //- Calculate the heat-flux
        void calcHeatFlux
        (
            const volScalarField& alpha,
            const volScalarField& he,
            volScalarField& NusseltNum
        );


public:

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


    // Constructors

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

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

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


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


    // Member Functions

        //- Read the NusseltNum data
        virtual bool read(const dictionary& dict);

        //- Calculate the wall heat-flux
        virtual bool execute();

        //- Write the wall heat-flux
        virtual bool write();
};


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

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

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

#endif

// ************************************************************************* //
NusseltNum.C
Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2016-2017 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 "NusseltNum.H"
#include "turbulentFluidThermoModel.H"
#include "solidThermo.H"
#include "surfaceInterpolate.H"
#include "fvcSnGrad.H"
#include "wallPolyPatch.H"
#include "turbulentFluidThermoModel.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

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


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

void Foam::functionObjects::NusseltNum::writeFileHeader(Ostream& os) const
{
    writeHeader(os, "Nusselt is Num");
    writeCommented(os, "Time");
    writeTabbed(os, "patch");
    writeTabbed(os, "min");
    writeTabbed(os, "max");
    writeTabbed(os, "integral");
    os  << endl;
}


void Foam::functionObjects::NusseltNum::calcHeatFlux
(
    const volScalarField& alpha,
    const volScalarField& he,
    volScalarField& NusseltNum
)
{
    volScalarField::Boundary& NusseltNumBf = NusseltNum.boundaryFieldRef();

    const volScalarField::Boundary& heBf = he.boundaryField();

    const volScalarField::Boundary& alphaBf = alpha.boundaryField();

    for (const label patchi : patchSet_)
    {
        NusseltNumBf[patchi] = alphaBf[patchi]*heBf[patchi].snGrad();
    }


    const auto* qrPtr = cfindObject<volScalarField>(qrName_);

    if (qrPtr)
    {
        const volScalarField::Boundary& radHeatFluxBf = qrPtr->boundaryField();

        for (const label patchi : patchSet_)
        {
            NusseltNumBf[patchi] -= radHeatFluxBf[patchi];
        }
    }
}


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

Foam::functionObjects::NusseltNum::NusseltNum
(
    const word& name,
    const Time& runTime,
    const dictionary& dict
)
:
    fvMeshFunctionObject(name, runTime, dict),
    writeFile(obr_, name, typeName, dict),
    patchSet_(),
    qrName_("qr")
{
    volScalarField* NusseltNumPtr
    (
        new volScalarField
        (
            IOobject
            (
                type(),
                mesh_.time().timeName(),
                mesh_,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh_,
            dimensionedScalar(dimMass/pow3(dimTime), Zero)
        )
    );

    mesh_.objectRegistry::store(NusseltNumPtr);

    read(dict);

    writeFileHeader(file());
}


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

bool Foam::functionObjects::NusseltNum::read(const dictionary& dict)
{
    fvMeshFunctionObject::read(dict);
    writeFile::read(dict);

    const polyBoundaryMesh& pbm = mesh_.boundaryMesh();

    patchSet_ =
        mesh_.boundaryMesh().patchSet
        (
            dict.getOrDefault<wordRes>("patches", wordRes())
        );

    dict.readIfPresent("qr", qrName_);

    Info<< type() << " " << name() << ":" << nl;

    if (patchSet_.empty())
    {
        forAll(pbm, patchi)
        {
            if (isA<wallPolyPatch>(pbm[patchi]))
            {
                patchSet_.insert(patchi);
            }
        }

        Info<< "    processing all wall patches" << nl << endl;
    }
    else
    {
        Info<< "    processing wall patches: " << nl;
        labelHashSet filteredPatchSet;
        for (const label patchi : patchSet_)
        {
            if (isA<wallPolyPatch>(pbm[patchi]))
            {
                filteredPatchSet.insert(patchi);
                Info<< "        " << pbm[patchi].name() << endl;
            }
            else
            {
                WarningInFunction
                    << "Requested wall heat-flux on non-wall boundary "
                    << "type patch: " << pbm[patchi].name() << endl;
            }
        }

        Info<< endl;

        patchSet_ = filteredPatchSet;
    }

    return true;
}


bool Foam::functionObjects::NusseltNum::execute()
{
    volScalarField& NusseltNum = lookupObjectRef<volScalarField>(type());

    if
    (
        foundObject<compressible::turbulenceModel>
        (
            turbulenceModel::propertiesName
        )
    )
    {
        const compressible::turbulenceModel& turbModel =
            lookupObject<compressible::turbulenceModel>
            (
                turbulenceModel::propertiesName
            );

        calcHeatFlux
        (
            turbModel.alphaEff()(),
            turbModel.transport().he(),
            NusseltNum
        );
    }
    else if (foundObject<fluidThermo>(fluidThermo::dictName))
    {
        const fluidThermo& thermo =
            lookupObject<fluidThermo>(fluidThermo::dictName);

        calcHeatFlux
        (
            thermo.alpha(),
            thermo.he(),
            NusseltNum
        );
    }
    else if (foundObject<solidThermo>(solidThermo::dictName))
    {
        const solidThermo& thermo =
            lookupObject<solidThermo>(solidThermo::dictName);

        calcHeatFlux(thermo.alpha(), thermo.he(), NusseltNum);
    }
    else
    {
        FatalErrorInFunction
            << "Unable to find compressible turbulence model in the "
            << "database" << exit(FatalError);
    }

    const fvPatchList& patches = mesh_.boundary();

    const surfaceScalarField::Boundary& magSf = mesh_.magSf().boundaryField();

    for (const label patchi : patchSet_)
    {
        const fvPatch& pp = patches[patchi];

        const scalarField& hfp = NusseltNum.boundaryField()[patchi];

        const scalar minHfp = gMin(hfp);
        const scalar maxHfp = gMax(hfp);
        const scalar integralHfp = gSum(magSf[patchi]*hfp);

        if (Pstream::master())
        {
            writeCurrentTime(file());

            file()
                << token::TAB << pp.name()
                << token::TAB << minHfp
                << token::TAB << maxHfp
                << token::TAB << integralHfp
                << endl;
        }

        Log << "    min/max/integ(" << pp.name() << ") = "
            << minHfp << ", " << maxHfp << ", " << integralHfp << endl;

        this->setResult("min(" + pp.name() + ")", minHfp);
        this->setResult("max(" + pp.name() + ")", maxHfp);
        this->setResult("int(" + pp.name() + ")", integralHfp);
    }


    return true;
}


bool Foam::functionObjects::NusseltNum::write()
{
    const volScalarField& NusseltNum = lookupObject<volScalarField>(type());

    Log << type() << " " << name() << " write:" << nl
        << "    writing field " << NusseltNum.name() << endl;

    NusseltNum.write();

    return true;
}


// ************************************************************************* //
Everthing compiles fine.


Now is the strange thing what happends


When I type
Code:
Solver -postProcess -lib "libCustom" -func NusseltNum
he finds the lib but does not find the function NusseltNum


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 NusseltNum
What am I doing wrong?
HorstvanGrass is offline   Reply With Quote

Old   August 3, 2021, 13:28
Default Add compiling log
  #2
Member
 
Horst van Gras
Join Date: Oct 2018
Posts: 45
Rep Power: 8
HorstvanGrass is on a distinguished road
Code:
./Allwmake 
wmake field
    ln: ./lnInclude
Making dependency list for source file NusseltNum.C
g++ -std=c++11 -m64 -pthread -DOPENFOAM=2012 -DWM_DP -DWM_LABEL_SIZE=32  -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter  -Wno-invalid-offsetof -Wno-attributes -Wno-unknown-pragmas  -O3   -DNoRepository -ftemplate-depth-100  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/finiteVolume/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/fileFormats/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/surfMesh/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/meshTools/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/sampling/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/lagrangian/basic/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/lagrangian/distributionModels/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/basic/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/turbulenceModels/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/incompressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/basic/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/solidThermo/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/chemistryModel/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/reactionThermo/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/specie/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/fvAgglomerationMethods/pairPatchAgglomeration/lnInclude  -iquote. -IlnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/OpenFOAM/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/OSspecific/POSIX/lnInclude    -fPIC -c NusseltNum/NusseltNum.C -o  Make/linux64GccDPInt32Opt/NusseltNum/NusseltNum.o
g++ -std=c++11 -m64 -pthread -DOPENFOAM=2012 -DWM_DP -DWM_LABEL_SIZE=32  -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter  -Wno-invalid-offsetof -Wno-attributes -Wno-unknown-pragmas  -O3   -DNoRepository -ftemplate-depth-100  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/finiteVolume/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/fileFormats/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/surfMesh/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/meshTools/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/sampling/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/lagrangian/basic/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/lagrangian/distributionModels/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/basic/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/turbulenceModels/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/incompressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/TurbulenceModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/transportModels/compressible/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/basic/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/solidThermo/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/chemistryModel/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/reactionThermo/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/thermophysicalModels/specie/lnInclude   -I/opt/software/OpenFoam/OpenFOAM-v2012/src/fvAgglomerationMethods/pairPatchAgglomeration/lnInclude  -iquote. -IlnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/OpenFOAM/lnInclude  -I/opt/software/OpenFoam/OpenFOAM-v2012/src/OSspecific/POSIX/lnInclude    -fPIC -shared -Xlinker --add-needed -Xlinker --no-as-needed   Make/linux64GccDPInt32Opt/NusseltNum/NusseltNum.o  -L/opt/software/OpenFoam/OpenFOAM-v2012/platforms/linux64GccDPInt32Opt/lib  \
    -lfiniteVolume -lfileFormats -lsurfMesh -lmeshTools -lsampling  -llagrangian -ldistributionModels -lfluidThermophysicalModels  -lsolidThermo -lincompressibleTransportModels -lturbulenceModels  -lcompressibleTransportModels -lincompressibleTurbulenceModels  -lcompressibleTurbulenceModels -lchemistryModel  -lreactionThermophysicalModels -lpairPatchAgglomeration  -o  #MYHomePath/platforms/linux64GccDPInt32Opt/lib/libCustom.so
HorstvanGrass is offline   Reply With Quote

Reply

Tags
custom application, field function, postprocess, wallheatflux


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
Create a custom function object t.oliveira OpenFOAM Programming & Development 13 June 24, 2022 06:41
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
Can i take contours from Custom field function i defined ? rahulohlan FLUENT 3 April 18, 2017 14:39
coded function object and field average matthias OpenFOAM Post-Processing 3 June 30, 2014 05:52
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 06:42


All times are GMT -4. The time now is 12:36.