Skip to main content

FIDELIOR: FInite-Difference-Equation LInear OperatoR package

Project description

FIDELIOR

FIDELIOR (latin: more reliable) stands for FInite-Difference-Equation LInear OperatoR package.

The purpose of FIDELIOR is to help with numerical solution of partial differential equations (PDE). In order to obtain a numerical solution, continuous functions and differential operators that enter a PDE are discretized. There are two main approaches to such discretization: the finite-difference (FD) method and the finite-element method (FEM). The main idea of the FD approach is to represent various differential operators entering the PDE as finite differences. A linear PDE is represented as a linear system Lu = f, where matrix L represents the action of a differential operator, vector u is the discretized unknown function, and f is the discretized inhomogeneous part. In FEM, the differential operators do not have to be supplied by the user; the FD equations emerge by writing the PDE in the weak form. Obtaining the discretized equation in FEM may be cumbersome. To help with discretization, there is an excellent Python package FEniCS which allows the user to automate the generation of linear systems (such as one given above) from the weak forms. FEniCS provides much flexibility with finite element choice, and thus is a rather large project. The present package, FIDELIOR, strives to do for the FD method the same that FEniCS does for FEM, namely to provide flexibility and convenience in setting up the FD schemes. The user must have the knowledge of how the differential operators are discretized. Some help, however, is provided with automatic generation of FD schemes (NOTE: this was done for the old interface, and I am in the process of rewriting it!). In case of a time-dependent PDE, the user must also provide the time-stepping scheme. We should point out that the stability of a time-stepping scheme is not guaranteed even in the FEM method, and this process is not automated even in FEniCS.

The FIDELIOR package has undergone some changes from the previous version. The most important change was to introduce a better and simpler interface, which allows much more flexibility in setting up complicated boundary conditions and other constraints. Some of the new interface, e.g., the use of == operator for setting up equations, was inspired by FEniCS. At the same time, the code became shorter, as some non-essential features were dropped. However, the functionality of the package did not suffer.

A good introduction to FD methods may be found, e.g., in

  • Randall J. LeVeque (2007), Finite Difference Methods for Ordinary and Partial Differential Equations, SIAM, Philadelphia.

FIDELIOR requires Python3, NumPy and SciPy to run and Matplotlib if you would like to plot the results. Plotting, in particular, is used in the examples.

Here is a quick demo of what FIDELIOR can do. The following is a complete program that sets up and solves a Poisson equation in 2D on a 100x100 cell grid and plots and checks the result:

import numpy as np
from matplotlib import pyplot as  plt
import fidelior as fdo
from fidelior import end, half

# Set up the simple geometry
N = 100
x1 = np.arange(N+1)-N/2; y1 = x1
box = fdo.Box((N, N))
x, y = box.ndgrid(x1, y1)[0:end, 0:end]

# Charge density
x0 = 25; y0 = -25; w = 10;
rho = fdo.exp(-((x-x0)**2+(y-y0)**2)/(2*w**2))

# Unknown electrostatic potential
phi = box.sym('phi')[0:end, 0:end]

# These functions use 'fdo.diff(u, axis)' which is itself defined as
# def diff(u, axis): u.shift(half, axis) - u.shift(-half, axis)
def grad(u):
    return (fdo.diff(u, axis=0), fdo.diff(u, axis=1))
def div(A):
    return fdo.diff(A[0], axis=0) + fdo.diff(A[1], axis=1)

# Unknown electric field
E = grad(-phi)

# Boundary conditions (constraints with which the equation will be solved)
(phi[[0, end], :] == 0).constraint('Dirichlet') # on left and right edges
(E[1][1:end-1, [half, end-half]] == 1).constraint('Neumann') # Ey = 1 on top and bottom

# Set up and solve the equation
phiv = (div(E) == rho).solve()

# Plot and check the error
plt.pcolor(x1, y1, phiv[:,:].T, shading='auto')
plt.gca().set_aspect('equal')
print('Error =', fdo.max(fdo.abs(div(grad(-phiv))-rho)))

Notice that this script does not use any pre-defined finite-difference approximations to differential operators or boundary conditions. Operators grad, div and custom boundary conditions are defined by the user within these few lines.

In summary, FIDELIOR allows the user

  1. to represent known and unknown functions as discretized values on a rectangular grid;
  2. to specify custom finite-difference operators which represent approximations to differential operators;
  3. to specify constraints (boundary conditions) on unknown discretized functions;
  4. to set up and solve linear PDE which take into account the given constraints.

Installation

FIDELIOR is now available at Python Package Index PyPI. You can install it by typing the following at the command prompt:

pip install fidelior

Use pip3 if you still have Python2 on your system. Or, if you prefer to use the absolutely latest version, download fidelior folder from src/ directory and put it in the path where Python looks for packages (sys.path).

After you have installed FIDELIOR, you can try running the above script to make sure it works.

Start using FIDELIOR

Capabilites of FIDELIOR are described in the manual and their usage is demonstrated by the included examples.

License

License: CC BY-ND 4.0

The project is free to use, however, it is protected by copyright. If you would like to use it in your publication, please cite the project webpage (https://gitlab.com/nleht/fidelior). A journal article is in preparation, and when it is available, it will have to be cited. If you have any suggestions for improvement (new features, bug fixes, etc.) please contact the the author, Nikolai G. Lehtinen, at his email address.

The examples are distributed under a less restrictive CC BY 4.0 License License: CC BY 4.0.

Acknowledgements

This study was supported by the European Research Council under the European Union's Seventh Framework Programme (FP7/2007-2013)/ERC grant agreement number 320839 and the Research Council of Norway under contracts 208028/F50, 216872/F50 and 223252/F50 (CoE).

Older versions

See also the previous interface version and the demonstration of some of its capabilities. Some of the examples were converted to the new interface, others are in the process of such conversion.

The former location of the project was here and then here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fidelior-0.7.4.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fidelior-0.7.4-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file fidelior-0.7.4.tar.gz.

File metadata

  • Download URL: fidelior-0.7.4.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/21.2.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for fidelior-0.7.4.tar.gz
Algorithm Hash digest
SHA256 30d42d98b493b0767d8a1802aea11ce8c33a0ae5bfa5661a2c4913ee17e5278e
MD5 657672b5ca99f1da12b52c3df800109a
BLAKE2b-256 4b72122502071c1296a22e60a680cd91ccb3c1a9c48d006740bceede14902ebf

See more details on using hashes here.

File details

Details for the file fidelior-0.7.4-py3-none-any.whl.

File metadata

  • Download URL: fidelior-0.7.4-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/21.2.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for fidelior-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8e230813bc9cdde2884f7618aa727357989e78646b47e222dea4cb91ef4f8f4e
MD5 ec9bba299a92593c051eb5924f97c68a
BLAKE2b-256 acbef8bb9d34e8111fc2059146d68b697ac5e62975dd3de7988eb13f99569651

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page