|
[Sponsors] |
September 10, 2020, 13:02 |
Call a constant in a function
|
#1 |
Senior Member
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10 |
Hello,
I'm having trouble calling a constant to be resolved within my turbulence model... could someone help me? The problem is as follows, within the v2f.C file there is the function: Code:
template<class BasicTurbulenceModel> tmp<volScalarField> v2f<BasicTurbulenceModel>::Ts() const { return max(k_/epsilon_, 6.0*sqrt(this->nu()/epsilon_)); } Code:
const volScalarField G(this->GName(), nut*S2); I tried that way: v2f.C Code:
template<class BasicTurbulenceModel> tmp<volScalarField> v2f<BasicTurbulenceModel>::Ts(const volScalarField& G) const { return max((k_*G)/epsilon_, 6.0*sqrt(this->nu()/epsilon_)); } v2f.H Code:
volScalarField Ts(const volScalarField& G) const; The CorrectNut() function requires the value of Ts() and since I didn't find out how to call the constant in the above function (Ts), I didn't progress. Thanks #OpenFoam 5.0 |
|
September 10, 2020, 15:57 |
|
#2 |
Senior Member
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17 |
The cleanest solution I can see here is to use function overloading, i.e. provide two different functions with the same name and return type but with different function arguments.
Code:
// v2f.H file //- default function declaration volScalarField Ts() const; //- newly added function volScalarField Ts(const volScalarField& G) const; Code:
// v2f.C template<class BasicTurbulenceModel> tmp<volScalarField> v2f<BasicTurbulenceModel>::Ts() const { return max(k_/epsilon_, 6.0*sqrt(this->nu()/epsilon_)); } template<class BasicTurbulenceModel> tmp<volScalarField> v2f<BasicTurbulenceModel>::Ts(const volScalarField& G) const { return max((k_*G)/epsilon_, 6.0*sqrt(this->nu()/epsilon_)); } |
|
September 10, 2020, 16:30 |
|
#3 |
Senior Member
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10 |
Hello,
Thanks for the answer. What about CorrectNut()? How would I do it? Since it calls the Ts() function return. |
|
September 10, 2020, 17:56 |
|
#4 |
Senior Member
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17 |
What exactly is the problem with CorrectNut()? Could you show the source code and explain what you are trying to do?
__________________
cfd.university |
|
September 11, 2020, 08:21 |
|
#5 | |
Senior Member
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10 |
Quote:
Code:
template<class BasicTurbulenceModel> void v2f<BasicTurbulenceModel>::correctNut() { this->nut_ = min(CmuKEps_*sqr(k_)/epsilon_, this->Cmu_*v2_*Ts()); this->nut_.correctBoundaryConditions(); fv::options::New(this->mesh_).correct(this->nut_); BasicTurbulenceModel::correctNut(); } Code:
template<class BasicTurbulenceModel> void v2f<BasicTurbulenceModel>::correctNut(G) { this->nut_ = min(CmuKEps_*sqr(k_)/epsilon_, this->Cmu_*v2_*Ts(G)); this->nut_.correctBoundaryConditions(); fv::options::New(this->mesh_).correct(this->nut_); BasicTurbulenceModel::correctNut(); } |
||
September 11, 2020, 10:28 |
|
#6 |
Senior Member
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17 |
well, the same logic as before applies here, you would need to have two function declarations in your header, i.e.
Code:
//- default template<class BasicTurbulenceModel> void v2f<BasicTurbulenceModel>::correctNut(); //- new declaration template<class BasicTurbulenceModel> void v2f<BasicTurbulenceModel>::correctNut(const volScalarField& G) Since these are all part of the same class v2f, it might be worthwhile to consider making G a private / protected member of the class and then initialise it in the constructor or wherever it makes sense. In this way you don't have to pass the variable around all the time (that's a clear code smell and we should avoid it). May I suggest to study up a bit more on c++ classes? I think there is some basic understanding missing, this is not a difficult problem (no offense) but with a bit more background in object orientated programming you will hit less of these problems. |
|
September 11, 2020, 14:56 |
|
#7 |
Senior Member
Guilherme
Join Date: Apr 2017
Posts: 245
Rep Power: 10 |
Hi,
I appreciate your help and understand the reasons for making such a recommendation. I know how to do the basics, but unfortunately something I don't understand, because of how the OF is built. See the error below, this happens when I declare that correctNut() has to receive the constant G for it to be used in the function Ts(): Code:
In file included from /opt/openfoam5/src/TurbulenceModels/turbulenceModels/lnInclude/LESeddyViscosity.H:42:0, from v2f.H:52, /opt/openfoam5/src/TurbulenceModels/turbulenceModels/lnInclude/eddyViscosity.H:69:22: note: void Foam::eddyViscosity<BasicTurbulenceModel>::correctNut() [with BasicTurbulenceModel = Foam::LESModel<Foam::IncompressibleTurbulenceModel<Foam::transportModel> >] virtual void correctNut() = 0; ^ /opt/openfoam5/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/makeTurbModel.o' failed I did it: Code:
template<class BasicTurbulenceModel> void v2f<BasicTurbulenceModel>::correctNut(const volScalarField& G) { this->nut_ = min(CmuKEps_*sqr(k_)/epsilon_, this->Cmu_*v2_*Ts(G)); this->nut_.correctBoundaryConditions(); fv::options::New(this->mesh_).correct(this->nut_); BasicTurbulenceModel::correctNut(??); //I don't know if it's necessary. } |
|
September 12, 2020, 08:19 |
|
#8 |
Senior Member
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17 |
The error is telling you that the file eddyViscosity.H only contains the definition for
Code:
virtual void correctNut() = 0; Code:
virtual void correctNut() = 0; virtual void correctNut(const volScalarField& G) = 0; TL;DR modify the eddyViscosity.H file so that you have the following function declarations: Code:
virtual void correctNut() = 0; virtual void correctNut(const volScalarField& G); |
|
Tags |
openfoam5 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[mesh manipulation] RefineMesh Error and Foam warning | jiahui_93 | OpenFOAM Meshing & Mesh Conversion | 4 | March 3, 2018 12:32 |
[snappyHexMesh] How to define to right point for locationInMesh | Mirage12 | OpenFOAM Meshing & Mesh Conversion | 7 | March 13, 2016 15:07 |
LiencubiclowRemodel | nzy102 | OpenFOAM Bugs | 14 | January 10, 2012 09:53 |
Error with Wmake | skabilan | OpenFOAM Installation | 3 | July 28, 2009 01:35 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |