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

Linking error for lagrangian solver: undefined reference to Foam::xxx::typeName

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 10, 2024, 12:14
Default Linking error for lagrangian solver: undefined reference to Foam::xxx::typeName
  #1
New Member
 
Join Date: Dec 2022
Posts: 2
Rep Power: 0
MartinHG is on a distinguished road
Hello dear Foamers!


I am new to solver development in OpenFoam and ran into an issue I can not resolve on my own despite days of trying. I should mention my C++-skills are not that sharpened, so it might be a very obvious mistake from my side. I am using OpenFoamv2106.

TL;DR: A solver for particle dissolution and evolution of the dissolved scalar field fails to compile with a linker error despite the individual libraries compiling without a problem. Linker error is of type: "undefined reference to xxx:typeName and ::dictionaryConstructorTablePtr_'".

My aim: I am looking into the alloying process in inductively stirred cast iron melts (e.g. with FeMo-particles). For that, I want to take particles with a certain (initial) size distribution and want to very crudely model their dissolution. This is done by estimating their "radius evolution function" r(t) from a known relation to the particle reynolds number. A scalar field "releasedScalar" shall be enriched in proportion to the volume lost in each timestep in the cell where the particle is located. I am mainly interested in the evolution of the scalar field, especially typical homogenization times, not the precise motion of the particles. As I only have 5 alloying elements in my research spectrum right now, my current plan is to hardcode the necessary physical properties of the particles (lamdba, cp, etc.) into r(t) for different libraries and then compile different solvers.



My approach right now: Please see the attached archives for a detailed overview of my files. My main approach was to make a template class MyKinematicParcel and add members for a pointer to "releasedScalar" and "dInitial"(which is needed for r(t), as I never track explicitely track the temperature distribution in the particle), as well as updating all the constructors and member functions. Then, I implemented (prototype) methods for calculating the particle size evolution and setting the releasedScalar-Field. The update of the radius happens in the move() method.

Code:
//MyKinematicParcel.C


template<class ParcelType>
template<class TrackCloudType>
bool Foam::MyKinematicParcel<ParcelType>::move
(
    TrackCloudType& cloud,
    trackingData& td,
    const scalar trackTime
)
{
    typename TrackCloudType::parcelType& p =
        static_cast<typename TrackCloudType::parcelType&>(*this);
    typename TrackCloudType::parcelType::trackingData& ttd =
        static_cast<typename TrackCloudType::parcelType::trackingData&>(td);

     // much more, unaltered existing logic here


         p.releaseScalar();
        p.age() += dt;
    // much more, unaltered existing logic here

}



  template<class ParcelType>
void Foam::MyKinematicParcel<ParcelType>::setReleasedScalar
(
    volScalarField* releasedScalar
)
{
    releasedScalar_ = releasedScalar;
}


template<class ParcelType>
void Foam::MyKinematicParcel<ParcelType>::releaseScalar()
{

    if (this->releasedScalar_)
        {
            // Compute the volume change
            Foam::scalar currentTime = this->age_;
            Foam::scalar currentDiameter = this->d_; 
            Foam::scalar newDiameter = evolveDiameter(currentTime);
            
            Foam::scalar currentRadius = currentDiameter/2.0;
            Foam::scalar newRadius = newDiameter/2.0;

            Foam::scalar oldVolume = (4.0 / 3.0) * M_PI * currentRadius * currentRadius * currentRadius;
            Foam::scalar newVolume = (4.0 / 3.0) * M_PI * newRadius * newRadius * newRadius;
            Foam::scalar deltaVolume = oldVolume - newVolume;
            
            Foam::label nearestCell = this->cell();
            // Update the scalar field in the nearest cell
            if (nearestCell != -1)
            {
                (*(this->releasedScalar_))[nearestCell] += deltaVolume*10; 
            }

            // Update particle diameter
            this->d_ = newDiameter;
        }
  }
   



template<class ParcelType>
Foam::scalar Foam::MyKinematicParcel<ParcelType>::evolveDiameter
(
    scalar age
) const
 { 

       //More involved logic will follow!

        scalar t_shelling = this->calculateTShelling(this->dInitial_);
        scalar t_lifetime = this->calculateTLifetime(this->dInitial_);
        scalar r_0 = this->dInitial_;

        if (age < t_shelling)
        {
            return r_0;
        }
        else if (age < t_lifetime)
        {
            return r_0 * (1 - (age - t_shelling) / (t_lifetime - t_shelling)) + SMALL;
        }
        else
        {
            return SMALL;
        }
   
}

template<class ParcelType>
Foam::scalar Foam::MyKinematicParcel<ParcelType>::calculateTShelling(scalar dInit) const
     {
         //More involved logic will follow!
         return 1.0;
    }
    
    
template<class ParcelType>
Foam::scalar Foam::MyKinematicParcel<ParcelType>::calculateTLifetime(scalar dInit) const
     {
        //More involved logic will follow!
         return 3.0;
    }
To pass down the pointer from my solver.c file directly to the releasedScalar field, I implemented methods in "MyKinematicCloud" and "Cloud". I have left the name "Cloud" for the class because many other classes seem to reference it and adding a method does not break anything (?).



Code:
//MyKinematicCloud.C
template<class CloudType>
void Foam::MyKinematicCloud<CloudType>::setReleasedScalar
(
    volScalarField* releasedScalar
)
{
    CloudType::setReleasedScalar(releasedScalar);
}
Code:
//Cloud.C
template<class ParticleType>
void Foam::Cloud<ParticleType>::setReleasedScalar
(
        volScalarField* releasedScalar
)

{
    // Loop over all particles
    for (ParticleType& p : *this)
    {
        p.setReleasedScalar(releasedScalar);
    }
}
I then updated all the derived classes, compiled
Code:
$WM_PROJECT_USER_DIR/src/lagrangian/intermediate -> libmylagrangianIntermediate.so
then went on to compile
Code:
 $WM_PROJECT_USER_DIR/src/lagrangian/ -> libmylagrangian
Please see the Make folders in the attached lagrangian.zip for details. Everything compiled without a problem.

Then I went on to my (still prototypy) solver solidParticleMeltFoam2.
I tried to compile it with the following Make/files and Make/options.


Code:
//Make/files

solidParticleMeltFoam2.C

EXE = $(FOAM_USER_APPBIN)/solidParticleMeltFoam2
Code:
//Make/options

EXE_INC = \
    -I$(WM_PROJECT_USER_DIR)/src/lagrangian/lnInclude \
    -I$(WM_PROJECT_USER_DIR)/src/lagrangian/intermediate/lnInclude \
    -I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \
    -I$(LIB_SRC)/dynamicMesh/lnInclude \
    -I$(LIB_SRC)/dynamicFvMesh/lnInclude \
    -I$(LIB_SRC)/lagrangian/basic/lnInclude \
    -I$(LIB_SRC)/lagrangian/solidParticle/lnInclude \
    -I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \
    -I$(LIB_SRC)/regionModels/regionModel/lnInclude \

EXE_LIBS = \
    -L$(FOAM_USER_LIBBIN) \
    -L$(FOAM_LIBBIN) \
    -lmylagrangian \
    -lmylagrangianIntermediate \
    -llagrangian \
    -llagrangianIntermediate \
    -llagrangianFunctionObjects \
    -lturbulenceModels \
    -lfiniteVolume \
    -lsampling \
    -lmeshTools \
    -lsolidParticle \
    -ldynamicMesh \
    -ldynamicFvMesh \
    -ltopoChangerFvMesh \
    -latmosphericModels \
    -lincompressibleTransportModels \
    -lincompressibleTurbulenceModels \
    -lregionModels \
    -lsurfaceFilmModels \
    -lOpenFOAM \
    -ldl
