-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_model.py
140 lines (114 loc) · 4.18 KB
/
create_model.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
"""
Author: Philip Ligthart
Date: April 2022
Create the dat files for a Monte-Carlo simulation
"""
import math
import pandas as pd
import configparser
from create_rectangle_proc_dat import create_rectangle_proc_dat
def create_rectangle(center_x: float , center_y: float, aspect_ratio: float, rotation_angle: float, area: float) -> list:
"""
Create a rectangle with a specified area, rotation_angle and aspect_ratio.
Args:
center_x: (float) The x-coordinate of the center of the rectangle.
center_y: (float) The y-coordinate of the center of the rectangle.
aspect_ratio: (float) The ratio of length to width
rotation_angle: (float) The angle (in degrees) by which to rotate the
rectangle. A positive angle rotates the rectangle clockwise.
area: (float) The area of the rectangle.
Returns:
corners (tuple): The four corners of the void.
(x1, y1, z1, x2, y2, z2, x3, y3, z3)
"""
# Calculate the side length of the rectangle
length = math.sqrt(area * aspect_ratio)
width = length / aspect_ratio
# Calculate the half-length of the rectangle
half_length = length / 2.0
half_width = width / 2.0
# Calculate the rotation angle in radians
alpha_rad = math.radians(rotation_angle)
center = [center_x, center_y]
# Calculate the vertices of the rectangle
vertices = [
[center[0] + half_length, center[1] + half_width],
[center[0] - half_length, center[1] + half_width],
[center[0] - half_length, center[1] - half_width],
[center[0] + half_length, center[1] - half_width],
]
# Apply the rotation alpha to each vertex
for i in range(len(vertices)):
x = vertices[i][0] - center[0]
y = vertices[i][1] - center[1]
vertices[i][0] = (
center[0] + x * math.cos(alpha_rad) - y * math.sin(alpha_rad)
)
vertices[i][1] = (
center[1] + x * math.sin(alpha_rad) + y * math.cos(alpha_rad)
)
# Adding the z displacements of zero which are required by mentat.
vertices = (
vertices[0][0],
vertices[0][1],
0,
vertices[1][0],
vertices[1][1],
0,
vertices[2][0],
vertices[2][1],
0,
vertices[3][0],
vertices[3][1],
0,
)
return vertices
def setup_proc_file_main():
"""
Setup the proc file from the input .csv file.
The loadcase parameters are read from the config.ini file.
The rectangle designs are read from the Rectangle_inputs.csv file.
Args:
None
Returns:
None
"""
# read the parameters from the config file
config_obj = configparser.ConfigParser()
config_obj.read("config.ini")
Params = config_obj["Parameters"]
pressure = float(Params["pressure"])
element_size = float(Params["element_size"])
min_fraction = float(Params["min_fraction"])
# read the csv file with the rectangle designs into a pandas dataframe
df = pd.read_csv(f"Rectangle_inputs.csv", header=None)
col_headings = ["center_x", "center_y", "aspect_ratio", "rotation", "area"]
df.columns = col_headings
# loop over every sample in the the df
for index, row in df.iterrows():
proc_file_name = f".\marcmentat_files\example_model_{index}"
dat_file_name = f"example_model_{index}"
# get the values from the dataframe row
center_x = row["center_x"]
center_y = row["center_y"]
angle = row["rotation"]
aspect_ratio = row["aspect_ratio"]
area = row["area"]
# create the rectangle
nodes = create_rectangle(center_x, center_y, aspect_ratio, angle, area)
x_vals = [nodes[0], nodes[3], nodes[6], nodes[9]]
y_vals = [nodes[1], nodes[4], nodes[7], nodes[10]]
# create the proc file
create_rectangle_proc_dat(
x_vals,
y_vals,
element_size,
pressure,
min_fraction,
area,
proc_file_name,
dat_file_name,
)
if __name__ == "__main__":
setup_proc_file_main()
print("create_model - completed")