Skip to content

Commit

Permalink
adding assertIsDefined() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinRayAngus committed Aug 26, 2024
1 parent 79a6c3f commit c79a810
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.H
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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); }

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions Source/FieldSolver/ImplicitSolvers/WarpXSolverVec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c79a810

Please sign in to comment.