proteus.Context module

Support for a global user context

Sub-models in multi-physics simulations sometimes need to be consistent with other sub-models through certain “global” information. This model provides methods for setting and getting such a global user context. It also alows declaring input options to the user context that can be set from the command line.

Example (set the global context from an object):

#create a simple context class
globalSettings = {"nnx":11, "T":10.0, "g"=9.8}
MyContext = namedtuple("MyContext",globalSettings.keys())
#set the global  context  object
proteus.Context.set(MyContext._make(globalSettings.values())

Example (set the global context from a module):

import globalSettingsModule
proteus.Context.setFromModule(globalSettingsModule)

Example (use the global context):

ct = proteus.Context.get()
nnx = ct.nnx
proteus.Context.context = None[source]

A string containing Python setting input options

proteus.Context.get()[source]

Get the global context object

proteus.Context.set(contextIn)[source]

Set the global context as an object

proteus.Context.setFromModule(moduleIn, mutable=False)[source]

Construct the global context object from a module

proteus.Context.Options(optionsList=None, mutable=False)[source]

Construct an o from proteus.LinearAlgebraToptions object (named tuple)

Parameters

optionsList – An iterable of options tuples. Each option is a 3-tuple, with the first entry the option name string, the second entry the default value, and the third entry a help string

Example:

opts=Context.Options([("nnx", 11, "number of mesh nodes in x-direction"),
                      ("nny", 21, "number of mesh nodes in y-direction"])
nnx = opts.nnx
nny = opts.nny