Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Python Bindings for the DUNE-FEM module

Authors: Andreas Dedner, Martin Nolte, and Robert Klöfkorn

dune-fempy aims to provide Python bindings for the dune-fem discretization module. Here an example for solving Poisson's equation:

import math
from ufl import *
import dune.ufl
import dune.create as create

grid = create.grid("ALUConform", dune.grid.cartesianDomain([0, 0], [1, 1], [8, 8]), dimgrid=2)

# set up a diffusion reaction model using UFL
uflSpace = dune.ufl.Space((grid.dimGrid, grid.dimWorld), 1, field="double")
u = TrialFunction(uflSpace)
v = TestFunction(uflSpace)
x = SpatialCoordinate(uflSpace.cell())
a = (inner(grad(u), grad(v)) + inner(u,v)) * dx
# provide an exact solution that will be used to add suitable forcing and dirichlet b.c.
exact = as_vector( [cos(2.*pi*x[0])*cos(2.*pi*x[1])] )
model = create.model("elliptic", grid, a==0, exact=exact, dirichlet={ 1:exact } )

# set up a space and a conforming finite element scheme and solve the PDE
space  = dune.create.space("Lagrange", grid, dimrange=1, order=1)
scheme = create.scheme("h1", space, model, "cg")
uh,info = scheme.solve()

# make 'exact' into a grid function for output and uh into an UFL coefficient for error computation
exact_gf = create.function("ufl", grid, "exact", 5, exact)
uh_coeff = dune.ufl.GridCoefficient(uh)
# now define a grid function representing the pointwise error
l2error_gf = create.function("ufl", grid, "error", 5, as_vector([(exact[0]-uh_coeff[0])**2]) )

error = math.sqrt( l2error_gf.integrate() )
print("size:",grid.size(0),"L2-error:",error)
grid.writeVTK("laplace", pointdata=[ uh, l2error_gf, exact_gf ])

See the file COPYING for full copying permissions.

If you find this tutorial helpful for getting your own projects up and running please cite

Title: Python Bindings for the DUNE-FEM module Authors: Andreas Dedner, Martin Nolte, and Robert Klöfkorn Publisher: Zenodoo, 2020 DOI 10.5281/zenodo.3706994

DOI

Dependencies

dune-fempy depends on the following DUNE modules:

  • dune-common 2.8+
  • dune-geometry 2.8+
  • dune-grid 2.8+
  • dune-python 2.8+
  • dune-fem 2.8+

In addition to the dependencies of these DUNE modules, the following software packages are required:

  • a C++17 compatible C++ compiler
  • Python 2.7+ (although mostly tested with 3.4+)

We strongly recommend installing the following Python packages to make full use of dune-fem's Python bindings:

  • numpy
  • mpi4py
  • ufl (2016.1.0+)

git-2d404a0a28ab3122f8ae41ce03c19f1b9699eb79

Release files for dune-fempy 2.8.0.dev20210521

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

Source distribution (sdist)

Source distribution for dune-fempy 2.8.0.dev20210521
File Size Uploaded
dune-fempy-2.8.0.dev20210521.tar.gz 20.6 MB Details

Release files / dune-fempy-2.8.0.dev20210521.tar.gz

Download URL dune-fempy-2.8.0.dev20210521.tar.gz
Size 20.6 MB
Tags Source
SHA-256 checksum
How to use checksums
1c9c848aab8d1beb34dcf8a7683cef78205e98b99be75f696a1dc2bbeecdd304
BLAKE2b-256 checksum
How to use checksums
bbab31418d66d2a2df98c6b44a4ae0db2b21dd2c6776406ea5c31f764d7efafb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
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