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

undefined reference_ linking error

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By nikhil108

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 17, 2020, 12:14
Question undefined reference_ linking error
  #1
Member
 
nikhil108's Avatar
 
Nikhil
Join Date: May 2020
Location: Freiburg
Posts: 43
Rep Power: 5
nikhil108 is on a distinguished road
Hallo Foamers,

I am trying to edit reactingFoam solver, to add porous capability. In the process, i got a error "temporary deallocated error", so, as to clear that error, i did some changes in the code. Now, deallocation error is gone, but getting a new error, which says "undefined reference to `trTU()'". trTu() is a tmp variable created in Ueqn.H. By some research, i came to know its a linker error, but dont know how to resolve it. Please have a look at the UEqn.H code and the error msg, and let me know, your views. Thanks.
Code:
MRF.correctBoundaryVelocity(U);

    tmp<fvVectorMatrix> tUEqn
    (
        fvm::ddt(rho, U) + fvm::div(phi, U)
      + MRF.DDt(rho, U)
      + turbulence->divDevTau(U)
     ==
        fvOptions(rho, U)
    );
    fvVectorMatrix& UEqn = tUEqn.ref();

    UEqn.relax();

    tmp<volScalarField> trAU(); //trAU;
    tmp<volTensorField> trTU(); //trTU;

    if (pressureImplicitPorosity)
    {
    tmp<volTensorField> tTU = tensor(I)*UEqn.A();
    pZones.addResistance(UEqn, tTU.ref());
    trTU() = inv(tTU());
    trTU().ref().rename("rAU");
    fvOptions.constrain(UEqn);
    volVectorField gradp(fvc::reconstruct
            ( (
                  - ghf*fvc::snGrad(rho)
                  - fvc::snGrad(p_rgh)
            )*mesh.magSf()
            ) );
        for (int UCorr=0; UCorr<nUCorr; UCorr++)
        {
         U = trTU() & (UEqn.H() - gradp);
        }
    U.correctBoundaryConditions();
    fvOptions.correct(U);
    K = 0.5*magSqr(U);
    }

   else

   {
   pZones.addResistance(UEqn);
   fvOptions.constrain(UEqn);
        if(pimple.momentumPredictor())
        {
        solve
        (
            UEqn
         ==
            fvc::reconstruct
            (
            (
                  - ghf*fvc::snGrad(rho)
                  - fvc::snGrad(p_rgh)
            )*mesh.magSf()
            )
        );

        fvOptions.correct(U);
        K = 0.5*magSqr(U);
        trAU() = 1.0/UEqn.A();
        trAU().ref().rename("rAU");
"UEqn.H" 88L, 1820C
cheers,
nm.
Attached Images
File Type: jpg Unbenannt.jpg (109.6 KB, 15 views)
nikhil108 is offline   Reply With Quote

Old   August 17, 2020, 13:05
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
Are you creating tmp variables like this directly?
Code:
tmp<volScalarField> trAU();
tmp<volTensorField> trTU();
I am not sure this is the right way, since you do not provide any information about the variable itself. The compiler probably thinks that
Code:
trAU()
is a function call, and since it cannot find a body for the function, it complains about an undefined reference.

You may want to check out parts of OpenFOAM code where they create and use tmp variables. In your case you probably need to provide a constructor to a volScalarField.
adhiraj is offline   Reply With Quote

Old   August 17, 2020, 13:39
Question
  #3
Member
 
nikhil108's Avatar
 
Nikhil
Join Date: May 2020
Location: Freiburg
Posts: 43
Rep Power: 5
nikhil108 is on a distinguished road
Thanks for the reply,

So, the code is supposed to look like this

Code:
MRF.correctBoundaryVelocity(U);

    tmp<fvVectorMatrix> tUEqn
    (
        fvm::ddt(rho, U) + fvm::div(phi, U)
      + MRF.DDt(rho, U)
      + turbulence->divDevTau(U)
     ==
        fvOptions(rho, U)
    );
    fvVectorMatrix& UEqn = tUEqn.ref();

    UEqn.relax();

    tmp<volScalarField> trAU;
    tmp<volTensorField> trTU;

    if (pressureImplicitPorosity)
    {
    tmp<volTensorField> tTU = tensor(I)*UEqn.A();
    pZones.addResistance(UEqn, tTU.ref());
    trTU = inv(tTU());
    trTU.ref().rename("rAU");
    fvOptions.constrain(UEqn);
    volVectorField gradp(fvc::reconstruct
            ( (
                  - ghf*fvc::snGrad(rho)
                  - fvc::snGrad(p_rgh)
            )*mesh.magSf()
            ) );
        for (int UCorr=0; UCorr<nUCorr; UCorr++)
        {
         U = trTU() & (UEqn.H() - gradp);
        }
    U.correctBoundaryConditions();
    fvOptions.correct(U);
    K = 0.5*magSqr(U);
    }

   else

   {
   pZones.addResistance(UEqn);
   fvOptions.constrain(UEqn);
        if(pimple.momentumPredictor())
        {
        solve
        (
            UEqn
         ==
            fvc::reconstruct
            (
            (
                  - ghf*fvc::snGrad(rho)
                  - fvc::snGrad(p_rgh)
            )*mesh.magSf()
            )
        );

        fvOptions.correct(U);
        K = 0.5*magSqr(U);
        trAU = 1.0/UEqn.A();
        trAU.ref().rename("rAU");
If it is like this, then it gets compiled, and executable is created. But when i tried to run it, with a tutorial case, it throws the following error.

Code:
Starting time loop

Courant Number mean: 0 max: 0
deltaT = 1.2e-10
Time = 1.2e-10

Selected 0 cells for refinement out of 107994.
Selected 0 split points out of a possible 0.
diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
DILUPBiCG:  Solving for C3H8, Initial residual = 0, Final residual = 0, No Iterations 0
DILUPBiCG:  Solving for h, Initial residual = 5.23194e-05, Final residual = 1.20767e-20, No Iterations 1
min/max(T) = 293, 293


--> FOAM FATAL ERROR:
tmp<N4Foam14GeometricFieldIdNS_12fvPatchFieldENS_7volMeshEEE> deallocated

    From function const T& Foam::tmp<T>::operator()() const [with T = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]
    in file /opt/OpenFOAM/OpenFOAM-8/src/OpenFOAM/lnInclude/tmpI.H at line 278.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::abort() at ??:?
#2  Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >::operator()() const in "/disk/nmittapa/FOAM_USER_APPBIN/2userFoam"
#3  ? in "/disk/nmittapa/FOAM_USER_APPBIN/2userFoam"
#4  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#5  ? in "/disk/nmittapa/FOAM_USER_APPBIN/2userFoam"
[1]+  Done                    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ParaView_LIB_DIR/mesa paraview foam.foam
Aborted

So, from Temporary deallocated error this post,

I changed trTU to trTU(), then i got undefined reference error.
Code:
Making dependency list for source file userFoam.C
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3  -DNoRepository -ftemplate-depth-100 -I. -I/opt/OpenFOAM/OpenFOAM-8/applications/solvers/combustion/reactingFoam -I/opt/OpenFOAM/OpenFOAM-8/src/MomentumTransportModels/momentumTransportModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/MomentumTransportModels/compressible/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ThermophysicalTransportModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ThermophysicalTransportModels/rhoReactionThermo/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/specie/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/reactionThermo/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/basic/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/chemistryModel/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ODE/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/combustionModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/finiteVolume/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/finiteVolume/cfdTools -I/opt/OpenFOAM/OpenFOAM-8/src/meshTools/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/sampling/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/dynamicFvMesh/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-8/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/OSspecific/POSIX/lnInclude   -fPIC -c userFoam.C -o Make/linux64GccDPInt32Opt/userFoam.o
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3  -DNoRepository -ftemplate-depth-100 -I. -I/opt/OpenFOAM/OpenFOAM-8/applications/solvers/combustion/reactingFoam -I/opt/OpenFOAM/OpenFOAM-8/src/MomentumTransportModels/momentumTransportModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/MomentumTransportModels/compressible/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ThermophysicalTransportModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ThermophysicalTransportModels/rhoReactionThermo/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/specie/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/reactionThermo/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/basic/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/thermophysicalModels/chemistryModel/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/ODE/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/combustionModels/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/finiteVolume/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/finiteVolume/cfdTools -I/opt/OpenFOAM/OpenFOAM-8/src/meshTools/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/sampling/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/dynamicFvMesh/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-8/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-8/src/OSspecific/POSIX/lnInclude   -fPIC -fuse-ld=bfd -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/userFoam.o -L/opt/OpenFOAM/OpenFOAM-8/platforms/linux64GccDPInt32Opt/lib \
    -lfluidThermophysicalModels -lspecie -lchemistryModel -lODE -lcombustionModels -lreactionThermophysicalModels -lmomentumTransportModels -lfluidThermoMomentumTransportModels -lthermophysicalTransportModels -lrhoReactionThermophysicalTransportModels -lfiniteVolume -ldynamicFvMesh -ltopoChangerFvMesh -lmeshTools -lsampling -lfvOptions -lOpenFOAM -ldl  \
     -lm -o /disk/nmittapa/FOAM_USER_APPBIN/2userFoam
/usr/bin/ld.bfd: Make/linux64GccDPInt32Opt/userFoam.o: in function `main':
userFoam.C:(.text.startup+0x635d): undefined reference to `trTU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x6e59): undefined reference to `trTU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x7465): undefined reference to `trAU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x79c9): undefined reference to `trAU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x863d): undefined reference to `trTU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x86c7): undefined reference to `trTU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x88b3): undefined reference to `trTU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x8cf3): undefined reference to `trAU()'
/usr/bin/ld.bfd: userFoam.C:(.text.startup+0x8d4e): undefined reference to `trAU()'
collect2: error: ld returned 1 exit status
make: *** [/opt/OpenFOAM/OpenFOAM-8/wmake/makefiles/general:142: /disk/nmittapa/FOAM_USER_APPBIN/2userFoam] Error 1
Actually i have some previous experience with the deallocation error. In the past also, i changed UEqn to UEqn() in the UEqn.H file then everything went well. Right now, its creating another error, dont know, exactly why.

