williamhunter / topy

Topology Optimization using Python
Other
481 stars 130 forks source link

Feature: Definition of problems directly in python #10

Closed gregerspoulsen closed 7 years ago

gregerspoulsen commented 8 years ago

Hi William

First of all great job creating topy, it has already been of great use to me! After working some time with topy I came up with a solution, which I think makes problem definitions easier and more flexible, I would love it if you would have a look and tell me what you think. If you like it, I will be happy to add some information to the wiki on how to use it.

The rest of the text is a brief description of the thoughts that led me to this idea.

To be honest, it took me some time in the beginning to get comfortable with the problem definitions, but after some paper sketches and debugging runs I managed to get going and have already manufactured a few items from the optimizations, thanks a lot! Later, when I was thinking about optimizing circular objects, I realized that it would be a bit cumbersome to define the problem, and that got me thinking that it maybe would make sense to define the problems directly in python to be able to calculate which nodes to constrain. That is when I started creating the class optimizer.py/Optimizer, and I realized that numpy slicing really could simplify problem definitions quite a lot. Try to have a look at the example file: examples/optimizer/basic.py, I think it is quite neat.

I also added the ability to optimize for multiple load cases. First of all, this is a very crude solution by creating multiple instances of the Topology class and swapping variables around - this can definitely be improved, but it works. I read the article by Sigmund: 'A 99 line topology optimization code written in Matlab', and tried to apply it to topy. To be honest, I am very new to the field of topology optimization and the mathematics behind it, so it would be great if you would have a look at the implementation to see if you think it makes sense. The code is not well documented yet, but hopefully enough for you to understand it; in the end, a lot is copy-pasted from other files. 'examples/optimizer/multi_load.py' demonstrated how to apply multiple load cases. Finally, I wrote an example to demonstrate how more advanced node constraints could be applied using equations to define circular objects: 'examples/optimizer/cylinder.py'

A few notes:

williamhunter commented 8 years ago

Hi, thanks for this, I will definitely look at it and will most probably include it. Will have some time over the weekend, will write again...

BTW, ToPy is loosely based on Sigmund's 99-liner..., see my thesis here, I think it is quite well explained: https://scholar.sun.ac.za/handle/10019.1/2648

On Wed, Dec 9, 2015 at 12:54 PM, gregerspoulsen notifications@github.com wrote:

Hi William

First of all great job creating topy, it has already been of great use to me! After working some time with topy I came up with a solution, which I think makes problem definitions easier and more flexible, I would love it if you would have a look and tell me what you think. If you like it, I will be happy to add some information to the wiki on how to use it.

The rest of the text is a brief description of the thoughts that led me to this idea.

To be honest, it took me some time in the beginning to get comfortable with the problem definitions, but after some paper sketches and debugging runs I managed to get going and have already manufactured a few items from the optimizations, thanks a lot! Later, when I was thinking about optimizing circular objects, I realized that it would be a bit cumbersome to define the problem, and that got me thinking that it maybe would make sense to define the problems directly in python to be able to calculate which nodes to constrain. That is when I started creating the class optimizer.py/Optimizer, and I realized that numpy slicing really could simplify problem definitions quite a lot. Try to have a look at the example file: examples/optimizer/basic.py, I think it is quite neat.

I also added the ability to optimize for multiple load cases. First of all, this is a very crude solution by creating multiple instances of the Topology class and swapping variables around - this can definitely be improved, but it works. I read the article by Sigmund: 'A 99 line topology optimization code written in Matlab', and tried to apply it to topy. To be honest, I am very new to the field of topology optimization and the mathematics behind it, so it would be great if you would have a look at the implementation to see if you think it makes sense. The code is not well documented yet, but hopefully enough for you to understand it; in the end, a lot is copy-pasted from other files. 'examples/optimizer/multi_load.py' demonstrated how to apply multiple load cases. Finally, I wrote an example to demonstrate how more advanced node constraints could be applied using equations to define circular objects: 'examples/optimizer/cylinder.py' A few notes:

  • I have only done 3D mechanical optimizations, I am quite sure the code does not work with lower dimensionality and other problem types.
  • I choose a lot of default values for parameters to make it simple to setup a problem without knowing what all parameters do, criticism is very welcome!
  • I thought about the idea that it might make sense to create multiple Optimizer classes with defaults for different types of problems
  • Optimizer.set_problem_dimensions was envisioned to make the problem scalable to easily increase resolution, the way I am using it right now that does not make perfectly sense, just ignore that.

You can view, comment on, or merge this pull request online at:

https://github.com/williamhunter/topy/pull/10 Commit Summary

  • Added Optimizer class for defining problems directly in python, this
  • Optimizer: Added ability to optimize with multiple load cases
  • Optimizer: Refined multiple load cases and added two examples on how to
  • Changed point ordering in vtk output to make ParaView axes match with
  • Realized that the node numbering started along y and not x, changed
  • Optimizer: bug fix multi load
  • Added cylinder example

File Changes

Patch Links:

— Reply to this email directly or view it on GitHub https://github.com/williamhunter/topy/pull/10.