-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28105 from c-randall/add-scikit-sundae
Add scikit-sundae
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |