|
[Sponsors] |
undefined reference to a C++'s class member function |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 9, 2017, 16:14 |
undefined reference to a C++'s class member function
|
#1 | |
Member
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11 |
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:
Thanks, Antelope |
||
May 10, 2017, 04:21 |
|
#2 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
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? |
|
May 10, 2017, 05:53 |
|
#3 | |
Member
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11 |
Dear Kevin,
Thanks for your reply! Quote:
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; 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 |
||
May 10, 2017, 06:25 |
|
#4 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
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? |
|
May 10, 2017, 06:40 |
|
#5 | |
Member
Linyan X
Join Date: Dec 2015
Posts: 43
Rep Power: 11 |
Quote:
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; } Code:
EC = mixture.EC(); |
||
May 12, 2017, 13:44 |
|
#6 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22 |
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. |
|
|
|
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 |