FEniCSx Compatible Observation Operators#

DolfinPointWise(configs)

An observation operator that interpolates values (DOF) over a FEniCSx-based mesh onto predefined observation (cartesian) coordinates.

create_DolfinPointWise_observation_operator(model)

A wrapper around DolfinPointWise.

This module presents observation operators only tailored for FEniCSx (dolfinx)-based simulation models. The module is thus optional for the PyOED package, and is provided only as an example to enable interfacing third-party packages.

class DolfinPointWiseConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', design=None, model=None, targets=None)[source]#

Bases: ObservationOperatorConfigs

Configuration class for DolfinPointWise observation operator

Parameters:
  • verbose (bool) – a boolean flag to control verbosity of the object.

  • debug (bool) – a boolean flag that enables adding extra functionality in a debug mode

  • output_dir (str | Path) – the base directory where the output files will be saved.

  • design (None | bool | Sequence[bool] | ndarray[bool]) –

    an experimental design to define active/inactive entries of the observation vector.

    Note

    An experimental design here is always binary (on/off) indicating which entries of the design space are active/inactive. This corresponds to turning on/off some of the observational sensors. Thus, if the design is None, it is set to all ones; that is everything is observed

  • model (SimulationModel | None) – the simulation model from which the source grid is extracted.

  • targets (ndarray | None) – 2D array with shape (n, 2) elements describing coordinates of the n observation/sensor points.

model: SimulationModel | None#
targets: ndarray | None#
__init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', design=None, model=None, targets=None)#
class DolfinPointWise(configs)[source]#

Bases: ObservationOperator

An observation operator that interpolates values (DOF) over a FEniCSx-based mesh onto predefined observation (cartesian) coordinates.

Parameters:

configs (DolfinPointWiseConfigs | dict) – an object holding the class configurations.

__init__(configs)[source]#
validate_configurations(configs, raise_for_invalid=True)[source]#

Check the passed configurations and make sure they are conformable with each other, and with current configurations once combined. This guarantees that any key-value pair passed in configs can be properly used

Note

Here only the locally-defined configurations in DolfinPointWiseConfigs are validated. Finally, super classes validators are called.

Parameters:
  • configs – full or partial (subset) configurations to be validated

  • raise_for_invalid – if True raise an error for invalid configurations type/key. Default True

Returns:

flag indicating whether passed configurations dictionary is valid or not

Raises:
update_configurations(**kwargs)[source]#

Take any set of keyword arguments, and lookup each in the configurations, and update as necessary/possible/valid

Raises:

TypeError – if any of the passed keys in kwargs is invalid/unrecognized

observation_vector(init_val=0.0, return_np=True)[source]#

Create an observation vector

is_observation_vector(observation, ignore_design=False, **kwargs)[source]#

Test whether the passed observation vector is valid or not

apply(state, eval_at_t=None, return_np=True)[source]#

Apply the observation operator to a model state, and return an observation instance

Parameters:
  • state – instance of a model state with entries corresponding the model grid passed upon instantiation

  • eval_at_t – the time at which the observation operator is evaluated. Since some observation operators are time-dependent, this parameter is added for generality and for a unified interface.

Returns:

an observation vector/instance

Raises:

TypeError is raised if state has the wrong shape.

Jacobian_T_matvec(observation, eval_at=None, eval_at_t=None, return_np=True)[source]#

Evaluate and return the product of the Jacobian (tangent-linear (TLM) of the observation operator), evaluated at eval_at transposed multiplied by the passed observation.

get_observation_grid()[source]#

Return a copy of the observational grid

update_design(design)[source]#
Update the design vector. The passed vector is regarded as boolean:

all nonzero values are replaced with 1

property shape#

A tuple holding the shape of the observation operator (observation size, model state size)

property model#

The underlying simulation model

property Vh#

The finite element function space of the model state

property targets#

A copy of the observation targets

create_DolfinPointWise_observation_operator(model, targets=None, num_obs_points=20, offset=0.1, exclude_boxes=[[(0.25, 0.15), (0.5, 0.4)], ((0.6, 0.625), (0.75, 0.85))], boxes_eps=0.02, verbose=False)[source]#

A wrapper around DolfinPointWise. This function creates a pointwise observation operator for dolfinx-based models.

Parameters:
  • model – the simulation model

  • targets – 2D array with shape (n, 2) elements describing coordinates of the n observation/sensor points. If None, a set of targets will be created using the following arguments

  • num_obs_points (int) – (approximate) number of observation points (sensors). This number will mostly change especially if there are buildings to avoid

  • offset – margin/offset to leave between boundary and extreme observation points

  • exclude_boxes – either None, or a list of tuples; each tuple must be a pair of tuples (xl, yl), (xu, yu) to exclude points in the box with corners set to these coordinates. This simulates buildings in the domain.

  • boxes_eps – distance from boxes (if passed) to keep sensors away

  • verbose (bool) – screen verbosity

Returns:

an observation operator; an instance of DolfinPointWise

DolfinPointWiseObservations#

alias of DolfinPointWise

create_pointwise_observation_operator(model, targets=None, num_obs_points=20, offset=0.1, exclude_boxes=[[(0.25, 0.15), (0.5, 0.4)], ((0.6, 0.625), (0.75, 0.85))], boxes_eps=0.02, verbose=False)#

A wrapper around DolfinPointWise. This function creates a pointwise observation operator for dolfinx-based models.

Parameters:
  • model – the simulation model

  • targets – 2D array with shape (n, 2) elements describing coordinates of the n observation/sensor points. If None, a set of targets will be created using the following arguments

  • num_obs_points (int) – (approximate) number of observation points (sensors). This number will mostly change especially if there are buildings to avoid

  • offset – margin/offset to leave between boundary and extreme observation points

  • exclude_boxes – either None, or a list of tuples; each tuple must be a pair of tuples (xl, yl), (xu, yu) to exclude points in the box with corners set to these coordinates. This simulates buildings in the domain.

  • boxes_eps – distance from boxes (if passed) to keep sensors away

  • verbose (bool) – screen verbosity

Returns:

an observation operator; an instance of DolfinPointWise