Use unique_ptr instead of shared and raw pointers.

This commit is contained in:
Atgeirr Flø Rasmussen 2015-05-29 14:57:49 +02:00
parent 2bec485184
commit 9b30e2e0d7
4 changed files with 9 additions and 8 deletions

View File

@ -23,6 +23,7 @@
#include <opm/autodiff/AutoDiffBlock.hpp> #include <opm/autodiff/AutoDiffBlock.hpp>
#include <opm/core/utility/parameters/ParameterGroup.hpp> #include <opm/core/utility/parameters/ParameterGroup.hpp>
#include <memory>
namespace Opm { namespace Opm {
@ -64,13 +65,13 @@ namespace Opm {
/// Construct solver for a given model. /// Construct solver for a given model.
/// ///
/// The model is a std::shared_ptr because the object to which model points to is /// The model is a std::unique_ptr because the object to which model points to is
/// not allowed to be deleted as long as the NewtonSolver object exists. /// not allowed to be deleted as long as the NewtonSolver object exists.
/// ///
/// \param[in] param parameters controlling nonlinear Newton process /// \param[in] param parameters controlling nonlinear Newton process
/// \param[in, out] model physical simulation model. /// \param[in, out] model physical simulation model.
explicit NewtonSolver(const SolverParameters& param, explicit NewtonSolver(const SolverParameters& param,
std::shared_ptr<PhysicalModel> model); std::unique_ptr<PhysicalModel> model);
/// Take a single forward step, after which the states will be modified /// Take a single forward step, after which the states will be modified
/// according to the physical model. /// according to the physical model.
@ -98,7 +99,7 @@ namespace Opm {
private: private:
// --------- Data members --------- // --------- Data members ---------
SolverParameters param_; SolverParameters param_;
std::shared_ptr<PhysicalModel> model_; std::unique_ptr<PhysicalModel> model_;
unsigned int newtonIterations_; unsigned int newtonIterations_;
unsigned int linearIterations_; unsigned int linearIterations_;
unsigned int newtonIterationsLast_; unsigned int newtonIterationsLast_;

View File

@ -29,9 +29,9 @@ namespace Opm
{ {
template <class PhysicalModel> template <class PhysicalModel>
NewtonSolver<PhysicalModel>::NewtonSolver(const SolverParameters& param, NewtonSolver<PhysicalModel>::NewtonSolver(const SolverParameters& param,
std::shared_ptr<PhysicalModel> model) std::unique_ptr<PhysicalModel> model)
: param_(param), : param_(param),
model_(model), model_(std::move(model)),
newtonIterations_(0), newtonIterations_(0),
linearIterations_(0) linearIterations_(0)
{ {

View File

@ -151,7 +151,7 @@ namespace Opm
WellState& well_state, WellState& well_state,
const Wells* wells); const Wells* wells);
Solver* createSolver(const Wells* wells); std::unique_ptr<Solver> createSolver(const Wells* wells);
void void
computeRESV(const std::size_t step, computeRESV(const std::size_t step,

View File

@ -330,7 +330,7 @@ namespace Opm
template <class Implementation> template <class Implementation>
auto SimulatorBase<Implementation>::createSolver(const Wells* wells) auto SimulatorBase<Implementation>::createSolver(const Wells* wells)
-> Solver* -> std::unique_ptr<Solver>
{ {
typedef typename Traits::Model Model; typedef typename Traits::Model Model;
typedef typename Model::ModelParameters ModelParams; typedef typename Model::ModelParameters ModelParams;
@ -354,7 +354,7 @@ namespace Opm
typedef typename Solver::SolverParameters SolverParams; typedef typename Solver::SolverParameters SolverParams;
SolverParams solverParams( param_ ); SolverParams solverParams( param_ );
return new Solver(solverParams, std::move(model)); return std::unique_ptr<Solver>(new Solver(solverParams, std::move(model)));
} }
template <class Implementation> template <class Implementation>