Skip to main content

centpy

Central schemes for conservation laws in Python.

The schemes are translated into Python from CentPack written by Jorge Balbás and Eitan Tadmor.

Usage

Centpy provides to the user three main classes for parameters, equations, and solvers. Examples of instances for parameters and equations are in tests/example_parameters.py and tests/example_equations.py.

The numerical solution of a one-dimensional Burgers equation is discussed below.

Parameters

The parameter classes are simple data classes without methods: Pars1d and Pars1d defined in parameters.py. Each attribute has a default variable, but it is recommended that all attributes are set explicitly. The attributes are:

Attribute Description
x_init left grid point
x_final right grid point
t_final evolution time
dt_out time step of storage
J number of interior grid points
cfl CFL number
scheme solver scheme (fd2, sd2, or sd3)

An instance of the parameter class can be created as follows.

pars_burgers1d = centpy.Pars1d(
    x_init=0.0,
    x_final=2.0 * np.pi,
    t_final=10,
    dt_out=0.05,
    J=400,
    cfl=0.75,
    scheme="sd3")

Note that the parameter data class does not have a member for the time step dt, because it is calculated dynamically during the solution of the equation based on the CFL number and maximum spectral radius.

Equations

The equations are abstract base classes which require methods for setting initial data, boundary conditions, fluxes, and spectral radius. Additional helper methods and parameters can be added depending on the problem. The equations class inherits all attributes of the parameters class. The space-time grid is constructed in this step based on the parameters. The Burgers equation class is defined below.

class Burgers1d(centpy.Equation1d):
    def initial_data(self):
        return np.sin(self.x) + 0.5 * np.sin(0.5 * self.x)

    def boundary_conditions(self, u):
        u[0] = u[-4]
        u[1] = u[-3]
        u[-2] = u[2]
        u[-1] = u[3]

    def flux_x(self, u):
        return 0.5 * u * u

    def spectral_radius_x(self, u):
        return np.abs(u)

The boundary conditions are periodic, so the data on the ghost points are copied from the interior points on the opposite end.

Solution

There are two solver classes: Solver1d and Solver2d defined in solver1d.py and solver2d.py respectively. To construct the solution, we create an instance of the Burgers1d class with the parameters, and give the equation instance as input to the solver class.

eqn_burgers1d = Burgers1d(pars_burgers1d)
soln_burgers = centpy.Solver1d(eqn_burgers1d)
soln_burgers.solve()

After the solver step, the instance soln_burgers includes the solution array u_n. Depending on the shape of the array, plots and animations can be easily constructed. Examples are given in the animations notebook tests/animations.ipynb.

The options for the central solver are fd2 for second order fully-discrete method, sd2 for second order semi-discrete method, and sd3 for third order semi-discrete method. Information about these solvers is given at the appendix of the CentPack User Guide.

LaTeX formulas and animations for the examples are given in the Jupyter notebook tests/animations.ipynb.

Metadata

Release files for centpy 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for centpy 0.1
File Size Uploaded
centpy-0.1.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for centpy 0.1
File Interpreter ABI Platform
centpy-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / centpy-0.1.tar.gz

Download URL centpy-0.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
85a653f1bcc894a2af5257211a5bba425ac83bc3d6ae63e382f481cb9453637f
BLAKE2b-256 checksum
How to use checksums
902fac3bb3b48e9c735d58f9071e2b9a1a37e206c9ed50a1597b4f77ef953879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

Release files / centpy-0.1-py3-none-any.whl

Download URL centpy-0.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
729f9a90353832294a8aac2c25d5562c3b6a44f0bcaa8f9729217381b28428ef
BLAKE2b-256 checksum
How to use checksums
92897cbdc92609ea7790eb6444f8a189826582d675f0b7f59ba539159c43c690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page