CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

namespace Foam

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

Like Tree4Likes
  • 4 Post By marupio

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 27, 2011, 21:10
Question namespace Foam
  #1
Member
 
Join Date: Jan 2010
Posts: 44
Rep Power: 13
Argen is on a distinguished road
namespace Foam
{
namespace radiation
{
defineTypeNameAndDebug(P1, 0);

addToRunTimeSelectionTable
(
radiationModel,
P1,
dictionary
);
}
}

Anyone can explain the above code line by line?
Argen is offline   Reply With Quote

Old   October 28, 2011, 03:55
Default
  #2
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 13
kathrin_kissling is on a distinguished road
your within namespace Foam
namespace radiation

a typeName is defined

the P1 model is added to the runTime selection table

What is your question? Can you please clarify what is unclear?

Best

Kathrin
kathrin_kissling is offline   Reply With Quote

Old   October 28, 2011, 11:53
Default
  #3
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 18
marupio is on a distinguished road
The first two lines are namespaces, as kathrin mentioned. If you don't know what those are, they are basic components of C++ created recently to avoid name collisions. If your book is old, it won't mention them - try googling it.

The next two are macros. OpenFOAM is full of macros. Many coding standards forbid all macros (except includes and include guards), but not in OpenFOAM. These make the code more difficult to read for a new-comer... but they also make it easier to work with. Many pros and cons. Anyways...

defineTypeNameAndDebug
OpenFOAM has a type naming convention to help keep track of the types of classes. These macros are in one of the files in src/OpenFOAM/db/typeInfo. Basically, just holds a word with the name of the class.

addToRunTimeSelectionTable
This is part of OpenFOAM's runTime selection mechanism. This is described here: http://openfoamwiki.net/index.php/Op...tion_mechanism
You probably don't want to go too deep into figuring it out - rather, just know it is part of the underlying machinery that other objects use to call its constructors.

Hope that helps.
utkunun, kindle, Stratos_ and 1 others like this.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   October 31, 2011, 03:34
Default
  #4
Senior Member
 
Kathrin Kissling
Join Date: Mar 2009
Location: Besigheim, Germany
Posts: 134
Rep Power: 13
kathrin_kissling is on a distinguished road
Hi David,

thank you for the typeInfo information. This is very helpful. I really searched for them but it was very hard to find!

Best

Kathrin
kathrin_kissling is offline   Reply With Quote

Old   February 5, 2019, 09:55
Default
  #5
New Member
 
Bruno Jorge Macedo dos Santos
Join Date: Feb 2019
Posts: 4
Rep Power: 4
Bruno_Jorge is on a distinguished road
Quote:
Originally Posted by Argen View Post
namespace Foam
{
namespace radiation
{
defineTypeNameAndDebug(P1, 0);

addToRunTimeSelectionTable
(
radiationModel,
P1,
dictionary
);
}
}

Anyone can explain the above code line by line?
Hello everyone!
I have the same problem. I am using OpenFOAM and it shows me this error message:


RAS/kEpsilonModelI/kEpsilonModelI.C:42:6: error: redefinition of ‘void Foam::RASModels::kEpsilonModelI<BasicTurbulenceMod el>::correctNut()’
void kEpsilonModelI<BasicTurbulenceModel>::correctNut()


According to the message, the bug is in line 42, but I do not see any problem. This is the flie kEpsilonModelI.C:


#include "kEpsilonModelI.H"
#include "fvOptions.H"
#include "bound.H"
#include "wallDist.H"
#include "wallFvPatch.H"

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

