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

creating functionObject for uTau - compilation i.O. - application error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 13, 2014, 11:29
Default creating functionObject for uTau - compilation i.O. - application error
  #1
Senior Member
 
Join Date: Nov 2012
Location: Bavaria
Posts: 145
Rep Power: 14
aylalisa is on a distinguished road
Hi Foamers,

I've tried to adapt a functionObject to finally get uTau during simulation.

Following error comes up once I've start the case with the 'new' FO activated:

Quote:
[2] --> FOAM FATAL ERROR:
[2] attempted to assign to a const reference to constant object of type N4Foam14GeometricFieldIdNS_12fvPatchFieldENS_7volM eshEEE
[2]
[2] From function Foam::tmp<T>:perator=(const tmp<T>&)
[2] in file /home/elisabeth/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/tmpI.H at line 306.
[2]
FOAM parallel run aborting
uTau.H
Code:
\*---------------------------------------------------------------------------*/

#ifndef uTau_H
#define uTau_H

#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "Switch.H"
#include "OFstream.H"

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

namespace Foam
{

// Forward declaration of classes
class objectRegistry;
class dictionary;
class polyMesh;
class mapPolyMesh;
class fvMesh;

/*---------------------------------------------------------------------------*\
                       Class uTau Declaration
\*---------------------------------------------------------------------------*/

class uTau
:
    public functionObjectFile
{
protected:

    // Protected data

        //- Name of this set of uTau object
        word name_;

        const objectRegistry& obr_;

        //- on/off switch
        bool active_;

        //- Switch to send output to Info as well as to file
        Switch log_;

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


    // Protected Member Functions

        //- File header information
        virtual void writeFileHeader(const label i);

        //- Calculate the shear stress
        void calcuTau
        (
            const fvMesh& mesh,
            volScalarField& uTau,
            const volVectorField& U,
            volScalarField nuLam

        );

        //- Disallow default bitwise copy construct
        uTau(const uTau&);

        //- Disallow default bitwise assignment
        void operator=(const uTau&);


public:

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


    // Constructors

        //- Construct for given objectRegistry and dictionary.
        //  Allow the possibility to load fields from files
        uTau
        (
            const word& name,
            const objectRegistry&,
            const dictionary&,
            const bool loadFromFiles = false
        );


    //- Destructor
    virtual ~uTau();


    // Member Functions

        //- Return name of the set of uTau
        virtual const word& name() const
        {
            return name_;
        }

        //- Read the uTau data
        virtual void read(const dictionary&);

        //- Execute, currently does nothing
        virtual void execute();

        //- Execute at the final time-loop, currently does nothing
        virtual void end();

        //- Called when time was set at the end of the Time::operator++
        virtual void timeSet();

        //- Calculate the uTau and write
        virtual void write();

        //- Update for changes of mesh
        virtual void updateMesh(const mapPolyMesh&)
        {}

        //- Update for changes of mesh
        virtual void movePoints(const polyMesh&)
        {}
};


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

} // End namespace Foam

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

#endif

// ************************************************************************* //
uTau.C

Code:
\*---------------------------------------------------------------------------*/

#include "uTau.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "incompressible/turbulenceModel/turbulenceModel.H"
#include "compressible/turbulenceModel/turbulenceModel.H"
#include "wallPolyPatch.H"

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

namespace Foam
{
defineTypeNameAndDebug(uTau, 0);
}


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

void Foam::uTau::writeFileHeader(const label i)
{
    // Add headers to output data
    writeHeader(file(), "uTau");
    writeCommented(file(), "Time");
    writeTabbed(file(), "patch");
    writeTabbed(file(), "min");
    writeTabbed(file(), "max");
}


void Foam::uTau::calcuTau
(
    const fvMesh& mesh,
    volScalarField& uTauField,
    const volVectorField& U,
    volScalarField nuLam
)
{
    forAllConstIter(labelHashSet, patchSet_, iter)
    {
        label patchI = iter.key();
        const polyPatch& pp = mesh.boundaryMesh()[patchI];

        scalarField& uTau_p = uTauField.boundaryField()[patchI];

        uTau_p = sqrt
                (
                    nuLam.boundaryField()[patchI]
                   *mag(U.boundaryField()[patchI].snGrad())
                );

        scalar minUTau = gMin(uTau_p);
        scalar maxUTau = gMax(uTau_p);

        if (Pstream::master())
        {
            file() << mesh.time().value()
                << token::TAB << pp.name()
                << token::TAB << minUTau
                << token::TAB << maxUTau
                << endl;
        }

        Info(log_)<< "    min/max(" << pp.name() << ") = "
            << minUTau << ", " << maxUTau << endl;
    }
}


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

