CrankNicolsonDdtScheme: Reorganized the code to simplify maintenance

This commit is contained in:
Henry Weller
2017-03-23 12:11:24 +00:00
parent f316980e29
commit 86bf44de10
2 changed files with 71 additions and 55 deletions

View File

@ -27,6 +27,7 @@ License
#include "surfaceInterpolate.H" #include "surfaceInterpolate.H"
#include "fvcDiv.H" #include "fvcDiv.H"
#include "fvMatrices.H" #include "fvMatrices.H"
#include "Constant.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -277,7 +278,70 @@ const FieldField<fvPatchField, Type>& ff
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
CrankNicolsonDdtScheme<Type>::CrankNicolsonDdtScheme(const fvMesh& mesh)
:
ddtScheme<Type>(mesh),
ocCoeff_(new Function1Types::Constant<scalar>("ocCoeff", 1))
{
// Ensure the old-old-time cell volumes are available
// for moving meshes
if (mesh.moving())
{
mesh.V00();
}
}
template<class Type>
CrankNicolsonDdtScheme<Type>::CrankNicolsonDdtScheme
(
const fvMesh& mesh,
Istream& is
)
:
ddtScheme<Type>(mesh, is)
{
token firstToken(is);
if (firstToken.isNumber())
{
const scalar ocCoeff = firstToken.scalarToken();
if (ocCoeff < 0 || ocCoeff > 1)
{
FatalIOErrorInFunction
(
is
) << "Off-centreing coefficient = " << ocCoeff
<< " should be >= 0 and <= 1"
<< exit(FatalIOError);
}
ocCoeff_ = new Function1Types::Constant<scalar>
(
"ocCoeff",
ocCoeff
);
}
else
{
is.putBack(firstToken);
dictionary dict(is);
ocCoeff_ = Function1<scalar>::New("ocCoeff", dict);
}
// Ensure the old-old-time cell volumes are available
// for moving meshes
if (mesh.moving())
{
mesh.V00();
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>> tmp<GeometricField<Type, fvPatchField, volMesh>>

View File

@ -91,7 +91,7 @@ SourceFiles
#define CrankNicolsonDdtScheme_H #define CrankNicolsonDdtScheme_H
#include "ddtScheme.H" #include "ddtScheme.H"
#include "Constant.H" #include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -153,7 +153,8 @@ class CrankNicolsonDdtScheme
}; };
//- Off-centering coefficient, 1 -> CN, less than one blends with EI //- Off-centering coefficient function
// 1 -> CN, less than one blends with EI
autoPtr<Function1<scalar>> ocCoeff_; autoPtr<Function1<scalar>> ocCoeff_;
@ -210,59 +211,10 @@ public:
// Constructors // Constructors
//- Construct from mesh //- Construct from mesh
CrankNicolsonDdtScheme(const fvMesh& mesh) CrankNicolsonDdtScheme(const fvMesh& mesh);
:
ddtScheme<Type>(mesh),
ocCoeff_(new Function1Types::Constant<scalar>("ocCoeff", 1))
{
// Ensure the old-old-time cell volumes are available
// for moving meshes
if (mesh.moving())
{
mesh.V00();
}
}
//- Construct from mesh and Istream //- Construct from mesh and Istream
CrankNicolsonDdtScheme(const fvMesh& mesh, Istream& is) CrankNicolsonDdtScheme(const fvMesh& mesh, Istream& is);
:
ddtScheme<Type>(mesh, is)
{
token firstToken(is);
if (firstToken.isNumber())
{
const scalar ocCoeff = firstToken.scalarToken();
if (ocCoeff < 0 || ocCoeff > 1)
{
FatalIOErrorInFunction
(
is
) << "Off-centreing coefficient = " << ocCoeff
<< " should be >= 0 and <= 1"
<< exit(FatalIOError);
}
ocCoeff_ = new Function1Types::Constant<scalar>
(
"ocCoeff",
ocCoeff
);
}
else
{
is.putBack(firstToken);
dictionary dict(is);
ocCoeff_ = Function1<scalar>::New("ocCoeff", dict);
}
// Ensure the old-old-time cell volumes are available
// for moving meshes
if (mesh.moving())
{
mesh.V00();
}
}
// Member Functions // Member Functions
@ -273,7 +225,7 @@ public:
return fv::ddtScheme<Type>::mesh(); return fv::ddtScheme<Type>::mesh();
} }
//- Return the off-centreing coefficient //- Return the current off-centreing coefficient
scalar ocCoeff() const scalar ocCoeff() const
{ {
return ocCoeff_->value(mesh().time().value()); return ocCoeff_->value(mesh().time().value());