Giter VIP home page Giter VIP logo

ranocha / summationbypartsoperators.jl Goto Github PK

View Code? Open in Web Editor NEW
74.0 5.0 11.0 3.73 MB

A Julia library of summation-by-parts (SBP) operators used in finite difference, Fourier pseudospectral, continuous Galerkin, and discontinuous Galerkin methods to get provably stable semidiscretizations, paying special attention to boundary conditions.

Home Page: https://ranocha.github.io/SummationByPartsOperators.jl

License: MIT License

Julia 98.12% Jupyter Notebook 1.88%
finite-difference summation-by-parts sbp boundary-conditions julia hacktoberfest discontinuous-galerkin continuous-galerkin fourier derivative-operator

summationbypartsoperators.jl's Introduction

SummationByPartsOperators.jl: A Julia library of provably stable discretization techniques with mimetic properties

Docs-stable Docs-dev Build Status Codecov Coveralls License: MIT JOSS DOI

The Julia library SummationByPartsOperators.jl provides a unified interface of different discretization approaches including finite difference, Fourier pseudospectral, continuous Galerkin, and discontinuous Galerkin methods. This unified interface is based on the notion of summation-by-parts (SBP) operators. Originally developed for finite difference methods, SBP operators are discrete derivative operators designed specifically to get provably stable (semi-) discretizations, mimicking energy/entropy estimates from the continuous level discretely and paying special attention to boundary conditions.

SummationByPartsOperators.jl is mainly written to be useful for both students learning the basic concepts and researchers developing new numerical algorithms based on SBP operators. Thus, this package uses Julia's multiple dispatch and strong type system to provide a unified framework of all of these seemingly different discretizations while being reasonably optimized at the same time, achieving good performance without sacrificing flexibility.

Installation

SummationByPartsOperators.jl is a registered Julia package. Thus, you can install it from the Julia REPL via

julia> using Pkg; Pkg.add("SummationByPartsOperators")

If you want to update SummationByPartsOperators.jl, you can use

julia> using Pkg; Pkg.update("SummationByPartsOperators")

As usual, if you want to update SummationByPartsOperators.jl and all other packages in your current project, you can execute

julia> using Pkg; Pkg.update()

A brief list of notable changes is available in NEWS.md.

Basic examples

Compute the derivative on a periodic domain using a central finite difference operator.

julia> using SummationByPartsOperators

julia> using Plots: plot, plot!

julia> D = periodic_derivative_operator(derivative_order=1, accuracy_order=2,
                                        xmin=0.0, xmax=2.0, N=20)
Periodic first-derivative operator of order 2 on a grid in [0.0, 2.0] using 20 nodes,
stencils with 1 nodes to the left, 1 nodes to the right, and coefficients of Fornberg (1998)
  Calculation of Weights in Finite Difference Formulas.
  SIAM Rev. 40.3, pp. 685-691.

julia> x = grid(D); u = sinpi.(x);

julia> plot(x, D * u, label="numerical")

julia> plot!(x, π .* cospi.(x), label="analytical")

You should see a plot like the following.

Compute the derivative on a bounded domain using an SBP finite difference operator.

julia> using SummationByPartsOperators

julia> using Plots: plot, plot!

julia> D = derivative_operator(MattssonNordström2004(), derivative_order=1, accuracy_order=2,
                               xmin=0.0, xmax=1.0, N=21)
SBP first-derivative operator of order 2 on a grid in [0.0, 1.0] using 21 nodes
and coefficients of Mattsson, Nordström (2004)
  Summation by parts operators for finite difference approximations of second
    derivatives.
  Journal of Computational Physics 199, pp. 503-540.

julia> x = grid(D); u = exp.(x);

julia> plot(x, D * u, label="numerical")

julia> plot!(x, exp.(x), label="analytical")

You should see a plot like the following.

Brief overview

The following derivative operators are implemented as "lazy"/matrix-free operators, i.e. no large (size of the computational grid) matrix is formed explicitly. They are linear operators and implement the same interface as matrices in Julia (at least partially). In particular, * and mul! are supported.

Periodic domains

  • periodic_derivative_operator(; derivative_order, accuracy_order, xmin, xmax, N)

    These are classical central finite difference operators using N nodes on the interval [xmin, xmax].

  • periodic_derivative_operator(Holoborodko2008(); derivative_order, accuracy_order, xmin, xmax, N)

    These are central finite difference operators using N nodes on the interval [xmin, xmax] and the coefficients of Pavel Holoborodko.

  • fourier_derivative_operator(; xmin, xmax, N)

    Fourier derivative operators are implemented using the fast Fourier transform of FFTW.jl.

