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

error: "namespace definition is not allowed here"

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By gwierink

Reply
 
LinkBack Thread Tools Display Modes
Old   October 24, 2012, 10:55
Default error: "namespace definition is not allowed here"
  #1
New Member
 
Join Date: Oct 2012
Posts: 3
Rep Power: 5
meinenn is on a distinguished road
Hej
I'm trying to adapt the twoPhaseEulerFoam solver in a way, that one can use the LaunderGibsonRSTM turbulence model instead of the kEpsilon model. I replaced the corresponding line in the main code (in myTwoPhaseEulerFoam.C) an defined all the necessary links in the make/options file. So far, everything is clear and ok.
Now, I'm trying to compile the new solver (with wmake) an I get always the same errors: for 6 H-files, the error "namespace definition is not allowed here" occurs. These are all unchanged files at the original place, so a bug in these files can be excluded, I assume.
Online, I found some similar problem descriptions, but without solutions. And I really have no idea in which direction I have to look for the solution...
Does somebody know this problem? I'd be really glad about an answer :-)
Thanks in advance!
Nik

PS: I'm working with OpenFoam 1.7.1
meinenn is offline   Reply With Quote

Old   October 24, 2012, 17:16
Default
  #2
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 10
gwierink is on a distinguished road
Hi Nik,

The reason is that you include a file with a namespace declaration where you shouldn't. Just test it by copying the original twoPhaseEulerFoam and putting
Code:
namespace Foam
{
at the top of kEpsilon.H and of course a closing curly bracket "}" at the bottom and try to compile. So, the problem is probably that you're including a class (e.g. LaunderGibsonRSTM.H) with a namespace declaration.
PicklER likes this.
__________________
Regards, Gijs
gwierink is offline   Reply With Quote

Old   October 25, 2012, 04:47
Default
  #3
New Member
 
Join Date: Oct 2012
Posts: 3
Rep Power: 5
meinenn is on a distinguished road
Thanks a lot for your answer. I also had the idea to test the original twoPhaseEulerFoam and I surprisingly remarked that there I get the same error message. Although, it is possible to run a case with my new solver, I just do not know if everything works fine or not, the results I get are generally quite reasonable, but a "rest-uncertainty" is still there. I think I have to discuss that tomorrow with my thesis-supervisor...
If I get more insight in that problem, I'll post that solution here...
meinenn is offline   Reply With Quote

Old   July 6, 2015, 11:36
Default namespace definition not allowed here
  #4
New Member
 
kh
Join Date: Jun 2015
Posts: 9
Rep Power: 3
KHoy is on a distinguished road
Hi everyone,

I, too, have this error when I am trying to compile meltFoam after changing the include file from readSIMPLEControls.H to simpleControl.H. In this thread it is suggested that the namespace is included where it shouldn't be.
However the simpleControl.H has the following lines:
...
#include "solutionControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
Class simpleControl Declaration
\*---------------------------------------------------------------------------*/
...
and the solutionControl.H has
...
#include "fvMesh.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
Class solutionControl Declaration
\*---------------------------------------------------------------------------*/
...

I don't know why this compiler error appears, since both the namespace declarations are "as is" in the lnInclude directory.
How is it that both namespace Foam declarations are included to the meltFoam.c code. Isn't this a conflict to start out with?

Thanks for helping me out here.

K
KHoy is offline   Reply With Quote

Old   August 4, 2015, 07:01
Default
  #5
New Member
 
as
Join Date: Jul 2015
Posts: 19
Rep Power: 3
anuja is on a distinguished road
Hi,
I am also getting this error of namespace definition..

mahaanu@HDHW3153 /opt/OpenFOAM/OpenFOAM-2.3.x/applications/solvers/trial
$ wmake
Making dependency files...
SOURCE=trial.C ; x86_64-w64-mingw32-g++ -m64 -Dcygwin64 -DWM_DP -DMSWIN -DLITTLE_ENDIAN -Wall -Wextra -Wno-un used-parameter -Wnon-virtual-dtor -O3 -DNDEBUG -DNoRepository -ftemplate-depth-100 -ItwoPhaseMixtureThermo -I /opt/OpenFOAM/OpenFOAM-2.3.x/src/transportModels/compressible/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/the rmophysicalModels/basic/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/transportModels/twoPhaseMixture/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/transportModels/interfaceProperties/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.3 .x/src/turbulenceModels/compressible/turbulenceModel -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude -I/opt/OpenFOAM/OpenFOAM-2.3.x/src/OSsp ecific/MSWindows/lnInclude -c $SOURCE -o Make/cygwin64mingw-w64DPOpt/trial.o
In file included from /opt/OpenFOAM/OpenFOAM-2.3.x/src/transportModels/compressible/lnInclude/PorousZones.H:41 :0,
from trial.C:56:
/opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/IOPtrList.H: In function ‘int main(int, char**)’:
/opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/IOPtrList.H:43:1: error: ‘namespace’ definition is not all owed here
namespace Foam
^
In file included from /opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/IOPtrList.H:104:0,
from /opt/OpenFOAM/OpenFOAM-2.3.x/src/transportModels/compressible/lnInclude/PorousZones.H:41 ,
from trial.C:56:
/opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/IOPtrList.C:30:1: error: a template declaration cannot app ear at block scope
template<class T>
^
/opt/OpenFOAM/OpenFOAM-2.3.x/src/OpenFOAM/lnInclude/IOPtrList.C:51:1: error: expected ‘;’ before ‘template’
template<class T>
^
trial.C:121:1: error: expected ‘}’ at end of input
}
^
trial.dep:578: die Regel für Ziel „Make/cygwin64mingw-w64DPOpt/trial.o“ scheiterte
make: *** [Make/cygwin64mingw-w64DPOpt/trial.o] Fehler 1