Foam::uTau::uTau
(
    const word& name,
    const objectRegistry& obr,
    const dictionary& dict,
    const bool loadFromFiles
)
:
    functionObjectFile(obr, name, typeName),
    name_(name),
    obr_(obr),
    active_(true),
    log_(true),
    patchSet_()
{
    // Check if the available mesh is an fvMesh, otherwise deactivate
    if (!isA<fvMesh>(obr_))
    {
        active_ = false;
        WarningIn
        (
            "uTau::uTau"
            "("
                "const word&, "
                "const objectRegistry&, "
                "const dictionary&, "
                "const bool"
            ")"
        )   << "No fvMesh available, deactivating " << name_ << nl
            << endl;
    }

    if (active_)
    {
        const fvMesh& mesh = refCast<const fvMesh>(obr_);

        volScalarField* uTauPtr
        (
            new volScalarField
            (
                IOobject
                (
                    type(),
                    mesh.time().timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh,
                dimensionedScalar
                (
                    "0",
                    dimless,
                    //sqr(dimLength)/sqr(dimTime),
                    0
                )
            )
        );

        mesh.objectRegistry::store(uTauPtr);
    }

    read(dict);
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::uTau::~uTau()
{}


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

void Foam::uTau::read(const dictionary& dict)
{
    if (active_)
    {
        log_ = dict.lookupOrDefault<Switch>("log", true);

        const fvMesh& mesh = refCast<const fvMesh>(obr_);
        const polyBoundaryMesh& pbm = mesh.boundaryMesh();

        patchSet_ =
            mesh.boundaryMesh().patchSet
            (
                wordReList(dict.lookupOrDefault("patches", wordReList()))
            );

        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;
            forAllConstIter(labelHashSet, patchSet_, iter)
            {
                label patchI = iter.key();
                if (isA<wallPolyPatch>(pbm[patchI]))
                {
                    filteredPatchSet.insert(patchI);
                    Info<< "        " << pbm[patchI].name() << endl;
                }
                else
                {
                    WarningIn("void uTau::read(const dictionary&)")
                        << "Requested uTau on non-wall boundary "
                        << "type patch: " << pbm[patchI].name() << endl;
                }
            }

            Info<< endl;

            patchSet_ = filteredPatchSet;
        }
    }
}


void Foam::uTau::execute()
{
    //typedef compressible::turbulenceModel cmpModel;
    typedef incompressible::turbulenceModel icoModel;

    if (active_)
    {
        functionObjectFile::write();

        const fvMesh& mesh = refCast<const fvMesh>(obr_);

        volScalarField& uTau =
            const_cast<volScalarField&>
            (
                mesh.lookupObject<volScalarField>(type())
            );

        Info(log_)<< type() << " " << name_ << " output:" << nl;

        //neu
       const volVectorField& U = obr_.lookupObject<volVectorField>("U");

        tmp<volScalarField> nuLam;

                if (mesh.foundObject<icoModel>("turbulenceModel"))
                {
                    const icoModel& model =
                        mesh.lookupObject<icoModel>("turbulenceModel");

                    nuLam = model.nu();
                }
                else
                {
                    FatalErrorIn("void Foam::uTau::write()")
                        << "Unable to find turbulence model in the "
                        << "database" << exit(FatalError);
                }

        calcuTau(mesh, uTau, U, nuLam);
    }
}


void Foam::uTau::end()
{
    if (active_)
    {
        execute();
    }
}


void Foam::uTau::timeSet()
{
    // Do nothing
}


void Foam::uTau::write()
{
    if (active_)
    {
        functionObjectFile::write();

        const volVectorField& uTau =
            obr_.lookupObject<volVectorField>(type());

        Info(log_)<< type() << " " << name_ << " output:" << nl
            << "    writing field " << uTau.name() << nl
            << endl;

        uTau.write();
    }
}


// ************************************************************************* //
Could somebody support me?

Thanks!
Ayla
aylalisa is offline   Reply With Quote

Old   September 18, 2014, 21:04
Default
  #2
New Member
 
Janaína de Andrade Silva
Join Date: Mar 2014
Posts: 8
Rep Power: 12
nainasjdr is on a distinguished road
How could you do this ?
nainasjdr is offline   Reply With Quote

Old   April 29, 2018, 15:50
Default
  #3
gu1
Senior Member
 
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10
gu1 is on a distinguished road
Quote:
Originally Posted by aylalisa View Post
Hi Foamers,

I've tried to adapt a functionObject to finally get uTau during simulation.

Following error comes up once I've start the case with the 'new' FO activated:

uTau.H
Code:
\*---------------------------------------------------------------------------*/

#ifndef uTau_H
#define uTau_H

#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "Switch.H"
#include "OFstream.H"

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

namespace Foam
{

// Forward declaration of classes
class objectRegistry;
class dictionary;
class polyMesh;
class mapPolyMesh;
class fvMesh;

/*---------------------------------------------------------------------------*\
                       Class uTau Declaration
\*---------------------------------------------------------------------------*/

class uTau
:
    public functionObjectFile
{
protected:

    // Protected data

        //- Name of this set of uTau object
        word name_;

        const objectRegistry& obr_;

        //- on/off switch
        bool active_;

        //- Switch to send output to Info as well as to file
        Switch log_;

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


    // Protected Member Functions

        //- File header information
        virtual void writeFileHeader(const label i);

        //- Calculate the shear stress
        void calcuTau
        (
            const fvMesh& mesh,
            volScalarField& uTau,
            const volVectorField& U,
            volScalarField nuLam

        );

        //- Disallow default bitwise copy construct
        uTau(const uTau&);

        //- Disallow default bitwise assignment
        void operator=(const uTau&);


public:

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


    // Constructors

        //- Construct for given objectRegistry and dictionary.
        //  Allow the possibility to load fields from files
        uTau
        (
            const word& name,
            const objectRegistry&,
            const dictionary&,
            const bool loadFromFiles = false
        );


    //- Destructor
    virtual ~uTau();


    // Member Functions

        //- Return name of the set of uTau
        virtual const word& name() const
        {
            return name_;
        }

        //- Read the uTau data
        virtual void read(const dictionary&);

        //- Execute, currently does nothing
        virtual void execute();

        //- Execute at the final time-loop, currently does nothing
        virtual void end();

        //- Called when time was set at the end of the Time::operator++
        virtual void timeSet();

        //- Calculate the uTau and write
        virtual void write();

        //- Update for changes of mesh
        virtual void updateMesh(const mapPolyMesh&)
        {}

        //- Update for changes of mesh
        virtual void movePoints(const polyMesh&)
        {}
};


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

} // End namespace Foam

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

#endif

// ************************************************************************* //
uTau.C

Code:
\*---------------------------------------------------------------------------*/

#include "uTau.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "incompressible/turbulenceModel/turbulenceModel.H"
#include "compressible/turbulenceModel/turbulenceModel.H"
#include "wallPolyPatch.H"

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

namespace Foam
{
defineTypeNameAndDebug(uTau, 0);
}


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

void Foam::uTau::writeFileHeader(const label i)
{
    // Add headers to output data
    writeHeader(file(), "uTau");
    writeCommented(file(), "Time");
    writeTabbed(file(), "patch");
    writeTabbed(file(), "min");
    writeTabbed(file(), "max");
}


void Foam::uTau::calcuTau
(
    const fvMesh& mesh,
    volScalarField& uTauField,
    const volVectorField& U,
    volScalarField nuLam
)
{
    forAllConstIter(labelHashSet, patchSet_, iter)
    {
        label patchI = iter.key();
        const polyPatch& pp = mesh.boundaryMesh()[patchI];

        scalarField& uTau_p = uTauField.boundaryField()[patchI];

        uTau_p = sqrt
                (
                    nuLam.boundaryField()[patchI]
                   *mag(U.boundaryField()[patchI].snGrad())
                );

        scalar minUTau = gMin(uTau_p);
        scalar maxUTau = gMax(uTau_p);

        if (Pstream::master())
        {
            file() << mesh.time().value()
                << token::TAB << pp.name()
                << token::TAB << minUTau
                << token::TAB << maxUTau
                << endl;
        }

        Info(log_)<< "    min/max(" << pp.name() << ") = "
            << minUTau << ", " << maxUTau << endl;
    }
}


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

Foam::uTau::uTau
(
    const word& name,
    const objectRegistry& obr,
    const dictionary& dict,
    const bool loadFromFiles
)
:
    functionObjectFile(obr, name, typeName),
    name_(name),
    obr_(obr),
    active_(true),
    log_(true),
    patchSet_()
{
    // Check if the available mesh is an fvMesh, otherwise deactivate
    if (!isA<fvMesh>(obr_))
    {
        active_ = false;
        WarningIn
        (
            "uTau::uTau"
            "("
                "const word&, "
                "const objectRegistry&, "
                "const dictionary&, "
                "const bool"
            ")"
        )   << "No fvMesh available, deactivating " << name_ << nl
            << endl;
    }

    if (active_)
    {
        const fvMesh& mesh = refCast<const fvMesh>(obr_);

        volScalarField* uTauPtr
        (
            new volScalarField
            (
                IOobject
                (
                    type(),
                    mesh.time().timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh,
                dimensionedScalar
                (
                    "0",
                    dimless,
                    //sqr(dimLength)/sqr(dimTime),
                    0
                )
            )
        );

        mesh.objectRegistry::store(uTauPtr);
    }

    read(dict);
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::uTau::~uTau()
{}


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

void Foam::uTau::read(const dictionary& dict)
{
    if (active_)
    {
        log_ = dict.lookupOrDefault<Switch>("log", true);

        const fvMesh& mesh = refCast<const fvMesh>(obr_);
        const polyBoundaryMesh& pbm = mesh.boundaryMesh();

        patchSet_ =
            mesh.boundaryMesh().patchSet
            (
                wordReList(dict.lookupOrDefault("patches", wordReList()))
            );

        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;
            forAllConstIter(labelHashSet, patchSet_, iter)
            {
                label patchI = iter.key();
                if (isA<wallPolyPatch>(pbm[patchI]))
                {
                    filteredPatchSet.insert(patchI);
                    Info<< "        " << pbm[patchI].name() << endl;
                }
                else
                {
                    WarningIn("void uTau::read(const dictionary&)")
                        << "Requested uTau on non-wall boundary "
                        << "type patch: " << pbm[patchI].name() << endl;
                }
            }

            Info<< endl;

            patchSet_ = filteredPatchSet;
        }
    }
}


void Foam::uTau::execute()
{
    //typedef compressible::turbulenceModel cmpModel;
    typedef incompressible::turbulenceModel icoModel;

    if (active_)
    {
        functionObjectFile::write();

        const fvMesh& mesh = refCast<const fvMesh>(obr_);

        volScalarField& uTau =
            const_cast<volScalarField&>
            (
                mesh.lookupObject<volScalarField>(type())
            );

        Info(log_)<< type() << " " << name_ << " output:" << nl;

        //neu
       const volVectorField& U = obr_.lookupObject<volVectorField>("U");

        tmp<volScalarField> nuLam;

                if (mesh.foundObject<icoModel>("turbulenceModel"))
                {
                    const icoModel& model =
                        mesh.lookupObject<icoModel>("turbulenceModel");

                    nuLam = model.nu();
                }
                else
                {
                    FatalErrorIn("void Foam::uTau::write()")
                        << "Unable to find turbulence model in the "
                        << "database" << exit(FatalError);
                }

        calcuTau(mesh, uTau, U, nuLam);
    }
}


void Foam::uTau::end()
{
    if (active_)
    {
        execute();
    }
}


void Foam::uTau::timeSet()
{
    // Do nothing
}


void Foam::uTau::write()
{
    if (active_)
    {
        functionObjectFile::write();

        const volVectorField& uTau =
            obr_.lookupObject<volVectorField>(type());

        Info(log_)<< type() << " " << name_ << " output:" << nl
            << "    writing field " << uTau.name() << nl
            << endl;

        uTau.write();
    }
}


// ************************************************************************* //
Could somebody support me?

Thanks!
Ayla
Can you teach me, how to plot y+/u+?
gu1 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
error compiling modified applications yvyan OpenFOAM Programming & Development 21 March 1, 2016 05:53
Mesquite - Adaptive mesh refinement / coarsening? philippose OpenFOAM Running, Solving & CFD 94 January 27, 2016 10:40
OpenFOAM without MPI kokizzu OpenFOAM Installation 4 May 26, 2014 10:17
Compiling dynamicTopoFvMesh for OpenFOAM 2.1.x Saxwax OpenFOAM Installation 25 November 29, 2013 06:34
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 21:50


All times are GMT -4. The time now is 20:00.