So, as you said, if i change the trTU() to trTU, then how to remove deallocation error. Is there a way to deallocate the variables after we use them?.
nikhil108 is offline   Reply With Quote

Old   August 17, 2020, 18:18
Default
  #4
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15
adhiraj is on a distinguished road
I believe you are using tmp incorrectly.
Take a look here:
https://openfoamwiki.net/index.php/OpenFOAM_guide/tmp
adhiraj is offline   Reply With Quote

Old   August 17, 2020, 18:42
Question
  #5
Member
 
nikhil108's Avatar
 
Nikhil
Join Date: May 2020
Location: Freiburg
Posts: 43
Rep Power: 5
nikhil108 is on a distinguished road
Thanks for the reference, Yah! you are right.
But If i do it in the right way, it causes other problems. Please have a look at this post. This is my actual problem. I am stuck here, please let me know what do you think of this.
suehirio likes this.
nikhil108 is offline   Reply With Quote

Reply

Tags
c++, linking, openfoam, solver compilation


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
[swak4Foam] swak4foam openfoam 7 installation problem Andrea23 OpenFOAM Community Contributions 1 February 17, 2020 18:11
[blockMesh] blockMesh with double grading. spwater OpenFOAM Meshing & Mesh Conversion 92 January 12, 2019 09:00
OpenFOAM 1.6-ext git installation on Ubuntu 11.10 x64 Attesz OpenFOAM Installation 45 January 13, 2012 12:38
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 18:44
checking the system setup and Qt version vivek070176 OpenFOAM Installation 22 June 1, 2010 12:34


All times are GMT -4. The time now is 08:51.