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/)
-   -   Adding new model to transportProperties (https://www.cfd-online.com/Forums/openfoam-programming-development/162126-adding-new-model-transportproperties.html)

agustinvo November 4, 2015 03:45

Adding new model to transportProperties
 
Hello everyone

I want to create a model to include inside the transportModel the thermal diffusivity, as it is already done with the viscosity (nu) for incompressible solvers.

I have modified the viscosityModel files in order to create the new model, but when I compile, I get this error:

Quote:

thermalDiffusivityModels/thermalDiffusivityModel/thermalDiffusivityModel.C: In constructor ‘Foam::thermalDiffusivityModel::thermalDiffusivity Model(const Foam::word&, const Foam::dictionary&, const volVectorField&, const surfaceScalarField&)’:
thermalDiffusivityModels/thermalDiffusivityModel/thermalDiffusivityModel.C:53:13: error: no matching function for call to ‘Foam::dictionary::dictionary(<unresolved overloaded function type>)’
phi_(phi)
^
thermalDiffusivityModels/thermalDiffusivityModel/thermalDiffusivityModel.C:53:13: note: candidates are:
In file included from thermalDiffusivityModels/thermalDiffusivityModel/thermalDiffusivityModel.H:48:0,
from thermalDiffusivityModels/thermalDiffusivityModel/thermalDiffusivityModel.C:26:
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:232:9: note: Foam::dictionary::dictionary(const Foam::Xfer<Foam::dictionary>&)
dictionary(const Xfer<dictionary>&);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:232:9: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const Foam::Xfer<Foam::dictionary>&’
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:229:9: note: Foam::dictionary::dictionary(const Foam::dictionary&, const Foam::Xfer<Foam::dictionary>&)
dictionary(const dictionary& parentDict, const Xfer<dictionary>&);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:229:9: note: candidate expects 2 arguments, 1 provided
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:226:9: note: Foam::dictionary::dictionary(const Foam::dictionary*)
dictionary(const dictionary*);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:226:9: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const Foam::dictionary*’
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:222:9: note: Foam::dictionary::dictionary(const Foam::dictionary&)
dictionary(const dictionary&);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:222:9: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const Foam::dictionary&’
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:219:9: note: Foam::dictionary::dictionary(const Foam::dictionary&, const Foam::dictionary&)
dictionary(const dictionary& parentDict, const dictionary&);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:219:9: note: candidate expects 2 arguments, 1 provided
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:216:9: note: Foam::dictionary::dictionary(Foam::Istream&, bool)
dictionary(Istream&, const bool keepHeader);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:216:9: note: candidate expects 2 arguments, 1 provided
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:212:9: note: Foam::dictionary::dictionary(Foam::Istream&)
dictionary(Istream&);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:212:9: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘Foam::Istream&’
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:203:9: note: Foam::dictionary::dictionary(const Foam::fileName&, const Foam::dictionary&, Foam::Istream&)
dictionary
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:203:9: note: candidate expects 3 arguments, 1 provided
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:199:9: note: Foam::dictionary::dictionary(const Foam::fileName&)
dictionary(const fileName& name);
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:199:9: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘const Foam::fileName&’
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:196:9: note: Foam::dictionary::dictionary()
dictionary();
^
/software/alternate/openfoam/fc20/2.3.0/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/dictionary.H:196:9: note: candidate expects 0 arguments, 1 provided
make: *** [Make/linux64GccDPOpt/thermalDiffusivityModel.o] Error 1
It seems there is a problem called no matching function for call to ‘Foam::dictionary::dictionary(<unresolved overloaded function type>)’ but all I found there are references in C++ that are not related with my problem.

Did you guys face this problem before?

Thank you!

agustinvo November 4, 2015 10:16

Hi, I was able to solve it, there was a mistake inside the code.

Now I have to link it to one solver and try it.

akidess November 5, 2015 02:21

Why not make this thread useful and share how you solved your problem? Someone in the future will thank you for it.

agustinvo November 5, 2015 02:35

Hello,

the error was a typing one, so the rest of the code was ok. But you are right in the fact I could explain a bit my procedure for other people who wanted to implement it.

The idea was to replace any term related with viscosity with the thermal diffusivity. Instead of creating the function "nu" you should type "alpha", "kappa"...

I defined as well a transport thermal model (transportModel) and a singlePhaseTransportModel, where "alpha" is used instead the kinematic viscosity.

In the solver, in yout readTransportProperties, you should add:

Code:

singlePhaseTransportThermalModel laminarTransportThermal(U, phi);
so in your case you have to give something like this in your transportProperties:
Code:

transportThermalModel  Newtonian;

alpha              alpha [ 0 2 -1 0 0 0 0 ]  1.75048355e-007;

My next step is to use this new transportModel in turbulence thermal models (working on it :)).