The error: After wclean and wmake, I get the following linker error (not full error, I will attach it as error.txt).
Code:
//truncated here
     -lm -o /home/heunisch/OpenFOAM/heunisch-v2106/platforms/linux64Gcc91DPInt32Opt/bin/solidParticleMeltFoam2
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::CloudFunctionObject<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::type() const':
solidParticleMeltFoam2.C:(.text._ZNK4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE4typeEv[_ZNK4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE4typeEv]+0x3): undefined reference to `Foam::CloudFunctionObject<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::typeName'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::ParticleForce<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::type() const':
solidParticleMeltFoam2.C:(.text._ZNK4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE4typeEv[_ZNK4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE4typeEv]+0x3): undefined reference to `Foam::ParticleForce<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::typeName'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::ParticleForce<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::New(Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > >&, Foam::fvMesh const&, Foam::dictionary const&, Foam::word const&)':
solidParticleMeltFoam2.C:(.text._ZN4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERS7_RKNS_6fvMeshERKNS_10dictionaryERKNS_4wordE[_ZN4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERS7_RKNS_6fvMeshERKNS_10dictionaryERKNS_4wordE]+0x55): undefined reference to `Foam::ParticleForce<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
solidParticleMeltFoam2.C:(.text._ZN4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERS7_RKNS_6fvMeshERKNS_10dictionaryERKNS_4wordE[_ZN4Foam13ParticleForceINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERS7_RKNS_6fvMeshERKNS_10dictionaryERKNS_4wordE]+0xf6): undefined reference to `Foam::ParticleForce<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::CloudFunctionObject<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::New(Foam::dictionary const&, Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > >&, Foam::word const&, Foam::word const&)':
solidParticleMeltFoam2.C:(.text._ZN4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_RKNS_4wordESF_[_ZN4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_RKNS_4wordESF_]+0x6f): undefined reference to `Foam::CloudFunctionObject<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
solidParticleMeltFoam2.C:(.text._ZN4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_RKNS_4wordESF_[_ZN4Foam19CloudFunctionObjectINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_RKNS_4wordESF_]+0x110): undefined reference to `Foam::CloudFunctionObject<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::InjectionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::New(Foam::dictionary const&, Foam::word const&, Foam::word const&, Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > >&)':
solidParticleMeltFoam2.C:(.text._ZN4Foam14InjectionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERKNS_4wordESE_RS7_[_ZN4Foam14InjectionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERKNS_4wordESE_RS7_]+0x55): undefined reference to `Foam::InjectionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
solidParticleMeltFoam2.C:(.text._ZN4Foam14InjectionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERKNS_4wordESE_RS7_[_ZN4Foam14InjectionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERKNS_4wordESE_RS7_]+0xf6): undefined reference to `Foam::InjectionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::DispersionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::New(Foam::dictionary const&, Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > >&)':
solidParticleMeltFoam2.C:(.text._ZN4Foam15DispersionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_[_ZN4Foam15DispersionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_]+0xb7): undefined reference to `Foam::DispersionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
solidParticleMeltFoam2.C:(.text._ZN4Foam15DispersionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_[_ZN4Foam15DispersionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_]+0x158): undefined reference to `Foam::DispersionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
Make/linux64Gcc91DPInt32Opt/solidParticleMeltFoam2.o: In function `Foam::PatchInteractionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::New(Foam::dictionary const&, Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > >&)':
solidParticleMeltFoam2.C:(.text._ZN4Foam21PatchInteractionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_[_ZN4Foam21PatchInteractionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_]+0xce): undefined reference to `Foam::PatchInteractionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'
solidParticleMeltFoam2.C:(.text._ZN4Foam21PatchInteractionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_[_ZN4Foam21PatchInteractionModelINS_16MyKinematicCloudINS_5CloudINS_17MyKinematicParcelINS_8particleEEEEEEEE3NewERKNS_10dictionaryERS7_]+0x16f): undefined reference to `Foam::PatchInteractionModel<Foam::MyKinematicCloud<Foam::Cloud<Foam::MyKinematicParcel<Foam::particle> > > >::dictionaryConstructorTablePtr_'



//truncated here



 collect2: error: ld returned 1 exit status
make: *** [/home/heunisch/OpenFOAM/heunisch-v2106/platforms/linux64Gcc91DPInt32Opt/bin/solidParticleMeltFoam2] Error 1
My resolution approaches: After googling similar errors, I saw multiple approaches to the resolution of this error
  • compiling with wmake libso instead of wmake - done.
  • compiling the library not only in the lagrangian folder, but before that in lagrangian/intermediate - done.
  • deleting all entries in $FOAM_USER_LIBBIN and then compiling the libraries again - done.
  • changing the order of library imports - done, but I can not recall all variations I tried.
  • asking ChatGPT 4o ;) -> adding a few libraries, which made the error message shorter. they are now all included in the "Make/options" file of the solver.
Right now, I think my lack of C++ proficiency keeps me from resolving the error here - can you guys help me?

Best regards
Martin
Attached Files
File Type: zip lagrangian.zip (51.1 KB, 2 views)
File Type: zip solidParticleMeltFoam2.zip (5.4 KB, 1 views)
File Type: txt error.txt (19.4 KB, 0 views)
MartinHG is offline   Reply With Quote

Old   July 13, 2024, 14:16
Default
  #2
Member
 
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 44
Rep Power: 6
reverseila is on a distinguished road
Hi,


Have you tried the following?


1. copy the whole $FOAM_SRC/lagrangian library into the user src/ directory (or pick the whole sublibraries you need (don't copy intermediate library partially)),
2. add your code,
3. add the necessary flags to the Make/{files,options}. Also let the name be liblagrangian, and liblagrangianIntermediate. the linker will identify your code if you tell it where to look for the them ($FOAM_USER_LIBBIN).


I also have a experience like this where I tried to change the name to mylagrangianIntermediate but it gave some strange linker error.
reverseila is offline   Reply With Quote

Old   July 16, 2024, 12:06
Default
  #3
New Member
 
Join Date: Dec 2022
Posts: 2
Rep Power: 0
MartinHG is on a distinguished road
Quote:
Originally Posted by reverseila View Post
Hi,


Have you tried the following?


1. copy the whole $FOAM_SRC/lagrangian library into the user src/ directory (or pick the whole sublibraries you need (don't copy intermediate library partially)),
2. add your code,
3. add the necessary flags to the Make/{files,options}. Also let the name be liblagrangian, and liblagrangianIntermediate. the linker will identify your code if you tell it where to look for the them ($FOAM_USER_LIBBIN).


I also have a experience like this where I tried to change the name to mylagrangianIntermediate but it gave some strange linker error.



Hi reverseila,


thank you very much for your advice, which actually helped me getting the thing compiled and running!

A little variation on your answer - I left the original class names (so e.g. not MyKinematicParcel but KinematicParcel), but named the libraries libMY2lagrangian and libMY2lagrangianIntermediate, so name conflicts in the Make/options file can never happen. This worked without a problem!

I know the "not-renaming" of classes is usually heavily discouraged. But no variation I tried with my own class names failed to compile, even when keeping the whole "intermediate" library. Does anyone know, why this behavior appeared? I still do not really understand.

Right now, my code is not producing the results I am expecting, but this a story for another time and I am still in very early test phase

Thank you again!

Best regards
Martin
MartinHG is offline   Reply With Quote

Reply

Tags
lagrangian solver, linker error, particle dissolution, undefined reference


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 SIGSEGV using VOF and UDF JERC_UTFSM Fluent UDF and Scheme Programming 14 November 8, 2021 00:17
LEMOS InflowGenerator r_gordon OpenFOAM Running, Solving & CFD 103 December 18, 2018 01:58
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 01:01
Error with Wmake skabilan OpenFOAM Installation 3 July 28, 2009 01:35
Parallel processing problem with mpich nzy102 OpenFOAM Running, Solving & CFD 14 October 18, 2007 01:05


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