Topology optimization

About the development of the FEM module/workbench.

Moderator: bernd

shIxx
Posts: 83
Joined: Wed Mar 28, 2018 10:13 am
Location: Bavaria (Germany)

Re: Topology optimization

Post by shIxx »

Hello at all,

It's now been over a year since I last saw this thread and I wonder how it will go on. This simple GUI is really practical, but the macro cannot be found in the addon manager. For most people it is not visible that FreeCAD offers such a great feature that I would never have dreamed of for an open source free software.
So the question arises whether the code can simply be transferred to the FEM WB, as a new feature of the FEM WB. I know beso could be optimized, especially with regard to the speed of the algorithm, but it works amazingly well and everyone should benefit from it.
fandaL
Posts: 440
Joined: Thu Jul 24, 2014 8:29 am

Re: Topology optimization

Post by fandaL »

Hi,
one way is to look how to make it available in Addon Manager and improve current algorithm which becomes messy due to other (experimental) features which are not much used.

Just a question, if you (or others) use beso:
1) Do you modify config file manually or use only features which are available through GUI?
2) Do you modify calculix input file?
3) Do you benefit from having a set of results for different volumes (iterations) or do you use only the final solution?

There are other methods than BESO, which are more efficient if typical solid-void results are required and only final solution is required. For that use case it would make more sense to remake the code from the beginning (ideally as a part of some existing FEM solver) or to implement other existing code to FreeCAD – there are good academic codes of solvers with topology optimization.
shIxx
Posts: 83
Joined: Wed Mar 28, 2018 10:13 am
Location: Bavaria (Germany)

Re: Topology optimization

Post by shIxx »

I actually only use FreeCAD at home for 3D printing cases and my mini CNC. It's much more of a hobby.
I'm also not familiar with topology optimization and I don't want to study the code from an academic point of view or anything.

I think it's just impressive what the open source community can do. BUT there are also practical use cases.
E.g. I have already used BESO a few times to save material and especially time when printing larger models.

And to be honest, optimized parts just looks more sexy 8-)

1.) I mainly use the GUI (98%)
2.) No
3.) It would be great having results for different iterations
User avatar
Pauvres_honteux
Posts: 728
Joined: Sun Feb 16, 2014 12:05 am
Location: Far side of the moon

Re: Topology optimization

Post by Pauvres_honteux »

fandaL wrote: Wed Dec 01, 2021 9:08 pm
Hi fandaL, will you try to get this into the AddonManager?

AstaBlak wrote: Fri Jun 18, 2021 8:52 am
Hi AstaBlak, will you try to update the code?
thschrader
Veteran
Posts: 3129
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Topology optimization

Post by thschrader »

shIxx wrote: Thu Dec 02, 2021 8:26 pm I actually only use FreeCAD at home for 3D printing cases and my mini CNC. It's much more of a hobby.
...
A industrial use is possible.
Optimizing the shape of a clamp using FC and Z88 Arion:
https://z88.de/z88arion/

Workflow:
1. in FC mesh body with 1.Order mesh
2. Export mesh as Abaqus inp-file
3. Load mesh in Arion, run optimization
4. Export shape as stl, load stl in FC
5. Redraw body ;)

Maybe it is possible to integrate Z88 Arion solvers in FC like Z88 Aurora solver...
clamp.JPG
clamp.JPG (131.57 KiB) Viewed 3703 times
ings3319
Posts: 1
Joined: Sat Jul 15, 2023 12:43 pm
Contact:

Re: Topology optimization

Post by ings3319 »

Hi, i'm trying beso since this year (2023), i know it since last year (2022) but never had a chance to use it. and now i can run it. Thanks for your effort.

1. For the 1st time run, i'm using GUI via freecad0.19. And then i usually edit the beso_conf.py and make some changes. The original beso_conf.py helps. in fc0.20 it usually produce this warning "calculix input not xxx\-u not found", i workaround this by rename the file inp to just "-u" and it works.
2. I didn't modify .inp, rather i open the .inp file to see which elset to be the design domain, and then i edit the beso_conf.py (thanks for case sensitive warning). And for the time being, im using inp file that produced from Prepomax1.4.0, since i just need simpler boundary condition and loads.
3. Yes, i need the iteration file, at least i can see the process. This is my beso_conf file look like,

Code: Select all

path_calculix = 'D:\\path2\\ccx_static2.exe'
path = 'D:\\_runbeso'
file_name = "Analysis-1.inp"

elset_name = 'Element_set-1'
domain_optimized[elset_name] = True
domain_density[elset_name] = [2.4e-15, 2.4e-09]

domain_material[elset_name] = ['*ELASTIC\n0.032, 0.17\n*DENSITY\n2.4e-15\n*CONDUCTIVITY\n0.0\n*EXPANSION\n0.0\n*SPECIFIC HEAT\n0.0\n',
                               '*ELASTIC\n32000.0, 0.17\n*DENSITY\n2.4e-09\n*CONDUCTIVITY\n0.0\n*EXPANSION\n0.0\n*SPECIFIC HEAT\n0.0\n']

mass_goal_ratio = 0.4
filter_list = [['simple', "auto"]]

optimization_base = 'stiffness'

mass_addition_ratio = 0.01
mass_removal_ratio = 0.02
ratio_type = 'relative'

iterations_limit = "auto" 
save_iteration_results = 1
save_solver_files = "frd"
save_resulting_format = "inp"
For the time being, im using this batch script to generate so-called animation file, i name it cgx_produce.bat, and run it in folder where the iteration file exist. This will create video file .mp4 that consist of merged 4 view (iso, top, front, side). i'm using cgx hcpy to create tga files (2nd lines).

Code: Select all

