Skip to content

Commit

Permalink
Merge pull request #28105 from c-randall/add-scikit-sundae
Browse files Browse the repository at this point in the history
Add scikit-sundae
  • Loading branch information
xhochy authored Nov 21, 2024
2 parents c6ce16c + c4c1e96 commit 7dd8852
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
52 changes: 52 additions & 0 deletions recipes/scikit-sundae/integrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np
import sksundae as sun


# ODE Solvers
# ------------------------------------------------------------------------------
def rhsfn(t, y, yp):
yp[0] = y[1]
yp[1] = 1e3*(1. - y[0]**2)*y[1] - y[0]


y0 = np.array([0.5, 0.5])
yp0 = np.zeros_like(y0)
tspan = np.linspace(0., 500., 200)

solver = sun.cvode.CVODE(rhsfn)
soln = solver.solve(tspan, y0)
print(f"CVODE ODE test - {soln.success=}")
assert soln.success


# DAE Solvers (should be able to solve both ODEs and DAEs)
# ------------------------------------------------------------------------------
def resfn(t, y, yp, res): # ODE example
res[0] = yp[0] - y[1]
res[1] = yp[1] - 1e3*(1. - y[0]**2)*y[1] + y[0]


y0 = np.array([0.5, 0.5])
yp0 = np.zeros_like(y0)
tspan = np.linspace(0., 500., 200)

solver = sun.ida.IDA(resfn, calc_initcond='yp0')
soln = solver.solve(tspan, y0, yp0)
print(f"IDA ODE test - {soln.success=}")
assert soln.success


def resfn(t, y, yp, res): # DAE example
res[0] = yp[0] + 0.04*y[0] - 1e4*y[1]*y[2]
res[1] = yp[1] - 0.04*y[0] + 1e4*y[1]*y[2] + 3e7*y[1]**2
res[2] = y[0] + y[1] + y[2] - 1.


y0 = np.array([1., 0., 0.])
yp0 = np.zeros_like(y0)
tspan = np.hstack([0., 4.*np.logspace(-6, 6)])

solver = sun.ida.IDA(resfn, algebraic_idx=[2], calc_initcond='yp0')
soln = solver.solve(tspan, y0, yp0)
print(f"IDA DAE test - {soln.success=}")
assert soln.success
62 changes: 62 additions & 0 deletions recipes/scikit-sundae/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% set name = "scikit_sundae" %}
{% set version = "1.0.0rc2" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
sha256: 644c5518203bc935c0ce242db004747caed53fe80ba6dd5ca2c550cfb2a82978

build:
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation
number: 0

requirements:
build:
- python
- setuptools
- cython
- numpy
- sundials >=7.1,<7.2
- {{ compiler('c') }}
- {{ stdlib('c') }}
host:
- python
- setuptools
- cython
- numpy
- libblas
- pip
- sundials >=7.1,<7.2
run:
- python
- numpy
- sundials >=7.1,<7.2

test:
imports:
- numpy
- sksundae
files:
- integrate.py
commands:
- python integrate.py

about:
home: https://github.com/NREL/scikit-sundae
summary: 'SUNDIALS bindings to differential aglebraic equation solvers.'
description: |
scikit-SUNDAE provides Python bindings to SUNDIALS integrators. Specifically,
it interfaces with the IDA and CVODE solvers. These are capable of efficiently
solving ordinary differential equations and differential algebraic equations.
license: BSD-3.0-Clause
license_family: BSD
license_file: LICENSE
doc_url: https://scikit-sundae.readthedocs.io/
dev_url: https://github.com/NREL/scikit-sundae

extra:
recipe-maintainers:
- c-randall

0 comments on commit 7dd8852

Please sign in to comment.