CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   undefined reference_ linking error (https://www.cfd-online.com/Forums/openfoam-programming-development/229620-undefined-reference_-linking-error.html)

nikhil108 August 17, 2020 12:14

undefined reference_ linking error
 
1 Attachment(s)
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:confused:. 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.

adhiraj August 17, 2020 13:05

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.

nikhil108 August 17, 2020 13:39

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 https://www.cfd-online.com/Forums/op...ted-error.html 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.:confused:

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?.

adhiraj August 17, 2020 18:18

I believe you are using tmp incorrectly.
Take a look here:
https://openfoamwiki.net/index.php/OpenFOAM_guide/tmp

nikhil108 August 17, 2020 18:42

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.:(


All times are GMT -4. The time now is 18:09.