# How to automate the operation of calculix

**URL:** <https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458>\
**Category:** Tool interfaces\
**Created:** [October 31, 2024, 2:55am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458 "2024-10-31T02:55:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liberty](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@liberty](https://calculix.discourse.group/u/liberty)\
**Post date:** [October 31, 2024, 2:55am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/1 "2024-10-31T02:55:03Z")

</div>

I now have many input files that need to be submitted for calculations, and these files must be calculated individually. My operating system is Windows 11, and I have two questions that I am quite confused about:

1. How to use code to automatically submit input files to the calculix solver for computation.
2. How to automatically read the specified value of each frd file and output it to a txt file.

The ideal process is: inp1 → frd1 → txt, inp2 → frd2 → txt, inp3 → frd3 → txt …  
txt has only one number, and the next one will overwrite the previous one.

---

<div class="post-metadata">

**Author:** ![Calc\_em](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@Calc\_em](https://calculix.discourse.group/u/Calc_em)\
**Post date:** [October 31, 2024, 8:07am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/2 "2024-10-31T08:07:03Z")

</div>

The first part is easy to do, a batch file should suffice if you want to submit multiple analyses in a sequence. The second part (automating results writing) is more tricky but cgx (GraphiX) may suffice:

> **[Parametric FEM model creation with Python and CalculiX GraphiX (cgx)](https://medium.com/daptablog/parametric-fem-model-creation-with-python-and-calculix-graphix-cgx-4b654bb8f33e)**
>
> Feb 2023 Update — Read the revised tutorial for the dapta app here: https://daptadocs.com/Tutorials/Chaining%20component%20analyses.html

> **[CalculiX-Examples/Scripts at master · calculix/CalculiX-Examples](https://github.com/calculix/CalculiX-Examples/tree/master/Scripts)**
>
> CalculiX examples by Prof. Martin Kraska from Brandenburg University of Applied Sciences. Excellent starting point to master parametric modelling with CGX and CCX. - calculix/CalculiX-Examples

---

<div class="post-metadata">

**Author:** ![liberty](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@liberty](https://calculix.discourse.group/u/liberty)\
**Post date:** [November 1, 2024, 3:02am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/3 "2024-11-01T03:02:44Z")

</div>

I also missed a step, and the specific method is as follows. I want to achieve automated operation of the following steps.

1. Prepare 2 set of data files and name them as ex. step\_1.inp and step\_2.inp

2. Copy step\_1.inp to step.inp  
“step\_1.inp” holds the original geometri & load for 1’st run

3. Run ccx -i step

4. Copy step.frd to step\_1.frd  
“step.frd” holds output specified in the cards “\*node file” & “\*element file” for 1’st step

5. Read step\_1.frd to get sdv6 and send it to txt file.

6. Copy step.rout to step.rin  
“step.rout” holds the stiffness matrice, strains & deformed geometri from first run

7. Copy step\_2.inp to step.inp  
“step\_2.inp” holds load for 2’nd run expected to be added to 1’st result

8. Run ccx -i step

9. Copy step.frd to step\_2.frd  
“step.frd” holds output specified in the cards “\*node file” & “\*element file” for 2’nd step

10. Read step\_2.frd to get sdv6 and send it to txt file.

---

<div class="post-metadata">

**Author:** ![Nobody-86](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Nobody-86](https://calculix.discourse.group/u/Nobody-86)\
**Post date:** [November 3, 2024, 10:24am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/4 "2024-11-03T10:24:23Z")

</div>

Hi,  
I usually use python for that kind of automation. Assuming you have the two files step\_1.inp and step\_2.inp, you could try something like

```auto
import os
import shutil

# step 2, copy step_1.inp to step.inp
shutil.copyfile("step_1.inp", "step_2.inp")

# step 3, run calculix
os.system("ccx -i step")

# step 4, copy step.frd to step_1.frd
shutil.copyfile("step.inp", "step_1.frd")

# step 5 get sdv6 from step_1.frd
with open("step_1.frd", "r") as f:
    content = f.readlines()
sdv6 = []
for line in content:
    # I actually don't have a file and don't know how to detect this exactly
    if "XXX" in line:
        sdv6 += [line]
with open("step_1.txt", "w") as f:
    for line in sdv6:
        f.write(line)

# step 6, copy step.out to step.rin
shutil.copy("step.out", "step.rin")

# step 7, copy step_2 to step
shutil.copy("step_2.inp", "step.inp")

# step 8, run ccx
os.system("ccx -i step")

# step 9, copy step.frd to step_2.frd
shutil.copy("step.frd", "step_2.frd")

# step 10, read step_2.frd to get sdv6 and save as txt
# same as step 5

```

Warning: typos included in the above script. I just wrote this down without checking every detail. There is also something you have to adapt at step 5 and 10 as I dont know exactly how to detect the sdv6 data.

---

<div class="post-metadata">

**Author:** ![liberty](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@liberty](https://calculix.discourse.group/u/liberty)\
**Post date:** [November 4, 2024, 3:19am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/5 "2024-11-04T03:19:03Z")

</div>

Thanks,I will have try.

---

<div class="post-metadata">

**Author:** ![rsmith](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/rsmith/32/1684_2.png) [@rsmith](https://calculix.discourse.group/u/rsmith)\
**Post date:** [November 4, 2024, 8:37am UTC](https://calculix.discourse.group/t/how-to-automate-the-operation-of-calculix/2458/6 "2024-11-04T08:37:32Z")

</div>

Windows lacks most of the tools natively available on UNIX-like operating systems, like `sed`, `awk` and `make`.

So installing a powerful scripting language like Python is a good idea.  
The code that @Nobody-86 provides is a good start.

The format of frd files is defined in the chapter “Result Format” in the manual for `cgx`, in the form of [FORTRAN `format` strings](https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html).

Nodal or element data is found on lines starting with " -1".  
Unfortunately the data fields are run together, so a simple `str.split()` does not work.

After having extracted node-related data from ascii `frd` files multiple times in Python, I consolidated that code into a module and program [calculix-frdconvert](https://github.com/rsmith-nl/calculix-frdconvert), available on github. You might find that useful.