namespace Foam
{
namespace RASModels
{

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

template<class BasicTurbulenceModel>
void kEpsilonModelI<BasicTurbulenceModel>::correctNut()
{
printf("\n nut\n");
const volScalarField& y_(wallDist::New(this->mesh_).y());

const tmp<volScalarField> tnuw = this->nu();

volScalarField &yPlus = Yplus.ref();
yPlus=this->rho_*uTau*y_/tnuw;

volScalarField &fmi_ = fmi.ref();
fmi_=1-exp(-0.0002*yPlus-0.0006*pow(yPlus,2)-0.00000025*pow(yPlus,3));
tmp<volScalarField> Ry=y_*sqrt(k_)/(this->nu());

tmp<volScalarField> D=epsilon_*exp(-0.095*(Ry));

this->nut_ = fmi_*Cmu_*sqr(k_)/(max(epsilon_-D,VSMALL*epsilon_));

this->nut_.correctBoundaryConditions();

fv:ptions::New(this->mesh_).correct(this->nut_);

const fvPatchList& patches = this->mesh_.boundary();
forAll(patches, patchi)
{
const fvPatch& patch = patches[patchi];
if (isA<wallFvPatch>(patch))
{
scalarField &nutboundary=this->nut_.boundaryFieldRef()[patchi];
nutboundary=0;
}
}
BasicTurbulenceModel::correctNut();
}


template<class BasicTurbulenceModel>
tmp<fvScalarMatrix> kEpsilonModelI<BasicTurbulenceModel>::kSource() const
{
return tmp<fvScalarMatrix>
(
new fvScalarMatrix
(
k_,
dimVolume*this->rho_.dimensions()*k_.dimensions()
/dimTime
)
);
}


template<class BasicTurbulenceModel>
tmp<fvScalarMatrix> kEpsilonModelI<BasicTurbulenceModel>::epsilonSourc e() const
{
return tmp<fvScalarMatrix>
(
new fvScalarMatrix
(
epsilon_,
dimVolume*this->rho_.dimensions()*epsilon_.dimensions()
/dimTime
)
);
}

template<class BasicTurbulenceModel>
tmp<volScalarField>kEpsilonModelI<BasicTurbulenceM odel>::alpha_DCoef()
{
//Correct the trace of the tensorial production to be consistent
// with the near-wall generation from the wall-functions

const volScalarField& y_(wallDist::New(this->mesh_).y());

const tmp<volScalarField> tnuw = this->nu();

volScalarField &yPlus = Yplus.ref();
yPlus=this->rho_*uTau*y_/tnuw;

volScalarField &fmi_ = fmi.ref();
fmi_=1-exp(-0.0002*yPlus-0.0006*pow(yPlus,2)-0.00000025*pow(yPlus,3));

tmp<volScalarField> Ry=y_*sqrt(k_)/(this->nu());

tmp<volScalarField> D=epsilon_*exp(-0.095*(Ry));

this->AlphaD= Cmu_*sqr(k_)*fmi_/(epsilon_-D);
this->AlphaD.correctBoundaryConditions();
fv:ptions::New(this->mesh_).correct(this->AlphaD);

return this->AlphaD;
}


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

template<class BasicTurbulenceModel>
kEpsilonModelI<BasicTurbulenceModel>::kEpsilonMode lI
(
const alphaField& alpha,
const rhoField& rho,
const volVectorField& U,
const surfaceScalarField& alphaRhoPhi,
const surfaceScalarField& phi,
const transportModel& transport,
const word& propertiesName,
const word& type
)
:
eddyViscosity<RASModel<BasicTurbulenceModel>>
(
type,
alpha,
rho,
U,
alphaRhoPhi,
phi,
transport,
propertiesName
),
Ceps1_
(
dimensioned<scalar>::lookupOrAddToDict
(
"Ceps1",
this->coeffDict_,
1.44
)
),
Ceps2_
(
dimensioned<scalar>::lookupOrAddToDict
(
"Ceps2",
this->coeffDict_,
1.92
)
),
Cmu_
(
dimensioned<scalar>::lookupOrAddToDict
(
"Cmu",
this->coeffDict_,
0.075
)
),
C1_
(
dimensioned<scalar>::lookupOrAddToDict
(
"C1",
this->coeffDict_,
1.44
)
),
C2_
(
dimensioned<scalar>::lookupOrAddToDict
(
"C2",
this->coeffDict_,
1.92
)
),
C3_
(
dimensioned<scalar>::lookupOrAddToDict
(
"C3",
this->coeffDict_,
-0.33
)
),
sigmak_
(
dimensioned<scalar>::lookupOrAddToDict
(
"sigmak",
this->coeffDict_,
1.3
)
),
sigmaEps_
(
dimensioned<scalar>::lookupOrAddToDict
(
"sigmaEps",
this->coeffDict_,
1.3
)
),

k_
(
IOobject
(
IOobject::groupName("k", U.group()),
this->runTime_.timeName(),
this->mesh_,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
this->mesh_
),
epsilon_
(
IOobject
(
IOobject::groupName("epsilon", U.group()),
this->runTime_.timeName(),
this->mesh_,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
this->mesh_
)
{
fmi=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"fmi",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("fmiCoef",dimensionSet(0,0,0,0,0 ,0, 0),0)
)
);

Yplus=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"yPlus",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("yPlus",dimensionSet(0,0,0,0,0,0 , 0),0)
)
);

Rp=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"Rp",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("Rp",dimensionSet(0,0,0,0,0,0, 0),0)
)
);

