diff --git a/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H b/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H index de088e86963..7cc0d178a32 100644 --- a/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H +++ b/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H @@ -91,7 +91,7 @@ public: [[nodiscard]] int numAMRLevels () const { return m_num_amr_levels; } - [[nodiscard]] const amrex::Geometry& GetGeometry (const int) const; + [[nodiscard]] const amrex::Geometry& GetGeometry (int) const; [[nodiscard]] const amrex::Array& GetFieldBoundaryLo () const; [[nodiscard]] const amrex::Array& GetFieldBoundaryHi () const; [[nodiscard]] const amrex::Array GetLinOpBCLo () const; @@ -160,7 +160,7 @@ protected: /** * \brief Convert from WarpX FieldBoundaryType to amrex::LinOpBCType */ - amrex::Array convertFieldBCToLinOpBC ( const amrex::Array& ) const; + [[nodiscard]] amrex::Array convertFieldBCToLinOpBC ( const amrex::Array& ) const; }; diff --git a/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp b/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp index 0b28e8007c7..5e9c133cbe9 100644 --- a/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp +++ b/Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp @@ -32,6 +32,7 @@ const Array ImplicitSolver::GetLinOpBCHi () const Array ImplicitSolver::convertFieldBCToLinOpBC (const Array& a_fbc) const { Array lbc; + for (auto bc : lbc) { bc = LinOpBCType::interior; } for (int i = 0; i < AMREX_SPACEDIM; i++) { if (a_fbc[i] == FieldBoundaryType::PML) { WARPX_ABORT_WITH_MESSAGE("LinOpBCType not set for this FieldBoundaryType"); diff --git a/Source/NonlinearSolvers/CurlCurlMLMGPC.H b/Source/NonlinearSolvers/CurlCurlMLMGPC.H index cb5ffd250e9..3cf164f61dc 100644 --- a/Source/NonlinearSolvers/CurlCurlMLMGPC.H +++ b/Source/NonlinearSolvers/CurlCurlMLMGPC.H @@ -68,15 +68,21 @@ class CurlCurlMLMGPC : public Preconditioner */ ~CurlCurlMLMGPC () override = default; + // Default move and copy operations + CurlCurlMLMGPC(const CurlCurlMLMGPC&) = default; + CurlCurlMLMGPC& operator=(const CurlCurlMLMGPC&) = default; + CurlCurlMLMGPC(CurlCurlMLMGPC&&) noexcept = default; + CurlCurlMLMGPC& operator=(CurlCurlMLMGPC&&) noexcept = default; + /** * \brief Define the preconditioner */ - virtual void Define (const T&, Ops* const) override; + void Define (const T&, Ops*) override; /** * \brief Update the preconditioner */ - virtual void Update (const T&) override; + void Update (const T&) override; /** * \brief Apply (solve) the preconditioner given a RHS @@ -86,12 +92,12 @@ class CurlCurlMLMGPC : public Preconditioner * where A is the linear operator, in this case, the curl-curl operator: * A x = curl (alpha * curl (x) ) + beta * x */ - virtual void Apply (T&, const T&) override; + void Apply (T&, const T&) override; /** * \brief Print parameters */ - virtual void printParameters() const override; + void printParameters() const override; /** * \brief Check if the nonlinear solver has been defined. @@ -189,7 +195,7 @@ void CurlCurlMLMGPC::printParameters() const template void CurlCurlMLMGPC::readParameters() { - amrex::ParmParse pp(PreconditionerTypes::curl_curl_mlmg); + const amrex::ParmParse pp(PreconditionerTypes::curl_curl_mlmg); pp.query("verbose", m_verbose); pp.query("bottom_verbose", m_bottom_verbose); pp.query("max_iter", m_max_iter); @@ -200,8 +206,6 @@ void CurlCurlMLMGPC::readParameters() pp.query("relative_tolerance", m_rtol); pp.query("use_gmres", m_use_gmres); pp.query("use_gmres_pc", m_use_gmres_pc); - - return; } template @@ -274,7 +278,6 @@ void CurlCurlMLMGPC::Define ( const T& a_U, #endif m_is_defined = true; - return; } template @@ -288,8 +291,8 @@ void CurlCurlMLMGPC::Update (const T& a_U) amrex::ignore_unused(a_U); // set the coefficients alpha and beta for curl-curl op - RT alpha = (m_ops->theta()*this->m_dt*PhysConst::c) * (m_ops->theta()*this->m_dt*PhysConst::c); - RT beta = RT(1.0); + const RT alpha = (m_ops->theta()*this->m_dt*PhysConst::c) * (m_ops->theta()*this->m_dt*PhysConst::c); + const RT beta = RT(1.0); // currently not implemented in 1D #ifndef WARPX_DIM_1D_Z @@ -303,8 +306,6 @@ void CurlCurlMLMGPC::Update (const T& a_U) << "alpha = " << alpha << ", " << "beta = " << beta << "\n"; } - - return; } template @@ -445,8 +446,6 @@ void CurlCurlMLMGPC::Apply (T& a_x, const T& a_b) copyWarpXAMFFromMLCCAMF(x_mfarrvec[n], solution, IntVect::TheZeroVector()); } - - return; } #endif diff --git a/Source/NonlinearSolvers/JacobianFunctionMF.H b/Source/NonlinearSolvers/JacobianFunctionMF.H index 68f7332c1de..11ef0828105 100644 --- a/Source/NonlinearSolvers/JacobianFunctionMF.H +++ b/Source/NonlinearSolvers/JacobianFunctionMF.H @@ -158,7 +158,7 @@ class JacobianFunctionMF } } - void define( const T&, Ops* const, const std::string& ); + void define( const T&, Ops*, const std::string& ); private: @@ -172,8 +172,8 @@ class JacobianFunctionMF std::string m_pc_type = "none"; T m_Z, m_Y0, m_R0, m_R; - Ops* m_ops; - Preconditioner* m_preCond; + Ops* m_ops = nullptr; + std::unique_ptr> m_preCond = nullptr; }; template @@ -188,12 +188,11 @@ void JacobianFunctionMF::define ( const T& a_U, m_ops = a_ops; - m_preCond = nullptr; m_usePreCond = (a_pc_type != "none"); if (m_usePreCond) { m_pc_type = a_pc_type; if (m_pc_type == PreconditionerTypes::curl_curl_mlmg) { - m_preCond = new CurlCurlMLMGPC(); + m_preCond = std::make_unique>(); } else { std::stringstream convergenceMsg; convergenceMsg << "JacobianFunctionMF::define(): " << m_pc_type << diff --git a/Source/NonlinearSolvers/Preconditioner.H b/Source/NonlinearSolvers/Preconditioner.H index bf5d2c019b4..3f9b7d72dc0 100644 --- a/Source/NonlinearSolvers/Preconditioner.H +++ b/Source/NonlinearSolvers/Preconditioner.H @@ -47,10 +47,16 @@ class Preconditioner */ virtual ~Preconditioner () = default; + // Default move and copy operations + Preconditioner(const Preconditioner&) = default; + Preconditioner& operator=(const Preconditioner&) = default; + Preconditioner(Preconditioner&&) noexcept = default; + Preconditioner& operator=(Preconditioner&&) noexcept = default; + /** * \brief Define the preconditioner */ - virtual void Define (const T&, Ops* const) = 0; + virtual void Define (const T&, Ops*) = 0; /** * \brief Update the preconditioner @@ -69,7 +75,7 @@ class Preconditioner /** * \brief Check if the nonlinear solver has been defined. */ - virtual bool IsDefined () const = 0; + [[nodiscard]] virtual bool IsDefined () const = 0; /** * \brief Print parameters