Sunday, November 26, 2017

Installing ToPy in Fedora 26

This post summarizes the steps to install ToPy in Fedora 26.

Dependencies

Get the latest pysparse off the sourceforge git repo:
$ git clone git://pysparse.git.sourceforge.net/gitroot/pysparse/pysparse

The compile failed for me straight off the repo. This tiny change to an fprintf fixed it for me:

$ git diff
diff --git a/pysparse/direct/superlu/src/util.c b/pysparse/direct/superlu/src/util.c
index 6647ec2..7864cbb 100644
--- a/pysparse/direct/superlu/src/util.c
+++ b/pysparse/direct/superlu/src/util.c
@@ -29,7 +29,7 @@ SuperLUStat_t SuperLUStat;

void superlu_abort_and_exit(char* msg)
{
- fprintf(stderr, msg);
+ fprintf(stderr, "%s", msg);
exit (-1);
}

With that fix you should be good to go with a python setup.py install for pysparse. Get the lastest PyVTK
git clone https://github.com/pearu/pyvtk.git
This should then install with no problems: python setup.py install.

The other dependencies you can install from the Fedora repository if you don't already have them:
$ dnf install numpy python2-matplotlib sympy

Install

Here are the simple steps from the read-me:
Once you've downloaded the dependencies (see the INSTALL file) all you need to do is the following:

$ git clone https://github.com/williamhunter/topy.git
$ cd topy/topy
$ python setup.py install

Alternatively, you can download the latest stable release, but it usually lags a little behind the Master branch (as can be expected).

Try an Examples

Check out the install by running one of the examples that ships with ToPy. From the directory where you cloned the repo,
$ cd examples/mbb_beam/
$ python optimise.py beam_2d_reci_gsf_fine.tpd

The first time you run ToPy it will do some symbolic algebra to generate the elements for the FEA, then it will start iterating through the problem defined by in beam_2d_reci_gsf_fine.tpd (tpd stands for ToPy Problem Definition, a text file describing the problem and solver parameters). After many iterations the solution should look something like the picture at the top of this post.

I also prefer to make png's of the output with the Image module using the fromarray function. I convert the ToPy design variables from floats to integers using Scipy's uint8 function. This will produce nicer pixel-for-pixel output of your topology optimization problem rather than mangling it through matplotlib.

2 comments:

  1. Fork of ToPy with 2D image output changed to use PIL instead of matplotlib: https://github.com/jstults/topy.git

    ReplyDelete