All of these periodic derivative operators support multiplication and addition such that polynomials and rational functions of them can be represented efficiently, e.g. to solve elliptic problems of the form u = (D^2 + I) \ f.

Finite (nonperiodic) domains

  • derivative_operator(source_of_coefficients; derivative_order, accuracy_order, xmin, xmax, N)

    Finite difference SBP operators for first and second derivatives can be obtained by using MattssonNordström2004() as source_of_coefficients. Other sources of coefficients are implemented as well. To obtain a full list of all operators, use subtypes(SourceOfCoefficients).

  • legendre_derivative_operator(; xmin, xmax, N)

    Use Lobatto Legendre polynomial collocation schemes on N, i.e. polynomials of degree N-1, implemented via PolynomialBases.jl.

Dissipation operators

Additionally, some artificial dissipation/viscosity operators are implemented. The most basic usage is Di = dissipation_operator(D), where D can be a (periodic, Fourier, Legendre, SBP FD) derivative operator. Use ?dissipation_operator for more details.

Continuous and discontinuous Galerkin methods

SBP operators on bounded domains can be coupled continuously or discontinuously to obtain CG//DG-type methods. You need to create an appropriate mesh and a basic operator D that should be used on each element. Then, global CG/DG operators are constructed lazily/matrix-free by calling couple_continuously(D, mesh) or couple_discontinuously(D, mesh, coupling::Union{Val{:plus}, Val{:central}, Val{:minus}}=Val(:central)). Choosing coupling=Val(:central) yields a classical SBP operator; the other two coupling types result in upwind SBP operators. Currently, only uniform meshes

  • UniformMesh1D(xmin::Real, xmax::Real, Nx::Integer)
  • UniformPeriodicMesh1D(xmin::Real, xmax::Real, Nx::Integer)

are implemented.

Conversion to other forms

Sometimes, it can be convenient to obtain an explicit (sparse, banded) matrix form of the operators. Therefore, some conversion functions are supplied, e.g.

julia> using SummationByPartsOperators

julia> D = derivative_operator(MattssonNordström2004(),
                               derivative_order=1, accuracy_order=2,
                               xmin=0.0, xmax=1.0, N=5)
SBP first-derivative operator of order 2 on a grid in [0.0, 1.0] using 5 nodes
and coefficients of Mattsson, Nordström (2004)
  Summation by parts operators for finite difference approximations of second
    derivatives.
  Journal of Computational Physics 199, pp. 503-540.

julia> Matrix(D)
5×5 Array{Float64,2}:
 -4.0   4.0   0.0   0.0  0.0
 -2.0   0.0   2.0   0.0  0.0
  0.0  -2.0   0.0   2.0  0.0
  0.0   0.0  -2.0   0.0  2.0
  0.0   0.0   0.0  -4.0  4.0

julia> using SparseArrays

julia> sparse(D)
5×5 SparseMatrixCSC{Float64, Int64} with 10 stored entries:
 -4.0   4.0             
 -2.0        2.0        
      -2.0        2.0   
           -2.0       2.0
                -4.0  4.0

julia> using BandedMatrices

julia> BandedMatrix(D)
5×5 BandedMatrix{Float64,Array{Float64,2},Base.OneTo{Int64}}:
 -4.0   4.0             
 -2.0   0.0   2.0        
      -2.0   0.0   2.0   
           -2.0   0.0  2.0
                -4.0  4.0

Documentation

The latest documentation is available online and under docs/src. Some additional examples can be found in the directory notebooks. In particular, examples of complete discretizations of the linear advection equation, the heat equation, and the wave equation are available. Further examples are supplied as tests.

Referencing

If you use SummationByPartsOperators.jl for your research, please cite it using the bibtex entry

