Topology optimization

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Topology optimization

Postby quick61 » Fri May 03, 2019 2:06 pm

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. :?

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
This post made with 0.0% Micro$oft products - GOT LINUX?
fandaL
Posts: 333
Joined: Thu Jul 24, 2014 8:29 am

Re: Topology optimization

Postby fandaL » Sat May 04, 2019 10:31 am

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)

Code: Select all

os.chdir("C:\\Users\\Fanda\\Application Data\\FreeCAD\\")  # directory with python files (macro directory)
2) 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"

3) 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:

Code: Select all

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)
4) Run beso_main.py as a macro in FC

5) 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
2D_example_in_Paraview.png (66.16 KiB) Viewed 620 times

EDIT: added point 1b, EDIT2: removed (code fixed)
Last edited by fandaL on Mon Aug 05, 2019 2:07 pm, edited 2 times in total.
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Topology optimization

Postby quick61 » Sat May 04, 2019 5:29 pm

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.

Code: Select all

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 -

Code: Select all

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. :?

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. ;)

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)
This post made with 0.0% Micro$oft products - GOT LINUX?
fandaL
Posts: 333
Joined: Thu Jul 24, 2014 8:29 am

Re: Topology optimization

Postby fandaL » Sat May 04, 2019 7:36 pm

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

Code: Select all

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

Code: Select all

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.
quick61 wrote:
Sat May 04, 2019 5:29 pm
... 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. ;)
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).
HoWil
Posts: 831
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Topology optimization

Postby HoWil » Tue May 14, 2019 8:00 am

quick61 wrote:
Fri May 03, 2019 2:06 pm
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?
+1 from my side and thanks for your efforts @fandaL
DMST1990
Posts: 7
Joined: Fri Jun 24, 2016 7:43 am

Re: Topology optimization

Postby DMST1990 » Wed May 29, 2019 12:47 pm

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
quick61 wrote:
Fri May 03, 2019 2:06 pm
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. :?

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
shIxx
Posts: 24
Joined: Wed Mar 28, 2018 10:13 am
Location: Bavaria (Germany)

Re: Topology optimization

Postby shIxx » Wed Jul 10, 2019 11:39 am

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

Code: Select all

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'
Jee-Bee
Posts: 1918
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Topology optimization

Postby Jee-Bee » Wed Jul 10, 2019 12:41 pm

DMST1990 wrote:
Wed May 29, 2019 12:47 pm
ping for shIxx
DMST1990
Posts: 7
Joined: Fri Jun 24, 2016 7:43 am

Re: Topology optimization

Postby DMST1990 » Fri Jul 19, 2019 8:58 am

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
shIxx wrote:
Wed Jul 10, 2019 11:39 am
@DMST1990
Hi,
I get this Error when using your Macro:

Code: Select all

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'
Last edited by DMST1990 on Mon Jul 22, 2019 8:51 am, edited 1 time in total.
jmaustpc
Posts: 9528
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Topology optimization

Postby jmaustpc » Fri Jul 19, 2019 1:36 pm

DMST1990 wrote:
Fri Jul 19, 2019 8:58 am
Hello shlxx,

well I think you are using FreeCAD 0.18, which is based on Python3
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.