DOLFIN-X
DOLFIN-X C++ interface
PETScOptions.h
1 // Copyright (C) 2013-2019 Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include "utils.h"
10 #include <boost/lexical_cast.hpp>
11 #include <petscoptions.h>
12 #include <string>
13 
14 namespace dolfinx::la
15 {
16 
22 
24 {
25 public:
27  static void set(std::string option);
28 
30  template <typename T>
31  static void set(std::string option, const T value)
32  {
33  if (option[0] != '-')
34  option = '-' + option;
35 
36  PetscErrorCode ierr;
37  ierr
38  = PetscOptionsSetValue(nullptr, option.c_str(),
39  boost::lexical_cast<std::string>(value).c_str());
40  if (ierr != 0)
41  petsc_error(ierr, __FILE__, "PetscOptionsSetValue");
42  }
43 
45  static void clear(std::string option);
46 
48  static void clear();
49 };
50 } // namespace dolfinx::la
dolfinx::la::petsc_error
void petsc_error(int error_code, std::string filename, std::string petsc_function)
Print error message for PETSc calls that return an error.
Definition: utils.cpp:246
dolfinx::la
Linear algebra interface.
Definition: DiscreteOperators.h:19
dolfinx::la::PETScOptions::set
static void set(std::string option, const T value)
Generic function for setting PETSc option.
Definition: PETScOptions.h:31
dolfinx::la::PETScOptions::set
static void set(std::string option)
Set PETSc option that takes no value.
Definition: PETScOptions.cpp:13
dolfinx::la::PETScOptions::clear
static void clear()
Clear PETSc global options database.
Definition: PETScOptions.cpp:29
dolfinx::la::PETScOptions
These class provides static functions that permit users to set and retrieve PETSc options via the PET...
Definition: PETScOptions.h:23