pathsim.blocks.sources module

class pathsim.blocks.sources.Constant(value=1)[source]

Bases: Block

Produces a constant output signal (SISO)

Parameters:

value (float) – constant defining block output

update(t)[source]

update system equation fixed point loop

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (always ‘0.0’ because source-type)

Return type:

float

class pathsim.blocks.sources.Source(func=<function Source.<lambda>>)[source]

Bases: Block

Source that produces an arbitrary time dependent output, defined by the func (callable).

\[y(t) = \mathrm{func}(t)\]

Note

This block is purely algebraic and its internal function (func) will be called multiple times per timestep, each time when Simulation._update(t) is called in the global simulation loop.

Example

For example a ramp:

from pathsim.blocks import Source

src = Source(lambda t : t)

or a simple sinusoid with some frequency:

import numpy as np
from pathsim.blocks import Source

#some parameter
omega = 100

#the function that gets evaluated
def f(t):
    return np.sin(omega * t)

src = Source(f)

Because the Source block only has a single argument, it can be used to decorate a function and make it a PathSim block. This might be handy in some cases to keep definitions concise and localized in the code:

import numpy as np
from pathsim.blocks import Source

#does the same as the definition above

@Source
def src(t):
    omega = 100
    return np.sin(omega * t)

#'src' is now a PathSim block
Parameters:

func (callable) – function defining time dependent block output

update(t)[source]

update system equation fixed point loop by evaluating the internal function ‘func’

Note

No direct passthrough, so the update method is optimized and has no convergence check

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (always 0.0 because source-type)

Return type:

float