Skip to content
Topology Optimization using Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs restructured the directory, also slipped minor updates to READMEs and… Jun 7, 2016
examples delete PNGs created by ToPY Aug 22, 2017
scripts fix Dec 3, 2016
templates updated contents, better explanations Sep 24, 2015
topy Update Jul 23, 2018
.gitignore Replace Topy logger with builtin logger (#32) Oct 16, 2017 Updated INSTALL, LICENSE and CHANGES files Aug 22, 2017 Updated INSTALL, LICENSE and CHANGES files Aug 22, 2017 Update Feb 18, 2019


ToPy is a lightweight topology optimization framework for Python that can solve compliance (stiffness), mechanism synthesis and heat conduction problems in 2D and 3D. Please refer to the ToPy Wiki for further information.


Once you've downloaded the depenencies (see the INSTALL file) all you need to do is the following:

Download the latest stable release from here:

Then do

$ cd topy/topy
$ python install

Getting started

The main class of ToPy is 'Topology'. It defines the main constraints, grid and parameters of optimization -- but you don't really have to bother yourself with this if you just want to get some results.

There are two ways of defining a problem

  1. TPD file: You define the problem with keywords (see Help) in a simple text file and solve via the command line. The text file must have the extension .tpd
  2. Config dictionary: This is similar to the TPD file approach, however, you define the problem directly in a Python file; it's very useful if you want to experiment and don't want to keep making changes to a text file. You can later save the Config keywords to a TPD file.

TPD (ToPy Problem Definition) file

There is a minimal set of parameters which is required for successful definition of a ToPy problem:

PROB_TYPE  : comp
PROB_NAME  : mbb_beam_minimal
ETA        : 0.5
DOF_PN     : 2
VOL_FRAC   : 0.5
FILT_RAD   : 1.5
P_FAC      : 3
ELEM_K     : Q4
NUM_ITER   : 10

You can read more about successful problem definition here.

When the TPD file is defined, then the rest is simple:

from topy import Topology

topology = Topology()

Config dictionary

First you have to define a config dictionary (note the similarity with a TPD file, especially the keywords):

config = {
     'DOF_PN': 2,
     'ELEM_K': 'Q4',
     'ETA': '0.5',
     'FILT_RAD': 1.5,
     'FXTR_NODE_X': range(1, 22),
     'FXTR_NODE_Y': 1281,
     'LOAD_NODE_Y': 1,
     'LOAD_VALU_Y': -1,
     'NUM_ELEM_X': 60,
     'NUM_ELEM_Y': 20,
     'NUM_ELEM_Z': 0,
     'NUM_ITER': 94,
     'PROB_NAME': 'beam_2d_reci',
     'PROB_TYPE': 'comp',
     'P_FAC': 3.0,
     'VOL_FRAC': 0.5

The requirements are the same as for the TPD file.

topology = Topology(config=config)

Optimization (solving the problem)

You can use the command line solution:

$ python topy/scripts/ <filename>.tpd

Or you can use a Python script:

import topy

config = {...}
t = topy.Topology(config)

Visualization (seeing the result)

Module topy.visualization allows one to save the output as a .png image for 2D problems or as a .vtk file for 3D. The VTK files can be viewed with Mayavi or ParaView. You can animate the PNG images with the convert tool.

convert -delay 35 *.png anim.gif



Solved examples


How to cite ToPy

If you've used ToPy in your research work, please consider to cite:

  author = {Hunter, William and others},
  title = {ToPy - Topology optimization with Python},
  year = {2017},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{}},
You can’t perform that action at this time.