Topology Optimization (SIMP) for CalculiX - View results in PrePoMax?

Hello all,

My research focuses on topology optimization and additive manufacturing. Currently, I use Python as my main framework, but it is limited to structured homogeneous grids, or better said, all hex meshes of the same size. I am planning to implement topology optimization (SIMP method — Solid Isotropic Material with Penalization) within CalculiX. Several ideas have come to mind.

Already 12 years ago, I managed to create an ESO (Evolutionary Structural Optimization) topology based on the input (.inp) and result (.frd) files from CalculiX. At that time, my programming skills were quite limited. Here is an easy example post-processed in CGX: (see next post)

I am aware that there is a BESO (Bi-directional Evolutionary Structural Optimization) script vailable for CCX, but the limitations are known.

It seems that an implementation of the SIMP method already exists in CCX. I have been in contact with the author, who claimed that changes in the CCX version were quite challenging, resulting in a lot of work to maintain the optimization code.

Therefore, I prefer to stick as much as possible with Python and just use CalculiX as a solver. I have added approximately 50 lines of code (in Fortran and C), which mainly consist of:

  • Checking if topology optimization is enabled via a specific initialization file
  • Writing element matrices, volumes, and centers of gravity (done only once during the initialization run)
    → This is necessary for the SIMP method’s sensitivity evaluation and filtering purposes
  • Reading density values per element

That’s all. The magic happens in Python. There might be potential for improvement by splitting the sensitivity loop into chunks to utilize available CPU cores and reduce computation time. Additionally ccx works as before, if there is no initialization file for the topology optimization.

Overall, I have conducted several examples, as shown here (GE-bracket and Nacelle bracket). The properties and simulation durations are listed. Convergence was reached probably at iteration 25-ish. Shortening the duration by half, ~15 min and 1.5 hours respectively.

Further development ideas:

  • Element set definition for design and non-design regions
  • Multiple load cases
  • Compiling CCX for Windows (currently Linux with Pardiso)

REQUEST:

Currently, the results are stored in a txt file with the following format:
ElementID\tDensity
1\t1.
2\t0.5
3\t0.1239

The txt file is generated for each iteration and process it in ParaView or PyVista. In the next step, the elemental results are extrapolated to the nodes, creating a much smoother visualization. The values are then limited using the “Iso Volume” to 0.5.

Is there a possibility to perform this in PrePoMax, to view the results directly within the software instead of using the VTK file format and ParaView.

Would this be a feasible request?

Thanks and best regards,
Stoli (from Germany)

1 Like

ESO: 12 years ago

image35

1 Like

GE bracket:

image25

1 Like

Nacelle bracket:

image26

1 Like

This is a really nice work that has been done. I plan to integrate topology optimization into PrePoMax at some point in the future, so I am very interested in this topic.

If I understand correctly, you would need the capability to import elemental densities and then use iso-surface visualization using the nodal-averaged values?

Is your code available as open-source code?

1 Like

Actually, there are 2 topology optimization solutions utilizing FreeCAD as GUI and CalculiX as solver - beso (that you’ve already mentioned) and this: GitHub - Foxelmanian/ToOptixFreeCADAddon: Addon for FreeCAD using ToOptix

However, they indeed seem to be quite limited. The latter is also not actively developed anymore while beso is more up-to-date and its author (fandaL) should still be reachable.

Today, someone also shared this on the FreeCAD forum: Making sure you're not a bot!

1 Like

@Matej
Thank you — especially for the great work regarding PrePoMax.

The code is not available yet. It is still not perfect and still function-oriented, in order to keep it very simple. The ability to view the results during the optimization with the pruposed method of “iso volume” would be an excellent feature for PrePoMax.
I can privately share some code snippets. Also compiling the altered ccx-src for Windows would be nice.

@FEAnalyst
Thanks for sharing ToOptix — I was not aware of that solution. The recent post on FreeCAD is also quite interesting.
All these developments highlight the demand for topology optimization, and having the ability to incorporate it into PrePoMax would be a significant benefit.

The main advantage of my approach is the manipulation of the elemental matrices within CalculiX (ccx). The input file does not change. During the iteration, the FE problem is solved based on the described density file (density-file.txt). The displacement vector is read by Python, and by looping through the elemental matrices (stored in a binary file), the sensitivities are derived. The optimizer (currently based on the optimality criterion method) then computes the new densities, which are again stored in the density file.
Again, this needs just minor interference with ccx. The python code is also quite efficient.

3 Likes

I just thought of a solution and probably writing a own %job_topOpt.frd file would be the best. The extrapolation of elemental values to the nodes is possible within my script. From that I might create this frd file. To have a nice possibility of clipping legend-values, the request regarding a feature in prepomax would be similar to this one:

https://prepomax.discourse.group/t/transparent-plot/1392

Best regards,
Stoli

PS: I am working on the code, to be published on github asap

3 Likes

Another reply:
I just used some of my time to create a frd file with “TOPO” as the topology (see figure below). The left shows the paraview equivalent. On the right there is also a cut view in prepomax. Unfortunately I can not use something similar like “Iso Volume” or the legend-clipping as discussed in the upper linked thread. In Paraview a threshold of 0.5 … 1 is used.

Besides working on improvements of the topology optimization code, I am working on a workflow to extract *stl. This is a research-topic on its own. I found a way, to extract a smoothed surface (without smoothing the boundaries) This resulted in a solid after importing in prepomax, which could be easily meshed with a tet mesh.
@Matej, are there any plans, to enhence also this workflow. Maybe even on improving the stl-mesh by collapsing edges and get rid of “bad” elements. Adding additionally the ability for a shape optimization (exisits already in ccx) would be nice. This would finalize all the efforts, thus creating a whole optimization workflow instead of “just” topology optimization.

Cheers,
Patrick

PS:
After some tests I do suggest, that using a specific *.frd will be the best solution. Here a short animation of a 2D MBB beam. Being able to hide all elements below and /or above a threshold, would be perfect going one step forward towards topology optimization in prepomax!

animated

Definitely. Even manually hiding selected elements would be very helpful, but Abaqus also has the feature you mentioned. It can be used to imitate element deletion as well (and the new release of CalculiX has damage initiation btw.).

Hi @stoli! Well, topology optimization is one of my favorite topics and I really appreciate your effort on developing a SIMP approach for CCX. When I was inspired last year, I tried to do something simple in this regard and could not get past the sensitivity calculation because CCX could not export the local stiffness matrix (at least I could not find a way to do it). I even contacted Guido who suggested for me to get the data from the element stiffness matrix “s(60,60)” in subroutine e_c3d.f, however this was far from my coding skills. Just out of curiosity, how did you manage to do it?

I would like to ask if you plan to release it as open-source software and if so, how could I test it. I’ve been using BESO module from @FandaL for quite a while now and would be nice to use your module as well.

If possible, it would be nice to couple this module with PrePoMax (I know it is hard and probably is not the top priority) and I’m pretty sure it would greatly expand the tools for this software which is already amazing.

If I could suggest something, for a similar application I saw a while ago a workaround was to apply maximum transparency (I think it is the alpha channel from colors) for specific colors in the legend bar. Not sure if it would help here though.

1 Like

This is exactly, how I did it (I used the file mafillsm.f, where the overall matrix is constructed).
It is just following line:
s = s * xPhys(i)
Besides that I export the elemental centers and masses, which are calculated within e_c3d.f. As I mentioned above, I added approx. 50 lines of code. This is mainly to determine, if topology optimization is requested. Additionally reading / writing with 1 CPU is crucial, due to race-conditions, caused by the huge elemental file. (it is a 60x60 matrix per element!)

A permanent implementation in the CCX source would be nice, so every compiled versions will have the ability to use topology optimization. I think I will have to talk to Guido.

Ansys is using a similar approach. Just by using a specific topo-keyword, the topology is activated and ready to be used.
I used also TOSCA in the past, but right now I am not aware, how they get the elemental matrices. Especially, FE-Design could do this, before bein part of SIMULIA.

Unfortunately the transparency will just show all the results on the outer faces. The transparency will just make it possible to view the results “at the back”.

….

And I got huge improvements regarding my code. The sensitivity evaluations for the upper problems were reduced from approx. 20 s to 6 s per iteration!
The code will be available soon.

The overall code has still some limitations (in order of priority):

  • Just one element type (Tet or Hex) priority regarding improvement
  • One load case
  • No element exclusion for now

Best regards,
Patrick

1 Like

Hello all,
the repository is now created and I’m working on polishing the topology optimization script topOpt4ccx.py

Please find the results of the ge-bracket-challenge here and also the *.exe for the topology optimization.

Cheers,
Patrick