Ramper#

class fridom.framework.modules.Ramper(start_time: float, ramp_period: float, update_parameters: Callable[[fr.ModelState, float], None] = <function Ramper.<lambda>>, ramp_function: Literal['exponential', 'power_3', 'cosine', 'linear'] | Callable[[float], float] = 'exponential')[source]#

Bases: Module

A module for ramping up and down parameters during a simulation.

Parameters#

start_timefloat

The time at which the ramping should start.

ramp_periodfloat

The period over which the ramping should occur.

update_parametersCallable[[fr.ModelState, float], None], optional

A method that updates the model parameters based on the ramped value. It should take the model state and the ramped value which is between 0 and 1.

ramp_functionstr or Callable[[float], float], optional

The ramp function. It can be one of the following strings: “exponential”, “power_3”, “cosine”, “linear” or a custom callable. The default is “exponential”.

Description#

This module contains a list of ramp functions that can be used to ramp up and down parameters during a simulation. This can be useful for adiabatic processes or for slowly changing parameters. For example to ramp up the nonlinear term.

__init__(start_time: float, ramp_period: float, update_parameters: Callable[[fr.ModelState, float], None] = <function Ramper.<lambda>>, ramp_function: Literal['exponential', 'power_3', 'cosine', 'linear'] | Callable[[float], float] = 'exponential') None[source]#

Methods

__init__(start_time, ramp_period[, ...])

cosine_ramp_func(theta)

Cosine ramp function.

disable()

Disable the module.

enable()

Enable the module.

exponential_ramp_func(theta)

Exponential ramp function.

is_enabled()

Whether the module is enabled or not.

linear_ramp_func(theta)

Linear ramp function.

power_3_ramp_func(theta)

Power 3 ramp function.

reset()

Stop and start the module.

setup(mset[, setup_mode])

Set the module up.

start()

Start the module.

stop()

Stop the module.

update(mz)

Update the model state.

Attributes

diff_module

The differentiation module to be used by this module.

grid

The grid of the model settings.

info

Return a dictionary with information about the time stepper.

interp_module

The interpolation module to be used by this module.

is_setup

Whether the module is set up.

mset

The model settings.

name

ramp_function

The ramp function.

required_halo

The required halo points for this module.

name = 'Ramper'#
update(mz: ModelState) ModelState[source]#

Update the model state.

Description#

This method is called by the model at each time step. Child classes should overwrite this method to update the module. Make sure to decorate the method with the @module_method decorator.

Parameters#

mzfr.ModelState

The model state at the current time step.

Returns#

fr.ModelState

The updated model state.

static exponential_ramp_func(theta: float) float[source]#

Exponential ramp function.

\[f(\theta) = \frac{e^{-\frac{1}{\theta}}} {e^{-\frac{1}{\theta}} + e^{-\frac{1}{1-\theta}}}\]
static power_3_ramp_func(theta: float) float[source]#

Power 3 ramp function.

\[f(\theta) = \frac{\theta^3}{\theta^3 + (1 - \theta)^3}\]
static cosine_ramp_func(theta: float) float[source]#

Cosine ramp function.

\[f(\theta) = \frac{1}{2} \left(1 - \cos(\pi \theta)\right)\]
static linear_ramp_func(theta: float) float[source]#

Linear ramp function.

\[f(\theta) = \theta\]
property info: dict[str, str]#

Return a dictionary with information about the time stepper.

Description#

This method should be overridden by the child class to return a dictionary with information about the time stepper. This information is used to print the time stepper in the __repr__ method.

property ramp_function: Callable[[float], float]#

The ramp function.

Parameters#

thetafloat

The scaled time value (between 0 and 1).

Returns#

float

The ramped value (between 0 and 1).