Skip to content

Commit 4cffd8c

Browse files
jhaleclaude
andcommitted
Replace CHECK_ERROR macros with a check() helper using std::source_location
Add la::petsc::check(ierr, petsc_function), a thin wrapper around error() that throws on a non-zero PETSc error code. Both take a std::source_location defaulted to the call site, so error() no longer needs a caller-supplied __FILE__ and reports the exact line, not just the file. Being a plain namespaced function rather than a macro, check() is usable from header-inline code, so it also replaces the private CHECK_ERROR macros duplicated across la/petsc.cpp, la/slepc.cpp, fem/petsc.h, and nls/SNESSolver.cpp, and the leftover explicit if (ierr != 0) sites in la/petsc.h and fem/petsc.cpp that those macros couldn't reach. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 1684178 commit 4cffd8c

6 files changed

Lines changed: 199 additions & 250 deletions

File tree

cpp/dolfinx/fem/petsc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ Vec fem::petsc::create_vector_block(
5757
PetscErrorCode ierr
5858
= VecCreateGhost(maps[0].first.get().comm(), local_size, PETSC_DETERMINE,
5959
_ghosts.size(), _ghosts.data(), &x);
60-
if (ierr != 0)
61-
la::petsc::error(ierr, __FILE__, "VecCreateGhost");
60+
la::petsc::check(ierr, "VecCreateGhost");
6261

6362
return x;
6463
}
@@ -85,8 +84,7 @@ Vec fem::petsc::create_vector_nest(
8584
Vec y;
8685
PetscErrorCode ierr = VecCreateNest(vecs.front()->comm(), petsc_vecs.size(),
8786
nullptr, petsc_vecs.data(), &y);
88-
if (ierr != 0)
89-
la::petsc::error(ierr, __FILE__, "VecCreateNest");
87+
la::petsc::check(ierr, "VecCreateNest");
9088

9189
return y;
9290
}

0 commit comments

Comments
 (0)