Md o_tga
for /f "delims=." %%a in ('dir *state*.inp /on /b') do (echo read %%a.inp add > %%a.tmp & echo rot y >> %%a.tmp & echo rot r 30 >> %%a.tmp & echo rot u 30 >> %%a.tmp & echo hcpy >> %%a.tmp & echo rot y >> %%a.tmp & echo rot r 90 >> %%a.tmp & echo hcpy >> %%a.tmp & echo rot y >> %%a.tmp & echo hcpy >> %%a.tmp & echo rot y >> %%a.tmp & echo rot u 90 >> %%a.tmp & echo hcpy >> %%a.tmp & echo exit >> %%a.tmp & cgx -b %%a.tmp & ren hcpy_1.tga %%ai.tga & ren hcpy_2.tga %%ax.tga & ren hcpy_3.tga %%ay.tga & ren hcpy_4.tga %%az.tga & del %%a.tmp & del %%a.fbd & move %%a*.tga o_tga)
del ?__.tga
cd o_tga
md 0 1
for /f "tokens=1,2 delims=." %%a in ('dir *state0*.tga /on /b') do (magick convert %%a.%%b -crop 608x628+169+4 0\%%a.%%b)
for /f "tokens=1,2 delims=." %%a in ('dir *state1*.tga /on /b') do (magick convert %%a.%%b -crop 608x628+169+4 1\%%a.%%b)
cd 0
for /f "tokens=1,2,3 delims= " %%a in ('dir *.tga /on /b ^| paste - - ^| nl -nrz ^| gawk "{print $1, $2, $3}"') do (magick convert +append %%b %%c %%a.jpg)
for /f "tokens=1,2,3 delims= " %%a in ('dir *.jpg /on /b ^| paste - - ^| nl -nrz ^| gawk "{print $1, $2, $3}"') do (magick convert -append %%b %%c %%a.png)
del *.jpg
md merge
move *.png merge
cd ..
cd 1
for /f "tokens=1,2,3 delims= " %%a in ('dir *.tga /on /b ^| paste - - ^| nl -nrz ^| gawk "{print $1, $2, $3}"') do (magick convert +append %%b %%c %%a.jpg)
for /f "tokens=1,2,3 delims= " %%a in ('dir *.jpg /on /b ^| paste - - ^| nl -nrz ^| gawk "{print $1, $2, $3}"') do (magick convert -append %%b %%c %%a.png)
del *.jpg
md merge
move *.png merge
cd ..
md gif
magick convert 0\file*state0i.tga gif\0i.gif
magick convert 0\file*state0x.tga gif\0x.gif
magick convert 0\file*state0y.tga gif\0y.gif
magick convert 0\file*state0z.tga gif\0z.gif
magick convert 1\file*state1i.tga gif\1i.gif
magick convert 1\file*state1x.tga gif\1x.gif
magick convert 1\file*state1y.tga gif\1y.gif
magick convert 1\file*state1z.tga gif\1z.gif
cd gif
for /f "tokens=1,2 delims=." %%a in ('dir *.gif /b') do (ffmpeg -i %%a.%%b -c:v libx264 -crf 23 -profile:v baseline -level 3.0 -pix_fmt yuv420p -c:a aac -ac 2 -b:a 128k -movflags faststart -filter:v fps=30 %%a.mp4)
rem for /f "tokens=1,2 delims=." %a in ('dir *.gif /b') do (ffmpeg -i %a.%b -c:v libx264 -crf 23 -profile:v baseline -level 3.0 -pix_fmt yuv420p -c:a aac -ac 2 -b:a 128k -movflags faststart -filter:v fps=30 %a.mp4)
rem --- disini ngambil dari iMVM02.bat
rem --- 1 -------------------------------
set nomor=1
set var_nama_out1=0i
set var_nama_out2=0x
set var_nama_out3=0y
set var_nama_out4=0z
set var_nama_outfolder=merge%nomor%%var_nama_out1%%var_nama_out2%%var_nama_out3%%var_nama_out4%
ffmpeg -i "%var_nama_out1%.mp4" -i "%var_nama_out2%.mp4" -i "%var_nama_out3%.mp4" -i "%var_nama_out4%.mp4" -filter_complex "[0:v][1:v]hstack[t];[2:v][3:v]hstack[b];[t][b]vstack[v]" -map "[v]" "%var_nama_outfolder%.mp4" <NUL
echo %var_nama_out1%
echo %var_nama_out2%
echo %var_nama_out3%
echo %var_nama_out4%
echo %var_nama_outfolder%
rem --- 2 -------------------------------
set nomor=2
set var_nama_out1=1i
set var_nama_out2=1x
set var_nama_out3=1y
set var_nama_out4=1z
set var_nama_outfolder=merge%nomor%%var_nama_out1%%var_nama_out2%%var_nama_out3%%var_nama_out4%
ffmpeg -i "%var_nama_out1%.mp4" -i "%var_nama_out2%.mp4" -i "%var_nama_out3%.mp4" -i "%var_nama_out4%.mp4" -filter_complex "[0:v][1:v]hstack[t];[2:v][3:v]hstack[b];[t][b]vstack[v]" -map "[v]" "%var_nama_outfolder%.mp4" <NUL
echo %var_nama_out1%
echo %var_nama_out2%
echo %var_nama_out3%
echo %var_nama_out4%
echo %var_nama_outfolder%
rem --- 3 -------------------------------
set nomor=3
set var_nama_out1=0i
set var_nama_out2=1i
set var_nama_out3=0y
set var_nama_out4=1y
set var_nama_outfolder=merge%nomor%%var_nama_out1%%var_nama_out2%%var_nama_out3%%var_nama_out4%
ffmpeg -i "%var_nama_out1%.mp4" -i "%var_nama_out2%.mp4" -i "%var_nama_out3%.mp4" -i "%var_nama_out4%.mp4" -filter_complex "[0:v][1:v]hstack[t];[2:v][3:v]hstack[b];[t][b]vstack[v]" -map "[v]" "%var_nama_outfolder%.mp4" <NUL
echo %var_nama_out1%
echo %var_nama_out2%
echo %var_nama_out3%
echo %var_nama_out4%
echo %var_nama_outfolder%
rem --- disini pindahin ke folder -------------
md ..\mp4
move *.mp4 ..\mp4
And i notice that since cgx 2.20, it has capabilities that i recently notice, i.e. cmap coolwarm, view vec. I can see the so-called stress trajectory with better color (red for tension, blue for compresion) with vector while i see the worstPS stress.

