Topology optimization

I have tried this way but callculix is giving an error.
Apparently, all materials must be meshed so that calculix can write the input file.

0.0: Check dependencies...
4.8: Write .inp file failed!

Report view:

ERROR: femelement_table != count_femelements
Count FEM elements as sum of constraints:  5302
Count FEM elements of the FreeCAD FEM Mesh:   5239
Error in get_femelement_sets -- > femelements_count_ok() failed!
Constraint fixed: FemConstraintFixed
  nodes will be retrieved by searching the appropriate nodes in the FEM mesh
  ReferenceShape ... Type: Face, Object name: Box, Object label: Solid, Element name: Face1
Constraint force: FemConstraintForce
Writing time input file: 4.76 seconds 
Problems on writing input file, check report prints.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16131 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 3129ae4296e40ed20e7b3d460b86e6969acbe1c3
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
NonDesignRegion_not_working.png

Hi Blaze,
Ordinary FreeCAD way for multiple materials (instead of booleans like cut, union, and intersection) is to use:
Part → Split → Boolean Fragments
and in its property view (data) select Mode=CompSolid
https://www.freecadweb.org/wiki/Part_BooleanFragments

since when this object is meshed, sub-shapes boundaries are connected properly by nodes. Than you apply materials to the CompSolid. Later, you select material object as a design domain in optimization.

Non-design domain (i.e. rest of the model) does not have to be explicitly defined in the optimization GUI (unless you want to track stress in the non-design domain during optimization or display also non-design mesh in the results).

I got same error if I defined explicitly one material to one box, second material to second box. The error means that there are overlapping mesh selections and FreeCAD does not know which material should be in the overlapping section.
The way around is to select geometry only for the “non-design” box inside “non-desing” material object. “Design” material (i.e. original geometry which is meshed) should have empty geometry selection, which means to select automatically rest of the elements which are not selected explicitly by other material objects.

THX for answer. Now I have another question. What am I doing wrong I can’t define non design area as domain in BESO GUI ? I am able to show in results only optimised area. I have done intersection, I have added material to both solids, but in gui i am able to chose only one solid.
Adnotacja 2019-10-18 140452.PNG.jpg

There was a bug related to FC0.18. Now it should be fixed, so you can download updated file https://github.com/fandaL/beso/blob/master/beso_fc_gui.py

Just a note to be sure: If you create new materials and have beso gui already opened, you should click “Update domains”. But be sure to also recreate inp file from FreeCAD as if you start ordinary analysis after model modifications.

Hi fandaL,

I am very interested in your macro. I tried to use it but I can’t get any results. Maybe I am not understanding something.

In the macro, I put the .inp file that it is generated by Freecad after running the calculix analysis; in the range, the double size of the element size and the rest as default and then I push the “Generate conf. file and run optimization” button.

But the output .inp file is the same as the original. In the log file I have the error: CalculiX result file not found, check your inputs.

Maybe am I using a wrong input file?

Best regards

I suppose that you checked original inp file by running CalucliX from FreeCAD and checked that results are correct.

In the working directory there should be „file000.inp“ which is rewritten inp file from the original input for the 0th iteration. There could be some error runnig CaluliX on it.
To check CalculiX errors, you can run ccx manually from command line, e.g. on windows by the command

C:/soft/FreeCAD_0.19.18234_x64_LP_12.1.2_PY3QT5-WinVS2015/bin/ccx.exe  C:/wording_dir/FEMMeshGmsh

where I took it according to parameters on the top of beso_conf.py, e.g.

path_calculix = 'C:/soft/FreeCAD_0.19.18234_x64_LP_12.1.2_PY3QT5-WinVS2015/bin/ccx.exe'
path = 'C:/wording_dir'
file_name = 'FEMMeshGmsh.inp'

Edit:
Results in file000.frd should than contain similar results as from original analysis (drug and drop it to FreeCAD). file000.dat should contain many numbers under the heading “internal energy density…”

Hi again, fandaL
It was my mistake. Although the FEM simulation was working well in Freecad, I wrote the .inp file in another folder but didn’t run calculix in it. That’s why the BESO macro didn’t work.

Thanks and best regards

Hi, fandaL

Can I suggest a couple of features in BESO GUI?

Is it possible to put an iteration limit and/or a button to cancel the optimization process?

Best regards

To enforce finishing, you can terminate CalculiX process in the Task Manager so that optimization should give the error due to missing CaluliX results. Maybe later I will add a button to do something like this.

Iterations limit can be set by editing configuration file beso_conf.py by adding a line (e.g. for 10 iterations)

iterations_limit = 10

Hi, fandaL

Thank you for your kind answers!

I have another question. Is it possible to convert the optimized FEM mesh into a solid infill? I can only get a hollow mesh after exporting it as a .stl and then importing it into the PART module.

