Skip to main content

Scikit-fdiff / skfdiff

The full documentation is available on read the doc.

DOI DOI

Installation

External requirements

This library is written for python >= 3.7.

On v0.7.0, it is possible to choose between numpy and numba (which provide similar features). numpy will be slower but with no compilation time, which is handy for testing and prototyping. On other hand, numba use a JIT compilation, and give access to faster and parallized routines in the cost of an extra dependency and a warm-up time.

via PyPI

pip install scikit-fdiff[numba,interactive]

will install the package and

pip install scikit-fdiff --upgrade

will update an old version of the library.

via github

You can install the latest version of the library using pip and the github repository:

pip install git+https://gitlab.com/celliern/scikit-fdiff

Introduction

Rational

The aim of this library is to have a (relatively) easy way to write transient systems of N-dimensional partial differential equations with finite difference discretization and fast temporal solvers.

The main two parts of the library are:

  • symbolic tools defining the spatial discretization, with boundary taking into account in a separated part
  • a fast temporal solver written in order to use the sparsity of the finite difference method to reduce the memory and CPU usage during the solving

Moreover, extra tools are provided and the library is written in a modular way, allowing an easy extension of these different parts (see the plug-in module of the library.)

The library fits well with an interactive usage (in a jupyter notebook). The dependency list is actually larger, but on-going work target a reduction of the stack complexity.

Model writing

All the models are written as function generating the F vector and the Jacobian matrix of the model defined as dtU = F(U).

The symbolic model is written as a simple mathematic equation. For example, a diffusion advection model can be written as:

from skfdiff import Model

equation_diff = "k * dxxU - c * dxU"
dependent_var = "U"
physical_parameters = ["k", "c"]

model = Model(equation_diff, dependent_var,
              physical_parameters)

Toy examples (more ambitious one are in the doc)

1D advection / diffusion system, Dirichlet boundary

>>> import pylab as pl
>>> import numpy as np
>>> from skfdiff import Model, Simulation

>>> model = Model("k * dxxU - c * dxU",
...               "U(x)", ["k", "c"],
...               boundary_conditions={("U", "x"): ("dirichlet", "dirichlet")}
...               )

>>> x, dx = np.linspace(0, 1, 200, retstep=True)
>>> U = np.cos(2 * np.pi * x * 5)

# The fields are ``xarray.Dataset`` objects, and all the
# tools / methods available in the ``xarray`` lib can be
# applied to the skfdiff.Fields.
>>> fields = model.Fields(x=x, U=U, k=0.001, c=0.3)

# fix the boundary values for the dirichlet condition
>>> fields["U"][0] = 1
>>> fields["U"][-1] = 0

>>> t = 0
>>> dt = 5E-1
>>> tmax = 2.5

>>> simul = Simulation(model, fields, dt, tmax=tmax)

# The containers are in-memory or persistant
# xarray Dataset with all or some time-steps available.
>>> container = simul.attach_container()
>>> simul.run()
(2.5, <xarray.Dataset>
 Dimensions:  (x: 200)
 Coordinates:
   * x        (x) float64 0.0 ... 1.0
 Data variables:
     U        (x) float64 ...
     k        float64 0.001
     c        float64 0.3)

>>> for t in container.data.t:
...     fig = pl.figure()
...     plot = container.data["U"].sel(t=t).plot()

2D advection / diffusion system, mixed robin / periodic boundary

>>> import pylab as pl
>>> import numpy as np
>>> from skfdiff import Model, Simulation

# some specialized scheme as the upwind scheme as been implemented.
# as the problem as a strong advective component, we can use it
# to reduce the numerical instabilities.
# the dirichlet condition mean that the boundary will stay fix,
# keeping the initial value.
>>> model = Model("k * (dxxU + dyyU) - (upwind(cx, U, x, 2) + upwind(cy, U, y, 2))",
...               "U(x, y)", ["k", "cx", "cy"],
...               boundary_conditions={("U", "x"): ("dxU - (U - sin(y) * cos(t))", "dxU - 5"),
...                                    ("U", "y"):  "periodic"})

>>> x = np.linspace(0, 10, 56)
>>> y = np.linspace(-np.pi, np.pi, 32)

>>> U = np.zeros((x.size, y.size))
>>> fields = model.Fields(x=x, y=y, U=U, k=0.001, cx=0.8, cy=0.3)

>>> dt = 1.
>>> tmax = 15.

>>> simul = Simulation(model, fields, dt, tmax=tmax, tol=5E-1)
>>> container = simul.attach_container()

>>> simul.run()
(15.0, <xarray.Dataset>
 Dimensions:  (x: 56, y: 32)
 Coordinates:
   * x        (x) float64 0.0 ... 10.0
   * y        (y) float64 -3.142 ... 3.142
 Data variables:
     U        (x, y) float64 ...
     k        float64 0.001
     cx       float64 0.8
     cy       float64 0.3)

>>> for t in np.linspace(0, tmax, 5):
...     fig = pl.figure()
...     plot = container.data["U"].sel(t=t, method="nearest").plot()

Contributing

See the contribute section of the doc.

Code of Conduct

See the dedicated page.

Metadata

Release files for scikit-fdiff 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scikit-fdiff 0.7.0
File Size Uploaded Provenance Actions
scikit-fdiff-0.7.0.tar.gz 44.5 kB Without provenance Details for scikit-fdiff-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scikit-fdiff 0.7.0
File Interpreter ABI Platform Actions
scikit_fdiff-0.7.0-py3-none-any.whl Python 3 none any Details for scikit_fdiff-0.7.0-py3-none-any.whl

Total release size: 96.8 kB

Release files / scikit-fdiff-0.7.0.tar.gz

Download URL scikit-fdiff-0.7.0.tar.gz
Size 44.5 kB
Tags Source
SHA-256 checksum
How to use checksums
05d39e607c553cbc3b3ec328b84a6f2665291cd095ef94ae8479819ad4fbe3ec
BLAKE2b-256 checksum
How to use checksums
6e2fdf50533f936336ed31cb609f78f331153526518a7e516eff047da9f5882f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

Release files / scikit_fdiff-0.7.0-py3-none-any.whl

Download URL scikit_fdiff-0.7.0-py3-none-any.whl
Size 52.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55121067c0cc7ea2cee9344918c403dba5acbdeb3d990aa41aa39340f54fbe2d
BLAKE2b-256 checksum
How to use checksums
9a46ae0f32a372ad2da3269be7ad65e08ebeeacf8efcb0d216e87a814e0ce19c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

Security for scikit-fdiff 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page