-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
95 lines (80 loc) · 3.84 KB
/
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
import math
import os
import pickle
import sys
import Materials.MaterialProperties as mat_prop
from Plots.plot_sim_result_1 import plot_sim_result_1
from Plots.plot_sim_result_energies_1 import plot_sim_result_energies_1
from Plots.plot_sim_result_gif_1 import make_sim_result_gif_1
from Simulator.simulator import Simulator
import time
def main():
# Setup material properties query
material_properties_query = mat_prop.MaterialPropertiesQuery()
# Select material
material_name = "Test 1"
material_properties = material_properties_query.get_material_properties(material_name)
# Print material properties
print("----------------------------------------------------")
print("Material properties:")
print(" Material name: {}".format(material_name))
print(" Young's modulus: {}".format(material_properties.youngs_modulus))
print(" Poisson ratio: {}".format(material_properties.poisson_ratio))
print(" Density: {}".format(material_properties.density))
print(" Damping coefficient: {}".format(material_properties.damping_coefficient))
print("----------------------------------------------------")
# Setup simulation settings
time_to_simulate = 4.0 # Seconds
time_step = 0.001 # Seconds
# time_step = 1 / 30
number_of_time_steps = math.ceil(time_to_simulate / time_step)
element_order = 2
# Cantilever settings
length = 6.0 # Meters
height = 2.0 # Meters
number_of_nodes_x = 5 # Number of nodes in x direction
number_of_nodes_y = 3 # Number of nodes in y direction
traction_force = [0, 0] # Newtons
gravity = [0, -3] # m/s^2
# Print simulation settings
print("----------------------------------------------------")
print("Simul ion settings:")
print(" Time to simulate: {}".format(time_to_simulate))
print(" Time step: {}".format(time_step))
print(" Number of time steps: {}".format(number_of_time_steps))
print("----------------------------------------------------")
simulator = Simulator(number_of_time_steps, time_step, material_properties,
length, height, number_of_nodes_x, number_of_nodes_y, traction_force,
gravity, element_order)
sim_file_name = f'result_{length}l_{height}h_{number_of_nodes_x}xn_{number_of_nodes_y}yn_{traction_force}tf_{time_to_simulate}t_{time_step}ts_{element_order}order_{material_name}mn_{gravity}g_{simulator.material_properties.damping_coefficient}dc'
try:
f = open(sim_file_name, 'rb')
result = pickle.load(f)
f.close()
except:
# Start simulation
result = simulator.simulate()
f = open(sim_file_name, 'wb')
pickle.dump(result, f)
f.close()
# Plot the final simulation result
plot_sim_result_1(simulator.FEM_V, simulator.FEM_encoding, result.nodal_displacements[-1],
simulator.number_of_nodes_x, simulator.number_of_nodes_y, simulator.traction_force,
result.time_steps[-1], simulator.element_order)
# Plot the various energies as a function of time
# plot_sim_result_energies_1(simulator.FEM_V, simulator.FEM_encoding,
# simulator.material_properties.density, result,
# simulator.gravity, simulator.all_A_e, simulator.lambda_, simulator.mu, simulator.element_order)
# make a gif of the simulation
make_sim_result_gif_1(simulator.FEM_V, simulator.FEM_encoding,
result, simulator.number_of_nodes_x, simulator.number_of_nodes_y,
simulator.traction_force, result.time_steps[-1], simulator.time_step,
sim_file_name, simulator.element_order)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
try:
sys.exit(0)
except SystemExit:
os._exit(0)