From 110c548f510688344c80dd9c85cbf410caca6944 Mon Sep 17 00:00:00 2001 From: Sachin Jalan Date: Tue, 18 Jul 2023 15:25:04 +0530 Subject: [PATCH 1/3] utility_funcitons_added --- utitlity_functions_benchmarks.py | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 utitlity_functions_benchmarks.py diff --git a/utitlity_functions_benchmarks.py b/utitlity_functions_benchmarks.py new file mode 100644 index 0000000..1f21012 --- /dev/null +++ b/utitlity_functions_benchmarks.py @@ -0,0 +1,48 @@ +import json +import os +import tomllib as tl + +def entity_sets(input_file_path: str, output_file_path: str): + """ + Creates a json file of entity_sets required by diff-mpm + code from the json file of entity_sets of the CB-Geo MPM code. + + Parameters + ---------- + input_file_path : str + output_file_path : str + + Returns + ------- + None + """ + if not os.path.exists(input_file_path): + raise FileNotFoundError("File does not exist") + f = open(input_file_path) + data = json.load(f) + dictionary = {} + dictionary2 = {} + for i in data["node_sets"]: + dictionary2[i["id"]] = i["set"] + dictionary["node_sets"] = dictionary2 + f.close() + json_object = json.dumps(dictionary, indent=4) + with open(output_file_path, "w") as outfile: + outfile.write(json_object) + + +def particles_txt_to_json(input_file_path: str, output_file_path: str): + if not os.path.exists(input_file_path): + raise FileNotFoundError("File does not exist") + with open(input_file_path, "r") as f: + lines = f.readlines() + + data = [] + for line in lines[1:]: + line = line.strip() + if line: + floats = line.split(" ") + data.append([[float(f) for f in floats]]) + + with open(output_file_path, "w") as f: + json.dump(data, f, indent=2) From 34633ebfc41754696b2b5e59915c860ea7abc0ad Mon Sep 17 00:00:00 2001 From: Sachin Jalan Date: Thu, 20 Jul 2023 16:21:36 +0530 Subject: [PATCH 2/3] Changes Implemented --- utitlity_functions_benchmarks.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/utitlity_functions_benchmarks.py b/utitlity_functions_benchmarks.py index 1f21012..63abcf1 100644 --- a/utitlity_functions_benchmarks.py +++ b/utitlity_functions_benchmarks.py @@ -18,17 +18,15 @@ def entity_sets(input_file_path: str, output_file_path: str): """ if not os.path.exists(input_file_path): raise FileNotFoundError("File does not exist") - f = open(input_file_path) - data = json.load(f) + with open(input_file_path) as f: + data = json.load(f) dictionary = {} dictionary2 = {} for i in data["node_sets"]: dictionary2[i["id"]] = i["set"] dictionary["node_sets"] = dictionary2 - f.close() - json_object = json.dumps(dictionary, indent=4) with open(output_file_path, "w") as outfile: - outfile.write(json_object) + json.dump(outfile, indent=2) def particles_txt_to_json(input_file_path: str, output_file_path: str): From d2050fbed8d6432046967234a51c6a162a5a54dc Mon Sep 17 00:00:00 2001 From: Sachin Jalan Date: Sat, 5 Aug 2023 14:24:04 +0530 Subject: [PATCH 3/3] support for particle_sets added --- utitlity_functions_benchmarks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utitlity_functions_benchmarks.py b/utitlity_functions_benchmarks.py index 63abcf1..626f397 100644 --- a/utitlity_functions_benchmarks.py +++ b/utitlity_functions_benchmarks.py @@ -22,6 +22,11 @@ def entity_sets(input_file_path: str, output_file_path: str): data = json.load(f) dictionary = {} dictionary2 = {} + if("particle_sets" in data): + for i in data["particle_sets"]: + dictionary2[i["id"]] = i["set"] + dictionary["particle_sets"] = dictionary2 + dictionary2 = {} for i in data["node_sets"]: dictionary2[i["id"]] = i["set"] dictionary["node_sets"] = dictionary2 @@ -30,6 +35,19 @@ def entity_sets(input_file_path: str, output_file_path: str): def particles_txt_to_json(input_file_path: str, output_file_path: str): + """ + Creates a json file of particles required by diff-mpm + code from the txt file of particles of the CB-Geo MPM code. + + Parameters + ---------- + input_file_path : str + output_file_path : str + + Returns + ------- + None + """ if not os.path.exists(input_file_path): raise FileNotFoundError("File does not exist") with open(input_file_path, "r") as f: