generate_initial_conditions - cchandre/HamLorenz GitHub Wiki

generate_initial_conditions (function)

Purpose

Generates an initial state x for a Hamiltonian system that satisfies a given energy and specified Casimir invariants using constrained optimization.

Parameters

  • N: Dimension of the state vector.
  • energy: Desired energy (default: 1).
  • casimirs: Single value or array of Casimir targets (default: 0).
  • ntry: maximum numbers of trials before an error is generated (default: 5)

How It Works

  1. Creates a random normalized vector scaled to match the target energy.
  2. Sets up equality constraints:
    • self.hamiltonian(x) == energy, i.e., $H(x)=\sum_{n=0}^{N-1} x_n^2/2 = E$
    • self.casimir(x, k) == casimirs[k] for each k, i.e., $C(x)=\sum_{n=0}^{N-1} a_n\phi(x_n)=C_k$, where the coefficients $a_n$ are given by the function determine_casimirs.
  3. Uses scipy.optimize.minimize with method 'SLSQP' to project the random vector onto the constraint surface.

Returns

  • x: A state vector satisfying energy and Casimir constraints.

Raises

  • RuntimeError if the optimizer fails ntry times.