LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Compiling in c++ (OpenFOAM) (https://www.linuxquestions.org/questions/linux-newbie-8/compiling-in-c-openfoam-940604/)

samiam1000 04-19-2012 02:49 AM

Compiling in c++ (OpenFOAM)
 
Dear All,

I am trying to compile a script (a new solver for OpenFOAM).

I get this error

Code:

lab@lab-laptop:~/OpenFOAM/lab-2.1.0/applications/solvers/chtMultiRegionFoam_Epta$ wmake
Making dependency list for source file fluid/compressibleCourantNo.C
Making dependency list for source file solid/solidRegionDiffNo.C
Making dependency list for source file chtMultiRegionFoam_Epta.C
SOURCE=fluid/compressibleCourantNo.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -Ifluid -Isolid -Iinclude -I/opt/openfoam210/src/meshTools/lnInclude -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam210/src/thermophysicalModels/basicSolidThermo/lnInclude -I/opt/openfoam210/src/turbulenceModels/compressible/turbulenceModel/lnInclude -I/opt/openfoam210/src/thermophysicalModels/radiationModels/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/compressibleCourantNo.o
SOURCE=solid/solidRegionDiffNo.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -Ifluid -Isolid -Iinclude -I/opt/openfoam210/src/meshTools/lnInclude -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam210/src/thermophysicalModels/basicSolidThermo/lnInclude -I/opt/openfoam210/src/turbulenceModels/compressible/turbulenceModel/lnInclude -I/opt/openfoam210/src/thermophysicalModels/radiationModels/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/solidRegionDiffNo.o
SOURCE=chtMultiRegionFoam_Epta.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -Ifluid -Isolid -Iinclude -I/opt/openfoam210/src/meshTools/lnInclude -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam210/src/thermophysicalModels/basicSolidThermo/lnInclude -I/opt/openfoam210/src/turbulenceModels/compressible/turbulenceModel/lnInclude -I/opt/openfoam210/src/thermophysicalModels/radiationModels/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/chtMultiRegionFoam_Epta.o
In file included from chtMultiRegionFoam_Epta.C:66:
solid/setRegionSolidFields.H: In function ‘int main(int, char**)’:
solid/setRegionSolidFields.H:1: warning: unused variable ‘mesh’
solid/setRegionSolidFields.H:15: warning: unused variable ‘T’
In file included from chtMultiRegionFoam_Epta.C:78:
solid/setRegionSolidFields.H:1: warning: unused variable ‘mesh’
solid/setRegionSolidFields.H:15: warning: unused variable ‘T’
fluid/setRegionFluidFields.H:1: warning: unused variable ‘mesh’
fluid/setRegionFluidFields.H:5: warning: unused variable ‘kappa’
fluid/setRegionFluidFields.H:6: warning: unused variable ‘U’
fluid/setRegionFluidFields.H:7: warning: unused variable ‘phi’
fluid/setRegionFluidFields.H:9: warning: unused variable ‘turb’
fluid/setRegionFluidFields.H:10: warning: unused variable ‘K’
fluid/setRegionFluidFields.H:11: warning: unused variable ‘dpdt’
fluid/setRegionFluidFields.H:13: warning: unused variable ‘p’
fluid/setRegionFluidFields.H:14: warning: unused variable ‘psi’
fluid/setRegionFluidFields.H:15: warning: unused variable ‘h’
fluid/setRegionFluidFields.H:18: warning: unused variable ‘gh’
fluid/setRegionFluidFields.H:19: warning: unused variable ‘ghf’
fluid/setRegionFluidFields.H:21: warning: unused variable ‘rad’
In file included from fluid/solveFluid.H:13,
                from chtMultiRegionFoam_Epta.C:106:
fluid/hEqn.H:11: error: ‘sources’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/chtMultiRegionFoam_Epta.o] Error 1

and I can not und why, since I did something similar for another solver and it works.

