Topology optimization

my first topology optimized part using “bezo” , this tool is awesome, thank you “fandaL”, (i want to send picture but as it is my first post on the forum i don’t know how)

The forum rules link above the help forum shows you how and other useful tips.

Hi!

it sounds to me there is a difference between topology optimization and shape optimization am I wrong?

Yes, but sometimes it is not so clear if you look at specific method.
Frequent classification in structural optimization is to

  • Size optimization - e.g. searching for width and high of cantilevered beam


  • Shape optimization - searching for outer shape, e.g. by moving surface nodes


  • Topology optimization - to find distribution of material in the space, i.e. each element is there or not

Thank’s for your answer!
Is there an order to run each optimization?

It depends on your task, tools available, and manufacturing possibilities. It’s hard to generalize.
When you are only improving existing model (solving some specific issue) you can use sizing optimization to vary radii, thickness of some features and so. If you are starting from a scratch you could use topology optimization, smooth results and then use shape optimization - maybe you can directly 3D print it, but if you would like to get rather inspired for drawing part by yourself, e.g. for milling, you can jump from topology optimization over shape optimization and use size optimization to get “human” readable or normalized dimensions instead of organic shapes.

@fandal

Thank’s for your answers ! it’s really interresting =)

I was wondering what is the status of the topology optimization using CalcliX FEM solver at this present time? its been 2 years, I was wondering if there are other topology optimization tools for FreeCAD

I can speak only according to my project https://github.com/fandaL/beso I don‘t know if someone else is planning to implement topology optimization to FreeCAD (e.g. https://github.com/DMST1990/ToOptiX )
I was thinking already long time ago about making a simple GUI for FreeCAD which would be easier to use for a basic task (in compare to setting manually all parameters in the python configuration file), but as you can see… I have not started yet. :neutral_face:

I created a macro for FreeCAD, so you can define a model in FreeCAD and start an optimization run by using a simple macro. The process will start externally, so that a termianl will pop up. There you have to wait for the results (which are located in the ToOptix folder ‘work’). (You can use FreeCAD during the analysis)


This works for simple 3D models with the first material definition as design space and the second material definition as the non design space by default.

https://github.com/DMST1990/ToOptixUpdate
You can use MayAvi as a post processor during the analysis as well (I would not recommend this and you have to install VTK).
The optimization settings can be defined in the file ‘run_optimization_freeCAD.py’.

So in may case you have to specify everything in a configuration file like in "fandaL"´s project.

Just a question, has anyone thought about making either one of these topology optimization, (beso or tooptix) scripts easier to use for us non-programmers? Like making them usable in FreeCAD’s Addon manager? I’ve been trying to get one or the other working for the past week and have no clue what the error messages are trying to tell me that fill up the report view. :confused:

Has anyone given any thought to rolling topology optimization into the FEM workbench? I’ve seen several videos on this being used in 3D printing and would like to explore the possibilities of this further. Seems like a useful tool to have included in the FEM workbench.

Mark

Hi Mark,
I was thinking about making a simple gui for basic function of beso, but did not get to do it. With that one could quickly get “cool looking” pictures, but for more realistic use you will still need to do some hacks.

You can try it in this way:

  1. Download python files from https://github.com/fandaL/beso (e.g. to your FC macro directory)

1b) Add this line in the beso_main.py after the 7th line “import os” (to enable running as a macro)

os.chdir("C:\\Users\\Fanda\\Application Data\\FreeCAD\\")  # directory with python files (macro directory)
  1. Make sure CalculiX folder location does not contain spaces, e.g. from “C:\Program Files (x86)\FreeCAD 0.18\bin\ccx.exe” I copied ccx.exe to “d:\soft\ccx.exe”

  2. Open FreeCAD FEM 2D example. Modify GMSH settings (Algorithm 2D = DelQuad, Characteristic Length Max = 50 mm, Element Order = 1st, Recombine All = true) to get fine and uniform mesh. Write the input for Calculix. I get “FEMMeshGmsh.inp” in the "c:\users\fanda\appdata\local\temp" folder.

  3. Modify these parameters in the beso_config.py file, e.g. on Windows I have:

path = "c:\\users\\fanda\\appdata\\local\\temp\\"  # path to your working directory
path_calculix = "d:\\soft\\ccx"  # CalculiX path must not contain spaces!
file_name = "FEMMeshGmsh.inp"
elset_name = "SolidMaterialElementGeometry2D"  # this is element set to be taken as the optimization domain. Name is found in the inp file
domain_thickness[elset_name] = [1000, 1000]  # thickness of void and solid elements if you use shells (in the 2D example)
filter_list = [["simple", 100]]  # filter range is 100 mm (I use 2times mesh size)
  1. Run beso_main.py as a macro in FC

  2. It takes time. Look at your working directory to .log file, import mesh to FC from fileXXX_state1.inp file or open resulting_states.vtk in Paraview (use threshold filter to look at various iterations)

P.S. trick to interrupt optimization (and defreeze FC) is to delete dat file which is actually being calculated by CalculiX in the working directory.
2D_example_in_Paraview.png
EDIT: added point 1b, EDIT2: removed (code fixed)

Thanks for the reply, but here is where I get with your instructions.

  1. Done
    2)Done
    3)Mod settngs-done. Write the input for Calculix -I get.
Traceback (most recent call last):
  File "/tmp/.mount_FreeCAwcg7MH/usr/Mod/Fem/femguiobjects/_ViewProviderFemSolverCalculix.py", line 68, in setEdit
    taskd = _TaskPanelFemSolverCalculix(self.Object)
  File "/tmp/.mount_FreeCAwcg7MH/usr/Mod/Fem/femguiobjects/_ViewProviderFemSolverCalculix.py", line 103, in __init__
    self.fea.setup_working_dir()
  File "/tmp/.mount_FreeCAwcg7MH/usr/Mod/Fem/femtools/ccxtools.py", line 517, in setup_working_dir
    self.working_dir = femutils.get_pref_working_dir(self.solver)
  File "/tmp/.mount_FreeCAwcg7MH/usr/Mod/Fem/femtools/femutils.py", line 140, in get_pref_working_dir
    setting_working_dir = run._getBesideDir(solver_obj)
  File "/tmp/.mount_FreeCAwcg7MH/usr/Mod/Fem/femsolver/run.py", line 174, in _getBesideDir
    os.makedirs(specificPath)
  File "/tmp/.mount_FreeCAwcg7MH/usr/lib/python3.7/os.py", line 211, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/tmp/.mount_FreeCAwcg7MH/usr/lib/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
<class 'OSError'>: [Errno 30] Read-only file system: '/tmp/.mount_FreeCAwcg7MH/usr/data/examples/FemCalculixCantilever2D'

Further, attempting to run beso_main.py gets me the following -

Traceback (most recent call last):
  File "/home/mark/.FreeCAD/Macro/beso_main.py", line 52, in <module>
    exec(open("beso_conf.py").read())
<class 'FileNotFoundError'>: [Errno 2] No such file or directory: 'beso_conf.py'
  • but the file, beso_conf.py, is right there in the macro folder along with all the other files from the repo. :confused:

Like I said, not a programmer and I certainly don’t want to sound like I’m complaining or begging for someone to hold my hand, as I know how hard everyone works that contributes to FreeCAD. Maybe I’ll drop this in to Open discussion as a feature request for the workbench. Topology optimization is evidently within the capabilities of Calculix and has just not been exploited on the workbench yet. Maybe one of the fine folks here might want to pick it up and add it to their list of 1001 things to do. :wink:

Mark

Edit - almost forgot -

OS: Kubuntu 18.04.2 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16540 (Git) AppImage
Build type: Release
Branch: master
Hash: 554985dede771f9a6694baba2372cc60db86f17b
Python version: 3.7.1
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)

Sorry, I did a mistake. See the EDIT (point 1b) in the previous post which should fix it for now (even it is not professional).

It happened since I typically copy the python code to the working directory (keeping its version with ccx inputs) and start the analysis from Ipython console with

cd d:\tmp\TaskDirectory
run beso_main

but cd and run does not work in FreeCAD console so I tried to run it as a macro, but for that one needs to set working directory to the macro directory, so the fix is to set working directory before running the macro

import os
os.chdir("C:\\Users\\Fanda\\Application Data\\FreeCAD\\")  # directory with python files (macro directory)

or add it directly to the code as in the EDIT (point 1b) in the post above.

CalculiX is here taken only as FE solver. The potential development options I see are:
a) Make a simple gui to the addon manager for beso or Tooptix or for both.
b) Write topology optimizer working with fcFEM instead of CalculiX. Direct access to the fcFEM solver code could make a lot of things easier (and be probably much faster).

+1 from my side and thanks for your efforts @fandaL

Hello Mark,

I will give it a shot. Right at the moment I need to get more familiar with the FreeCAD API,
so that the optimization depends on FreeCAD itself and not as a stand alone program.

I am working on a Micro-Service based architecture, so that you can switch between GUIS and several other aspects. So that fandls solution can use these GUI as well. In addition there are some code guidelines which are not covered by my code. This takes some time. The last problem in my Case is the Python2 dependency of FreeCAD. I am working with Python3, so that an external python installation is required until the implementation of Python3 in FreeCAD. So to summarize I need to implement:

  • GUI Development.
  • Micro Service architecture or service oriented architecture.
  • FreeCAD Python 2 to Python 3 dependencies.

I will start with these topics in about two month (There are some call for papers for me, with a dead line until the end of Juli).
If there are some dead lines by your side, I can at least craft a small GUI if necessary.


(Sorry for the late response, I am only looking only once a month in the FreeCAD forum)

Best Regards

Martin

@DMST1990
Hi,
I get this Error when using your Macro:

Traceback (most recent call last):
  File "C:/Users/TOM/AppData/Roaming/FreeCAD/Macro/FreeCADMacro.py", line 14, in <module>
    import commands
<class 'ModuleNotFoundError'>: No module named 'commands'

Hello shlxx,

well I think you are using precompiled version of FreeCAD 0.18 with Python3. In that FreeCAD-Version the module “commands” is not included.
Additionally in FreeCAD 0.18 the API has changed a little bit, so that it wont run.

This Macro is working for FreeCAD 0.17 precompiled on Python2.

Best Regards

Martin

Just a quick clarification, that is not correct which is one of the reasons why we always are telling people to post their version data in the manner explained in the forum rules. FreeCAD 0.18 supports Python 3 but can be compiled with Python 2, we agreed to transition all our recompiled install packages to Python3 on all platforms where is was practical to do so. However Ubuntu 16.04 LTS for example, is still a current supported LTS version but its Python3 version was too old to work with FreeCAD so it is offered with Python2. People who compile their own could also still compile with Python2. Of course Python2 is end of life very soon, if not already, so we are moving to Python3 wherever practical.