To make generated still image, im using batch script that can be named "generate_section_fbl.bat". This is run in folder where file named "analysis-1.frd" reside. the batch file will produce run.fbl than can be run by cgx.

Code: Select all

if [%1]==[] goto exit
set batas_bawah=-3500
set batas_atas=15500
set jarak=%1
seq -f %%05g %batas_bawah% %jarak% %batas_atas% | gawk "{print $1, $1, $1, 0, 1, 0, 0, 0, 1}" | gawk "{print $1, $2, $3}" | tr " " \n > temp_x
seq -f %%05g %batas_bawah% %jarak% %batas_atas% | gawk "{print $1, $1, $1, 0, 1, 0, 0, 0, 1}" | gawk "{print $4, $5, $6}" | tr " " \n > temp_y
seq -f %%05g %batas_bawah% %jarak% %batas_atas% | gawk "{print $1, $1, $1, 0, 1, 0, 0, 0, 1}" | gawk "{print $7, $8, $9}" | tr " " \n > temp_z
paste temp_x temp_y temp_z | gawk "{print $1, $2, $3}" | nl -nrz | gawk "{print \"pnt psc\"$1, $2, $3, $4}" > temp_pnt
type temp_pnt | gawk "{print $2}" | paste - - - | gawk "{print \"cut\", $1, $2, $3}" | nl | gawk "{print \"# Cut ke-\"$1\",\"$2, $3, $4, $5}" | sed "s/$/,hcpy/g" | tr , \n > temp_cut
rename temp_pnt header2
rename temp_cut content
del temp_*

echo read Analysis-1.frd new > header1
echo view edge >> header1
echo view elem off >> header1
echo rot x >> header1
echo rot c 90 >> header1
echo rot r 45 >> header1
echo rot u 30 >> header1
echo frame >> header1
echo cmap coolwarm >> header1
echo ds 2 e 23 >> header1
echo mm >> header1
echo scal s 0.5 >> header1

echo exit > footer

copy header1+header2+content+footer run.fbl
cgx -b run.fbl
rem call moveaja_wo_frd.bat %1
:exit
i m using ccx 2.20, cgx 2.20, ccx2paraview, magick, ffmpeg, unxutil(grep, sed, gawk,nl, seq etc). at least cgx, magick, ffmpeg, and unxutils should be in path.

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29603 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Behave-Dark-Colors 0.1.1
  * BIM 2021.12.0
  * Curves 0.5.7
  * Dracula 0.0.2
  * ExtremeProDark 1.0.4
  * FEMbyGEN 1.2.0
  * Help 1.0.3
  * ProDarkThemePreferencePack 1.0.0
fandaL wrote: Wed Dec 01, 2021 9:08 pm Hi,
one way is to look how to make it available in Addon Manager and improve current algorithm which becomes messy due to other (experimental) features which are not much used.

Just a question, if you (or others) use beso:
1) Do you modify config file manually or use only features which are available through GUI?
2) Do you modify calculix input file?
3) Do you benefit from having a set of results for different volumes (iterations) or do you use only the final solution?

There are other methods than BESO, which are more efficient if typical solid-void results are required and only final solution is required. For that use case it would make more sense to remake the code from the beginning (ideally as a part of some existing FEM solver) or to implement other existing code to FreeCAD – there are good academic codes of solvers with topology optimization.
Attachments
pic
pic
out.png (96.24 KiB) Viewed 1124 times
Last edited by ings3319 on Sat Jul 15, 2023 1:51 pm, edited 1 time in total.
Post Reply