EDIT:

now, in order to integrate your new transportModel in your turbulence models, you have to create a new turbulenceModel library. In my case it is an incompressible one. If you copy & paste the already existing one, you have to do some modifications:

Code:

autoPtr<turbulenceThermalModel> turbulenceThermalModel::New
(
    const volVectorField& U,
    const surfaceScalarField& phi,
    const volScalarField& T,
    transportModel& transport,
    transportThermalModel& transportThermal,
    const word& turbulenceThermalModelName
)

and you should add transportThermalModel& transportThermal, each time you see this kind of declaration.

In this other declaration you have to do similarly:
Code:

(U, phi, T, transport, transportThermal, turbulenceThermalModelName)
Inside the turbulenceModel.H you can define your equation terms for T (like turbulence->divDevReff()).

Ok. Now the turbulent thermal models are there, but RAS models must be created as well to use them in our simulations.

Other library RASModel must be created. Copying the existing one, applying the second replacement I explained, and modifying a bit the RASModels.C and .H it should be ok. After that you have to implement your own turbulence RAS thermal models.

Passing throught the first library (models for nut) to the thermal one (alphat) is quite straightforward, in the sense there are already some terms that need a little modification (ie, change nu for alpha, U for T ...). If further explanation is required, please make me know. Even this could be considered to create another thread :rolleyes:.

agustinvo November 5, 2015 06:15

I have modified my second post in order to include the use of the new transport model in the turbulence models.

Maybe for C++ users and programmers, it is quite obvious the way to do it, but for people like me, it can be very helpful.

agustinvo November 6, 2015 11:07

Hello,

once this library is working, I want to implement a polynomial expression for alpha, in the same way I did it already for nu. It was just a copy and paste, and replacements of nu, viscosity ... for their equivalents.

But I get this error when I compile:
Code:

