Giter Club home page Giter Club logo

beso's Introduction

beso

Python code for a topology optimization using CalculiX FEM solver. beso stands for a method coined:

Bi-directional
Evolutionary
Structural
Optimization

An in-depth description of beso and its capabilities are available on the dedicated beso wiki.

fine mesh initial smooth

Prerequisites

  • CalculiX >= v2.17
  • numpy
  • FreeCAD >= v0.18

Installation

Usage

Description with a simple example are in wiki.

Developer

@fandaL

License

LGPLv3 (LICENSE)

beso's People

Contributors

fandal avatar grindhold avatar habermannr avatar luzpaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beso's Issues

GUI example not compatible with Python version >3.4?

Hello,

I've been trying to get the GUI demo working on my computer (MacOS 10.15.5 and FreeCAD v0.18.4) and it looks like PySide has transitioned to PySide2 for versions of Python beyond 3.4 (I'm running 3.6.7). However, it looks like the two are not easily interchangeable and the macro debugging features in FreeCAD are not working for me. Please let me know how I can extract a more helpful error message, but the only feedback I'm getting from FreeCAD is that when I try to run the macro, a traceback shows up at the bottom of the window but gets cut off before I can see any actually useful information.

The reason I'm suspecting PySide as a culprit is because when I try to run the macro from the terminal, I get an exception about not being able to find the PySide module, which I can't have for the version of Python I'm using. I would continue to debug in this way, but eventually I'd need the FreeCADGui module, and I haven't found how to install it outside of the FreeCAD environment (if that even makes sense to try).

If there's any additional information I can provide to help, please let me know. Thanks!

Discontinuity in Optimisation Results Using Stiffness as Base

Hello,

I am working on an optimization problem where I am using stiffness as the base. Here are the details of my setup:

  • Load: 1200N
  • Mass goal ratio: 0.3
  • Material: Aluminium 6061-T6

For the boundary condition preservation, I have added the nodes into another ELSET and set its domain optimisation
to false.

I have attached an image showing the boundary conditions for my problem. However, I am observing some discontinuities in the result file, which I did not expect. I have also attached an image of these results for reference.

Could anyone provide some insight into why these discontinuities might be occurring? Any help would be greatly appreciated.

Thank you.
GEBracketInputs
GEBracketIssue

Deflection constraint and goal

Hi again. :)

While being able to minimize compliance with the optimization_base = "stiffness" is great, I feel that there's a need for being able to also have the stiffness as an input since it is often a requirement in the part design and in my opinion would make more sense as an input than having a goal mass does. When we design mechanical components, the constraints are often: space usage, interface faces, stress level and a either certain or minimum stiffness while the mass is just to be kept as low as possible within the constraints in addition to manufacturing constraints.
The beso script allows for control of all except for the stiffness constraint so if that could be implemented, then it would improve the usefulness.

I imagine that an implementation might be similar to how the failure index imposes an optimization constraint. The constraint could either be maximum deflection of all the nodes in the *ELSET or it could be the deflection of a particular node. The constraint should be possible to be placed on either the total deflection or a directional deflection.

A related thing is if the deflection in a node was an optimization goal like the mass is in the beso code. This would allow the design of flexible mechanisms while under load. A deflection boundary condition also does something to create flexible mechanisms by making something that moves a certain way with low stresses but I believe that this should then be used in addition to a load and a deflection goal in another direction as that could be among the functional requirements for a mechanism but where a boundary condition would not be realistic due to reacting forces through it.

How to set the value of radius in filter_list?

When radius = 1.0, the result is mass.
When radius = 4.0, the result is OK.
When radius = 10.0, the result is Good.
The radius of filter_list has too much influence on the result. So I have two questions about it.
1、The radius cannot be too small for this model, Why is avarage values of nearby elements so important?
2、How to set the value of radius for the users?
part2
rad1
rad4
rad10

part2.zip

Documentation for non-design spaces

Hi,

I have been using this project for a little while now and have got some nice designs out of it for my 3D printer.

One area that I have really struggled to understand is how to exclude areas from the optimization. For example areas that must fit with other parts.

I notice in Example 2 in the wiki it makes mention of "Geometry was divided by intersections to obtain non-design space around bolts and a pin." I wonder if this could please be expanded on as I am not sure how to achieve this? I did take a look on the forums, and while I found some discussions about the project. I still couldn't figure this out.

If I am able to understand how it work, I would happily write up some documentation with screenshots etc to help others use this project for 3D printing etc.

Thanks,
hopoffbaby

No module named 'beso_lib'

I had problems setting "Aluminum-Generic" as the material card:

Traceback (most recent call last):
File "C:/Users/User/Downloads/beso-master/beso_fc_gui.py", line 936, in on_click24
self.on_click21() # generate beso_conf.py
File "C:/Users/User/Downloads/beso-master/beso_fc_gui.py", line 637, in on_click21
raise Exception(" units not recognised in " + self.materials[elset_id].Name)
Exception: units not recognised in MaterialSolid

Then, I changed it to "Aluminium-6061-T6" and the error changed to this:

Traceback (most recent call last):
File "C:/Users/User/Downloads/beso-master/beso_fc_gui.py", line 937, in on_click24
self.on_click23() # run optimization
File "C:/Users/User/Downloads/beso-master/beso_fc_gui.py", line 933, in on_click23
exec(open(os.path.join(beso_gui.beso_dir, "beso_main.py")).read())
File "", line 12, in
File "C:\Users\User\AppData\Local\Programs\FreeCAD 0.20\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport_feature_.py", line 142, in _import
return original_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'beso_lib'

The same happened when I setted the material to "PLA-Generic". I'm new to this CAD and I'm sorry if this was just a stupid minor mistake from myself.

Some questions about examples

I have two questions:
1、All the examples show that non-design-space material is same with design-space. Non-design-space is often loading or fixing area, So the same material would get better result, Is it right?
2、Calculix can solve nonlinear contacting model. If some contacting elements are removed or added back, The vonmises values of those elements maybe not exact. So topo optimazition is better match for linear analysis type. Is it right?

when trying to run optimization error accures

14:41:59 Traceback (most recent call last):
14:41:59 File "A:/beso-master\beso_lib.py", line 633, in import_FI_int_pt
14:41:59 f = open(file_nameW + ".dat", "r")
14:41:59 FileNotFoundError: [Errno 2] No such file or directory: 'A:/beso-master\file000.dat'
14:41:59
During handling of the above exception, another exception occurred:

14:41:59 Traceback (most recent call last):
14:41:59 File "A:/beso-master/beso_fc_gui.py", line 937, in on_click24
14:41:59 self.on_click23() # run optimization
14:41:59 File "A:/beso-master/beso_fc_gui.py", line 933, in on_click23
14:41:59 exec(open(os.path.join(beso_gui.beso_dir, "beso_main.py")).read())
14:41:59 File "", line 392, in
14:41:59 File "A:/beso-master\beso_lib.py", line 637, in import_FI_int_pt
14:41:59 assert False, msg
14:41:59 AssertionError: CalculiX result file not found, check your inputs

FreeCad Version: 0.20.1

Calculix doesn't output results for very large meshes in the default solver option.

I appreciate the great implementation that you have made for Freecad, but I had some issues regarding massive meshes.
I am having a general issue of not getting any results out of Calculix whenever the mesh size is huge. For example, it seems to happen when the mesh has more than 1 million nodes. Please refer to this thread I posted in the Freecad forum: https://forum.freecad.org/viewtopic.php?p=728901#p728901

I did find a way to make it work by selecting either of the iterativescaling or iterativecholesky option rather than the default solver option. However, the beso implementation seems to stop functioning when using the iterative solver options. It works to the point where file000.12d, file000.cvg, file000.dat, file000.frd, file000.sta, and etc are created but after that, it simply stops the process and cpu utilization goes to idle while still having all the ram loaded up with the data. I tried leaving it for multiple hours, but it appears to be stuck. Do you have any ideas of what might be a issue here?

Mass is removed from the surface under load

Hi,
I've noticed an unexpected behavior in the simulation where mass seems to be removed from the surface under load. The constraints are depicted in the attached image. The mass goal ratio is set to 0.5. In the output image provided, it's evident that some mass has been removed from the loaded surface. I have highlighted the removed region in the image.

Appreciate any insights or suggestions on how to resolve this issue.

OriginalFileWithInputs
LoadSurfaceIssue

path not used

Line 294 in beso_main should be:
file_nameW = os.path.join(path, "file" + str(i).zfill(3))

gui - CalculiX opens in foreground

When using python inside command line, CalculiX runs in that command line. But when FreeCAD GUI is used, CalculiX opens everytime in foreground, which is not comfortable.

Can not run CalculiX

Hello,
When I run the example, I always get the following error, which looks like CalculiX is not analyzing the file000.inp file.
`Traceback (most recent call last):
File "D:\beso-master\wiki_files\example_2\beso_lib.py", line 578, in import_FI_int_pt
f = open(file_nameW + ".dat", "r")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'file000.dat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\beso-master\wiki_files\example_2\beso_main.py", line 297, in
[FI_step, energy_density_step] = beso_lib.import_FI_int_pt(reference_value, file_nameW, domains, criteria,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\beso-master\wiki_files\example_2\beso_lib.py", line 582, in import_FI_int_pt
assert False, msg
AssertionError: CalculiX result file not found, check your inputs

进程已结束,退出代码1`
I tried to run it alone in cmd and also encountered an error.
2

I also tried to import file000.inp into FreeCAD, but it seems that the analysis cannot be carried out, maybe the way I imported was wrong.
3

Looking forward to your reply, thank you very much!

Specification of units

Hi,

Not really an issue with the code as such. But I am playing around with this implementation on geometry I have created but I am struggling to understand how the effective density, von-mises stress criteria, and elastic modulus are specified. From what I can tell, there are two values, essentially the same but out by a factor of say 10^3 or 10^6 to separate the two states 0 and 1 (I think?). But what are the actual units of these? Is density in g/mm3, g/cm3, kg/m3 ? Elastic modulus in GPa, MPa? Von-mises in MPa?

Wont the scale of these affect the optimization parameters? i.e. the scale of the y-axis in each of the plots? does this matter?

The other issue that, for me as a user of the code, is that I am not actually sure what the filter is doing? I get that theres different types of filters which aim to mitigate certain things. But there isnt any description of say what a 'simple, 3' does compared to a 'simple, 10'. With the number being the radius apparently? radius of what?

I understand that I should probably go read through the underlying theory behind it that you have indeed referenced, but nevertheless, it would be good to specify the units and what the filter is there for in general (as in why filter? and filtering what?).

Issue running example-1

Hello.

I am trying to tun the first example.
My systems are FreeCAD 18.04 on Pop_OS 18.04, Python 3.6.9
Both FreeCAD and Calculix are installed via repo.

To run the Calculix for the first time, the provided freecad_input.FCStd file need to be modified. I cannot run the solver even after activating the analysis container. So:

  • I made a new analysis container (standard calculix solver).
  • Remove the old container. All the data inside the container are preserved.
  • Move the mesh, load, and boundary condition.
  • Remove the remaining old files.
  • Create a new solid material and 2D mesh thickness.

After the step above, calculix can be run.

The beso_conf.py is generated via gui:

# This is the configuration file with input parameters. It will be executed as python commands
# Written by beso_fc_gui.py at 2020-01-01 22:26:48.005422

path_calculix = '/usr/bin/ccx'
path = '/home/iwan/Documents/freecad-beso-example/ex-1'
file_name = 'Plane_Mesh.inp'

elset_name = 'SolidMaterialElementGeometry2D'
domain_optimized[elset_name] = True
domain_density[elset_name] = [7.9e-15, 7.9e-09]
domain_thickness[elset_name] = [1, 1]
domain_FI[elset_name] = [[('stress_von_Mises', 4.5e+14)],
                         [('stress_von_Mises', 4.5e+08)]]
domain_material[elset_name] = ['*ELASTIC\n0.21, 0.3\n*DENSITY\n7.9e-15\n*CONDUCTIVITY\n4.3e-05\n*EXPANSION\n1.2e-11\n*SPECIFIC HEAT\n590.0\n',
                               '*ELASTIC\n2.1e+05, 0.3\n*DENSITY\n7.9e-09\n*CONDUCTIVITY\n43.0\n*EXPANSION\n1.2e-05\n*SPECIFIC HEAT\n5.9e+08\n']

mass_goal_ratio = 0.4
filter_list = [['simple', 2],
               ]

optimization_base = 'stiffness'

mass_addition_ratio = 0.015
mass_removal_ratio = 0.03
ratio_type = 'relative'

Running python3 ./beso_main.py on terminal gives output:

domains: 1
nodes  : 3131
TRIA3  : 0
TRIA6  : 0
QUAD4  : 3000
QUAD8  : 0
TETRA4 : 0
TETRA10: 0
HEXA8  : 0
HEXA20 : 0
PENTA6 : 0
PENTA15: 0

initial optimization domains mass 2.370000000000088e-05

iterations_limit set automatically to 86
Usage: CalculiX.exe -i jobname
Traceback (most recent call last):
  File "/home/iwan/Documents/freecad-beso-example/beso-master/beso_lib.py", line 597, in import_FI_int_pt
    f = open(file_nameW + ".dat", "r")
FileNotFoundError: [Errno 2] No such file or directory: '/home/iwan/Documents/freecad-beso-example/ex-1/file000.dat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./beso_main.py", line 349, in <module>
    domains_from_config, steps_superposition, displacement_graph)
  File "/home/iwan/Documents/freecad-beso-example/beso-master/beso_lib.py", line 601, in import_FI_int_pt
    assert False, msg
AssertionError: CalculiX result file not found, check your inputs

I checked the directory, there is file000.inp but no file000.dat file.
Any idea why do I get such error ?
Kind regards,
Iwan

Enforcing symmetry

Hi there

Are there any way of enforcing symmetry if I ensure that my mesh is symmetric? I can't seem to find anything in the script that hints at it being implemented.
When the load is also symmetric, I can do this by modelling half the part and using a frictionless constraint on the symmetry plane but when the load is not symmetric across the geometric symmetry plane, then the full geometry need to be analyzed. What I can do in Mecway is to mesh half the part and mirror the mesh but then something would need to be added to the beso script that only performs topology optimizing on one side of the symmetry plane and applying the same state to the matching element across the symmetry plane.

I imagine that the implementation of this could make use of the computed center of gravity coordinates as these should be exact mirrors across the symmetry plane if the mesh is mirrored. In cases where the mesh is not mirrored, the matching element could be found by searching for elements for which the center of gravity of the "slave" element is positioned within some spherical tolerance of the "master" element.
This implementation could then also be used for multiple symmetry planes as long as the order of mirroring the element state is chosen such that it doesn't copy the state of an element that will then later have its state altered in the same iteration.

What do you think about this?

beso_main.py unable to run as macro

Since I began using beso half a year ago, i haven't been able to 'run optimization' in fc-gui freecad macro, or run beso_main.py as a freecad macro at all.

I've found a workaround to this, by writing a conf file with fc-gui macro, and then running beso_main.py in the terminal.
After issuing the command python beso_main.py in the .Freecad/Macro/ directory, an empty window with title '11' shows up. Closing window '11', opens window '12', and so forth until i close window '15'. Only now, the actual optimization would start.

I experienced this problem while using Freecad 0.18, 0.19 and 0.20 in both Linux Mint and Manjaro.

Report view output when pressing 'run optimization' from fc-gui macro:

22:55:46 Traceback (most recent call last):
22:55:46 File "/home/jacob/.FreeCAD/Macro/beso_fc_gui.py", line 829, in on_click23
22:55:46 exec(open(os.path.join(beso_gui.beso_dir, "beso_main.py")).read())
22:55:46 File "", line 6, in
22:55:46 File "/home/jacob/.FreeCAD/Mod/retr3d/multiprocessing/init.py", line 64, in
22:55:46 from multiprocessing.process import Process, current_process, active_children
22:55:46 File "/home/jacob/.FreeCAD/Mod/retr3d/multiprocessing/process.py", line 262
22:55:46 except SystemExit, e:
22:55:46 ^
22:55:46 SyntaxError: invalid syntax

One line chang eto make it run on MacOS

Hi,

I tried getting it to run on MacOS. It seems that in beso_main (line 384) only
if sys.platform.startswith('darwin'):
needs to change to
if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):

Cheers,

Max

Error when using finer mesh settings

So far I am impressed with your implementation of topology optimization in an opensource software. I appreciate the work from all the devs. I was recently playing around with this nice feature, but realized that it doesn't seem to work when I use a that has more details. I would like to use a finer mesh to get a result with better resolution, but whenever I decrease the maximum element size in Netgen, it gives an error:
image

I have tried reverting the settings back to a coarse mesh, and it starts working totally fine again.
Would there be a way to make this work on a finer mesh?

beso_fc_gui hidpi support

Buttons in beso_fc_gui are terribly placed on my high resolution screen.

I don't know whether this issue stems from Freecad, KDE Plasma or beso.
It's sorta possible to push the correct buttons thanks to tooltips, so I'm not stranded. It is however quite annoying.

beso_fc-gui_HIDPI

Cannot run examples

I tried example 2:
Downloaded the zip, opened the freecad file, adapted a little bit to freecad 2024.104 (freecad-realthunder), added beso_fc_gui.py and run it from Macro.
I select analysis /home/pm/Downloads/input_and_results/file057_state1.inp
I can generate and edit beso_conf.py:

# This is the configuration file with input parameters. It will be executed as python commands
# Written by beso_fc_gui.py at 2024-01-16 20:48:29.361423

path_calculix = '/snap/freecad-realthunder/124/usr/bin/ccx'
path = '/home/pm/Downloads/input_and_results'
file_name = 'file057_state1.inp'

elset_name = 'MaterialSolidSolid'
domain_optimized[elset_name] = True
domain_density[elset_name] = [4.43e-15, 4.43e-09]
domain_material[elset_name] = ['*ELASTIC\n0.114, 0.33\n*DENSITY\n4.43e-15\n*CONDUCTIVITY\n6.7e-06\n*EXPANSION\n8.6e-12\n*SPECIFIC HEAT\n553.0\n',
                               '*ELASTIC\n1.14e+05, 0.33\n*DENSITY\n4.43e-09\n*CONDUCTIVITY\n6.7\n*EXPANSION\n8.6e-06\n*SPECIFIC HEAT\n5.53e+08\n']

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

optimization_base = 'stiffness'

mass_addition_ratio = 0.015
mass_removal_ratio = 0.03
ratio_type = 'relative'

I click on the big square button, and it throws:

20:50:01  Traceback (most recent call last):
20:50:01    File "/home/pm/Downloads/input_and_results/beso_fc_gui.py", line 944, in on_click24
20:50:01      self.on_click23()  # run optimization
20:50:01    File "/home/pm/Downloads/input_and_results/beso_fc_gui.py", line 940, in on_click23
20:50:01      exec(open(os.path.join(beso_gui.beso_dir, "beso_main.py")).read())
20:50:01    File "<string>", line 51, in <module>
20:50:01  FileNotFoundError: [Errno 2] No such file or directory: 'beso_conf.py'

Everything is in /home/pm/Downloads/input_and_results/, including beso_conf.py, so I don't get what is wrong.

Please, move to the Calculix organization

Dear Mr. Löffelmann,

I'm trying to develop CalculiX organization on the GitHub to unite all developers and tools in one place. I've sent you an invitation. Please, could join us and move your 'beso' project to Calculix organization?

All your permissions will be kept, so do not afraid. Current URL will remain accessible. New URL will be: github.com/calculix/beso.

In your project Settings go to Options -> Danger Zone -> Transfer ownership. Click on ‘Transfer’ button, then type ‘calculix’ as user.

Thank you in advance!

Setting initial state

Hi there

I can't seem to find any settings meant to set the initial state of an element set and I believe that such a setting could be very useful.
A part that is conventionally designed is likely much closer to the optimum than having the whole design space as initially in the high state so having the option to place an initial seed could possibly bring down the computation time or just result in different resulting geometries.
If I could set the initial state of one *ELSET as high and another as low, then the iterations needed could possibly be cut down while still having a large design space.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.