Skip to main content

ellipt2d

https://img.shields.io/pypi/v/ellipt2d.svg https://img.shields.io/travis/pletzer/ellipt2d.svg Documentation Status

A package for solving second order elliptic problems in 2D

Features

How to solve an elliptic problem with Ellipt2d

Define the domain. We recommend to use the pytriangle package to triangule a domain. This involves specifying boundary points and segments. If there are holes in the domain, then you’ll need to specify those as well. As an example, we’ll triangulate an annulus:

import triangle
import numpy

# number of outer and inner poloidal points
nto, nti = 16, 8

dto, dti = 2*numpy.pi / nto, 2*numpy.pi / nti
to = numpy.linspace(0., 2*numpy.pi - dto, nto)
ti = numpy.linspace(0., 2*numpy.pi - dti, nti)

# outer boundary, points and segments go counterclockwise
bound_pts = [(numpy.cos(t), numpy.sin(t)) for t in to]
bound_seg = [(i, i + 1) for i in range(nto - 1)] + [(nto - 1, 0)] # close the contour

# add the inner boundary, points and segments go clockwise
bound_pts += [(0.3*numpy.cos(t), 0.3*numpy.sin(t)) for t in ti]
bound_seg += [(i, i+1) for i in range(nto, nto + nti - 1)] + [(nto + nti - 1, nto)]

# now create the triangulation
grid = triangle.Triangle()
grid.set_points(bound_pts)
grid.set_segments(bound_seg)
grid.set_holes([(0., 0.)])
grid.triangulate()

Create an Ellipt2d instance, here a Laplace operator:

import ellipt2d

# - div F . grad u + g = s
# F = [[fxx, fxy], [fxy, fyy]] and g are defined on cells and s on nodes
# here fxx = fyy = 1 and fxy = g = 0
nnodes = grid.get_num_points()
ncells = grid.get_num_triangles()
fxx = fyy = numpy.ones(ncells)
fxy = g = numpy.zeros(ncells)
s = numpy.zeros(nnodes)

equ = ellipt2d.Ellipt2d(grid=grid, fxx=fxx, fxy=fxy, fyy=fyy, g=g, s=s)

Set the boundary conditions. You only need to specify boundary conditions if they are different from the zero flux boundary conditions. Here we specify the Dirichlet boundary conditions on the outer contour (first nto - 1 points):

# gather all the points that are on the external boundary where the radius is larger than 0.31
nodes = grid.get_points() # [(x, y, 0 or 1), ...]
ext_pts = [(i, nodes[i][0][0], nodes[i][0][1]) for i in range(nnodes) if nodes[i][1] == 1 and nodes[i][0][0]**2 + nodes[i][0][1]**2 > 0.31**2]
# Dirichlet BC is cos of angle
db = {bp[0]: numpy.cos(numpy.arctan2(bp[2], bp[1])) for bp in ext_pts}
equ.setDirichletBoundaryConditions(db)

Solve the linear system:

u = equ.solve()

Save the solution in a VTK file for plotting with Paraview or VisIt:

equ.saveVTK(filename='sol.vtk', solution=u, sol_name='u')
images/sol.png

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

2.0.0 (2020-12-15)

  • First release on PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ellipt2d-2.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ellipt2d-2.1.0-py3.7.egg (9.4 kB view details)

Uploaded Egg

File details

Details for the file ellipt2d-2.1.0.tar.gz.

File metadata

  • Download URL: ellipt2d-2.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.4

File hashes

Hashes for ellipt2d-2.1.0.tar.gz
Algorithm Hash digest
SHA256 90115b5900f1e275c71d1a6ecfc54fee0bed78f2a4725314e97c0994466636e1
MD5 87f6b698ac2525c78eb10161c1eed849
BLAKE2b-256 8ed44b903dcabeabb709af78a7f94241d954c6f85f4bc499b36a35dc52ec7e2c

See more details on using hashes here.

File details

Details for the file ellipt2d-2.1.0-py3.7.egg.

File metadata

  • Download URL: ellipt2d-2.1.0-py3.7.egg
  • Upload date:
  • Size: 9.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.4

File hashes

Hashes for ellipt2d-2.1.0-py3.7.egg
Algorithm Hash digest
SHA256 6866c02c1b5a92da5006a881043141bcb88bae50cb0edb8d0de624b2d27e094b
MD5 def6ca24bf33157bc4acf6270ee8676e
BLAKE2b-256 0ce83d74028a1a7f0dd54e60701b97542bd3ad844f28afd3da7a7871139ca98a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page