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

    Function printHires

    • Print solution of the HIRES benchmark problem

      Returns void

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

      printHires();
      # 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 suitable for HIRES
      
      # -------------------------
      # 1. Define HIRES ODE
      # -------------------------
      def hires(t, y):
         y1, y2, y3, y4, y5, y6, y7, y8 = y
         dy = np.zeros(8)
         dy[0] = -1.71 * y1 + 0.43 * y2 + 8.32 * y3 + 0.0007
         dy[1] = 1.71 * y1 - 8.75 * y2
         dy[2] = -10.03 * y3 + 0.43 * y4 + 0.035 * y5
         dy[3] = 8.32 * y2 + 1.71 * y3 - 1.12 * y4
         dy[4] = -1.745 * y5 + 0.43 * y6 + 0.43 * y7
         dy[5] = -280 * y6 * y8 + 0.69 * y4 + 1.71 * y5 - 0.43 * y6 + 0.69 * y7
         dy[6] = 280 * y6 * y8 - 1.81 * y7
         dy[7] = -280 * y6 * y8 + 1.81 * y7
         return dy
      
      # -------------------------
      # 2. Initial conditions and time
      # -------------------------
      y0 = [1, 0, 0, 0, 0, 0, 0, 0.0057]
      
      t_start = 0.0
      t_end = 321.8122
      t_step = 0.01
      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(
         hires,
         t_span,
         y0,
         method=METHOD,
         t_eval=t_eval,
         rtol=1e-10,
         atol=1e-10
      )
      
      print("Success:", sol.success)
      print("Message:", sol.message)
      
      # -------------------------
      # 4. Save solution to CSV
      # -------------------------
      # Combine time + concentrations
      data = np.column_stack((sol.t, sol.y.T))
      
      # Column names
      col_names = ['t'] + ['y1','y2','y3','y4','y5','y6','y7','y8']
      
      # Create DataFrame and save
      df = pd.DataFrame(data, columns=col_names)
      filename = f'HIRES-using-{METHOD}.csv'
      df.to_csv(filename, index=False)
      
      print(f"Solution saved to '{filename}'")