Could you please tell me what I can do?
Thanks in advance!
anuja is offline   Reply With Quote

Old   August 4, 2015, 16:36
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,419
Rep Power: 25
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

There are .H files that are supposed to be included from within the solver main function (like createTime.H, createMesh.H, UEqn.H, pEqn.H etc) and there are .H files that are supposed to be included outside main function.

Unfortunately they have the same extension (for example in controversial Google C++ style guide extensions of header files that a part of class code and that are meant just for textual inclusion have different extensions).

So I guess, you have to provide more details about your code and what you are trying to achieve. Right now answer is "you are trying to include file inside your main function that is not supposed to be included there".
alexeym is offline   Reply With Quote

Old   December 3, 2015, 07:29
Default
  #7
Member
 
Christa
Join Date: Apr 2011
Posts: 50
Rep Power: 7
user_of_cfx is on a distinguished road
update:I moved the inclusion of the header file outside of the main, just below # inlcude pimpleControl.H, and that seems to sort out this problem. Several more to go, but it's progress.

Hi, I am running against this issue as well.

Brief overview of what I'm trying to do:

- modify sonicLiquidFoam.C and createFields.H so I can run non Newtonian fluid simulation
- build compressible transport model library, by modifying the files structured as in this directory
- compile and run compressible non Newtonian simulations

So I have now build and successfully compiled my compressibleTransportModels library in the user directory, but I am getting the error in namespace definition when trying to compile the solver.

My new solver looks like this (I am highlighting the changes I have made from the original):

Code:
#include "fvCFD.H"
#include "pimpleControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"

    pimpleControl pimple(mesh);

    #include "readThermodynamicProperties.H"
    #include "compressibleSinglePhaseTransportModel.H" //"readTransportProperties.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readTimeControls.H"
        #include "compressibleCourantNo.H"

        fluid.correct();

        solve(fvm::ddt(rho) + fvc::div(phi));

        // --- Pressure-velocity PIMPLE corrector loop
        while (pimple.loop())
        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(rho, U)
              + fvm::div(phi, U)
              - fvm::laplacian(fluid.mu(), U)
            );

            solve(UEqn == -fvc::grad(p));

            // --- Pressure corrector loop
            while (pimple.correct())
            {
                volScalarField rAU("rAU", 1.0/UEqn.A());
                surfaceScalarField rhorAUf
                (
                    "rhorAUf",
                    fvc::interpolate(rho*rAU)
                );

                U = rAU*UEqn.H();

                surfaceScalarField phid
                (
                    "phid",
                    psi
                   *(
                       (fvc::interpolate(U) & mesh.Sf())
                     + rhorAUf*fvc::ddtCorr(rho, U, phi)/fvc::interpolate(rho)
                    )
                );

                phi = (rhoO/psi)*phid;

                fvScalarMatrix pEqn
                (
                    fvm::ddt(psi, p)
                  + fvc::div(phi)
                  + fvm::div(phid, p)
                  - fvm::laplacian(rhorAUf, p)
                );

                pEqn.solve();

                phi += pEqn.flux();

                solve(fvm::ddt(rho) + fvc::div(phi));
                #include "compressibleContinuityErrs.H"

                U -= rAU*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        rho = rhoO + psi*p;

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}


