integrals.py

openconcept.utilities.math.integrals.bdf3_cache_matrix(n, all_bdf=False)

This implements the base block Jacobian of the BDF3 method. BDF3 is third order accurate and suitable for stiff systems.

The first couple of points are handled by 3rd-order offset finite difference stencils.

openconcept.utilities.math.integrals.multistep_integrator(q0, dqdt, dts, tri_mat, repeat_mat, segment_names=None, segments_to_count=None, partials=True)

This implements the base block Jacobian of the BDF3 method. BDF3 is third order accurate and suitable for stiff systems. A central-difference approximation and BDF2 are used for the first couple of points, so strictly speaking this method is only second order accurate.

class openconcept.utilities.math.integrals.Integrator(**kwargs)

Bases: ExplicitComponent

Integrates rate variables implicitly. Add new integrated quantities by using the add_integrand method. “q” inputs here are illustrative only.

Inputs:
  • duration (float) – The duration of the integration interval (can also use dt) (scalar)

  • dq_dt (float) – Rate to integrate (vector)

  • q_initial (float) – Starting value of quantity (scalar)

Outputs:
  • q (float) – The vector quantity corresponding integral of dqdt over time Will have units ‘rate_units’ / ‘diff_units’

  • q_final (float) – The final value of the vector (scalar) Useful for connecting the end of one integrator to beginning of another

Options:
  • num_nodes (int) – num_nodes = 2N + 1 where N = num_intervals The total length of the vector q is 2N + 1

  • diff_units (str) – The units of the integrand (none by default)

  • method (str) – Numerical method (default ‘bdf3’; alternatively, ‘simpson’)

  • time_setup (str) – Time configuration (default ‘dt’) ‘dt’ creates input ‘dt’ ‘duration’ creates input ‘duration’ ‘bounds’ creates inputs ‘t_initial’, ‘t_final’

add_integrand(name, rate_name=None, start_name=None, end_name=None, val=0.0, start_val=0.0, units=None, rate_units=None, zero_start=False, final_only=False, lower=-1e+30, upper=1e+30)

Add a new integrated variable q = integrate(dqdt) + q0 This will add an output with the integrated quantity, an output with the final value, an input with the rate source, and an input for the initial quantity.

Parameters:
  • name (str) – The name of the integrated variable to be created.

  • rate_name (str) – The name of the input rate (default name”_rate”)

  • start_name (str) – The name of the initial value input (default value name”_initial”)

  • end_name (str) – The name of the end value output (default value name”_final”)

  • units (str or None) – Units for the integrated quantity (or inferred automatically from rate_units)

  • rate_units (str or None) – Units of the rate (can be inferred automatically from units)

  • zero_start (bool) – If true, eliminates start value input and always begins from zero (default False)

  • final_only (bool) – If true, only integrates final quantity, not all the intermediate points (default False)

  • val (float) – Default value for the integrated output (default 0.0) Can be scalar or shape num_nodes

  • start_val (float) – Default value for the initial value input (default 0.0)

  • upper (float) – Upper bound on integrated quantity

  • lower (float) – Lower bound on integrated quantity

class openconcept.utilities.math.integrals.OldIntegrator(**kwargs)

Bases: ExplicitComponent

This component integrates a vector using a BDF3 formulation with 2nd order startup.

Inputs:
  • dqdt (float) – The vector quantity to integrate. Length of the vector = (2 * num_intervals + 1) * num_segments

  • segment|dt (float) – The timestep of “segment” (scalar) 1 per segment

  • q_initial (float) – Starting value of the quantity (scalar)

Outputs:
  • q (float) – The vector quantity corresponding integral of dqdt over time Will have units ‘rate_units’ / ‘diff_units’

  • q_final (float) – The final value of the vector (scalar) Useful for connecting the end of one integrator to beginning of another

Options:
  • segment_names (list) – A list of str with the names of the individual segments By default, if no segment_names are provided, one segment will be assumed and segment|dt will just be named “dt”

  • segments_to_count (list) – A list of str with the names of segments to be included in the integration. By default, ALL segments will be included.

  • num_nodes (int) – num_nodes = 2N + 1 where N = num_intervals The total length of the vector q is n_segments x (2N + 1)

  • quantity_units (str) – The units of quantity being integrated (not the rate)

  • diff_units (str) – The units of the integrand (none by default)

  • rate_units (str) – The units of the rate being integrated

  • method (str) – Numerical method (default ‘bdf3’; alternatively, ‘simpson)

  • zero_start (bool) – If True, disables q_initial input (default False)

  • final_only (bool) – If True, disables q output (q_final only) (default False)

  • time_setup (str) – Time configuration (default ‘dt’) ‘dt’ creates input ‘dt’ ‘duration’ creates input ‘duration’ ‘bounds’ creates inputs ‘t_initial’, ‘t_final’