@article{ranocha2021sbp,
  title={{SummationByPartsOperators.jl}: {A} {J}ulia library of provably stable
         semidiscretization techniques with mimetic properties},
  author={Ranocha, Hendrik},
  journal={Journal of Open Source Software},
  year={2021},
  month={08},
  doi={10.21105/joss.03454},
  volume={6},
  number={64},
  pages={3454},
  publisher={The Open Journal},
  url={https://github.com/ranocha/SummationByPartsOperators.jl}
}

License and contributing

This project is licensed under the MIT license (see LICENSE.md). Since it is an open-source project, we are very happy to accept contributions from the community. Please refer to CONTRIBUTING.md for more details.

summationbypartsoperators.jl's People

Contributors

chrisrackauckas avatar dependabot[bot] avatar dougal-s avatar eschnett avatar github-actions[bot] avatar goggle avatar jlchan avatar joshualampert avatar juliatagbot avatar ranocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

summationbypartsoperators.jl's Issues

Remove Travis CI testing - at least on on Mac, maybe completely???

https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing:

macOS builds need special care and attention. We want to make sure that builders on Mac have the highest quality experience at the fastest possible speeds. Therefore, we are separating out macOS usage from other build usage and offering a distinct add-on plan that will correlate directly to your macOS usage. Purchase only the credits you need and use them until you run out.

We love our OSS teams who choose to build using TravisCI and we fully want to support that community. However, recently we have encountered significant abuse of the intention of this offering. Abusers have been tying up our build queues and causing performance reductions for everyone. In order to bring the rules back to fair playing grounds, we are implementing some changes for our public build repositories.

  • For those of you who have been building on public repositories (on travis-ci.com, with no paid subscription), we will upgrade you to our trial (free) plan with a 10K credit allotment (which allows around 1000 minutes in a Linux environment).
  • You will not need to change your build definitions when you are pointed to the new plan
  • When your credit allotment runs out - we’d love for you to consider which of our plans will meet your needs.
  • We will be offering an allotment of OSS minutes that will be reviewed and allocated on a case by case basis. Should you want to apply for these credits please open a request with Travis CI support stating that you’d like to be considered for the OSS allotment. Please include:
    • Your account name and VCS provider (like travis-ci.com/github/[your account name] )
    • How many credits (build minutes) you’d like to request (should your run out of credits again you can repeat the process to request more)
  • Usage will be tracked under your account information so that you can better understand how many credits/minutes are being used

Any ideas, suggestions?

Combine SBP operators

  • continuosly on periodic grids
  • discontinuosly on periodic grids
  • continuosly on bounded grids
  • discontinuosly on bounded grids

Both with and without additional interface dissipation.

Periodic wavelet collocation operators

See Jameson (1993) On the wavelet based differentiation matrix. These schemes are identical with classical centered FD schemes for orders of accuracy 2 and 4 but differ slightly for higher orders of accuracy.

Error while precompiling on Julia 1.0.3

ERROR: LoadError: LoadError: invalid subtyping in definition of ODEIntegrator
Stacktrace:
 [1] top-level scope at none:0
 [2] include at ./boot.jl:317 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1044
 [4] include at ./sysimg.jl:29 [inlined]
 [5] include(::String) at /home/sck/.julia/packages/OrdinaryDiffEq/RqsYx/src/OrdinaryDiffEq.jl:1
 [6] top-level scope at none:0
 [7] top-level scope at none:2
in expression starting at /home/sck/.julia/packages/OrdinaryDiffEq/RqsYx/src/integrators/type.jl:49
in expression starting at /home/sck/.julia/packages/OrdinaryDiffEq/RqsYx/src/OrdinaryDiffEq.jl:91
ERROR: LoadError: Failed to precompile OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed] to /home/sck/.julia/compiled/v1.0/OrdinaryDiffEq/DlSvy.ji.
Stacktrace:
 [1] top-level scope at none:2
in expression starting at /home/sck/.julia/packages/DiffEqCallbacks/rV4BA/src/DiffEqCallbacks.jl:9
ERROR: LoadError: Failed to precompile DiffEqCallbacks [459566f4-90b8-5000-8ac3-15dfb0a30def] to /home/sck/.julia/compiled/v1.0/DiffEqCallbacks/TKs5l.ji.
Stacktrace:
 [1] top-level scope at none:2
in expression starting at /home/sck/.julia/packages/SummationByPartsOperators/Acxc0/src/SummationByPartsOperators.jl:15
ERROR: LoadError: Failed to precompile SummationByPartsOperators [9f78cca6-572e-554e-b819-917d2f1cf240] to /home/sck/.julia/compiled/v1.0/SummationByPartsOp
Stacktrace:
 [1] compilecache(::Base.PkgId, ::String) at ./loading.jl:1203
 [2] _require(::Base.PkgId) at ./loading.jl:960
 [3] require(::Base.PkgId) at ./loading.jl:858
 [4] require(::Module, ::Symbol) at ./loading.jl:853
 [5] include(::String) at ./client.jl:392
 [6] top-level scope at none:0
in expression starting at /home/sck/plasma/alfven_currents/plot_curr.jl:3

I got this error when i tried to use the SBP-Operator package. Im using Julia 1.0.3 from the rpm repository of Fedora 29 Amd64 KDE.

