npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

finite-difference-stencil

v1.0.2

Published

Compute the coefficients of explicit or implicit finite difference schemes

Downloads

9

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:

In this case, the input would be represented as:

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

// Average two points (zeroth derivative):
var c = [-1, 1]
stencil(0, c)
// => c = [ 0.5, 0.5 ]


// Central first derivative:
var c = [-1, 0, 1]
stencil(1, c)
// => c = [ -0.5, 0, 0.5 ]


// One-sided first derivative:
var c = [0, 1, 2]
stencil(1, c)
// => c = [ -1.5, 2, -0.5 ]


// Sixth order compact second derivative:
var c = [-2, -1, 1, 2, -2, -1, 0, 1, 2]
stencil(1, c, 4)
// => c = [ 0.027777777777778206,
//          0.44444444444444775,
//          0.4444444444444405,
//          0.027777777777777398,
//         -0.11574074074074253,
//         -0.7407407407407423,
//          7.771561172376096e-15,
//          0.7407407407407378,
//          0.11574074074073923 ]

Installation

$ npm 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:

  • derivative: A non-negative integer specifying the desired derivative. If zero, it will generate an interpolation scheme. One and two would indicate the first and second derivatives, respectively.
  • points: A list of coordinate points included in the stencil. The first numImplicit points are treated as coefficients of implicit terms (left-hand side in the equation above). The remaining points are treated explicitly.
  • numImplicit (optional): An integer indicating the number of points treated explicitly. If numImplicit is omitted, all points are treated explicitly.
  • A (optional): Given array points of length n, A may be provided as an n×n ndarray work matrix. If not provided, it will be allocated and freed automatically.
  • P (optional): A permutation vector for the matrix inverstion. May simply be an empty Array.

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.