Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Ex2Ab/Ex2Ab.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
102 lines (82 sloc)
4.12 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
############################################################################### | |
### This is the Ex2Ab conversion utility for creating Abaqus format mesh files | |
### and MCNP skeletal input files from an Exodus II mesh file. | |
### Author: Peter Kowal | |
### Year: 2020, minor updates 2022 | |
############################################################################### | |
############################################################################### | |
def run(filename = None): | |
"""Runs Ex2Ab Utility | |
Parameters | |
---------- | |
Running without input arguments will invoke the GUI. | |
filename : str, optional | |
Exodus II Mesh. | |
""" | |
# Opens a window to select your mesh file. | |
print( | |
'\n ███████╗██╗ ██╗██████╗ █████╗ ██████╗ \n' | |
+' ██╔════╝╚██╗██╔╝╚════██╗██╔══██╗██╔══██╗\n' | |
+' █████╗ ╚███╔╝ █████╔╝███████║██████╔╝\n' | |
+' ██╔══╝ ██╔██╗ ██╔═══╝ ██╔══██║██╔══██╗\n' | |
+' ███████╗██╔╝ ██╗███████╗██║ ██║██████╔╝\n' | |
+' ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ \n') | |
print('Welcome to the Exodus II to Abaqus Conversion Script!\n') | |
valid_mesh = False | |
while(valid_mesh == False): | |
mesh = Ex2Ab.get_mesh(filename) | |
valid_mesh = mesh[1] | |
if(mesh[1] == False and filename is None): | |
print('EPIC FAIL!\n' + mesh[0] + ' is not a valid Exodus II mesh ' | |
+ '(no netCDF4 Datasets were found)\n' + 'Please Try Again\n') | |
if(mesh[1] == False and filename != None): | |
print('EPIC FAIL!\n' + mesh[0] + ' is not a valid Exodus II mesh ' | |
+ '(no netCDF4 Datasets were found)\n') | |
sys.exit() | |
# Read in Exodus II file. | |
rootgrp = Dataset(mesh[0], 'r', | |
format = 'NETCDF3_64BIT_OFFSET') | |
# Get the number of blocks (element sets). | |
# Note that if a single block has volumes using different meshes, it will | |
# register as 2 blocks. This will result in multiple pseudo-cells for the mixed | |
# mesh block. If materials were assigned in Cubit (using block attributes), | |
# then these cells will have the same material. This may look like extra | |
# pseudo-cells were created, but is fine. | |
b = rootgrp.variables['eb_prop1'] | |
blocks = len(b) | |
el_types = [] | |
# Check element types. | |
Ex2Ab.check_elements(blocks, rootgrp, el_types) | |
# Automatic file naming based on source mesh file. | |
#filename = str(main_win.sourceFile) | |
job = Ex2Ab.name_files(mesh[0]) | |
print('Mesh Conversion begins\nSource Mesh: ' | |
+ mesh[0] | |
+ '\nJob name: ' + job + '\n\n' | |
+ str(blocks) + ' block(s) were detected') | |
start_time = time.time() | |
# Define materials for each block. | |
mats = np.zeros([blocks]) | |
att = Ex2Ab.get_materials(blocks, rootgrp, mats) | |
# Get xyz node coordinates for entire mesh. | |
xyz = Ex2Ab.get_nodes(rootgrp) | |
len_node = len(xyz[:, 0]) | |
# Write the MCNP skeletal input file. | |
Ex2Ab.mcnp(rootgrp, blocks, att, xyz, job, mats) | |
print('\nSkeletal MCNP input has been written\n') | |
# Write the Abaqus mesh file. | |
Ex2Ab.abaqus(rootgrp, blocks, len_node, el_types, mats, job, start_time, xyz) | |
print('\nThe conversion took ' + str(Ex2Ab.timing(start_time)) + ' sec\n' | |
+ 'Mesh converted to Abaqus inp format') | |
if __name__ == '__main__': | |
import sys | |
import numpy as np | |
from netCDF4 import Dataset | |
import time | |
import Ex2Ab_modules as Ex2Ab | |
try: | |
filename = sys.argv[1] | |
except IndexError: | |
filename = None | |
run(filename) |