diff --git a/README.md b/README.md index aabfc4af5e504828505a342f576e51d242f16b5b..90c9c3084d799873371d2f780548a735ab6a7d9e 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 0000000000000000000000000000000000000000..5f08c254b6afc799a7eae8230e4413b26809db49 --- /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)