-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceTermFit.py
More file actions
135 lines (109 loc) · 3.05 KB
/
Copy pathSourceTermFit.py
File metadata and controls
135 lines (109 loc) · 3.05 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 4 08:57:32 2022
@author: maycon
"""
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.integrate import simpson as sp
p = [0.1, 1.0, 2.0, 6.0, 10.0] ## MPa Units, Accepts: [0.1, 1, 2, 6, 10]
peak = []
def fitline(P, xx, low, high):
k1 = 0.46 * P + 0.42 - 1
k2 = 1.14 * P + 0.323 - 1
k3 = 1.0
a = 1.0
max_fun = -0.0990568*P**2 + 2.79722*P + 0.322469 #1.713 * P + 1.98
k4 = np.log(max_fun - k2/2 - k1/2) / (0.5*(1-0.5))
phi = np.linspace(0,1, 101)
fun = lambda i: (k1) * i + (k2) * (1-i) + k3 * np.exp(k4 * i * (1 - i) / a)
y = [fun(i) for i in phi]
z = []
for i in xx:
val = i
if i < low:
phi = 1
elif i > high:
phi = 0
else:
phi = 1 - (( low - val ) * (1 - 0) / (low - high) )
z.append(fun(phi))
return y, z
df = pd.read_csv("heatfluxdata2.csv", dtype=np.float64, skiprows=1)
df_1atm_x = df.values[:108,8]
df_1atm_y = df.values[:108,9]
df_10atm_x = df.values[:50,6]
df_10atm_y = df.values[:50,7]
df_20atm_x = df.values[:91,4]
df_20atm_y = df.values[:91,5]
df_60atm_x = df.values[:113,2]
df_60atm_y = df.values[:113,3]
df_100atm_x = df.values[:171,0]
df_100atm_y = df.values[:171,1]
a = 1.0
c = ['lightseagreen','yellowgreen','gold','darkorange','orangered']
v = 0
for P in p:
if P == 10:
xx = df_100atm_x
yy = df_100atm_y
low = 200 - 10 * a**2.6
high = 200 + 10 * a**2.6
elif P == 6:
xx = df_60atm_x
yy = df_60atm_y
low = 200 - 13 *a**2
high = 200 + 10 * a**2
elif P == 2:
xx = df_20atm_x
yy = df_20atm_y
low = 180
high = 220
elif P == 1:
xx = df_10atm_x
yy = df_10atm_y
low = 165
high = 225
elif P == 0.1:
xx = df_1atm_x
yy = df_1atm_y
low = 190
high = 210
y,z = fitline(P, xx, low, high)
peak.append(max(y))
plt.plot(xx, yy, label = str(P)+" MPa (Data)",ls = '--', c = c[v])
plt.plot(xx, z, label = str(P)+" MPa (Fit)" , ls = "-", c=c[v])
v += 1
plt.legend(prop={'size':9})
plt.xlabel("Spatial Variable" )
plt.ylabel("Heat Flux [kW / cm$^2$]" )
#plt.title("Heat Flux Data Fitting")
plt.grid()
print(p)
print(peak)
pout = ""
for i,j in zip(p,peak):
pout += f"({i},{j}),"
print(pout)
plt.figure()
plt.plot(p, peak)
plt.show()
#plt.savefig("/home/mmeierdo/Paper_Folder/EpsFit1.pdf", format = "pdf" )
'''
int_exp = sp(yy,xx)
int_mod = sp(z,xx)
error = 100 * abs(int_exp - int_mod) / int_exp
print("Data Integral: " + str(int_exp))
print("Model Integral: " + str(int_mod))
print("%Error: " + str(error))
plt.figure()
plt.plot(xx, yy, label = "experiment", c = "black" )
plt.plot(xx, z, label = "Model", c = "red" , ls = "-.")
plt.legend()
plt.xlabel("Spacial Variable" )
plt.ylabel("Heat Flux - [kW / cm^2]" )
plt.title("Model Fit" )
plt.figtext(0.14, 0.7, "Integral %Error " + str(round(error, 2)))
'''