-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
163 lines (137 loc) · 5.1 KB
/
app.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
156
157
158
159
160
161
162
163
from flask import Flask, render_template, request
import shutil
import os
from typing import SupportsAbs, TypeVar
# import project specific files
from application import launch_mapdl_in_dir, solve_vm_35, get_analytic_solution
from application import (
IMAGE_DIR_PATH,
WORK_DIR_NAME,
JOB_NAME,
RUN_COMPLETE_MESSAGE,
FINAL_IMAGE_PATH,
)
# Set some type hints
_T = TypeVar("_T", bound=SupportsAbs)
app = Flask(__name__)
# Get current working directory as a string
cwd = os.getcwd()
# Set path to dir with images for template
path_to_images = os.path.join(cwd, IMAGE_DIR_PATH)
def pyMAPDL_vm35(
plate_length: float,
plate_thickness: float,
elastic_modulus1: float,
elastic_modulus2: float,
cte_mat1: float,
cte_mat2: float,
reference_temperature: float,
ambient_temperature: float,
):
"""
Solve model and get result image path and max displacement value
"""
# Get MAPDL instance and working dir
mapdl, dir_to_run = launch_mapdl_in_dir(work_dir=WORK_DIR_NAME, job_name=JOB_NAME)
# Solve task and get result path to result image
png_path, uz_max = solve_vm_35(
path_to_images=path_to_images,
mapdl=mapdl,
plate_length=plate_length,
plate_thickness=plate_thickness,
elastic_modulus1=elastic_modulus1,
elastic_modulus2=elastic_modulus2,
cte_mat1=cte_mat1,
cte_mat2=cte_mat2,
reference_temperature=reference_temperature,
ambient_temperature=ambient_temperature,
)
return [png_path, round(uz_max, 3)]
# Render template (displacement calculator)
@app.route(rule="/", methods=["POST", "GET"])
def calculator():
# Set default values
default_plate_length = 10.0
default_plate_thickness = 0.1
default_elastic_modulus1 = 3.0e7
default_elastic_modulus2 = 3.0e7
default_cte_mat1 = 1e-5
default_cte_mat2 = 2e-5
default_reference_temperature = 70
default_ambient_temperature = 170
usum = ""
output_image_path = ""
analytic_value = ""
solution_error = ""
flag = ""
# Get values from page form
if request.method == "POST":
# Get default values if the requested data doesn't exist
default_plate_length = float(request.form.get("Length"))
default_plate_thickness = float(request.form.get("Thickness"))
default_elastic_modulus1 = float(request.form.get("mat1ex"))
default_elastic_modulus2 = float(request.form.get("mat2ex"))
default_cte_mat1 = float(request.form.get("mat1cte"))
default_cte_mat2 = float(request.form.get("mat2cte"))
default_reference_temperature = float(request.form.get("tref"))
default_ambient_temperature = float(request.form.get("tamb"))
# Run solution with entered values
solution_results = pyMAPDL_vm35(
plate_length=default_plate_length,
plate_thickness=default_plate_thickness,
elastic_modulus1=default_elastic_modulus1,
elastic_modulus2=default_elastic_modulus2,
cte_mat1=default_cte_mat1,
cte_mat2=default_cte_mat2,
reference_temperature=default_reference_temperature,
ambient_temperature=default_ambient_temperature,
)
print(RUN_COMPLETE_MESSAGE)
# Move result image file or directory to final location
shutil.move(solution_results[0], FINAL_IMAGE_PATH)
# Set path to result image file
output_image_path = FINAL_IMAGE_PATH
# Get max displacement value from solution
usum = solution_results[1]
# Set flag to switch image rendering mode (1 - solution completed)
flag = 1
analytic_value = get_analytic_solution(
plate_length=default_plate_length,
plate_thickness=default_plate_thickness,
elastic_modulus1=default_elastic_modulus1,
elastic_modulus2=default_elastic_modulus2,
cte_mat1=default_cte_mat1,
cte_mat2=default_cte_mat2,
reference_temperature=default_reference_temperature,
ambient_temperature=default_ambient_temperature,
)
if not abs(usum) > 0.0:
# Set dummy solution error in case of no error
solution_error = 0.000
else:
# Get solution error in %
solution_error = (
(solution_results[1] - analytic_value) / solution_results[1]
) * 100
# Round solution error to 3 decimal digits
solution_error = round(solution_error, 3)
return render_template(
template_name_or_list="index.html",
Flag=flag,
TotalDeformation=usum,
SolveStatus="Solved",
RoarksZmax=analytic_value,
error=solution_error,
output_image_url=output_image_path,
input_image_url=IMAGE_DIR_PATH,
L2=default_plate_length,
t2=default_plate_thickness,
E21=default_elastic_modulus1,
E22=default_elastic_modulus2,
c21=default_cte_mat1,
c22=default_cte_mat2,
T1=default_reference_temperature,
T2=default_ambient_temperature,
)
if __name__ == "__main__":
app.run(debug=True)