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:
How to use code to automatically submit input files to the calculix solver for computation.
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.
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:
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
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.
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.
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, available on github. You might find that useful.