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/)
-   -   Problem while compiling a turbulence model in OF 4.1 (https://www.cfd-online.com/Forums/openfoam-programming-development/201814-problem-while-compiling-turbulence-model-4-1-a.html)

alexvaleije May 11, 2018 10:38

Problem while compiling a turbulence model in OF 4.1
 
Hi everybody,

I am having some problems compiling a modified k-epsilon turbulence model in OpenFoam 4.1

To be sure I'm not writing anything wrong in the files, I have copied the original files of the model and I have changed all of the "kEpsilon" terms for "mykEpsilon" and nothing else.

My Make/files has the following:

Quote:

mykEpsilon.C

LIB = $(FOAM_USER_LIBBIN)/libmyIncompressibleRASModels
and my Make/options is:

Quote:

EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude

LIB_LIBS = \
-lfiniteVolume \
-lmeshTools
Despite of that, the error when I try to compile is this:

Quote:

g++ -std=c++0x -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 -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam4/src/finiteVolume/lnInclude -I/opt/openfoam4/src/meshTools/lnInclude -I/opt/openfoam4/src/TurbulenceModels/turbulenceModels/lnInclude -IlnInclude -I. -I/opt/openfoam4/src/OpenFOAM/lnInclude -I/opt/openfoam4/src/OSspecific/POSIX/lnInclude -fPIC -c mykEpsilon.C -o Make/linux64GccDPInt32Opt/mykEpsilon.o
mykEpsilon.C:40:6: error: redefinition of \u2018void Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :correctNut()\u2019
void mykEpsilon<BasicTurbulenceModel>::correctNut()
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:40:6: error: \u2018virtual void Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :correctNut()\u2019 previously declared here
void mykEpsilon<BasicTurbulenceModel>::correctNut()
^
mykEpsilon.C:51:21: error: redefinition of \u2018Foam::tmp<Foam::fvMatrix<double> > Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :kSource() const\u2019
tmp<fvScalarMatrix> mykEpsilon<BasicTurbulenceModel>::kSource() const
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:51:21: error: \u2018virtual Foam::tmp<Foam::fvMatrix<double> > Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :kSource() const\u2019 previously declared here
tmp<fvScalarMatrix> mykEpsilon<BasicTurbulenceModel>::kSource() const
^
mykEpsilon.C:66:21: error: redefinition of \u2018Foam::tmp<Foam::fvMatrix<double> > Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :epsilonSource() const\u2019
tmp<fvScalarMatrix> mykEpsilon<BasicTurbulenceModel>::epsilonSource() const
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:66:21: error: \u2018virtual Foam::tmp<Foam::fvMatrix<double> > Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :epsilonSource() const\u2019 previously declared here
tmp<fvScalarMatrix> mykEpsilon<BasicTurbulenceModel>::epsilonSource() const
^
mykEpsilon.C:83:1: error: redefinition of \u2018Foam::RASModels::mykEpsilon<BasicTurbulenceM odel>::mykEpsilon(const alphaField&, const rhoField&, const volVectorField&, const surfaceScalarField&, const surfaceScalarField&, const transportModel&, const Foam::word&, const Foam::word&)\u2019
mykEpsilon<BasicTurbulenceModel>::mykEpsilon
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:83:1: error: \u2018Foam::RASModels::mykEpsilon<BasicTurbulenceM odel>::mykEpsilon(const alphaField&, const rhoField&, const volVectorField&, const surfaceScalarField&, const surfaceScalarField&, const transportModel&, const Foam::word&, const Foam::word&)\u2019 previously declared here
mykEpsilon<BasicTurbulenceModel>::mykEpsilon
^
mykEpsilon.C:200:6: error: redefinition of \u2018bool Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :read()\u2019
bool mykEpsilon<BasicTurbulenceModel>::read()
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:200:6: error: \u2018virtual bool Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :read()\u2019 previously declared here
bool mykEpsilon<BasicTurbulenceModel>::read()
^
mykEpsilon.C:221:6: error: redefinition of \u2018void Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :correct()\u2019
void mykEpsilon<BasicTurbulenceModel>::correct()
^
In file included from mykEpsilon.H:213:0,
from mykEpsilon.C:26:
mykEpsilon.C:221:6: error: \u2018virtual void Foam::RASModels::mykEpsilon<BasicTurbulenceModel>: :correct()\u2019 previously declared here
void mykEpsilon<BasicTurbulenceModel>::correct()
^
make: *** [Make/linux64GccDPInt32Opt/mykEpsilon.o] Error 1
Since I have not redefined anything, I don't know why is this happening. Could anybody help me with this?
Thank you very much!!
Alex

clapointe May 14, 2018 00:13

I've been able to compile my own turbulence models by creating the necessary .H and .C files. Then using an (eg) makeTurbulenceModel.C to create the new library. I've included example code for a new les model in 4.x -- it will hopefully work for you in 4.1. I've found that I get warnings at run time about various duplicates, but the new model works (once the new library is included in the control dict). I believe I originally pulled code to do this from here : http://hassankassem.me/posts/newturbulencemodel/.

Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2013-2016 OpenFOAM Foundation
    \\/    M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.
    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/

#include "CompressibleTurbulenceModel.H"
#include "compressibleTransportModel.H"
#include "fluidThermo.H"
#include "addToRunTimeSelectionTable.H"
#include "makeTurbulenceModel.H"

#include "ThermalDiffusivity.H"
#include "EddyDiffusivity.H"

#include "laminar.H"
#include "RASModel.H"
#include "LESModel.H"

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

makeBaseTurbulenceModel
(
    geometricOneField,
    volScalarField,
    compressibleTurbulenceModel,
    CompressibleTurbulenceModel,
    ThermalDiffusivity,
    fluidThermo
);

#define makeLESModel(Type)                                                    \
    makeTemplatedTurbulenceModel                                              \
    (fluidThermoCompressibleTurbulenceModel, LES, Type)

// -------------------------------------------------------------------------- //
// LES models
// -------------------------------------------------------------------------- //

#include "customModel.H"
makeLESModel(customModel);

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


alexvaleije May 14, 2018 12:26

Thank you very much!!!

When I first read that post you referenced I didn't understand it, but now thanks to you and reading it calmly, I could be able to compile my model.

I had to do some minor changes, though, because I haven't copied the entire turbulence library, so I had to change some of the directions of the includes, but the important thing is that it works :)

Thanks again :)


All times are GMT -4. The time now is 23:13.