f3=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"f3",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("f3",dimensionSet(0,0,0,0,0,0, 0),0)
)
);

f2=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"f2",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("f2",dimensionSet(0,0,0,0,0,0, 0),0)
)
);

E=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"E",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("E",dimensionSet(0,2,-4,0,0,0, 0),0)
)
);
De=tmp<volScalarField>
(new volScalarField
(
IOobject
(
"DE",
this->runTime_.timeName(),
this->mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
this->mesh_,
dimensionedScalar("DE",dimensionSet(0,2,-4,0,0,0, 0),0)
)
);

IOdictionary transportProperties
(
IOobject
(
"transportProperties",
this->runTime_.constant(),
this->mesh_,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::AUTO_WRITE
)
);

Info<< "Reading uTau\n" << endl;
uTau.dimensions().reset(dimensionSet(0,1,-1,0,0,0, 0));
uTau=dimensionedScalar
(
transportProperties.lookup("uTau")
);
Info<< "Read uTau\n" << endl;

bound(k_, this->kMin_);
bound(epsilon_, this->epsilonMin_);

if (type == typeName)
{
this->printCoeffs(type);
}
}


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

template<class BasicTurbulenceModel>
bool kEpsilonModelI<BasicTurbulenceModel>::read()
{
if (eddyViscosity<RASModel<BasicTurbulenceModel>>::re ad())
{
Cmu_.readIfPresent(this->coeffDict());
C1_.readIfPresent(this->coeffDict());
C2_.readIfPresent(this->coeffDict());
C3_.readIfPresent(this->coeffDict());
sigmak_.readIfPresent(this->coeffDict());
sigmaEps_.readIfPresent(this->coeffDict());

return true;
}
else
{
return false;
}
}
template<class BasicTurbulenceModel>
const volScalarField kEpsilonModelI<BasicTurbulenceModel>::Calculatef3( volScalarField G )
{
volScalarField &Rp_ref = Rp.ref();
Rp_ref=min((G/(k_*sqrt(epsilon_*Cmu_/this->nu()))),k_/k_);


volScalarField &f3_ref = f3.ref();
f3_ref=exp(1.8*pow3(Rp_ref));

return f3_ref;
}

