Last active
December 8, 2016 01:19
-
-
Save pshriwise/b4ba2ec647d25e1b39286859d0856c2d to your computer and use it in GitHub Desktop.
Preliminary replacement for dagmc_preproc based on new DAGMC-Trelis plugins
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
# make sure that trelis/cubit 'bin' directory is added to PYTHONPATH environment variable | |
import cubit | |
import sys | |
import argparse as ap | |
def import_file(cubit_instance, filename): | |
extension = filename[-4:] | |
if extension == ".sat": | |
file_type = "acis" | |
elif extension == ".cub": | |
file_type = "cubit" | |
elif extension == ".trelis": | |
file_type = "trelis" | |
else: | |
raise Exception("CAD file is of invalid type") | |
cubit_instance.silent_cmd("import " + file_type + "'" + filename + "'") | |
def import_and_facet(cubit_instance, | |
filename, | |
outfile = "", | |
facet_tol = 1e-04, | |
length_tol = -1, | |
normal_tol = -1, | |
imp = False, | |
merge = False, | |
make_watertight = False, | |
fatal_curves = False, | |
verbose = False): | |
assert(type(filename) == str) | |
#make sure there isn't anything in the current instance | |
cubit_instance.destroy() | |
#start Trelis/Cubit engine with no journaling | |
cubit_instance.init(["-nojournal"]) | |
#import acis file | |
import_file(cubit_instance, filename) | |
# if requested, do imprint and merge | |
if (imp): | |
cubit_instance.silent_cmd("imprint body all") | |
if (merge): | |
cubit_instance.silent_cmd("merge body all") | |
#prep to facet the file | |
#output filename handling | |
out_extension = ".h5m" | |
if outfile == "": | |
basename = filename.split(".")[0] | |
outfile = basename+out_extension | |
else: | |
assert(outfile[-4:] == out_extension) | |
mw = " make_watertight " if make_watertight else " " | |
fc = " fatal_on_curves " if fatal_curves else " " | |
v = " verbose " if verbose else "" | |
#construct command string (starting with minial arguments) | |
command_string = "export dagmc " + "'" + outfile + "'" | |
command_string += " faceting_tolerance " + str(facet_tol) | |
command_string += " length_tolerance " + str(length_tol) if length_tol >= 0 else " " | |
command_string += " normal_tolerance " + str(normal_tol) if normal_tol >= 0 else " " | |
command_string += " make_watertight " if make_watertight else " " | |
command_string += " fatal_on_curves " if fatal_curves else " " | |
command_string += " verbose " if verbose else " " | |
print "Command string provided to Trelis/Cubit:" | |
print command_string | |
#facet the file | |
cubit_instance.silent_cmd(command_string) | |
#remove everything in the cubit instance | |
cubit_instance.destroy() | |
if __name__ == "__main__": | |
#program arguments/options | |
parser = ap.ArgumentParser( description = "Script for preprocessing of Acis (.sat) or Trelis/Cubit (.trelis/.cub) files into DAGMC .h5m files.") | |
parser.add_argument('filename', type = str, help = "CAD file to facet.") | |
parser.add_argument('-f', type = float, dest = 'facet_tol', default = 1e-04, | |
help = "Desired faceting tolerance.") | |
parser.add_argument('-l', type = float, dest = 'length_tol', default = -1, | |
help = "Desired facet length tolerance.") | |
parser.add_argument('-n', type = float, dest = 'normal_tol', default = -1, | |
help = "Desired facet normal tolerance.") | |
parser.add_argument('-o', type = str, dest = 'output_filename', default = "", | |
help = "Output filename. If not provided, the output file will be input base filename + .h5m") | |
parser.add_argument('-I', action = 'store_true', dest = 'imprint', default = False, | |
help = "If provided, the model will be imprinted before faceting.") | |
parser.add_argument('-M', action = 'store_true', dest = 'merge', default = False, | |
help = "If provided, the model will be merged before faceting.") | |
parser.add_argument('-W', action = 'store_true', dest = 'make_watertight', default = False, | |
help = "If provided, the model will be made watertight after faceting.") | |
parser.add_argument('-F', action = 'store_true', dest = 'fatal_curves', default = False, | |
help = "If provided, faceting will fail if curve facets cannot be successfully exported.") | |
parser.add_argument('-V', action = 'store_true', dest = 'verbose', default = False, | |
help = "If provided, additional output will appear.") | |
args = parser.parse_args(sys.argv[1:]) | |
#do the work here | |
import_and_facet(cubit, | |
args.filename, | |
args.output_filename, | |
args.facet_tol, | |
args.length_tol, | |
args.normal_tol, | |
args.imprint, | |
args.merge, | |
args.make_watertight, | |
args.fatal_curves, | |
args.verbose) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment