DOLFIN
DOLFIN C++ interface
PETScOptions.h
1 // Copyright (C) 2013 Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef __DOLFIN_PETSC_OPTIONS_H
19 #define __DOLFIN_PETSC_OPTIONS_H
20 
21 #ifdef HAS_PETSC
22 
23 #include <string>
24 #include <boost/lexical_cast.hpp>
25 #include <petscoptions.h>
26 #include <dolfin/common/SubSystemsManager.h>
27 #include <dolfin/log/log.h>
28 #include "PETScObject.h"
29 
30 namespace dolfin
31 {
40 
42  {
43  public:
44 
46  static void set(std::string option);
47 
49  static void set(std::string option, bool value);
50 
52  static void set(std::string option, int value);
53 
55  static void set(std::string option, double value);
56 
58  static void set(std::string option, std::string value);
59 
61  template<typename T>
62  static void set(std::string option, const T value)
63  {
65 
66  if (option[0] != '-')
67  option = '-' + option;
68 
69  PetscErrorCode ierr;
70  ierr = PetscOptionsSetValue(NULL, option.c_str(),
71  boost::lexical_cast<std::string>(value).c_str());
72  if (ierr != 0)
73  PETScObject::petsc_error(ierr, __FILE__, "PetscOptionsSetValue");
74  }
75 
77  static void clear(std::string option);
78 
80  static void clear();
81 
82  };
83 }
84 
85 #endif
86 #endif
Definition: adapt.h:29
static void init_petsc()
Initialize PETSc without command-line arguments.
Definition: SubSystemsManager.cpp:125
Definition: PETScOptions.h:41
static void petsc_error(int error_code, std::string filename, std::string petsc_function)
Print error message for PETSc calls that return an error.
Definition: PETScObject.cpp:29
static void clear()
Clear PETSc global options database.
Definition: PETScOptions.cpp:63