Roland's homepage

My random knot in the Web

Automating CalculiX with make(1)

The make program is a staple UNIX development tool. In this article I will show how it can be used to automate and simplify the usage of CalculiX.

My CalculiX projects are all kept in their own directories. In each of those directories there exists a Makefile. This contains instructions for the make program.

By default, invoking make in this directory runs the pre-processor and the solver. But there are also specific sub-commands, for example:

  • “make mesh” shows the mesh used in the FEA.
  • “make disp” shows the deformed product in the post-processor.
  • “make stress” shows the stresses in the product in the post-processor.

What make does is re-build targets if their sources are more recent then the target. Targets can be real files, but they don’t need to be. Targets that are not files are called “phony”. By default it rebuilds the first target that it finds in the Makefile. The first targets in my standard Makefile for CalculiX look like this.

all: static.frd

# Run the pre-processor
all.msh: pre.fbd
    cgx -bg pre.fbd

# Run the solver
static.frd: static.inp all.msh
    /usr/bin/time -lh env OMP_NUM_THREADS=4 ccx -i static
    rm -f static.log spooles.out *.12d *.cvg *.sta

So by default, it tries to rebuild the all target, which depends on the file static.frd. That file depends in turn on static.inp and all.msh.

The target file all.msh depends on the source file pre.fbd. To rebuild all.msh, the command cgx -bg pre.fbd is run.

Note

The commands should be indented with an actual tab character, not spaces!

Dependencies can be nested. As shown above, all.msh is both a target and a source. To create the file static.frd, the solver is run in the first command. After that some temporary files are cleaned up in the second command.

So if I invoke make after having edited either pre.fbd or static.inp, it will call the required programs to rebuild the targets.

Next to these real targets, there are some “phony” targets to view the results.

# view the mesh
mesh: all.msh
        cgx -b view-mesh.fbd

# view displacements
disp: static.frd view-disp.fbd
        cgx -b view-disp.fbd

# view (laminate) stress
stress: static.frd view-stress.fbd
        cgx -b view-stress.fbd

# view core stress
core: static.frd view-core.fbd
        cgx -b view-core.fbd

To view the calculated stress, I can now just use:

make stress

The .fbd files used here are convenient groupings of post-processor commands. An example of a view-stress.fbd.

# Titles
capt Sandwich panel 3-point bending
ulin Worst principal stress

# Read data
read static.frd
read static.inp

# Mirror because of symmetry.
copy all new mir x a
comp all do

# Orient the view.
rot y
rot r 30
rot u 15
frame
zoom 0.8

# Select and display data.
cmap turbo
ds 12 e 23
view disp
view elem

These will be slightly different depending on the simulation, but the pattern is generally the same.


For comments, please send me an e-mail.


Related articles


←  Mooney-Rivlin rubber data for CalculiX Continuum properties of aluminium honeycomb  →