https://github.com/bjodah/finitediff

Finite difference weights for any derivative order on arbitrarily spaced grids. C89, C++ and Fortran 90 implementations with Python bindings.

https://github.com/bjodah/finitediff

Science Score: 49.0%

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

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary

Keywords

finite-differences grid method-of-lines stencil
Last synced: 5 months ago · JSON representation

Repository

Finite difference weights for any derivative order on arbitrarily spaced grids. C89, C++ and Fortran 90 implementations with Python bindings.

Basic Info
  • Host: GitHub
  • Owner: bjodah
  • License: bsd-2-clause
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 2.84 MB
Statistics
  • Stars: 40
  • Watchers: 5
  • Forks: 5
  • Open Issues: 1
  • Releases: 0
Topics
finite-differences grid method-of-lines stencil
Created about 12 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License Authors

README.rst

finitediff
==========
.. image:: http://hackspett.bjodah.se/api/badges/12/status.svg
   :target: http://hackspett.bjodah.se/repos/12
   :alt: Build status
.. image:: https://img.shields.io/pypi/v/finitediff.svg
   :target: https://pypi.python.org/pypi/finitediff
   :alt: PyPI version
.. image:: https://zenodo.org/badge/14988640.svg
   :target: https://zenodo.org/badge/latestdoi/14988640
   :alt: Zenodo DOI
.. image:: https://img.shields.io/pypi/l/finitediff.svg
   :target: https://github.com/bjodah/finitediff/blob/master/LICENSE
   :alt: License
.. image:: http://hera.physchem.kth.se/~finitediff/branches/master/htmlcov/coverage.svg
   :target: http://hera.physchem.kth.se/~finitediff/branches/master/htmlcov
   :alt: coverage

``finitediff`` containts three implementations of Begnt Fornberg's
formulae for generation of finite difference weights on aribtrarily
spaced one dimensional grids:

- `C89 `_
- `Fortran 90 `_
- `C++ `_

The finite difference weights can be
used for optimized inter-/extrapolation data series for up to
arbitrary derivative order. Python_ bindings (to the C versions) are also provided.

.. _Python: https://www.python.org
.. _finitediff: https://github.com/bjodah/finitediff


Capabilities
------------
``finitediff`` currently provides callbacks for estimation of derivatives
or interpolation either at a single point or over an array (available
from the Python bindings).

The user may also manually generate the corresponding weights. (see
``calculate_weights``)

Finitediff can be conditionally compiled to make ``finitediff_interpolate_by_finite_diff``
multithreaded (when ``FINITEDIFF_OPENMP`` is defined). Then the number of threads used is
set through the environment variable ``FINITEDIFF_NUM_THREADS`` (or ``OMP_NUM_THREADS``).


Documentation
-------------
Autogenerated API documentation for latest stable release is found here:
``_
(and the development version for the current master branch is found here:
``_).

Examples
--------
Generating finite difference weights is simple using C++11:

.. code:: C++

   #include "finitediff_templated.hpp"
   #include 
   #include 
   #include 

   int main(){
       const unsigned max_deriv = 2;
       std::vector labels {"0th derivative", "1st derivative", "2nd derivative"};
       std::vector x {0, 1, -1, 2, -2};  // Fourth order of accuracy
       auto coeffs = finitediff::generate_weights(x, max_deriv);
       for (unsigned deriv_i = 0; deriv_i <= max_deriv; deriv_i++){
           std::cout << labels[deriv_i] << ": ";
           for (unsigned idx = 0; idx < x.size(); idx++){
               std::cout << coeffs[deriv_i*x.size() + idx] << " ";
           }
           std::cout << std::endl;
       }
   }


::

   $ cd examples/
   $ g++ -std=c++11 demo.cpp -I../include
   $ ./a.out
   Zeroth derivative (interpolation): 1 -0 0 0 -0
   First derivative: -0 0.666667 -0.666667 -0.0833333 0.0833333
   Second derivative: -2.5 1.33333 1.33333 -0.0833333 -0.0833333


and of course using the python bindings:

.. code:: python

   >>> from finitediff import get_weights
   >>> import numpy as np
   >>> c = get_weights(np.array([0, -1., 1]), 0, maxorder=1)
   >>> np.allclose(c[:, 1], [0, -.5, .5])
   True


from Python you can also use the finite differences to interpolate
values (or derivatives thereof):

.. code:: python

    >>> from finitediff import interpolate_by_finite_diff as ifd
    >>> x = np.array([0, 1, 2])
    >>> y = np.array([[2, 3, 5], [3, 4, 7], [7, 8, 9], [3, 4, 6]])
    >>> xout = np.linspace(0.5, 1.5, 5)
    >>> r = ifd(x, y, xout, maxorder=2)
    >>> r.shape
    (5, 4, 3)


see the ``examples/`` directory for more examples.

Installation
------------
Simplest way to install is to use the `conda package manager `_:

::

   $ conda install -c conda-forge finitediff pytest
   $ python -m pytest --pyargs finitediff

tests should pass.

Manual installation
~~~~~~~~~~~~~~~~~~~
You can install ``finitediff`` by using ``pip``::

   $ python -m pip install --user finitediff

(you can skip the ``--user`` flag if you have got root permissions),
to run the tests you need ``pytest`` too::

   $ python -m pip install --user --upgrade pytest
   $ python -m pytest --pyargs finitediff


Dependencies
------------
You need either a C, C++ or a Fortran 90 compiler. On debian based linux systems you may install (all) by issuing::

    $ sudo apt-get install gfortran g++ gcc

See `setup.py `_ for optional (Python) dependencies.


Citing
------
The algortihm is from the following paper:

http://dx.doi.org/10.1090/S0025-5718-1988-0935077-0

::

    @article{fornberg_generation_1988,
      title={Generation of finite difference formulas on arbitrarily spaced grids},
      author={Fornberg, Bengt},
      journal={Mathematics of computation},
      volume={51},
      number={184},
      pages={699--706},
      year={1988}
      doi={10.1090/S0025-5718-1988-0935077-0}
    }

You may want to, in addition to the paper, cite finitediff (for e.g. reproducibility),
and you can get per-version DOIs from the zenodo archive:

.. image:: https://zenodo.org/badge/14988640.svg
   :target: https://zenodo.org/badge/latestdoi/14988640
   :alt: Zenodo DOI


Licensing
---------
The source code is Open Source and is released under the very permissive
`"simplified (2-clause) BSD license" `_.
See `LICENSE `_ for further details.


Author
------
Björn Ingvar Dahlgren (gmail address: bjodah). See file `AUTHORS `_ in root for a list of all authors.

Owner

  • Name: Bjorn
  • Login: bjodah
  • Kind: user

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 198
  • Total Committers: 2
  • Avg Commits per committer: 99.0
  • Development Distribution Score (DDS): 0.015
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Björn Dahlgren b****h@g****m 195
Ondřej Čertík o****k@g****m 3

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 2
  • Total pull requests: 27
  • Average time to close issues: about 1 year
  • Average time to close pull requests: 6 days
  • Total issue authors: 2
  • Total pull request authors: 2
  • Average comments per issue: 9.0
  • Average comments per pull request: 0.37
  • Merged pull requests: 26
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • twmitchel (1)
  • wanglongqi (1)
Pull Request Authors
  • bjodah (26)
  • certik (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 87 last-month
  • Total docker downloads: 365
  • Total dependent packages: 1
    (may contain duplicates)
  • Total dependent repositories: 2
    (may contain duplicates)
  • Total versions: 27
  • Total maintainers: 1
pypi.org: finitediff

Finite difference weights for any derivative order on arbitrarily spaced grids.

  • Versions: 23
  • Dependent Packages: 1
  • Dependent Repositories: 2
  • Downloads: 87 Last month
  • Docker Downloads: 365
Rankings
Docker downloads count: 2.4%
Dependent packages count: 4.7%
Stargazers count: 11.0%
Average: 11.1%
Dependent repos count: 11.6%
Forks count: 15.3%
Downloads: 21.4%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: finitediff
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Stargazers count: 40.7%
Average: 43.9%
Forks count: 49.6%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

setup.py pypi
  • numpy *