The files involved are these:
Code:

    // Initialise fluid field pointer lists
    PtrList<basicRhoThermo> thermoFluid(fluidRegions.size());
    PtrList<volScalarField> rhoFluid(fluidRegions.size());
    PtrList<volScalarField> kappaFluid(fluidRegions.size());
    PtrList<volVectorField> UFluid(fluidRegions.size());
    PtrList<surfaceScalarField> phiFluid(fluidRegions.size());
    PtrList<uniformDimensionedVectorField> gFluid(fluidRegions.size());
    PtrList<compressible::turbulenceModel> turbulence(fluidRegions.size());
    PtrList<volScalarField> p_rghFluid(fluidRegions.size());
    PtrList<volScalarField> ghFluid(fluidRegions.size());
    PtrList<surfaceScalarField> ghfFluid(fluidRegions.size());
    PtrList<radiation::radiationModel> radiation(fluidRegions.size());
    PtrList<volScalarField> KFluid(fluidRegions.size());
    PtrList<volScalarField> dpdtFluid(fluidRegions.size());

    List<scalar> initialMassFluid(fluidRegions.size());

    // Populate fluid field pointer lists
    forAll(fluidRegions, i)
    {
        Info<< "*** Reading fluid mesh thermophysical properties for region "
            << fluidRegions[i].name() << nl << endl;

        Info<< "    Adding to thermoFluid\n" << endl;
        thermoFluid.set
        (
            i,
            basicRhoThermo::New(fluidRegions[i]).ptr()
        );

        Info<< "    Adding to rhoFluid\n" << endl;
        rhoFluid.set
        (
            i,
            new volScalarField
            (
                IOobject
                (
                    "rho",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                thermoFluid[i].rho()
            )
        );

        Info<< "    Adding to kappaFluid\n" << endl;
        kappaFluid.set
        (
            i,
            new volScalarField
            (
                IOobject
                (
                    "kappa",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                thermoFluid[i].Cp()*thermoFluid[i].alpha()
            )
        );

        Info<< "    Adding to UFluid\n" << endl;
        UFluid.set
        (
            i,
            new volVectorField
            (
                IOobject
                (
                    "U",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                fluidRegions[i]
            )
        );

        Info<< "    Adding to phiFluid\n" << endl;
        phiFluid.set
        (
            i,
            new surfaceScalarField
            (
                IOobject
                (
                    "phi",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::READ_IF_PRESENT,
                    IOobject::AUTO_WRITE
                ),
                linearInterpolate(rhoFluid[i]*UFluid[i])
                    & fluidRegions[i].Sf()
            )
        );

        Info<< "    Adding to gFluid\n" << endl;
        gFluid.set
        (
            i,
            new uniformDimensionedVectorField
            (
                IOobject
                (
                    "g",
                    runTime.constant(),
                    fluidRegions[i],
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE
                )
            )
        );

        Info<< "    Adding to turbulence\n" << endl;
        turbulence.set
        (
            i,
            autoPtr<compressible::turbulenceModel>
            (
                compressible::turbulenceModel::New
                (
                    rhoFluid[i],
                    UFluid[i],
                    phiFluid[i],
                    thermoFluid[i]
                )
            ).ptr()
        );

        Info<< "    Adding to ghFluid\n" << endl;
        ghFluid.set
        (
            i,
            new volScalarField("gh", gFluid[i] & fluidRegions[i].C())
        );

        Info<< "    Adding to ghfFluid\n" << endl;
        ghfFluid.set
        (
            i,
            new surfaceScalarField("ghf", gFluid[i] & fluidRegions[i].Cf())
        );

        p_rghFluid.set
        (
            i,
            new volScalarField
            (
                IOobject
                (
                    "p_rgh",
                    runTime.timeName(),
                    fluidRegions[i],
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                fluidRegions[i]
            )
        );

        // Force p_rgh to be consistent with p
        p_rghFluid[i] = thermoFluid[i].p() - rhoFluid[i]*ghFluid[i];

        radiation.set
        (
            i,
            radiation::radiationModel::New(thermoFluid[i].T())
        );

        initialMassFluid[i] = fvc::domainIntegrate(rhoFluid[i]).value();

        Info<< "    Adding to KFluid\n" << endl;
        KFluid.set
        (
            i,
            new volScalarField
            (
                "K",
                0.5*magSqr(UFluid[i])
            )
        );

        Info<< "    Adding to dpdtFluid\n" << endl;
        dpdtFluid.set
        (
            i,
            new volScalarField
            (
                "dpdt",
                fvc::ddt(thermoFluid[i].p())
            )
        );
    IObasicSourceList sources(fluidRegions[i]);
    }

and
Code:

{
    fvScalarMatrix hEqn
    (
        fvm::ddt(rho, h)
      + fvm::div(phi, h)
      - fvm::laplacian(turb.alphaEff(), h)
    ==
        dpdt
      - (fvc::ddt(rho, K) + fvc::div(phi, K))
      + rad.Sh(thermo)
      + sources(rho, h)
    );

    hEqn.relax();
    sources.constrain(hEqn);
    hEqn.solve(mesh.solver(h.select(finalIter)));

    thermo.correct();

    rad.correct();

    Info<< "Min/max T:" << min(thermo.T()).value() << ' '
        << max(thermo.T()).value() << endl;
}

Could anyone help?

Thanks a lot,
Samuele

pan64 04-19-2012 03:00 AM

sorry, but it looks insufficient. I do not know which code belongs to which file, and they are only part of the files. line numbers are also unavailable.
So you need to believe: sources cannot be resolved at chtMultiRegionFoam_Epta.C:106 because it is not defined in the current scope. You need to check the scope (together with the includes)...

samiam1000 04-19-2012 03:14 AM

solver
 
This is the solver. If you provide an email address, I can send you 4 cases:

buoyantSimpleFoam, buoyantSimpleFoam_Epta, chtMultiRegionFoam and chtMultiRegionFoam_Epta.

The buoyantSimpleFoam and the chtMultiRegionFoam are the `original' solvers, as they are implemented in OpenFOAM, while buoyantSimpleFoam_Epta and chtMultiRegionFoam_Epta are the modified (by me) solvers.
The former works, while the latter doesn't.

Thanks a lot,

Samuele

PS: if you prefer, you can download the 2 edited solvers from here ( http://www.cfd-online.com/Forums/ope...egionfoam.html ).

pan64 04-19-2012 07:53 AM

in such cases I would try g++ -E <original options> and -o filename not needed.
this will run preprocessor, will resolve includes and evaluate macros. In the result we may check the scope. Maybe there is a type mismatch problem, or you tried to call a protected/private member. Unfortunately I cannot run g++ from here.

samiam1000 04-19-2012 08:57 AM

Do you think that it could be a problem of compiler? If so could you help me to edit the Make file properly.

pan64 04-20-2012 01:32 AM

I do not think it is a compiler or makefile issue (maybe the compiler is too strict and maybe an older version would allow this construction, but I'm not sure about it).
You defined the class sources at the end of createFluidFields.H, maybe this is not the right place, you can try to move this line at the beginning of the file, or even in the main function.
Could you try that -E flag? I would like to see the output of the command

samiam1000 04-20-2012 02:29 AM

Pardon the fool question: what does this mean? How can I give the -E options and where?
Something like
Code:

wmake -E
?

Thanks a lot,

Samuele

pan64 04-20-2012 02:36 AM

no, that is not wmake. run wmake as usual, and look at the last executed command before the error message:
Quote:

SOURCE=chtMultiRegionFoam_Epta.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -Ifluid -Isolid -Iinclude -I/opt/openfoam210/src/meshTools/lnInclude -I/opt/openfoam210/src/finiteVolume/lnInclude -I/opt/openfoam210/src/turbulenceModels -I/opt/openfoam210/src/turbulenceModels/compressible/RAS/lnInclude -I/opt/openfoam210/src/finiteVolume/cfdTools -I/opt/openfoam210/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam210/src/thermophysicalModels/specie/lnInclude -I/opt/openfoam210/src/thermophysicalModels/basicSolidThermo/lnInclude -I/opt/openfoam210/src/turbulenceModels/compressible/turbulenceModel/lnInclude -I/opt/openfoam210/src/thermophysicalModels/radiationModels/lnInclude -IlnInclude -I. -I/opt/openfoam210/src/OpenFOAM/lnInclude -I/opt/openfoam210/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/chtMultiRegionFoam_Epta.o
here is the command we need: remove -o Make/linux64GccDPOpt/chtMultiRegionFoam_Epta.o and add -E > somefilename (do not forget to set SOURCE)
it will create a preprocessed source file, you will see the result.


All times are GMT -5. The time now is 06:39 PM.