opencmp.controllers package

Submodules

opencmp.controllers.base_controller module

class opencmp.controllers.base_controller.Controller(t_params, model, config_rel_path, import_dir)[source]

Bases: abc.ABC

Base class which other controllers will subclass

_apply_dynamics_equation(next_control_action, prev_control_action, t_param)[source]

Function add dynamics to the transition between two control actions.

Parameters
  • next_control_action (float) – float representing the new control action

  • prev_control_action (float) – float representing the previous control action

  • t_param (Parameter) – Parameter representing time

Returns

Coefficient function

Return type

~

_evaluate_control_variables(soln)[source]

Function to measure the values of the control variables.

Parameters

soln (GridFunction) – GridFunction containing the results of the most recent time solve

Returns

A list containing the values of the control variables.

Both scale and vector values will return as a tuple.

Return type

~

_update_time_of_next_action()[source]

Function to update the time at which the next control action occurs. This function must be called when

Return type

None

abstract calculate_control_action(soln, rk_scheme)[source]

Function which calculates what the new value for the manipulated variable should be.

Parameters
  • soln (GridFunction) – GridFunction containing the results of the most recent time solve

  • rk_scheme (bool) – bool indicating if the time scheme being used is an RK scheme, and thus requiring the recalculation of control actions for all values in t_params

Returns

Dictionary containing new values for the BCs representing the manipulated variables

Return type

bc_dict_patch

opencmp.controllers.controller_group module

class opencmp.controllers.controller_group.ControllerGroup(t_params, model, main_config)[source]

Bases: object

Class which holds multiple controllers

calculate_control_all_actions(soln, rk_scheme=False)[source]

Calculate all of the control actions taken at this timestep.

NOTE: If two or more models try to change the same boundary condition, the final value will be that of the last controller that tried to change it.

DO NOT rely on this behaviour. If you use more than one controller, make sure that they are

Parameters
  • soln (GridFunction) – GridFunction containing the results of the most recent time solve

  • rk_scheme (bool) – bool indicating if the time scheme being used is an RK scheme, and thus requiring the recalculation of control actions for all values in t_params

Returns

Dictionary containing new values for the BCs representing the manipulated variables

Return type

bc_dict_patch

get_time_for_next_two_control_actions()[source]

Function to obtain the times for the next two control actions. Used by the solvers to adjust timesteps to ensure that the model is solved at the times required for control

Returns

The time at which the next control action will occur

Return type

~

opencmp.controllers.misc module

Module containing helper functions related to models

opencmp.controllers.misc.get_controller(controller_type, t_params, model, config_rel_path)[source]

Function to get the controller to use.

Parameters
  • controller_type (str) – The name of the controller to initialize

  • t_params (List[Parameter]) – An ngsolve Parameter representing the current time

  • model (Model) – The model to hook the controller up to

  • config_rel_path (str) – The filename, and relative path, for the config file for this controller

Returns

An initialized controller of the type specified.

Return type

~

opencmp.controllers.pid_controller module

class opencmp.controllers.pid_controller.PID(t_params, model, config_rel_path, import_dir)[source]

Bases: opencmp.controllers.base_controller.Controller

A Discrete PID controller.

_error_derivative()[source]

Function to estimate the derivative term for the controller

Return type

float

_error_integral()[source]

Function to estimate the integral term for the controller

Return type

float

calculate_control_action(soln, rk_scheme)[source]

Function which calculates what the new value for the manipulated variable should be.

Parameters
  • soln (GridFunction) – GridFunction containing the results of the most recent time solve

  • rk_scheme (bool) – bool indicating if the time scheme being used is an RK scheme, and thus requiring the recalculation of control actions for all values in t_params

Returns

Dictionary containing new values for the BCs representing the manipulated variables

Return type

bc_dict_patch

Module contents