# ELLIPT2D: A Flexible Finite Element Code Written Python

## Abstract

The use of the Python scripting language for scientific applications and in particular to solve partial differential equations is explored. It is shown that Python's rich data structure and object-oriented features can be exploited to write programs that are not only significantly more concise than their counter parts written in Fortran, C or C++, but are also numerically efficient. To illustrate this, a two-dimensional finite element code (ELLIPT2D) has been written. ELLIPT2D provides a flexible and easy-to-use framework for solving a large class of second-order elliptic problems. The program allows for structured or unstructured meshes. All functions defining the elliptic operator are user supplied and so are the boundary conditions, which can be of Dirichlet, Neumann or Robbins type. ELLIPT2D makes extensive use of dictionaries (hash tables) as a way to represent sparse matrices.Other key features of the Python language that have been widely used include: operator over loading, error handling, array slicing, and the Tkinter module for building graphical use interfaces. As an example of the utility of ELLIPT2D, a nonlinear solution of the Grad-Shafranov equation is computed using a Newton iterative scheme. A second application focuses on a solution of the toroidal Laplace equation coupled to a magnetohydrodynamicmore »

- Authors:

- Publication Date:

- Research Org.:
- Princeton Plasma Physics Lab., NJ (US)

- Sponsoring Org.:
- USDOE Office of Energy Research (ER) (US)

- OSTI Identifier:
- 781479

- Report Number(s):
- PPPL-3552

TRN: US0102986

- DOE Contract Number:
- AC02-76CH03073

- Resource Type:
- Technical Report

- Resource Relation:
- Other Information: PBD: 22 Mar 2001

- Country of Publication:
- United States

- Language:
- English

- Subject:
- 70 PLASMA PHYSICS AND FUSION TECHNOLOGY; 75 CONDENSED MATTER PHYSICS, SUPERCONDUCTIVITY AND SUPERFLUIDITY; E CODES; FINITE ELEMENT METHOD; BOUNDARY CONDITIONS; GRAD-SHAFRANOV EQUATION; LAPLACE EQUATION; MAGNETOHYDRODYNAMICS; PARTIAL DIFFERENTIAL EQUATIONS; STABILITY; PROGRAMMING LANGUAGES; USES

### Citation Formats

```
Pletzer, A., and Mollis, J.C..
```*ELLIPT2D: A Flexible Finite Element Code Written Python*. United States: N. p., 2001.
Web. doi:10.2172/781479.

```
Pletzer, A., & Mollis, J.C..
```*ELLIPT2D: A Flexible Finite Element Code Written Python*. United States. doi:10.2172/781479.

```
Pletzer, A., and Mollis, J.C.. Thu .
"ELLIPT2D: A Flexible Finite Element Code Written Python". United States.
doi:10.2172/781479. https://www.osti.gov/servlets/purl/781479.
```

```
@article{osti_781479,
```

title = {ELLIPT2D: A Flexible Finite Element Code Written Python},

author = {Pletzer, A. and Mollis, J.C.},

abstractNote = {The use of the Python scripting language for scientific applications and in particular to solve partial differential equations is explored. It is shown that Python's rich data structure and object-oriented features can be exploited to write programs that are not only significantly more concise than their counter parts written in Fortran, C or C++, but are also numerically efficient. To illustrate this, a two-dimensional finite element code (ELLIPT2D) has been written. ELLIPT2D provides a flexible and easy-to-use framework for solving a large class of second-order elliptic problems. The program allows for structured or unstructured meshes. All functions defining the elliptic operator are user supplied and so are the boundary conditions, which can be of Dirichlet, Neumann or Robbins type. ELLIPT2D makes extensive use of dictionaries (hash tables) as a way to represent sparse matrices.Other key features of the Python language that have been widely used include: operator over loading, error handling, array slicing, and the Tkinter module for building graphical use interfaces. As an example of the utility of ELLIPT2D, a nonlinear solution of the Grad-Shafranov equation is computed using a Newton iterative scheme. A second application focuses on a solution of the toroidal Laplace equation coupled to a magnetohydrodynamic stability code, a problem arising in the context of magnetic fusion research.},

doi = {10.2172/781479},

journal = {},

number = ,

volume = ,

place = {United States},

year = {Thu Mar 22 00:00:00 EST 2001},

month = {Thu Mar 22 00:00:00 EST 2001}

}