petsc4py.PETSc.Options#

class petsc4py.PETSc.Options#

Bases: object

The options database object.

A dictionary-like object to store and operate with command line options.

Parameters:

prefix (str, optional) – Optional string to prepend to all the options.

Examples

Create an option database and operate with it.

>>> from petsc4py import PETSc
>>> opts = PETSc.Options()
>>> opts['a'] = 1 # insert the command-line option '-a 1'
>>> if 'a' in opts: # if the option is present
>>>     val = opts['a'] # return the option value as 'str'
>>> a_int = opts.getInt('a') # return the option value as 'int'
>>> a_bool = opts.getBool('a') # return the option value as 'bool'

Read command line and use default values.

>>> from petsc4py import PETSc
>>> opts = PETSc.Options()
>>> b_float = opts.getReal('b', 1) # return the value or 1.0 if not present

Read command line options prepended with a prefix.

>>> from petsc4py import PETSc
>>> opts = PETSc.Options('prefix_')
>>> opts.getString('b', 'some_default_string') # read -prefix_b xxx

Methods Summary

clear()

Clear an options database.

create()

Create an options database.

delValue(name)

Delete an option from the database.

destroy()

Destroy an options database.

getAll()

Return all the options and their values.

getBool(name[, default])

Return the boolean value associated with the option.

getBoolArray(name[, default])

Return the boolean values associated with the option.

getInt(name[, default])

Return the integer value associated with the option.

getIntArray(name[, default])

Return the integer array associated with the option.

getReal(name[, default])

Return the real value associated with the option.

getRealArray(name[, default])

Return the real array associated with the option.

getScalar(name[, default])

Return the scalar value associated with the option.

getScalarArray(name[, default])

Return the scalar array associated with the option.

getString(name[, default])

Return the string associated with the option.

hasName(name)

Return the boolean indicating if the option is in the database.

insertString(string)

Insert a string in the options database.

prefixPop()

Pop a prefix for the options database.

prefixPush(prefix)

Push a prefix for the options database.

setValue(name, value)

Set a value for an option.

view([viewer])

View the options database.

Attributes Summary

prefix

Prefix for options.

Methods Documentation

clear()#

Clear an options database.

Source code at petsc4py/PETSc/Options.pyx:91

Return type:

Self

create()#

Create an options database.

Source code at petsc4py/PETSc/Options.pyx:79

Return type:

Self

delValue(name)#

Delete an option from the database.

Logically collective.

Source code at petsc4py/PETSc/Options.pyx:195

Parameters:

name (str)

Return type:

None

destroy()#

Destroy an options database.

Source code at petsc4py/PETSc/Options.pyx:85

Return type:

Self

getAll()#

Return all the options and their values.

Not collective.

Source code at petsc4py/PETSc/Options.pyx:414

Return type:

dict[str, str]

getBool(name, default=None)#

Return the boolean value associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

bool

Source code at petsc4py/PETSc/Options.pyx:218

getBoolArray(name, default=None)#

Return the boolean values associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

ArrayBool

Source code at petsc4py/PETSc/Options.pyx:238

getInt(name, default=None)#

Return the integer value associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

int

Source code at petsc4py/PETSc/Options.pyx:258

getIntArray(name, default=None)#

Return the integer array associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

ArrayInt

Source code at petsc4py/PETSc/Options.pyx:278

getReal(name, default=None)#

Return the real value associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

float

Source code at petsc4py/PETSc/Options.pyx:298

getRealArray(name, default=None)#

Return the real array associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

ArrayReal

Source code at petsc4py/PETSc/Options.pyx:318

getScalar(name, default=None)#

Return the scalar value associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

Scalar

Source code at petsc4py/PETSc/Options.pyx:338

getScalarArray(name, default=None)#

Return the scalar array associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

ArrayScalar

Source code at petsc4py/PETSc/Options.pyx:358

getString(name, default=None)#

Return the string associated with the option.

Not collective.

Parameters:
  • name (str) – The option name.

  • default – The default value. If None, it raises a KeyError if the option is not found.

Return type:

str

Source code at petsc4py/PETSc/Options.pyx:378

hasName(name)#

Return the boolean indicating if the option is in the database.

Source code at petsc4py/PETSc/Options.pyx:144

Parameters:

name (str)

Return type:

bool

insertString(string)#

Insert a string in the options database.

Logically collective.

Source code at petsc4py/PETSc/Options.pyx:400

Parameters:

string (str)

Return type:

None

prefixPop()#

Pop a prefix for the options database.

Logically collective.

Source code at petsc4py/PETSc/Options.pyx:131

Return type:

None

prefixPush(prefix)#

Push a prefix for the options database.

Logically collective.

Source code at petsc4py/PETSc/Options.pyx:116

Parameters:

prefix (str | Options | Object | None)

Return type:

None

setValue(name, value)#

Set a value for an option.

Logically collective.

Parameters:
Return type:

None

Source code at petsc4py/PETSc/Options.pyx:153

view(viewer=None)#

View the options database.

Collective.

Parameters:

viewer (Viewer | None) – A Viewer instance or None for the default viewer.

Return type:

None

Source code at petsc4py/PETSc/Options.pyx:97

Attributes Documentation

prefix#

Prefix for options.

Source code at petsc4py/PETSc/Options.pyx:67