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

undefined reference to a C++'s class member function

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 9, 2017, 16:14
Default undefined reference to a C++'s class member function
  #1
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11
linyanx is on a distinguished road
Hi Foamers.

I am trying to compile a solver based on 'multiphaseInterFoam' after adding one user-defined member function into the 'multiphaseMixture' part. Specifically, I was trying to add one volumeScalarField in every phase just like rho(density).

Hence, I monkey the rho(density) part in the multiphaseMixture code and transfer all of these into the field I created. However, the system complains like this:

Quote:
test.C.text.startup+0xfbf): undefined reference to `Foam::multiphaseMixture::EC() const'
test.C.text.startup+0x2f40): undefined reference to `Foam::multiphaseMixture::EC() const'
test.C.text.startup+0x44b9): undefined reference to `Foam::multiphaseMixture::EC() const'
Do I need to define the mixture.EC() term in advance in the test.c file?

Thanks,
Antelope
linyanx is offline   Reply With Quote

Old   May 10, 2017, 04:21
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
Did you #include the appropriate header in your test file?
Did you add the member function declaration to the header file that belongs to the source file in which you added the member function?
floquation is offline   Reply With Quote

Old   May 10, 2017, 05:53
Default
  #3
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11
linyanx is on a distinguished road
Dear Kevin,
Thanks for your reply!

Quote:
Originally Posted by floquation View Post
Did you #include the appropriate header in your test file?
Did you add the member function declaration to the header file that belongs to the source file in which you added the member function?
1. I did include the header file in my test.C because the field I want to add is dealt with the 'multiphaseMixture' package(sub-package of the multiphaseInterFoam solver). And this header file has already been #include in the test.C file as '#include <multiphaseMixture.H>.

2. I am not sure if I declare this member function correctly. Please correct me if I am doing wrong. Plus, the only modification I've made for multiphaseMixture.H is writing code below.

Best regards,
Linyan

Code:
        //- Return the mixture EC
        tmp<volScalarField> EC() const;

        //- Return the mixture EC for patch
        tmp<scalarField> EC(const label patchi) const;
I also attach the whole multiphaseMixture.H file and highlight the modification part for your convenience.

Code:
SourceFiles
    multiphaseMixture.C

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

#ifndef multiphaseMixture_H
#define multiphaseMixture_H

#include "incompressible/transportModel/transportModel.H"
#include "IOdictionary.H"
#include "phase.H"
#include "PtrDictionary.H"
#include "volFields.H"
#include "surfaceFields.H"

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

namespace Foam
{

/*---------------------------------------------------------------------------*\
                      Class multiphaseMixture Declaration
\*---------------------------------------------------------------------------*/

class multiphaseMixture
:
    public IOdictionary,
    public transportModel
{
public:

    class interfacePair
    :
        public Pair<word>
    {
    public:

        class hash
        :
            public Hash<interfacePair>
        {
        public:

            hash()
            {}

            label operator()(const interfacePair& key) const
            {
                return word::hash()(key.first()) + word::hash()(key.second());
            }
        };


        // Constructors

            interfacePair()
            {}

            interfacePair(const word& alpha1Name, const word& alpha2Name)
            :
                Pair<word>(alpha1Name, alpha2Name)
            {}

            interfacePair(const phase& alpha1, const phase& alpha2)
            :
                Pair<word>(alpha1.name(), alpha2.name())
            {}


        // Friend Operators

            friend bool operator==
            (
                const interfacePair& a,
                const interfacePair& b
            )
            {
                return
                (
                    ((a.first() == b.first()) && (a.second() == b.second()))
                 || ((a.first() == b.second()) && (a.second() == b.first()))
                );
            }

            friend bool operator!=
            (
                const interfacePair& a,
                const interfacePair& b
            )
            {
                return (!(a == b));
            }
    };


private:

    // Private data

        //- Dictionary of phases
        PtrDictionary<phase> phases_;

        const fvMesh& mesh_;
        const volVectorField& U_;
        const surfaceScalarField& phi_;

        surfaceScalarField rhoPhi_;
        volScalarField alphas_;

        volScalarField nu_;

        typedef HashTable<scalar, interfacePair, interfacePair::hash>
            sigmaTable;

        sigmaTable sigmas_;
        dimensionSet dimSigma_;

        //- Stabilisation for normalisation of the interface normal
        const dimensionedScalar deltaN_;

        //- Conversion factor for degrees into radians
        static const scalar convertToRad;


    // Private member functions

        void calcAlphas();

        void solveAlphas(const scalar cAlpha);

        tmp<surfaceVectorField> nHatfv
        (
            const volScalarField& alpha1,
            const volScalarField& alpha2
        ) const;

        tmp<surfaceScalarField> nHatf
        (
            const volScalarField& alpha1,
            const volScalarField& alpha2
        ) const;

        void correctContactAngle
        (
            const phase& alpha1,
            const phase& alpha2,
            surfaceVectorField::Boundary& nHatb
        ) const;

        tmp<volScalarField> K(const phase& alpha1, const phase& alpha2) const;


public:

    // Constructors

        //- Construct from components
        multiphaseMixture
        (
            const volVectorField& U,
            const surfaceScalarField& phi
        );


    //- Destructor
    virtual ~multiphaseMixture()
    {}


    // Member Functions

        //- Return the phases
        const PtrDictionary<phase>& phases() const
        {
            return phases_;
        }

        //- Return the velocity
        const volVectorField& U() const
        {
            return U_;
        }

        //- Return the volumetric flux
        const surfaceScalarField& phi() const
        {
            return phi_;
        }

        const surfaceScalarField& rhoPhi() const
        {
            return rhoPhi_;
        }

        //- Return the mixture density
        tmp<volScalarField> rho() const;

        //- Return the mixture density for patch
        tmp<scalarField> rho(const label patchi) const;


        //- Return the mixture EC
        tmp<volScalarField> EC() const;

        //- Return the mixture EC for patch
        tmp<scalarField> EC(const label patchi) const;


        //- Return the face-interpolated dynamic laminar viscosity
        tmp<surfaceScalarField> muf() const;

        //- Return the kinematic laminar viscosity
        tmp<volScalarField> nu() const;

        //- Return the laminar viscosity for patch
        tmp<scalarField> nu(const label patchi) const;

        //- Return the face-interpolated dynamic laminar viscosity
        tmp<surfaceScalarField> nuf() const;

        tmp<surfaceScalarField> surfaceTensionForce() const;

        //- Indicator of the proximity of the interface
        //  Field values are 1 near and 0 away for the interface.
        tmp<volScalarField> nearInterface() const;

        //- Solve for the mixture phase-fractions
        void solve();

        //- Correct the mixture properties
        void correct();

        //- Read base transportProperties dictionary
        bool read();
};


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

} // End namespace Foam

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

#endif
linyanx is offline   Reply With Quote

Old   May 10, 2017, 06:25
Default
  #4
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
That seems fine to me.

New questions:
1) Did you implement these members functions in multiphaseMixture.C? Post how you did that.
2) How do you attempt to call this function in your test file?
floquation is offline   Reply With Quote

Old   May 10, 2017, 06:40
Default
  #5
Member
 
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11
linyanx is on a distinguished road
Quote:
Originally Posted by floquation View Post
That seems fine to me.

New questions:
1) Did you implement these members functions in multiphaseMixture.C? Post how you did that.
2) How do you attempt to call this function in your test file?
1) In multiphaseMixture.C, I write the function as below:
Code:
//Member functions part
.
.
.
Foam::tmp<Foam::volScalarField>
Foam::multiphaseMixture::EC() const 
{
    PtrDictionary<phase>::const_iterator iter = phases_.begin();

    tmp<volScalarField> tEC = iter()*iter().EC();
    volScalarField& EC = tEC.ref();

    for (++iter; iter != phases_.end(); ++iter)
    {
        EC += iter()*iter().EC();
    }

    return tEC;
}


Foam::tmp<Foam::scalarField>
Foam::multiphaseMixture::EC(const label patchi) const
{
    PtrDictionary<phase>::const_iterator iter = phases_.begin();

    tmp<scalarField> tEC = iter().boundaryField()[patchi]*iter().EC().value();
    scalarField& EC = tEC.ref();

    for (++iter; iter != phases_.end(); ++iter)
    {
        EC += iter().boundaryField()[patchi]*iter().EC().value();
    }

    return tEC;
}
2) In the main part of the code, I attempt to call this function by coding:
Code:
EC = mixture.EC();
in order to get the overall EC field(just like the density rho field) that mix the three phases EC into one volumeScalarField.
linyanx is offline   Reply With Quote

Old   May 12, 2017, 13:44
Default
  #6
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
Making changes to OF primary source code is not a good idea. You should copy the parts you need into your local (user) directory and alter the code there. Then compile it into your local (user) library.

What you try to do is to add a new function to the existing OF class. Right? If so you have to recompile it into a binary code not just alter a source code. Anyway, as I said it's a bad idea.
Zeppo 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
LEMOS InflowGenerator r_gordon OpenFOAM Running, Solving & CFD 103 December 18, 2018 01:58
LiencubiclowRemodel nzy102 OpenFOAM Bugs 14 January 10, 2012 09:53
OpenFOAM-2.1.x on fedora 16 x86_64 anand_30 OpenFOAM Installation 3 December 26, 2011 03:09
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
G95 + CGNS Bruno Main CFD Forum 1 January 30, 2007 01:34


All times are GMT -4. The time now is 17:05.