From 2359374ad86546a40d1c5b436213f3dcd25e6759 Mon Sep 17 00:00:00 2001 From: whimsial <ai1v14@soton.ac.uk> Date: Tue, 28 Aug 2018 16:38:28 +0100 Subject: [PATCH] Added a tool to extract critical buckling loads from the Abaqus data files for parametric studies --- README.md | 2 ++ datExtract.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 datExtract.py diff --git a/README.md b/README.md index aabfc4a..90c9c30 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Welcome to the Spindle FEA application repository [](https://opensource.org/licenses/MIT) +[] + ## Installation instructions diff --git a/datExtract.py b/datExtract.py new file mode 100755 index 0000000..5f08c25 --- /dev/null +++ b/datExtract.py @@ -0,0 +1,53 @@ +""" +This script should be executed from the directory that contains .dat files generated by Abaqus CAE during analysis. +It can be used to extract the critical buckling load values from each analysis .dat file and then store them within a +single .dat file. +""" + +import os +import csv + + +def eigenvals(path): + """ + This function extracts all the eigenvalues from the list of .dat + files and saves them into a single .dat file + + :param path: path to the .dat files generated by Abaqus CAE + + :type path: str + + :return: list of eigenvalues + + :rtype: list + """ + + walk_dir = os.path.abspath(path) # Convert to absolute path + print('Root directory is %s' % walk_dir) + content = [] + # Extract content of each .dat file + files = next(os.walk(walk_dir))[2] + files.sort() + for filename in [f for f in files if f.endswith(".dat")]: + with open(os.path.join(walk_dir, filename), 'r') as f: + content.append(f.read().splitlines()) + # Extract eigenvalues + eig_list = [] + for item in content: + for index, line in enumerate(item): + if ' MODE NO EIGENVALUE' in line: + # Extracting eig by its position + eig_list.append(item[index + 3:index + 11]) + # Transforming to float: + eig_float = [[float(j.split()[1]) for j in x] for x in eig_list] + # Write into a .csv file + with open("eig_list_new.dat", "w") as f: + writer = csv.writer(f) + writer.writerows(eig_float) + return eig_float + + +if __name__ == '__main__': + # Exporting mesh statistics: + path = './' + eigfloat = eigenvals(path) -- GitLab