No project description provided
Project description
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dune-fempy-2.8.0.dev20210524.tar.gz
.
File metadata
- Download URL: dune-fempy-2.8.0.dev20210524.tar.gz
- Upload date:
- Size: 20.6 MB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a24022bfb41bf9762b5c8fae7a50a4e939d0b2824cd1439a61f30fedff5f47a7 |
|
MD5 | 5cfba195774ec2db4456bbe00f8dde50 |
|
BLAKE2b-256 | 3e74bad04706b0bf0278f61551357e4067c18c0da3a4ffcfeae58e2dd8d8535b |