// ************************************************************************* //
So the main change is that I am including a new header for compressibleSinglePhaseTransportModel.H, whose job is to calculate the dynamic viscosity and return it to the solver, similarly to how nonNewtonianIcoFoam works.

When compiling this code, I receive an error that the namespace definition is not allowed in this syntax (inside the compressibleTransportModel.H):

Code:
#ifndef compressibleTransportModel_H
#define compressibleTransportModel_H

#include "primitiveFieldsFwd.H"
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
                Class compressibleTransportModel Declaration
\*---------------------------------------------------------------------------*/

class compressibleTransportModel
{
    // Private Member Functions

        //- Disallow copy construct
        compressibleTransportModel(const compressibleTransportModel&);

        //- Disallow default bitwise assignment
        void operator=(const compressibleTransportModel&);


public:

    //- Runtime type information
    TypeName("compressibleTransportModel");


    // Constructors

        //- Construct from components
        compressibleTransportModel
        ();


    //- Destructor
    virtual ~compressibleTransportModel();


    // Member Functions

        //- Return the dynamic laminar viscosity
        virtual tmp<volScalarField> mu() const = 0;

        //- Return the dynamic laminar viscosity for patch
        virtual tmp<scalarField> mu(const label patchi) const = 0;

        //- Return the laminar viscosity
        // virtual tmp<volScalarField> nu() const = 0;

        //- Return the laminar viscosity for patch
        // virtual tmp<scalarField> nu(const label patchi) const = 0;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif
and a host of errors underneath that, but this is the first one I get.

I am confused because as mentioned by people above:
1. the part of the code that crashes is left as is i.e. I did not modify this file
2. the way the header is included in exactly the same as in the case of nonNewtonianIcoFoam, the only standard solver to include a transport model and which I used as my model for the modification.

Any help will be greatly appreciated.

Cheers,

Christa
user_of_cfx is offline   Reply With Quote

Old   December 3, 2015, 09:58
Default
  #8
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,419
Rep Power: 25
alexeym will become famous soon enoughalexeym will become famous soon enough
Hi,

Let me repeat:

1. There are headers just for textual inclusion (like UEqn.H, pEqn.H, readPISOControls.H etc) that SHOULD be included inside main function. There is no class definitions inside, just a sequence of statements that for convenience are put in a separate file.

2. There are header with class definitions (like compressibleSinglePhaseTransportModel.H, incompressibleTurbulenceModel.H etc). Inside these files APIs are defined, they should be included outside main function (just in the beginning of the file).

So returning to your colourful code.

1. Red include statement should be outside main function.
2. Red fluid object should be created in createFields.H file (or elsewhere before while loop but inside main function).
alexeym is offline   Reply With Quote

Old   December 3, 2015, 19:26
Default
  #9
Member
 
Christa
Join Date: Apr 2011
Posts: 50
Rep Power: 7
user_of_cfx is on a distinguished road
Quote:
Originally Posted by alexeym View Post
So returning to your colourful code.

1. Red include statement should be outside main function.
2. Red fluid object should be created in createFields.H file (or elsewhere before while loop but inside main function).
Thanks Alexey. I have fixed #1 and I had already created fluid in createFields.H, that was not a problem. Had to do some more syntax debugging (see: c++ novice) and now my new solver runs. Waiting to see if it does what I am asking it to, and if it does I will be very happy.

Sorry for making you repeat things. I read your message many times and only now do I actually understand what you're saying about the different header files. Coding is a bit of a struggle for me.

Many thanks again,

Christa
user_of_cfx is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ansys Fluent 13.0 UDF compilation problem in Window XP (32 bit) Yogini Fluent UDF and Scheme Programming 7 October 3, 2012 07:24
CFX problem in ubuntu (linux) Vigneshramaero CFX 0 July 13, 2012 10:22
CFX-Pre problem, pls help!!! cth_yao CFX 0 February 17, 2012 01:52
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
CFX Post: Problem with Macro Shafiul CFX 12 January 5, 2011 16:24


All times are GMT -4. The time now is 01:31.