Upwind SBP operators of Mattsson (2017)

  • Order 2, first derivative operator
  • Order 3, first derivative operator
  • Order 4, first derivative operator
  • Order 5, first derivative operator
  • Order 6, first derivative operator
  • Order 7, first derivative operator
  • Order 8, first derivative operator
  • Order 9, first derivative operator
  • Order 2, second derivative operators
  • Order 3, second derivative operators
  • Order 4, second derivative operators
  • Order 5, second derivative operators
  • Order 6, second derivative operators
  • Order 7, second derivative operators
  • Order 8, second derivative operators
  • Order 9, second derivative operators
  • Difference operator as dissipation operator
  • Something collecting them all (#156)

Reconstruction and filtering methods to reduce oscillations

  • Gegenbauer reconstruction for Fourier methods, cf. Script 3.18 of Hesthaven (2018) Numerical methods for conservation laws
  • Some Padé reconstructions?
  • Total variation denoising, cf. Condat (2013) A Direct Algorithm for 1-D Total Variation Denoising
  • Total variation denoising with overlapping group sparsity, cf. Selesnick and Chen (2013)

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Bug with empty coefficients

julia> using SummationByPartsOperators

julia> Dp = periodic_derivative_operator(1, 2, 0//1, 5//1, 6, 0)
Periodic 1st derivative operator of order 2 {T=Rational{Int64}, Parallel=Val{:serial}} 
on a grid in [0//1, 5//1] using 6 nodes, 
stencils with 0 nodes to the left, 2 nodes to the right, and coefficients from 
  Fornberg (1998) 
  Calculation of Weights in Finite Difference Formulas. 
  SIAM Rev. 40.3, pp. 685-691. 


julia> Dp * grid(Dp)
ERROR: BoundsError: attempt to access ()
  at index [0]
Stacktrace:
 [1] getindex(::Tuple, ::Int64) at ./tuple.jl:24
 [2] getindex at StaticArrays/1g9bq/src/SVector.jl:37 [inlined]
 [3] macro expansion at SummationByPartsOperators/src/periodic_operators.jl:152 [inlined]
 [4] convolve_periodic_boundary_coefficients!(::Array{Rational{Int64},1}, ::StaticArrays.SArray{Tuple{0},Rational{Int64},1,0}, ::Rational{Int64}, ::StaticArrays.SArray{Tuple{2},Rational{Int64},1,2}, ::LinRange{Rational{Int64}}, ::Rational{Int64}) at SummationByPartsOperators/src/periodic_operators.jl:116
 [5] mul!(::Array{Rational{Int64},1}, ::SummationByPartsOperators.PeriodicDerivativeCoefficients{Rational{Int64},0,2,Val{:serial},Fornberg1998}, ::LinRange{Rational{Int64}}, ::Rational{Int64}) at SummationByPartsOperators/src/periodic_operators.jl:61
 [6] mul! at SummationByPartsOperators/src/periodic_operators.jl:646 [inlined]
 [7] mul! at SummationByPartsOperators/src/general_operators.jl:31 [inlined]
 [8] *(::PeriodicDerivativeOperator{Rational{Int64},0,2,Val{:serial},Fornberg1998,LinRange{Rational{Int64}}}, ::LinRange{Rational{Int64}}) at SummationByPartsOperators/src/general_operators.jl:40
 [9] top-level scope at REPL[34]:1

Provide Scalar Products

Big picture: SBP operators on possibly multiple domains correspond to Hilbert spaces, so the coefficients (on multiple domains) should reflect this behaviour and define scalar products and norms using the corresponding mass/norm matrices.

See also JuliaLang/julia#25565

Number of grid points for periodic and Fourier operators

There is some inconsistency between the number of grid points requested:

julia> using SummationByPartsOperators

julia> D_FD = periodic_derivative_operator(1, 2, 0., 1., 11)
Periodic 1st derivative operator of order 2 {T=Float64, Parallel=Val{:serial}} 
on a grid in [0.0, 1.0] using 11 nodes, 
stencils with 1 nodes to the left, 1 nodes to the right, and coefficients from 
  Fornberg (1998) 
  Calculation of Weights in Finite Difference Formulas. 
  SIAM Rev. 40.3, pp. 685-691. 


julia> grid(D_FD)
0.0:0.1:0.9

julia> D_Fourier = fourier_derivative_operator(0., 1., 11)
Periodic 1st derivative Fourier operator {T=Float64} 
on a grid in [0.0, 1.0] using 11 nodes and 6 modes. 


julia> grid(D_Fourier)
0.0:0.09090909090909091:0.9090909090909091

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.