diff-grok - v1.0.10
    Preparing search index...

    Function printOrego

    • Print solution of the OREGO benchmark problem

      Returns void

      // TypeScript usage example
      import {printOrego} from 'diff-grok';

      printOrego();
      # Python reference calculation for comparison
      import numpy as np
      import pandas as pd
      from scipy.integrate import solve_ivp
      
      # -------------------------
      # 0. Solver method
      # -------------------------
      METHOD = "Radau"  # stiff solver recommended
      
      # -------------------------
      # 1. Define OREGO ODE
      # -------------------------
      def orego(t, y):
         y1, y2, y3 = y
         dy1 = 77.27 * (y2 - y1 * y2 + y1 - 0.000008375 * y1**2)
         dy2 = ( -y2 - y1 * y2 + y3 ) / 77.27
         dy3 = 0.161 * (y1 - y3)
         return [dy1, dy2, dy3]
      
      # -------------------------
      # 2. Initial conditions and time
      # -------------------------
      y0 = [1, 2, 3]
      t_start = 0.0
      t_end = 360.0
      t_step = 0.01
      
      # Use linspace to ensure t_eval within t_span
      n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
      t_eval = np.linspace(t_start, t_end, n_points)
      
      # -------------------------
      # 3. Solve ODE
      # -------------------------
      sol = solve_ivp(
         orego,
         (t_start, t_end),
         y0,
         method=METHOD,
         t_eval=t_eval,
         rtol=1e-8,
         atol=1e-8
      )
      
      print("Success:", sol.success)
      print("Message:", sol.message)
      
      # -------------------------
      # 4. Save solution to CSV
      # -------------------------
      data = np.column_stack((sol.t, sol.y.T))
      col_names = ['t', 'y1', 'y2', 'y3']
      
      df = pd.DataFrame(data, columns=col_names)
      filename = f"OREGO-using-{METHOD}.csv"
      df.to_csv(filename, index=False)
      
      print(f"Solution saved to '{filename}'")