-
Notifications
You must be signed in to change notification settings - Fork 0
/
DEMGen_framework_main.py
155 lines (108 loc) · 5.56 KB
/
DEMGen_framework_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#/////////////////////////////////////////////////
__author__ = "Chengshun Shang (CIMNE)"
__copyright__ = "Copyright (C) 2023-present by Chengshun Shang"
__version__ = "0.0.1"
__maintainer__ = "Chengshun Shang"
__email__ = "cshang@cimne.upc.edu"
__status__ = "development"
__date__ = "June 20, 2024"
__license__ = "BSD 2-Clause License"
#/////////////////////////////////////////////////
import os
import json
from tkinter import Tk
from tkinter.filedialog import askopenfilename
from src import *
from data_processing.pre_processing import *
from data_processing.post_processing import *
class DEMGenMainFramework():
def __init__(self) -> None:
print('-'*76 + '\n')
####################main processes#############################################
def Initilization(self, aim_path):
#read parameter.json file
#file_path = self.choose_file()
file_path = aim_path
if file_path:
self.set_working_directory(file_path)
self.parameters = self.read_json(file_path)
else:
print("No file selected")
exit(0)
def GenerationRun(self):
#particle packing generation
if self.parameters["generator_name"] == "gravitational_deposition_method":
from dynamic_methods import gravitational_deposition_method
MyDEM = gravitational_deposition_method.GravitationalDepositionMethod()
MyDEM.Run(self.parameters, self.ini_path)
elif self.parameters["generator_name"] == "isotropic_compression_method":
from dynamic_methods import isotropic_compression_method
MyDEM = isotropic_compression_method.IsotropicCompressionMethod()
MyDEM.Run(self.parameters, self.ini_path)
elif self.parameters["generator_name"] == "radius_expansion_method":
from dynamic_methods import radius_expansion_method
MyDEM = radius_expansion_method.RadiusExpansionMethod()
MyDEM.Run(self.parameters, self.ini_path)
elif self.parameters["generator_name"] == "radius_expansion_method_with_servo_control":
from dynamic_methods import radius_expansion_method_with_servo_control
MyDEM = radius_expansion_method_with_servo_control.RadiusExpansionMethodWithServoControl()
MyDEM.Run(self.parameters, self.ini_path)
elif self.parameters["generator_name"] == "cubic_arrangement_method":
from constructive_methods import cubic_arrangement_method
MyDEM = cubic_arrangement_method.CubicArrangementMethod()
MyDEM.Run(self.parameters, self.ini_path)
elif self.parameters["generator_name"] == "hpc_arrangement_method":
from constructive_methods import hpc_arrangement_method
MyDEM = hpc_arrangement_method.HpcArrangementMethod()
MyDEM.Run(self.parameters, self.ini_path)
else:
print("No (or wrong) generator name given")
#what we get from above processes is a .mdpa file of DEM particles
def CharacterizationRun(self):
#particle packing characterization
if self.parameters["packing_charcterization_option"] is True:
if self.parameters["regular_shape_option"] is True:
if self.parameters["packing_num"] > 1:
from data_processing.post_processing import packing_characterization_multi
MyDEMChara = packing_characterization_multi.PackingCharacterizationMulti()
MyDEMChara.Run(self.parameters, self.ini_path)
else:
from data_processing.post_processing import packing_characterization_single
MyDEMChara = packing_characterization_single.PackingCharacterizationSingle()
MyDEMChara.Run(self.parameters, self.ini_path)
else:
pass
else:
print("No packing analysis has been done because [packing_charcterization_option] is set as [False]")
def Finilization(self):
print("Successfully finish!")
####################detail functions################################################
def choose_file(self):
print(f'Please select a ParametersDEMGen.json file for starting:')
root = Tk()
root.withdraw()
file_path = askopenfilename(
filetypes=[("JSON files", "*.json")],
title="Select ParametersDEMGen.json file"
)
print("Parameters file for DEMGen selected.")
return file_path
def set_working_directory(self, file_path):
self.ini_path = os.getcwd()
if self.ini_path.endswith('src'):
self.ini_path = os.path.dirname(self.ini_path)
directory = os.path.dirname(file_path)
os.chdir(directory)
print(f"Set current working directory: {os.getcwd()}")
def read_json(self, file_path):
with open(file_path, 'r') as file:
parameters = json.load(file)
return parameters
if __name__ == "__main__":
TestDEM = DEMGenMainFramework()
aim_path = 'C:\\Users\\cshang.PCCB201\\Desktop\\particle_packing_generator\\example\\test_radius_expansion_method_with_servo_control\\ParametersDEMGen.json'
#aim_path = 'C:\\Users\\10237\\Desktop\\DEMGen\\example\\test_radius_expansion_method_with_servo_control\\ParametersDEMGen.json'
TestDEM.Initilization(aim_path)
TestDEM.GenerationRun()
TestDEM.CharacterizationRun()
TestDEM.Finilization()