Using step/iges file with ccx

Hey all,
Till now, I used CalculiX by manually writing .fbd files for the geometry and then solving it with ccx.
Is there any option, where I can use a .step/iges file geometry with the ccx, instead of creating the .inp myself ?

My aim is to run an optimisation loop (with another open source optimisation software) where the parameters in the .inp file are changed every loop. Both ccx and the optimisation software are called within a shell script

You will have to mesh the step/iges files and apply analysis features to be written in the input file. If you want to run parametric studies involving geometry, you could try using FreeCAD. It supports CalculiX in its FEM workbench, has Python scripting and even some add-ons specifically for parametric studies.

Which one?

Thanks for the quick reply and Sorry, there was a mistake in my original question:
What if wanted to say was “instead of writing the .fbd file myself”. So how can the mesh and boundary files usually created by cgx for input to ccx, be created by using a step file ?
Could you please provide little more detail on the method you suggested ?
The other software is dakota

In FreeCAD, you can create geometry like in any other CAD software (no need to use step files if you stay in FreeCAD). Then in the FEM workbench set CalculiX study by meshing the geometry and applying analysis features to it. There are many tutorials covering basic setup. Once you get familiar with that, you can try some parametrization/optimization. There is a Spreadsheet workbench to parameterize many aspects of FreeCAD models but for automatic submission you will need a Python script or some ready-made solution like this add-on workbench: FemByGen Workbench - Parametric FEM Analysis - FreeCAD Forum

That is assuming that you want to change the geometry on every iteration. If it’s just about changing the analysis feature while the geometry and mesh always stay the same then there are easier ways since you can just use a script to change the input deck written in text format.

It’s also possible to use step files in GraphiX but I would try FreeCAD anyway: https://www.dhondt.de/cgx_2.22.pdf#subsection.B.16

Thanks… that’s sounds great and I will look into it.
But for now, I actually have solidworks files and I do not want to remodel them again in another CAD software. Also I am familiar with using dakota and would like to do the optimisation part with it. So is there also a way I can realise that with solidworks cad files and dakota, instead of having to model the parts again ?
Can this be done with PrePoMax ? and is PrePoMax better than FreeCAD for pre processing (meshing/boundary conditions, etc) ?

FreeCAD can also work with step files. You just won’t be able to parameterize the geometry (unless you add e.g. some cutouts or new extrusions to it). But the rest can be scripted with Python. PrePoMax is great as a pre- and postprocessor for CalculiX but doesn’t have any scripting capabilities yet. The chooce of preprocessor also depends on what kinds of analysis features you want to use - whether they are supported and easy to define in a given preprocessor or not. Of course, basic features like force/pressure loads and displacement boundary conditions are common for all preprocessing tools.

as alternative, iges/step file can be opened in Netgen for meshing. CGX capable to import *.vol mesh file generates of solid and shell element.

As far as I understood, the last version of Prepomax include some scripting features to run from the command line directly.

Hi @MS_d,
you could also take a look at Cubit.
There is a free component to allow pre- and postprocessing for calculix that’s already got a pyhton interface to query results.

There is already a webinar that at least describes a Dakota, Cubit Moose workflow too.

There is also to possibility to change geometric features.

Here is a example.

A plate with a hole under tension. I tweak the hole to get a bigger radius and rerun the simulation until a limit mises stress in the hole is reached.

And it’s fully scriptable either with a journal in cubit or python.
Here is the journal for this short example.

#!python
import numpy
import matplotlib.pyplot as plt

#!cubit
reset
#beam geometry
create brick x 10 y 4 z 0.25

create Cylinder height 2 radius 0.5

subtract volume 2 from volume 1 

block 1 add volume 1

# node sets
nodeset 1 add surface 4  
nodeset 1 name "x0"
nodeset 2 add surface 6  
nodeset 2 name "xl"

# material
create material "Steel" property_group "CalculiX-FEA"
modify material "Steel" scalar_properties "CCX_ELASTIC_USE_CARD" 1
modify material "Steel" scalar_properties "CCX_ELASTIC_ISO_USE_CARD" 1
modify material "Steel" matrix_property "CCX_ELASTIC_ISO_MODULUS_VS_POISSON_VS_TEMPERATURE" 210000 0.3 0 
modify material "Steel" scalar_properties "CCX_PLASTIC_ISO_USE_CARD" 1
modify material "Steel" scalar_properties "CCX_EXPANSION_ISO_USE_CARD" 1
modify material "Steel" scalar_properties "CCX_CONDUCTIVITY_ISO_USE_CARD" 1

# section
ccx create section solid block 1 material 1

# vertices for ref and rot node
create vertex location on surface 6 center  
create vertex location on surface 6 center  

# rigid body constraint
#!python
cubit.cmd(f"ccx create constraint rigid body nodeset 2 ref {cubit.get_last_id('vertex')-1} rot {cubit.get_last_id('vertex')}")
#!cubit

# load 
#!python
cubit.cmd(f"create force  on vertex {cubit.get_last_id('vertex')-1} force value 20 direction 1 0 0")
#!cubit

# bc
create displacement  on nodeset 1  dof 1 dof 2 dof 3 fix 0 