template<class BasicTurbulenceModel>
const volScalarField kEpsilonModelI<BasicTurbulenceModel>::Calculatef22 ()
{
const volScalarField& y_(wallDist::New(this->mesh_).y());

tmp<volScalarField> Ry=y_*sqrt(k_)/(this->nu());

tmp<volScalarField> D=epsilon_*exp(-0.095*(Ry));

tmp<volScalarField> PseudoEpsilon = epsilon_-D;

return PseudoEpsilon/epsilon_;
}
template<class BasicTurbulenceModel>
const volScalarField kEpsilonModelI<BasicTurbulenceModel>::CalculateE(v olVectorField U)
{
volVectorField dkdn=fvc::grad(k_);
volTensorField dUdn=fvc::grad(U);
volScalarField dUdy=dUdn.component(3);
volVectorField d2Udn2=fvc::grad(dUdy);
volScalarField &E_ref = E.ref();
E_ref=1.2*this->nu()*this->nut()*fvc::magSqrGradGrad(U)+
0.0075*this->nu()*k_/epsilon_*dkdn.component(1)*dUdn.component(3)*d2Udn 2.component(1);

return E_ref;
}
template<class BasicTurbulenceModel>
const volScalarField kEpsilonModelI<BasicTurbulenceModel>::Calculatef21 ()
{
tmp<volScalarField> Rt = sqr(k_)/(this->nu()*epsilon_);

return 1 - 0.22*exp(-0.3357*sqrt(Rt));
}
template<class BasicTurbulenceModel>
const volScalarField kEpsilonModelI<BasicTurbulenceModel>::Calculatef2( volScalarField G)
{
return Calculatef21()*Calculatef22()+Calculatef3(G)-1;
}

template<class BasicTurbulenceModel>
void kEpsilonModelI<BasicTurbulenceModel>::correct()
{

printf("kepsilon\n");
if (!this->turbulence_)
{
return;
}
// Local references
// const alphaField& alpha = this->alpha_;
// const rhoField& rho = this->rho_;
const surfaceScalarField& alphaRhoPhi = this->alphaRhoPhi_;
const volVectorField& U = this->U_;
// volScalarField& nut = this->nut_;
//fv:ptions& fvOptions(fv:ptions::New(this->mesh_));

eddyViscosity<RASModel<BasicTurbulenceModel>>::cor rect();


tmp<volTensorField> tgradU = fvc::grad(this->U_);
volScalarField G(this->GName(), this->nut()*(twoSymm(tgradU()) && tgradU()));
tgradU.clear();

tgradU.clear();

// Update epsilon and G at the wall
epsilon_.boundaryFieldRef().updateCoeffs();


const volScalarField f2_(Calculatef2(G));
volScalarField &f2_ref = f2.ref();
f2_ref=f2_;
volScalarField &DE_ref = De.ref();
DE_ref=Ceps2_*f2_*sqr(epsilon_)/k_;
printf("inicio eq dissipacao");
// Dissipation equation
tmp<fvScalarMatrix> epsEqn
(
fvm::ddt(epsilon_)
+ fvm::div(alphaRhoPhi, epsilon_)
- fvm::laplacian(DepsilonEff(), epsilon_)
==
Ceps1_*G*epsilon_/k_
- fvm::Sp(Ceps2_*f2_*epsilon_/k_, epsilon_)
+ CalculateE(U)
);

printf("\nfim eq epsilon\n");
epsEqn.ref().relax();
epsEqn.ref().boundaryManipulate(epsilon_.boundaryF ieldRef());
solve(epsEqn);
bound(epsilon_, this->epsilonMin_);


// // Turbulent kinetic energy equation
tmp<fvScalarMatrix> kEqn
(
fvm::ddt(k_)
+ fvm::div(alphaRhoPhi, k_)
- fvm::laplacian(DkEff(), k_)
==
G
- fvm::Sp(epsilon_/k_, k_)
);

kEqn.ref().relax();
solve(kEqn);
bound(k_, this->kMin_);


correctNut();
}


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

} // End namespace RASModels
} // End namespace Foam

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


If someone see the bug, please, help me.
Best regards.
Bruno_Jorge is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Commercial meshers] Using starToFoam clo OpenFOAM Meshing & Mesh Conversion 33 September 26, 2012 05:04
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 15:11
[Gmsh] Import problem ARC OpenFOAM Meshing & Mesh Conversion 0 February 27, 2010 11:56
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 09:19


All times are GMT -4. The time now is 07:32.