Best regards

You can select the mesh and use command from Part workbench: Part → Create shape from mesh…

It works on geometric meshes (e.g. as you import from stl). FreeCAD can convert also FEM meshes but they need to be first converted to geometric mesh in the FEM workbench: Mesh → FEM mesh to mesh

You can get easily to difficulties with working with geometry converted from mesh due to many faces. It can be partially useful to refine at least flat faces of new geometry (Part → Refine shape), but in case of topologically optimizer results there are often not much of them.
Imported mesh also often contains errors which (if not much serious) can be repaired in the Mesh module: Meshes → Analyze → Evaluate and repair mesh…

Thank you very much, fandaL

Is it possible to use these macros on Linux or do they need some code adaptations?

Best regards

It is written in python and uses libraries which are available in FreeCAD, CalculiX path is taken from path defined in FreeCAD FEM settings so it should work on both Linux and Windows fluently. I did not try it on MAC. You need FreeCAD 0.18 or 0.19.

I tried it on i think 0.18 on osx some time back but not recently

Hi,

I am having trouble getting this macro to work. I am unable to select a domain in the macro GUI and am receiving the error “None optimized domain has been found. Check your inputs.” in the log file.

Thanks!

Hi and welcome to the forum.
Supposing you use new FreeCAD version 0.19, some naming has changed since I tested it last time. It should be fixed now (by added new lines 466 and 467 in beso_fc_gui.py https://github.com/fandaL/beso/commit/98f884ff75e749f6266d9044a2bbcac4d8656dbd ).

if your intention is type checking of FEM object better to use https://github.com/FreeCAD/FreeCAD/blob/45b96ca3516c8a0b4c7cb6ec55fc594837659878/src/Mod/Fem/femtools/membertools.py#L39 if inside an analysis (see module end for examples) or for single type checking see https://github.com/FreeCAD/FreeCAD/blob/45b96ca3516c8a0b4c7cb6ec55fc594837659878/src/Mod/Fem/femtools/femutils.py#L86 all type can be found here: https://github.com/FreeCAD/FreeCAD/blob/45b96ca3516c8a0b4c7cb6ec55fc594837659878/src/Mod/Fem/femtest/app/test_object.py#L149

I am stepping through the release announcement of FC 0.19 to update the Wiki accordingly. This way I found this feature.

When using the addon manager I don’t find a macro named “Beso”. Can you please add it so that beso can be installed via the AddonManager?

I can use the macro but as it is, it needs some work until everything is set up. Thus having Beso in our addon manager would be very helpful.

One remark: after starting the optimization, Windows steps quickly in telling me the application is not responding. It attempts to stop it. Can you therefore please have a look. The program needs of course a lot of time until it finished the calculation, but it must tell the OS that it is still alive.

Many thanks. However, I cannot find your addon on the Addon Manager of FreeCAD. Can you please add your macro there?

I tried ToOptix via
https://github.com/VoxelBeaver/ToOptixFreeCADAddon
But the instructions there are outdated. At least the development version of FreeCAD 0.19 uses by default Python 3 (despite Python 2 is still supported). So I have Python 3 with FreeCAD, but when executing ToOptix, I get:

<class 'SyntaxError'>: ('invalid syntax', ('C:/Users/stoehr/AppData/Roaming/FreeCAD/Macro/FreeCADMacro.py', 9, 35, 'python3_path = # Enter python path\n'))

Therefore It would be cool, if this path is automatically detected.

However, I tried to add the path by myself, but get

<class 'SyntaxError'>: ("(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape", ('C:/Users/stoehr/AppData/Roaming/FreeCAD/Macro/FreeCADMacro.py', 10, 20, "installation_path = 'C:\\Users\\stoehr\\AppData\\Roaming\\FreeCAD\\Macro'\n"))

In the macro I have this:

python3_path = 'D:\FreeCAD-build\FreeCADLibs_12.3.2_x64_VC15\bin'
installation_path = 'C:\Users\stoehr\AppData\Roaming\FreeCAD\Macro'

So one first have to learn Python to understand that '' has to be input as ‘\’.

OK, I managed to specify the path to Python 3, but then I get this error:

  File "C:/Users/stoehr/AppData/Roaming/FreeCAD/Macro/FreeCADMacro.py", line 14, in <module>
    import commands
<class 'ModuleNotFoundError'>: No module named 'commands'

I am now stuck. What do I have to do?

my system:

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22440 (Git)
Build type: Release
Branch: master
Hash: 42d643c8f70df94944cf87848574b79ab536f888
Python version: 3.6.8
Qt version: 5.12.6
Coin version: 4.0.0a
OCC version: 7.4.0.beta
Locale: German/Germany (de_DE)