From c79a81032e7868b531d6ed940ac8852c047bfda4 Mon Sep 17 00:00:00 2001 From: Justin Angus Date: Sun, 25 Aug 2024 20:00:09 -0700 Subject: [PATCH] adding assertIsDefined() function. --- .../ImplicitSolvers/WarpXSolverVec.H | 21 +++++++++++++------ .../ImplicitSolvers/WarpXSolverVec.cpp | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H index 1140aa28268..ca8608bf557 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H @@ -72,9 +72,7 @@ public: inline void Define ( const WarpXSolverVec& a_solver_vec ) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - a_solver_vec.IsDefined(), - "WarpXSolverVec::Define(solver_vec) called with undefined solver_vec"); + assertIsDefined( a_solver_vec ); Define( WarpXSolverVec::m_WarpX, a_solver_vec.getArrayVecType(), a_solver_vec.getScalarVecType() ); @@ -88,9 +86,7 @@ public: inline void Copy ( const WarpXSolverVec& a_solver_vec ) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - a_solver_vec.IsDefined(), - "WarpXSolverVec::Copy(solver_vec) called with undefined solver_vec"); + assertIsDefined( a_solver_vec ); if (IsDefined()) { assertSameType( a_solver_vec ); } else { Define(a_solver_vec); } @@ -130,6 +126,7 @@ public: inline void operator+= ( const WarpXSolverVec& a_solver_vec ) { + assertIsDefined( a_solver_vec ); assertSameType( a_solver_vec ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { if (m_array_type != warpx::fields::FieldType::None) { @@ -146,6 +143,7 @@ public: inline void operator-= (const WarpXSolverVec& a_solver_vec) { + assertIsDefined( a_solver_vec ); assertSameType( a_solver_vec ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { if (m_array_type != warpx::fields::FieldType::None) { @@ -165,6 +163,8 @@ public: inline void linComb (const RT a, const WarpXSolverVec& X, const RT b, const WarpXSolverVec& Y) { + assertIsDefined( X ); + assertIsDefined( Y ); assertSameType( X ); assertSameType( Y ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { @@ -188,6 +188,7 @@ public: */ void increment (const WarpXSolverVec& X, const RT a) { + assertIsDefined( X ); assertSameType( X ); for (int lev = 0; lev < m_num_amr_levels; ++lev) { if (m_array_type != warpx::fields::FieldType::None) { @@ -245,6 +246,14 @@ public: } } + inline + void assertIsDefined( const WarpXSolverVec& a_solver_vec ) const + { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + a_solver_vec.IsDefined(), + "WarpXSolverVec::function(X) called with undefined WarpXSolverVec X"); + } + inline void assertSameType( const WarpXSolverVec& a_solver_vec ) const { diff --git a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp index 3bfbf4aad43..61b67701da0 100644 --- a/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp +++ b/Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp @@ -99,6 +99,7 @@ void WarpXSolverVec::Copy ( FieldType a_array_type, [[nodiscard]] amrex::Real WarpXSolverVec::dotProduct ( const WarpXSolverVec& a_X ) const { + assertIsDefined( a_X ); assertSameType( a_X ); amrex::Real result = 0.0;