Making dependency list for source file thermalDiffusivityModels/TempPolyLaw/TempPolyLaw.C
thermalDiffusivityModels/TempPolyLaw/TempPolyLaw.dep:489: warning: overriding recipe for target `Make/linux64Gcc48DPOpt/TempPolyLaw.o'
viscosityModels/TempPolyLaw/TempPolyLaw.dep:489: warning: ignoring old recipe for target `Make/linux64Gcc48DPOpt/TempPolyLaw.o'
SOURCE=thermalDiffusivityModels/TempPolyLaw/TempPolyLaw.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -I/software/alternate/openfoam/fc20/2.3.1/OpenFOAM-2.3.1/src/transportModels/incompressible/lnInclude -I/software/alternate/openfoam/fc20/2.3.1/OpenFOAM-2.3.1/src/transportModels/incompressible/twoPhaseMixture/lnInclude -I/software/alternate/openfoam/fc20/2.3.1/OpenFOAM-2.3.1/src/finiteVolume/lnInclude -IlnInclude -I. -I/software/alternate/openfoam/fc20/2.3.1/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude -I/software/alternate/openfoam/fc20/2.3.1/OpenFOAM-2.3.1/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64Gcc48DPOpt/TempPolyLaw.o
TempPolyLaw.o:(.bss+0x18): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::typeName'
TempPolyLaw.o:(.bss+0x18): first defined here
TempPolyLaw.o:(.bss+0x10): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::debug'
TempPolyLaw.o:(.bss+0x10): first defined here
TempPolyLaw.o:(.bss+0x8): multiple definition of `Foam::thermalDiffusivityModels::addTempPolyLawToDebug_'
TempPolyLaw.o:(.bss+0x8): first defined here
TempPolyLaw.o:(.bss+0x0): multiple definition of `Foam::thermalDiffusivityModels::addTempPolyLawdictionaryConstructorTothermalDiffusivityModelTable_'
TempPolyLaw.o:(.bss+0x0): first defined here
TempPolyLaw.o: In function `Foam::thermalDiffusivityModels::TempPolyLaw::calcAlpha() const':
TempPolyLaw.C:(.text+0x880): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::calcAlpha() const'
TempPolyLaw.o:TempPolyLaw.C:(.text+0x880): first defined here
TempPolyLaw.o: In function `Foam::thermalDiffusivityModels::TempPolyLaw::TempPolyLaw(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&)':
TempPolyLaw.C:(.text+0xb60): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::TempPolyLaw(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&)'
TempPolyLaw.o:TempPolyLaw.C:(.text+0xb60): first defined here
TempPolyLaw.o: In function `Foam::thermalDiffusivityModels::TempPolyLaw::TempPolyLaw(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&)':
TempPolyLaw.C:(.text+0xb60): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::TempPolyLaw(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&)'
TempPolyLaw.o:TempPolyLaw.C:(.text+0xb60): first defined here
TempPolyLaw.o: In function `Foam::thermalDiffusivityModels::TempPolyLaw::read(Foam::dictionary const&)':
TempPolyLaw.C:(.text+0x1100): multiple definition of `Foam::thermalDiffusivityModels::TempPolyLaw::read(Foam::dictionary const&)'
TempPolyLaw.o:TempPolyLaw.C:(.text+0x1100): first defined here
collect2: error: ld returned 1 exit status
make: *** [/students/phd_ea/villaortiz/OpenFOAM/villaortiz-2.3.1/platforms/linux64Gcc48DPOpt/lib/libmyIncompressibleTransportModels.so] Error 1

Has someone had this error before? It seems there is something already defined over there, but I am not able to see it. I tried to change the name of my model (TempPolyLaw) but it does not work.

file.C
Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2011 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 "TempPolyLaw.H"
#include "addToRunTimeSelectionTable.H"
#include "surfaceFields.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace thermalDiffusivityModels
{
    defineTypeNameAndDebug(TempPolyLaw, 0);

    addToRunTimeSelectionTable
    (
        thermalDiffusivityModel,
        TempPolyLaw,
        dictionary
    );
}
}


// * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //

Foam::tmp<Foam::volScalarField>
Foam::thermalDiffusivityModels::TempPolyLaw::calcAlpha() const
{


    const volScalarField& T= U_.mesh().lookupObject<volScalarField>("T");
    //const volScalarField& rho= U_.mesh().lookupObject<volScalarField>("rho");   
   
    return (base_+slope_*T+slope2_*pow(T,2.0)+slope3_*pow(T,3.0));
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::thermalDiffusivityModels::TempPolyLaw::TempPolyLaw
(
    const word& name,
    const dictionary& thermalDiffusivityProperties,
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
    thermalDiffusivityModel(name, thermalDiffusivityProperties, U, phi),
    TempPolyLawCoeffs_(thermalDiffusivityProperties.subDict(typeName + "Coeffs")),
    base_(TempPolyLawCoeffs_.lookup("base")),
    slope_(TempPolyLawCoeffs_.lookup("slope")),
    slope2_(TempPolyLawCoeffs_.lookup("slope2")),
    slope3_(TempPolyLawCoeffs_.lookup("slope3")),
    alpha_
    (
        IOobject
        (
            name,
            U_.time().timeName(),
            U_.db(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        calcAlpha()
    )
{}


// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //

bool Foam::thermalDiffusivityModels::TempPolyLaw::read
(
    const dictionary& thermalDiffusivityProperties
)
{
    thermalDiffusivityModel::read(thermalDiffusivityProperties);

    TempPolyLawCoeffs_ = thermalDiffusivityProperties.subDict(typeName + "Coeffs");

    TempPolyLawCoeffs_.lookup("base") >> base_;
    TempPolyLawCoeffs_.lookup("slope") >> slope_;
    TempPolyLawCoeffs_.lookup("slope2") >> slope2_;   
    TempPolyLawCoeffs_.lookup("slope3") >> slope3_;
   

    return true;
}


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

file.H
Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2011 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/>.

Class
    Foam::viscosityModels::TempPolyLaw

Description
    Standard polynomial-law non-Newtonian viscosity model.
   
    mu=a0+a1*T+a2*T2+...

SourceFiles
    TempPolyLaw.C

\*---------------------------------------------------------------------------*/

#ifndef TempPolyLaw_H
#define TempPolyLaw_H

#include "thermalDiffusivityModel.H"
#include "dimensionedScalar.H"
#include "volFields.H"

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

namespace Foam
{
namespace thermalDiffusivityModels
{

/*---------------------------------------------------------------------------*\
                          Class TempPolyLaw Declaration
\*---------------------------------------------------------------------------*/

class TempPolyLaw
:
    public thermalDiffusivityModel
{
    // Private data

        dictionary TempPolyLawCoeffs_;

        dimensionedScalar base_;
        dimensionedScalar slope_;
        dimensionedScalar slope2_;
        dimensionedScalar slope3_;   

        volScalarField alpha_;


    // Private Member Functions

        //- Calculate and return the laminar viscosity
        tmp<volScalarField> calcAlpha() const;


public:

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


    // Constructors

        //- Construct from components
        TempPolyLaw
        (
            const word& name,
            const dictionary& thermalDiffusivityProperties,
            const volVectorField& U,
            const surfaceScalarField& phi
        );


    //- Destructor
    ~TempPolyLaw()
    {}


    // Member Functions

        //- Return the laminar viscosity
        tmp<volScalarField> alpha() const
        {
            return alpha_;
        }
   
        //- Return the laminar viscosity for patch
        tmp<scalarField> alpha(const label patchi) const
        {
            return alpha_.boundaryField()[patchi];
        }   
   

        //- Correct the laminar viscosity
        void correct()
        {
            alpha_ = calcAlpha();
        }

        //- Read transportProperties dictionary
        bool read(const dictionary& thermalDiffusivityProperties);
};


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

} // End namespace viscosityModels
} // End namespace Foam

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

#endif

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

SOLVED

I was using the same fileName.C
for the polynomial of nu() and alpha, so there was a conflict with the internal functions (the only difference between both files are the viscosity and thermal diffusivity references, not the C++ and functions ones). I changed the names, so I have
Quote:

viscosityModels/TempPolyLaw/TempPolyLaw.C
thermalDiffusivityModels/TempPolyLaw/thermalTempPolyLaw.C
and they are present in corresponding *.o files. Before they have the same *.o file name.


Now it is possible to implement the same functions for each diffusion term (nu and alpha), just be sure the names are different!

agustinvo November 9, 2015 05:59

The previous problem was solved. It is explained on its post.

I think it would be interesting to create a post of "How to implement a new transport model library", in a nicer way than the one here.

PositronCascade December 5, 2016 07:34

Dear agustinvo, thank you so much for this post. I try to do the exactly the same thing with you and your post helped me a lot to understand where I should start. In your code, these lines below refer to viscosity or thermal conductivity? I am little bit confused.

Code:

//- Calculate and return the laminar viscosity
        tmp<volScalarField> calcAlpha() const;

Would you mind to share TempPolyLaw and thermalTempPolyLaw source code and header files with me, if you don't mind?

And my other question is, how did you compile it? Did you add these models to src folder or did you compile them individually using usr libbin?

Thanks a lot for your answer and time.


Quote:

Originally Posted by agustinvo (Post 572576)
The previous problem was solved. It is explained on its post.

I think it would be interesting to create a post of "How to implement a new transport model library", in a nicer way than the one here.


agustinvo December 5, 2016 08:47

Quote:

Originally Posted by PositronCascade (Post 628365)
Dear agustinvo, thank you so much for this post. I try to do the exactly the same thing with you and your post helped me a lot to understand where I should start. In your code, these lines below refer to viscosity or thermal conductivity? I am little bit confused.

Code:

//- Calculate and return the laminar viscosity
        tmp<volScalarField> calcAlpha() const;

Would you mind to share TempPolyLaw and thermalTempPolyLaw source code and header files with me, if you don't mind?

And my other question is, how did you compile it? Did you add these models to src folder or did you compile them individually using usr libbin?

Thanks a lot for your answer and time.

Hello,

for me, alpha is the thermal diffusivity, it is \alpha=\frac{\kappa}{\rho c_p}. Since I have other libraries, I put them in USER_LIBBIN, so I don't mess up the installation folder with all my implementations. What you can use to know how to implement different models is this PDF, more or less they explain what to do in each part. My implementations are done in OF 2.3.1, but I don't know if it changed a lot or not for OF 3.0.x or OF 4.x

PositronCascade December 5, 2016 17:01

Thank you so much!


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