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

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

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 13, 2014, 10:29
Default creating functionObject for uTau - compilation i.O. - application error
  #1
Senior Member
 
Join Date: Nov 2012
Location: Bavaria
Posts: 144
Rep Power: 4
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, 20:04
Default
  #2
New Member
 
Janaína de Andrade Silva
Join Date: Mar 2014
Posts: 8
Rep Power: 3
nainasjdr is on a distinguished road
How could you do this ?
nainasjdr is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mesquite - Adaptive mesh refinement / coarsening? philippose OpenFOAM Running, Solving & CFD 93 September 19, 2014 04:42
OpenFOAM without MPI kokizzu OpenFOAM Installation 4 May 26, 2014 09:17
Compiling dynamicTopoFvMesh for OpenFOAM 2.1.x Saxwax OpenFOAM Installation 25 November 29, 2013 06:34
error compiling modified applications yvyan OpenFOAM Programming & Development 18 December 17, 2011 15:39
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50


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