openfoam/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phaseModel/phaseModel.H
Mark Olesen 660f3e5492 ENH: cleanup autoPtr class (issue #639)
Improve alignment of its behaviour with std::unique_ptr

  - element_type typedef
  - release() method - identical to ptr() method
  - get() method to get the pointer without checking and without releasing it.
  - operator*() for dereferencing

Method name changes

  - renamed rawPtr() to get()
  - renamed rawRef() to ref(), removed unused const version.

Removed methods/operators

  - assignment from a raw pointer was deleted (was rarely used).
    Can be convenient, but uncontrolled and potentially unsafe.
    Do allow assignment from a literal nullptr though, since this
    can never leak (and also corresponds to the unique_ptr API).

Additional methods

  - clone() method: forwards to the clone() method of the underlying
    data object with argument forwarding.

  - reset(autoPtr&&) as an alternative to operator=(autoPtr&&)

STYLE: avoid implicit conversion from autoPtr to object type in many places

- existing implementation has the following:

     operator const T&() const { return operator*(); }

  which means that the following code works:

       autoPtr<mapPolyMesh> map = ...;
       updateMesh(*map);    // OK: explicit dereferencing
       updateMesh(map());   // OK: explicit dereferencing
       updateMesh(map);     // OK: implicit dereferencing

  for clarity it may preferable to avoid the implicit dereferencing

- prefer operator* to operator() when deferenced a return value
  so it is clearer that a pointer is involve and not a function call
  etc    Eg,   return *meshPtr_;  vs.  return meshPtr_();
2018-02-26 12:00:00 +01:00

350 lines
9.1 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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::phaseModel
SourceFiles
phaseModel.C
\*---------------------------------------------------------------------------*/
#ifndef phaseModel_H
#define phaseModel_H
#include "dictionary.H"
#include "dimensionedScalar.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "transportModel.H"
#include "rhoThermo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class twoPhaseSystem;
class diameterModel;
template<class Phase>
class PhaseCompressibleTurbulenceModel;
/*---------------------------------------------------------------------------*\
Class phaseModel Declaration
\*---------------------------------------------------------------------------*/
class phaseModel
:
public volScalarField,
public transportModel
{
// Private data
//- Reference to the twoPhaseSystem to which this phase belongs
const twoPhaseSystem& fluid_;
//- Name of phase
word name_;
dictionary phaseDict_;
//- Return the residual phase-fraction for given phase
// Used to stabilize the phase momentum as the phase-fraction -> 0
dimensionedScalar residualAlpha_;
//- Optional maximum phase-fraction (e.g. packing limit)
scalar alphaMax_;
//- Thermophysical properties
autoPtr<rhoThermo> thermo_;
//- Velocity
volVectorField U_;
//- Volumetric flux of the phase
surfaceScalarField alphaPhi_;
//- Mass flux of the phase
surfaceScalarField alphaRhoPhi_;
//- Volumetric flux of the phase
autoPtr<surfaceScalarField> phiPtr_;
//- Diameter model
autoPtr<diameterModel> dPtr_;
//- Turbulence model
autoPtr<PhaseCompressibleTurbulenceModel<phaseModel>> turbulence_;
public:
// Constructors
phaseModel
(
const twoPhaseSystem& fluid,
const dictionary& phaseProperties,
const word& phaseName
);
//- Destructor
virtual ~phaseModel();
// Member Functions
//- Return the name of this phase
const word& name() const
{
return name_;
}
//- Return the twoPhaseSystem to which this phase belongs
const twoPhaseSystem& fluid() const
{
return fluid_;
}
//- Return the other phase in this two-phase system
const phaseModel& otherPhase() const;
//- Return the residual phase-fraction for given phase
// Used to stabilize the phase momentum as the phase-fraction -> 0
const dimensionedScalar& residualAlpha() const
{
return residualAlpha_;
}
//- Optional maximum phase-fraction (e.g. packing limit)
// Defaults to 1
scalar alphaMax() const
{
return alphaMax_;
}
//- Return the Sauter-mean diameter
tmp<volScalarField> d() const;
//- Return the turbulence model
const PhaseCompressibleTurbulenceModel<phaseModel>&
turbulence() const;
//- Return non-const access to the turbulence model
// for correction
PhaseCompressibleTurbulenceModel<phaseModel>&
turbulence();
//- Return the thermophysical model
const rhoThermo& thermo() const
{
return *thermo_;
}
//- Return non-const access to the thermophysical model
// for correction
rhoThermo& thermo()
{
return *thermo_;
}
//- Return the laminar viscosity
tmp<volScalarField> nu() const
{
return thermo_->nu();
}
//- Return the laminar viscosity for patch
tmp<scalarField> nu(const label patchi) const
{
return thermo_->nu(patchi);
}
//- Return the laminar dynamic viscosity
tmp<volScalarField> mu() const
{
return thermo_->mu();
}
//- Return the laminar dynamic viscosity for patch
tmp<scalarField> mu(const label patchi) const
{
return thermo_->mu(patchi);
}
//- Return the thermal conductivity on a patch
tmp<scalarField> kappa(const label patchi) const
{
return thermo_->kappa(patchi);
}
//- Return the thermal conductivity
tmp<volScalarField> kappa() const
{
return thermo_->kappa();
}
//- Return the laminar thermal conductivity
tmp<volScalarField> kappaEff
(
const volScalarField& alphat
) const
{
return thermo_->kappaEff(alphat);
}
//- Return the laminar thermal conductivity on a patch
tmp<scalarField> kappaEff
(
const scalarField& alphat,
const label patchi
) const
{
return thermo_->kappaEff(alphat, patchi);
}
//- Return the laminar thermal diffusivity for enthalpy
tmp<volScalarField> alpha() const
{
return thermo_->alpha();
}
//- Return the laminar thermal diffusivity for enthalpy on a patch
tmp<scalarField> alpha(const label patchi) const
{
return thermo_->alpha(patchi);
}
//- Return the effective thermal diffusivity for enthalpy
tmp<volScalarField> alphaEff
(
const volScalarField& alphat
) const
{
return thermo_->alphaEff(alphat);
}
//- Return the effective thermal diffusivity for enthalpy on a patch
tmp<scalarField> alphaEff
(
const scalarField& alphat,
const label patchi
) const
{
return thermo_->alphaEff(alphat, patchi);
}
//- Return the specific heat capacity
tmp<volScalarField> Cp() const
{
return thermo_->Cp();
}
//- Return the density
const volScalarField& rho() const
{
return thermo_->rho();
}
//- Return the velocity
const volVectorField& U() const
{
return U_;
}
//- Return non-const access to the velocity
// Used in the momentum equation
volVectorField& U()
{
return U_;
}
//- Return the volumetric flux
const surfaceScalarField& phi() const
{
return *phiPtr_;
}
//- Return non-const access to the volumetric flux
surfaceScalarField& phi()
{
return *phiPtr_;
}
//- Return the volumetric flux of the phase
const surfaceScalarField& alphaPhi() const
{
return alphaPhi_;
}
//- Return non-const access to the volumetric flux of the phase
surfaceScalarField& alphaPhi()
{
return alphaPhi_;
}
//- Return the mass flux of the phase
const surfaceScalarField& alphaRhoPhi() const
{
return alphaRhoPhi_;
}
//- Return non-const access to the mass flux of the phase
surfaceScalarField& alphaRhoPhi()
{
return alphaRhoPhi_;
}
//- Ensure that the flux at inflow/outflow BCs is preserved
void correctInflowOutflow(surfaceScalarField& alphaPhi) const;
//- Correct the phase properties
// other than the thermodynamics and turbulence
// which have special treatment
void correct();
//- Read phaseProperties dictionary
virtual bool read(const dictionary& phaseProperties);
//- Dummy Read for transportModel
virtual bool read()
{
return true;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //