pydae.core

pydae.core - Core DAE solver engine

This is the main entry point for building and running DAE models.

Quick start:

from pydae.core import Builder, Model

# Define your system symbolically
sys_dict = { ... }

# Build (generates compiled C code)
builder = Builder(sys_dict, target='ctypes')
builder.build()

# Run
model = Model('my_system')
model.ini({'param': value}, xy_0=initial_guess)
model.run(t_end, {'input': new_value})
model.post()
class pydae.core.Builder(system_dict, verbose=False, API=False, target='cffi', sparse=True)[source]

Bases: object

build()[source]

The main orchestration pipeline.

class pydae.core.Model(model_name, matrices_folder='./build', data_folder='.')[source]

Bases: object

A_eval()[source]

Compute the reduced linearized state matrix A.

Eliminates the algebraic variables from the DAE linearization via the Schur complement:

A = F_x - F_y @ inv(G_y) @ G_x

Requires that jac_run_eval has been called (or calls it lazily) so that F_x, F_y, G_x, G_y are available.

Returns:

The (N_x, N_x) state matrix of the linearized system dx/dt = A @ dx around the current operating point.

Return type:

numpy.ndarray

dict2xy0(xy_0_dict)[source]

Maps a dictionary of initial guesses to the flat xy_0 array.

get_value(name)[source]

Gets a single scalar value from the current system state.

get_values(name)[source]

Gets a time-series array of a variable from the stored simulation history.

ini(params_dict, xy_0='None')[source]

Solves the steady-state (Newton-Raphson).

ini2run()[source]

Transforms initialization states into runtime states.

jac_run_eval()[source]

Evaluate the run Jacobian jac_run = [[F_x, F_y], [G_x, G_y]].

Calls the compiled jac_trap_eval at the current operating point to obtain jac_trap:

jac_trap = [[I - alpha*Dt*F_x,  -alpha*Dt*F_y],
            [       G_x,               G_y    ]]

then recovers the run-Jacobian blocks:

F_x = (I - jac_trap[:N_x, :N_x]) / (alpha*Dt)
F_y = -jac_trap[:N_x, N_x:]      / (alpha*Dt)
G_x =  jac_trap[N_x:, :N_x]
G_y =  jac_trap[N_x:, N_x:]
load_params(data_input)[source]
load_xy_0(file_name='xy_0.json')[source]
post()[source]

Truncates pre-allocated arrays and reshapes results.

report_params(fmt='5.2f')[source]
report_u(fmt='5.2f')[source]
report_x(fmt='5.2f')[source]
report_y(fmt='5.2f')[source]
report_z(fmt='5.2f')[source]
run(t_end, inputs_dict)[source]

Simulates the time-domain evolution.

save_inputs_ini(file_name='inputs_ini.json')[source]
save_params(file_name='parameters.json')[source]
save_xy_0(file_name='xy_0.json')[source]
set_value(name_, value)[source]

Sets a parameter or input safely.

Modules

builder

diagnostics

model_class

The Model class orchestrates the interaction between Python and the compiled C solver.