DOLFINx
0.12.0.0
DOLFINx C++
Toggle main menu visibility
Loading...
Searching...
No Matches
dolfinx
common
petsc.h
1
// Copyright (C) 2004-2026 Johan Hoffman, Johan Jansson, Anders Logg,
2
// Garth N. Wells and Jack S. Hale
3
//
4
// This file is part of DOLFINx (https://www.fenicsproject.org)
5
//
6
// SPDX-License-Identifier: LGPL-3.0-or-later
7
8
#pragma once
9
10
#ifdef HAS_PETSC
11
12
#include <format>
13
#include <petscsys.h>
14
#include <source_location>
15
#include <string>
16
#include <string_view>
17
18
namespace
dolfinx::common
19
{
22
namespace
petsc
23
{
31
void
error
(PetscErrorCode error_code, std::string_view petsc_function,
32
std::source_location loc = std::source_location::current());
33
41
inline
void
check
(PetscErrorCode ierr, std::string_view petsc_function,
42
std::source_location loc = std::source_location::current())
43
{
44
if
(ierr != 0)
45
error
(ierr, petsc_function, loc);
46
}
47
52
void
set_option
(std::string option);
53
59
template
<
typename
T>
60
requires
requires
(
const
T& value) { std::format(
"{}"
, value); }
61
void
set_option
(std::string option,
const
T& value)
62
{
63
if
(option[0] !=
'-'
)
64
option =
'-'
+ option;
65
66
check
(PetscOptionsSetValue(
nullptr
, option.c_str(),
67
std::format(
"{}"
, value).c_str()),
68
"PetscOptionsSetValue"
);
69
}
70
73
void
clear_option
(std::string option);
74
76
void
clear_options
();
77
}
// namespace petsc
78
}
// namespace dolfinx::common
79
80
#endif
dolfinx::common::petsc
PETSc error handling helpers shared across DOLFINx's PETSc wrappers.
Definition
petsc.h:23
dolfinx::common::petsc::check
void check(PetscErrorCode ierr, std::string_view petsc_function, std::source_location loc=std::source_location::current())
Throw a std::runtime_error via error() if ierr indicates a PETSc call failed.
Definition
petsc.h:41
dolfinx::common::petsc::error
void error(PetscErrorCode error_code, std::string_view petsc_function, std::source_location loc=std::source_location::current())
Print error message for a PETSc call that returned an error and throw a std::runtime_error.
Definition
petsc.cpp:21
dolfinx::common::petsc::clear_option
void clear_option(std::string option)
Clear a PETSc option from the PETSc options/parameter database.
Definition
petsc.cpp:47
dolfinx::common::petsc::clear_options
void clear_options()
Clear the PETSc global options/parameter database.
Definition
petsc.cpp:56
dolfinx::common::petsc::set_option
void set_option(std::string option)
Set a PETSc option in the PETSc options/parameter database. The option must not be prefixed by '-',...
Definition
petsc.cpp:42
dolfinx::common
Miscellaneous classes, functions and types.
Definition
dolfinx_common.h:8
Generated by
1.18.0