Skip to main content

pyfvm

PyPi Version PyPI pyversions GitHub stars PyPi downloads

Discord

Creating finite volume equation systems with ease.

pyfvm provides everything that is needed for setting up finite volume equation systems. The user needs to specify the finite volume formulation in a configuration file, and pyfvm will create the matrix/right-hand side or the nonlinear system for it. This package is for everyone who wants to quickly construct FVM systems.

Examples

Linear equation systems

pyfvm works by specifying the residuals, so for solving Poisson's equation with Dirichlet boundary conditions, simply do

import meshplex
import meshzoo
import numpy as np
from scipy.sparse import linalg

import pyfvm
from pyfvm.form_language import Boundary, dS, dV, integrate, n_dot_grad


class Poisson:
    def apply(self, u):
        return integrate(lambda x: -n_dot_grad(u(x)), dS) - integrate(lambda x: 1.0, dV)

    def dirichlet(self, u):
        return [(lambda x: u(x) - 0.0, Boundary())]


# Create mesh using meshzoo
vertices, cells = meshzoo.rectangle_tri(
    np.linspace(0.0, 2.0, 401), np.linspace(0.0, 1.0, 201)
)
mesh = meshplex.Mesh(vertices, cells)

matrix, rhs = pyfvm.discretize_linear(Poisson(), mesh)

u = linalg.spsolve(matrix, rhs)

mesh.write("out.vtk", point_data={"u": u})

This example uses meshzoo for creating a simple mesh, but anything else that provides vertices and cells works as well. For example, reading from a wide variety of mesh files is supported (via meshio):

mesh = meshplex.read("pacman.e")

Likewise, PyAMG is a much faster solver for this problem

import pyamg

ml = pyamg.smoothed_aggregation_solver(matrix)
u = ml.solve(rhs, tol=1e-10)

More examples are contained in the examples directory.

Nonlinear equation systems

Nonlinear systems are treated almost equally; only the discretization and obviously the solver call is different. For Bratu's problem:

import pyfvm
from pyfvm.form_language import *
import meshzoo
import numpy as np
from sympy import exp
import meshplex


class Bratu:
    def apply(self, u):
        return integrate(lambda x: -n_dot_grad(u(x)), dS) - integrate(
            lambda x: 2.0 * exp(u(x)), dV
        )

    def dirichlet(self, u):
        return [(u, Boundary())]


vertices, cells = meshzoo.rectangle_tri(
    np.linspace(0.0, 2.0, 101), np.linspace(0.0, 1.0, 51)
)
mesh = meshplex.Mesh(vertices, cells)

f, jacobian = pyfvm.discretize(Bratu(), mesh)


def jacobian_solver(u0, rhs):
    from scipy.sparse import linalg

    jac = jacobian.get_linear_operator(u0)
    return linalg.spsolve(jac, rhs)


u0 = np.zeros(len(vertices))
u = pyfvm.newton(f.eval, jacobian_solver, u0)

mesh.write("out.vtk", point_data={"u": u})

Note that the Jacobian is computed symbolically from the Bratu class.

Instead of pyfvm.newton, you can use any solver that accepts the residual computation f.eval, e.g.,

import scipy.optimize

u = scipy.optimize.newton_krylov(f.eval, u0)

Metadata

Release files for pyfvm 0.5.3

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

Built distributions (wheels)

Table of built distributions (wheels) for pyfvm 0.5.3
File Actions
pyfvm-0.5.3-cp315-none-any.whl CPython 3.15 none any Details for pyfvm-0.5.3-cp315-none-any.whl
pyfvm-0.5.3-cp314-none-any.whl CPython 3.14 none any Details for pyfvm-0.5.3-cp314-none-any.whl
pyfvm-0.5.3-cp313-none-any.whl CPython 3.13 none any Details for pyfvm-0.5.3-cp313-none-any.whl
pyfvm-0.5.3-cp312-none-any.whl CPython 3.12 none any Details for pyfvm-0.5.3-cp312-none-any.whl
pyfvm-0.5.3-cp311-none-any.whl CPython 3.11 none any Details for pyfvm-0.5.3-cp311-none-any.whl
pyfvm-0.5.3-cp310-none-any.whl CPython 3.10 none any Details for pyfvm-0.5.3-cp310-none-any.whl

Total release size: 411.2 kB

Release files / pyfvm-0.5.3-cp315-none-any.whl

Download URL pyfvm-0.5.3-cp315-none-any.whl
Size 75.6 kB
Tags CPython 3.15
SHA-256 checksum
How to use checksums
540aac4f0b7eeeb2ab70466610693a6d11ce2e2d87dd7d8b25eaf98edfabe083
BLAKE2b-256 checksum
How to use checksums
d6dfd695713042da07da7ad369c58b5720fb5e9d56edbeb830c87655fe7f84ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pyfvm-0.5.3-cp314-none-any.whl

Download URL pyfvm-0.5.3-cp314-none-any.whl
Size 75.3 kB
Tags CPython 3.14
SHA-256 checksum
How to use checksums
9ebe2a9138bf3d8aa047237c76366d64f5528bfe1e11c2453bd1a2a03b15f103
BLAKE2b-256 checksum
How to use checksums
d7b17f7af0795fdcbe884fdf9a76250b945e6784824b0e8140863fbe82912bc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pyfvm-0.5.3-cp313-none-any.whl

Download URL pyfvm-0.5.3-cp313-none-any.whl
Size 71.1 kB
Tags CPython 3.13
SHA-256 checksum
How to use checksums
cf9d982273124868fae8117bfb6bbaf7e51c32e5354fdc0ad06d2ebf7cc89160
BLAKE2b-256 checksum
How to use checksums
fb1ac8b746c64fd926a3f85e73106149b894650e2efb09c5457da5b0358d913c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pyfvm-0.5.3-cp312-none-any.whl

Download URL pyfvm-0.5.3-cp312-none-any.whl
Size 69.9 kB
Tags CPython 3.12
SHA-256 checksum
How to use checksums
955cec5d9df46d8480ae8f56d220f026eaeb0baa8dac6e45c7bd4d6d3d9f9fce
BLAKE2b-256 checksum
How to use checksums
5de3bfa6e096bb24c8211d690c3a6b45c814463443bcaacf912d41e5e5015b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pyfvm-0.5.3-cp311-none-any.whl

Download URL pyfvm-0.5.3-cp311-none-any.whl
Size 77.5 kB
Tags CPython 3.11
SHA-256 checksum
How to use checksums
b2d4a2722148d8d852d9fa4d545fcdde8e6e49a261f780bec63548e9b7f2b9bc
BLAKE2b-256 checksum
How to use checksums
02ffcf1681dba5f32e086671479f594c7cf4f830c7d45cae7317d8363e8d04fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pyfvm-0.5.3-cp310-none-any.whl

Download URL pyfvm-0.5.3-cp310-none-any.whl
Size 41.9 kB
Tags CPython 3.10
SHA-256 checksum
How to use checksums
21e21f48b2a3bbcc5aec54f93d9b21c305b9d6b554ebc886b74c7e1cf4c972ed
BLAKE2b-256 checksum
How to use checksums
5d91797be7850afc1f7778da0bfc7b1347a072ee97b426bf27a5799552e93bbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for pyfvm 0.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pyfvm-0.5.3-cp315-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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