I am writing a code that carry outs the calculation:
JavaScript
x
17
17
1
def elastic_buckling_pressure(corroded_wall_thickness,
2
external_radius_mm,
3
lambda_value,
4
n_value,
5
youngs_modulus_mpa,
6
poissons_ratio):
7
"""
8
"""
9
section_1 = (1 / ((n_value ** 2 + 0.5 * (lambda_value ** 2)) - 1)
10
) * ((youngs_modulus_mpa * corroded_wall_thickness) / external_radius_mm)
11
section_2_part_1 = ((n_value**2 + lambda_value**2 - 1)**2 / (12 *(1 - poissons_ratio**2))) * (
12
corroded_wall_thickness / external_radius_mm)
13
section_2_part_2 = lambda_value**4 / (n_value**2 + lambda_value**2)**2
14
section_2 = section_2_part_1 + section_2_part_2
15
calculated_pel_value = section_1 * section_2
16
return calculated_pel_value
17
I want to pass incremental n_value value starting from 2 then +0.10 each time it iterates.
For the iteration I am writing while loop counter however, codes does not work.
JavaScript
1
34
34
1
def iteration_calculation(corroded_wall_thickness,
2
external_radius_mm,
3
lambda_value,
4
n_value,
5
youngs_modulus_mpa,
6
poissons_ratio):
7
epsilon = 0.00001
8
count = 0
9
max_iteration = 1000
10
beta = 0.001
11
while count < max_iteration:
12
calculated_pel = elastic_buckling_pressure(corroded_wall_thickness=corroded_wall_thickness,
13
external_radius_mm=external_radius_mm,
14
lambda_value=lambda_value,
15
n_value=n_value,
16
youngs_modulus_mpa=youngs_modulus_mpa,
17
poissons_ratio=poissons_ratio)
18
changed_n_value = n_value + 0.10
19
changed_calculated_pel = elastic_buckling_pressure(corroded_wall_thickness=corroded_wall_thickness,
20
external_radius_mm=external_radius_mm,
21
lambda_value=lambda_value,
22
n_value=changed_n_value,
23
youngs_modulus_mpa=youngs_modulus_mpa,
24
poissons_ratio=poissons_ratio)
25
change_value = changed_calculated_pel - calculated_pel
26
if abs(change_value) < epsilon:
27
beta = calculated_pel
28
break
29
else:
30
beta = changed_calculated_pel
31
count += 1
32
value_calculated = beta * 1
33
return value_calculated
34
JavaScript
1
8
1
training dataset
2
'corroded_wall_thickness': np.array([10]),
3
'external_radius_mm': np.array([250]),
4
'lambda_value': np.array([0.5]),
5
'n_value': np.array([2]),
6
'youngs_modulus_mpa': np.array([350000]),
7
'poissons_ratio': np.array([0.33])
8
However the code does not iterate and I am kind of struggling how to create the iterative loop. I want to achieve difference between calculated_pel and changed_calculated_pel at minimum as stated by epsilon value 0.00001. once that is achieved, code should break and give the converged value. However, lack of my coding ability has created further issues. So, today I have come to you for help. Any suggestion would be appreciated.
Thank You !
Advertisement
Answer
For anyone who might stumble in similar situation: I have managed to solve the issue.
JavaScript
1
34
34
1
2
def iteration_calculation(corroded_wall_thickness,
3
external_radius_mm,
4
lambda_value,
5
youngs_modulus_mpa,
6
poissons_ratio):
7
list_value = {}
8
epsilon = 25
9
count = 0
10
max_iteration = 100000
11
min_value = float("inf")
12
last_value = float("inf")
13
changed_n_value = 2
14
while count < max_iteration:
15
16
new_value = elastic_buckling_pressure(corroded_wall_thickness=corroded_wall_thickness,
17
external_radius_mm=external_radius_mm,
18
lambda_value=lambda_value,
19
n_value=changed_n_value,
20
youngs_modulus_mpa=youngs_modulus_mpa,
21
poissons_ratio=poissons_ratio)
22
list_value[changed_n_value] = new_value
23
if abs(last_value - new_value) < epsilon:
24
break
25
last_value = new_value
26
27
28
changed_n_value +=0.10
29
30
if new_value < min_value:
31
min_value = new_value
32
count+=1
33
return min_value, list_value
34