From f7d61c3b367d7aad0dec8f40f47b1d5ed847d4be Mon Sep 17 00:00:00 2001 From: Lukas Hof Date: Thu, 18 Jan 2024 17:29:38 +0100 Subject: [PATCH] func generate_abaqus_event_series now returns a tuple for direct use with ABAQUS. Closes #14 --- example/validation_submodel/call_aniso.py | 2 +- pyGCodeDecode/abaqus_file_generator.py | 34 +++++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/example/validation_submodel/call_aniso.py b/example/validation_submodel/call_aniso.py index 5f042d4..a715b56 100644 --- a/example/validation_submodel/call_aniso.py +++ b/example/validation_submodel/call_aniso.py @@ -18,7 +18,7 @@ print("---Simulation took %s seconds ---" % (time.time() - start_time)) # ---RESULTS--- # -afg.generate_abaqus_events(simulation=simulation, filename="example/validation_submodel/time_series.inp") +afg.generate_abaqus_event_series(simulation=simulation, filename="example/validation_submodel/time_series.inp") print_layertimes(simulation=simulation, filename="example/validation_submodel/layertime_aniso.csv") diff --git a/pyGCodeDecode/abaqus_file_generator.py b/pyGCodeDecode/abaqus_file_generator.py index bfb74c2..e8982e4 100644 --- a/pyGCodeDecode/abaqus_file_generator.py +++ b/pyGCodeDecode/abaqus_file_generator.py @@ -11,20 +11,24 @@ 0.0, 1.0, 0.0, 2.0, 1 0.44, 1.0, 22.0, 2.0, 0 -timepoints generated are always at segment beginnings / endings, so interpolation linearly is the exact solution +time points generated are always at segment beginnings / endings, so interpolation linearly is the exact solution """ -tolerance = float("1e-12") -def generate_abaqus_events(simulation: "gi.simulation", filename="pyGcodeDecode_abaqus_events.inp"): +def generate_abaqus_event_series( + simulation: gi.simulation, filename: str = "pyGcodeDecode_abaqus_events.inp", tolerance: float = 1e-12 +) -> tuple: """Generate abaqus event series. - Parameters: - simulation: (simulation) simulation instance - filename: (string, default = "pyGcodeDecode_abaqus_events.inp") output file name + Args: + simulation (gi.simulation): simulation instance + filename (string, default = "pyGcodeDecode_abaqus_events.inp"): output file name + tolerance (float, default = 1e-12): tolerance to determine whether extrusion is happening + + Returns: + tuple: the event series as a tuple for use in ABAQUS-Python """ - # get all positions and timings unpacked = gi.unpack_blocklist(simulation.blocklist) pos = [unpacked[0].pos_begin.get_vec(withExtrusion=True)] time = [0] @@ -40,8 +44,14 @@ def generate_abaqus_events(simulation: "gi.simulation", filename="pyGcodeDecode_ pos[id][3] = 0 pos[-1][3] = 0 - # writeout to file - f = open(filename, "w") - for time, pos in zip(time, pos): - f.write(str(time) + "," + str(pos[0]) + "," + str(pos[1]) + "," + str(pos[2]) + "," + str(pos[3]) + "\n") - f.close() + event_series_list = [] + + # write to file + with open(filename, "w") as outfile: + for time, pos in zip(time, pos): + outfile.write( + str(time) + "," + str(pos[0]) + "," + str(pos[1]) + "," + str(pos[2]) + "," + str(pos[3]) + "\n" + ) + event_series_list.append((time, pos[0], pos[1], pos[2], pos[3])) + + return tuple(event_series_list)