# outputs
ccx create fieldoutput name "node_output" node
ccx modify fieldoutput 1 node
ccx modify fieldoutput 1 node key_on RF U 
ccx modify fieldoutput 1 node key_off CP DEPF DEPT DTF HCRI KEQ MACH MAXU MF NT PNT POT PRF PS PSF PT PTF PU RFL SEN TS TSF TT TTF TURB V VF 
ccx create fieldoutput name "element_output" element
ccx modify fieldoutput 2 element
ccx modify fieldoutput 2 element key_on E S ERR
ccx modify fieldoutput 2 element key_off CEEQ ECD EMFB EMFE ENER HER HFL HFLF MAXE MAXS ME PEEQ PHS SF SMID SNEG SPOS SVF SDV THE ZZS 
ccx create historyoutput name "node_output" node
ccx create historyoutput name "element_output" element
ccx modify historyoutput 1 node nodeset 3
ccx modify historyoutput 1 node key_on U RF 
ccx modify historyoutput 1 node key_off NT TSF TTF PN PSF PTF MACH CP VF DEPF TURB MF RFL 
ccx modify historyoutput 2 element block 1
ccx modify historyoutput 2 element key_on S E 
ccx modify historyoutput 2 element key_off SVF ME PEEQ CEEQ ENER SDV HFL HFLF COORD ELSE ELKE EVOL EMAS EBHE CENT 


# steps
ccx create step name "Static" static
#ccx modify step 1 parameter nlgeom_yes
#ccx modify step 1 static totaltimeatstart 0 initialtimeincrement 0.1 timeperiodofstep 1 minimumtimeincrement 0.01 maximumtimeincrement 0.1
ccx step 1 add load force 1
ccx step 1 add bc displacement 1
ccx step 1 add fieldoutput 1 2
#ccx step 1 add historyoutput 1 2

# mesh
block 1 element type HEX20
curve 11  interval 1
curve 11  scheme equal
curve 16  interval 24
curve 16  scheme equal
vol 1 size auto factor 8

#remesh and run again until value is reached
#!python

current_radius = 0.5
dr=0.05
limit_mises = 100
r_values = []
r_values.append(current_radius)
node_values = []
i = 1

# mesh
cubit.cmd(f"mesh vertex all")
cubit.cmd(f"mesh volume all")
# jobs
cubit.cmd(f"ccx create job name 'simple_study_{i}'")
cubit.cmd(f"ccx run job {i} no_conversion")
cubit.cmd(f"ccx wait job {i}")
node_ids = cubit.parse_cubit_list("node","all in surface 10")
max_mises=0
for node_id in node_ids:
 node_value = ccx.frd_get_node_value(i,node_id,1,"STRESS","MISES")
 if node_value > max_mises:
  max_mises=node_value
node_values.append(max_mises)
i+=1
i_values.append(i)

while (max_mises < limit_mises):
 # mesh
 cubit.cmd(f"delete mesh")
 current_radius = current_radius + 0.1
 cubit.cmd(f"tweak surface 10 offset -{dr}")
 r_values.append(current_radius)
 cubit.cmd(f"mesh vertex all")
 cubit.cmd(f"mesh volume all")
 # jobs
 cubit.cmd(f"ccx create job name 'simple_study_{i}'")
 cubit.cmd(f"ccx run job {i} no_conversion")
 cubit.cmd(f"ccx wait job {i}")
 node_ids = cubit.parse_cubit_list("node","all in surface 10")
 max_mises=0
 for node_id in node_ids:
  node_value = ccx.frd_get_node_value(i,node_id,1,"STRESS","MISES")
  if node_value > max_mises:
   max_mises=node_value
 node_values.append(max_mises)
 i+=1
 i_values.append(i)
 if i==20:
  break

# Data for plotting
x_data = numpy.asarray(r_values)
y_data = numpy.asarray(node_values)

fig, ax = plt.subplots()
ax.plot(x_data, y_data)

ax.set(xlabel='Radius', ylabel='Mises',title='Mises over radius')
ax.grid()
plt.show()

for ii in range(len(node_values)):
 print(str(r_values[ii]) + " " + str(node_values[ii]))  
 
print("finished!")

Yes, but the OP is asking about running CalculiX with some optimization code, not just automating ccx setup itself.

there is a converter available for step/iges files to fbd. You could find that on the download page. For windows there is a binary which needs a certain version of open cascade but for Linux you would have to compile it. You find a README in the downloaded package how to do what is required. Actually I use cgx with my own user functions to generate the geometry based on some geometry parameters (included in my private userFunction.c file) for optimization purposes. I do not use tet elements for that since I prefer to have a deterministic mesh topology. I use the CAD converter only for my manual work with cad geometry. You find some hints in the cgx manual “How to deal with CAD geometry”. If the geometry is easy the whole meshing process could work in batch mode but it could turn out that some of the examples would need manual corrections for line divisions etc.

1 Like

Calc_em is right, the question is what are you changing in your parameters. That’s what is driving the whole scenario. I’m working in Process Integration and Design Optimization for 20+ years… :grinning:
Based on what you write, I think you have different geometries for which you want to perform the same analysis (or maybe vary also the BC/Loads).
I have played with FreeCAD, SW etc and basically, if yo ustart sith a set of step file, you need to mesh them 1st, then apply BC/Load/Analysis case and run.
What is important is that you work in iso-topology, otherwise, you won’t be able to script.
What I mean is that your geometry should be “similar”. A simple example is a cantilever H beam, if you modify the lengths, thicknesses etc but that remains a H, it’s an isotopology, but if you have a C,H,I beam, that’s almost impossible to automate the scripting.
Personnaly, I used Gmsh a lot to go from the Step, to a compatible mesh.
thne in my inp that I created manually for my load case, I #include that mesh.

1 Like