scikit-finite-diff, a new tool for PDE solving

scikit-finite-diff, a new tool for PDE solving - Published in JOSS (2019)

https://gitlab.com/celliern/scikit-fdiff

Science Score: 87.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 7 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Scientific Fields

Mathematics Computer Science - 35% confidence
Last synced: 4 months ago · JSON representation

Repository

A 1D temporal partial differential equations solver

Basic Info
  • Host: gitlab.com
  • Owner: celliern
  • License: mit
  • Default Branch: master
Statistics
  • Stars: 20
  • Forks: 5
  • Open Issues: 9
  • Releases: 0
Created almost 7 years ago

https://gitlab.com/celliern/scikit-fdiff/blob/master/

# Scikit-fdiff / skfdiff

The full documentation is available on [read the doc.](https://scikit-fdiff.readthedocs.io/en/latest/)

[![DOI](http://joss.theoj.org/papers/10.21105/joss.01356/status.svg)](https://doi.org/10.21105/joss.01356)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3236970.svg)](https://doi.org/10.5281/zenodo.3236970)

- [Scikit-fdiff / skfdiff](#scikit-fdiff--skfdiff)
  - [Installation](#installation)
    - [External requirements](#external-requirements)
    - [via PyPI](#via-pypi)
    - [via github](#via-github)
  - [Introduction](#introduction)
    - [Rational](#rational)
  - [Model writing](#model-writing)
    - [Toy examples (more ambitious one are in the doc)](#toy-examples-more-ambitious-one-are-in-the-doc)
      - [1D advection / diffusion system, Dirichlet boundary](#1d-advection--diffusion-system-dirichlet-boundary)
      - [2D advection / diffusion system, mixed robin / periodic boundary](#2d-advection--diffusion-system-mixed-robin--periodic-boundary)
    - [Contributing](#contributing)
    - [Code of Conduct](#code-of-conduct)

## 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

```bash
pip install scikit-fdiff[numba,interactive]
```

will install the package and

```bash
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:

```bash
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:

```python
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

```python
>>> 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, 
 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

```python
>>> 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, 
 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](https://scikit-fdiff.readthedocs.io/en/latest/contribute.html).

### Code of Conduct

See [the dedicated page](COC.md).

JOSS Publication

scikit-finite-diff, a new tool for PDE solving
Published
June 03, 2019
Volume 4, Issue 38, Page 1356
Authors
Nicolas Cellier ORCID
Université Savoie Mont-Blanc
Christian Ruyer-Quil
Université Savoie Mont-Blanc
Editor
Kevin M. Moerman ORCID
Tags
python pde physical modelling

Committers

Last synced: 4 months ago

All Time
  • Total Commits: 773
  • Total Committers: 5
  • Avg Commits per committer: 154.6
  • Development Distribution Score (DDS): 0.473
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Nicolas Cellier c****t@n****t 407
Nicolas CELLIER e****e@g****m 363
Hans Fangohr f****r@u****m 1
Kevin Mattheus Moerman k****n@g****m 1
Nicolas CELLIER c****n@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 44 last-month
  • Total dependent packages: 1
    (may contain duplicates)
  • Total dependent repositories: 3
    (may contain duplicates)
  • Total versions: 6
  • Total maintainers: 1
pypi.org: scikit-fdiff

Automatic finite difference discretization for 1D PDE with fast temporal solvers.

  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 2
  • Downloads: 36 Last month
Rankings
Dependent packages count: 4.8%
Dependent repos count: 11.6%
Forks count: 14.2%
Average: 14.3%
Stargazers count: 14.5%
Downloads: 26.3%
Maintainers (1)
Last synced: 4 months ago
pypi.org: skfdiff

Automatic finite difference discretization for 1D PDE with fast temporal solvers.

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 8 Last month
Rankings
Dependent packages count: 10.1%
Forks count: 14.2%
Stargazers count: 14.5%
Average: 20.8%
Dependent repos count: 21.6%
Downloads: 43.5%
Maintainers (1)
Last synced: 4 months ago