scijs/finite-difference-stencil

Name: finite-difference-stencil

Owner: scijs

Description: Compute the coefficients of explicit or implicit finite difference schemes

Created: 2016-01-14 07:06:03.0

Updated: 2018-01-31 17:14:30.0

Pushed: 2016-01-15 01:36:57.0

Homepage: null

Size: 23

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

finite-difference-stencil Build Status npm version js-standard-style

Compute the coefficients of explicit or implicit finite difference schemes

Introduction

This module uses a Taylor series expansion to compute the coefficients of finite difference schemes. It generates schemes of any derivative and order of accuracy and generates either explicit or implicit schemes.

For example, a staggered scheme with four points treated explicitly and two implicitly would be written as:

\alpha f'_{i-1} + f'_i + \beta f'_{i + 1} = a \, f_{i - \frac{3}{2}} + b \, f_{i - \frac{1}{2}} + c \, f_{i + \frac{1}{2}} + d \, f_{i + \frac{3}{2}}

In this case, the input would be represented as:

stencil(1, [-1, 1, -1.5, -0.5, 0.5, 1.5], 2)

where the 1 indicates a first derivative and the final 2 indicates that the first two coordinate points will be treated implicitly. Since the grid spacing is just a scale factor that doesn't affect the solution, it is excluded.

For explicit schemes, the resulting coefficients are multiplied by the respective grid points to compute the derivative. Making use of implicit Padé-type (compact) schemes requires simultaneous solution for the desired derivative at each grid point. In one dimension, this typically leads to a tridiagonal or pentadiagonal system of equations that must be inverted. In two or more dimensions, it tends to result in a block-diagonal system.

Examples
verage two points (zeroth derivative):
c = [-1, 1]
cil(0, c)
> c = [ 0.5, 0.5 ]


entral first derivative:
c = [-1, 0, 1]
cil(1, c)
> c = [ -0.5, 0, 0.5 ]


ne-sided first derivative:
c = [0, 1, 2]
cil(1, c)
> c = [ -1.5, 2, -0.5 ]


ixth order compact second derivative:
c = [-2, -1, 1, 2, -2, -1, 0, 1, 2]
cil(1, c, 4)
> c = [ 0.027777777777778206,
        0.44444444444444775,
        0.4444444444444405,
        0.027777777777777398,
       -0.11574074074074253,
       -0.7407407407407423,
        7.771561172376096e-15,
        0.7407407407407378,
        0.11574074074073923 ]
Installation
m install finite-difference-stencil
Usage
require('finite-difference-stencil')(derivative, points[, numImplicit[, A[, P]]])

Given a list of coordinate points, generates a finite difference stencil giving the specified derivative.

Arguments:

References

Lele, S. K. (1992). Compact Finite Difference Schemes with Spectral-like Resolution. Journal of Computational Physics, 103, 16-42.

License

© 2016 Ricky Reusser. MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.