summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPravin Dalve2022-07-21 16:35:06 +0530
committerPravin Dalve2022-07-21 16:35:06 +0530
commite06865e49a7872b7a3dfe4257e63eb8e547f7fe6 (patch)
treecacf914321bbe2b7b73ec2966b838068f780466b
parentad85f90494241f1bea34dbbbfb2f61128e443fbc (diff)
downloadcrude-characterization-plugin-DWSIM-e06865e49a7872b7a3dfe4257e63eb8e547f7fe6.tar.gz
crude-characterization-plugin-DWSIM-e06865e49a7872b7a3dfe4257e63eb8e547f7fe6.tar.bz2
crude-characterization-plugin-DWSIM-e06865e49a7872b7a3dfe4257e63eb8e547f7fe6.zip
characterization for weight fraction and SG data added
-rw-r--r--Characterization/characterization.py186
1 files changed, 185 insertions, 1 deletions
diff --git a/Characterization/characterization.py b/Characterization/characterization.py
index 95e97d6..569de11 100644
--- a/Characterization/characterization.py
+++ b/Characterization/characterization.py
@@ -216,6 +216,13 @@ def characterization_wt(SG, x_data, y_data):
# print(tb)
def characterization_vol(SG, x_data, y_data):
+ '''
+ Function for characterizing TBP data which creates pseudo cuts and returns Ti, Tf, W%, V%, M%, MW, SG and Tb of pseudo cuts
+ :param SG: Specific gravity of whole crude
+ :param x_data: list of volume percent data points
+ :param y_data: list of Temperature data points in deg C
+ :return: lists of Ti(K), Tf(K), W%, V%, M%, MW, SG and Tb(K)
+ '''
for i in range(len(y_data)):
y_data[i] = (y_data[i] + 273.15)
@@ -339,4 +346,181 @@ def characterization_vol(SG, x_data, y_data):
# print(mf)
# print(mw)
# print(sg)
-# print(tb) \ No newline at end of file
+# print(tb)
+
+
+def characterization_wt_SG(SG, x_data, y_data, SG_data):
+ '''
+ Function for characterizing TBP data which creates pseudo cuts and returns Ti, Tf, W%, V%, M%, MW, SG and Tb of pseudo cuts
+ :param SG: Specific gravity of whole crude
+ :param x_data: list of weight percent data points
+ :param y_data: list of Temperature data points in deg C
+ :param SG_data: list of Specific gravity data points
+ :return: lists of Ti(K), Tf(K), W%, V%, M%, MW, SG and Tb(K)
+ '''
+
+ for i in range(len(y_data)):
+ y_data[i] = (y_data[i] + 273.15)
+
+ P = np.linspace(0, y_data[0], 100)
+
+ rms_error = math.inf
+ Pf = 0
+ fitA = 0
+ fitB = 0
+ E = []
+
+ for i in range(len(P)):
+ P0 = P[i]
+
+
+ def fun(x, A, B):
+ y = np.empty(len(x))
+ for i in range(len(x)):
+ y[i] = P0 * (((A / B) * log(1 / (1 - x[i] / 100))) ** B + 1)
+ return y
+
+
+ parameters, covariance = curve_fit(fun, x_data, y_data)
+ A = parameters[0]
+ B = parameters[1]
+ error = np.empty(len(x_data))
+ for i in range(len(x_data)):
+ error[i] = abs(y_data[i] - fun([x_data[i]], A, B))[0]
+ E.append(np.sqrt(np.mean(error ** 2)))
+ if rms_error > np.sqrt(np.mean(error ** 2)):
+ Pf = P0
+ rms_error = np.sqrt(np.mean(error ** 2))
+ fitA = A
+ fitB = B
+
+
+ def fun1(y, A, B):
+ x = np.empty(len(y))
+ for i in range(len(y)):
+ x[i] = 1 - exp(-B / A * ((y[i] - Pf) / Pf) ** (1 / B))
+ return x
+
+
+ def fun2(x, A, B):
+ y = np.empty(len(x))
+ for i in range(len(x)):
+ y[i] = Pf * (((A / B) * log(1 / (1 - x[i] / 100))) ** B + 1)
+ return y
+
+
+ rms_error = math.inf
+ Pf_SG = 0
+ fitA_SG = 0
+ fitB_SG = 0
+ E_SG = []
+
+
+ P_SG = np.linspace(0, 500, 1000)
+ for i in range(len(P_SG)):
+ P0 = P_SG[i]
+
+
+ def fun_SG(x, A, B):
+ y = np.empty(len(x))
+ for i in range(len(x)):
+ y[i] = P0 * (((A / B) * log(1 / (1 - x[i]))) ** B + 1)
+ return y
+
+
+ try:
+ parameters, covariance = curve_fit(fun_SG, SG_data, y_data)
+ except RuntimeError:
+ parameters = [1, 1]
+ print(P0)
+
+ A_SG = parameters[0]
+ B_SG = parameters[1]
+ error_SG = np.empty(len(SG_data))
+ for i in range(len(SG_data)):
+ error_SG[i] = abs(y_data[i] - fun_SG([SG_data[i]], A_SG, B_SG))[0]
+ E_SG.append(np.sqrt(np.mean(error_SG ** 2)))
+ if rms_error > np.sqrt(np.mean(error_SG ** 2)):
+ Pf_SG = P0
+ rms_error = np.sqrt(np.mean(error_SG ** 2))
+ fitA_SG = A_SG
+ fitB_SG = B_SG
+
+
+ def fun1_SG(y, A, B):
+ x = np.empty(len(y))
+ for i in range(len(y)):
+ x[i] = 1 - exp(-B / A * ((y[i] - Pf_SG) / Pf_SG) ** (1 / B))
+ return x
+
+
+ def fun2_SG(x, A, B):
+ y = np.empty(len(x))
+ for i in range(len(x)):
+ y[i] = Pf_SG * (((A / B) * log(1 / (1 - x[i]))) ** B + 1)
+ return y
+
+
+ IBP = fun2([0], fitA, fitB)[0]
+ FBP = fun2([99.99], fitA, fitB)[0]
+
+ data = create_cuts(IBP, FBP)
+
+ data["cut T"] = data["cuts_f"] - 273.15
+ data["Tb"] = (data["cuts_i"] + data["cuts_f"]) / 2
+
+ # calculation of SG and wt%
+ data["wt%"] = fun1(data["Tb"], fitA, fitB)
+ data["cut wt%"] = data["wt%"].diff().fillna(data["wt%"])
+ data["SG"] = fun1_SG(data["Tb"], fitA_SG, fitB_SG)
+
+ # Normalising SG
+ SG_t = 1 / sum(data["cut wt%"] / data["SG"])
+ data["SG"] = data["SG"] * SG / SG_t
+
+ data["MW"] = calc_MW(data["Tb"], data["SG"])
+
+ V = np.empty(len(data.index))
+
+ V[0] = data.at[0, "wt%"] / data.at[0, "SG"]
+
+ V[1:] = [(data.at[i, "wt%"] - data.at[i - 1, "wt%"]) / data.at[i, "SG"] for i in range(1, len(data.index))]
+
+ V = data["wt%"].diff().fillna(data["wt%"]) / data["SG"]
+
+ V = V / sum(V)
+ data["V%"] = V.cumsum()
+
+ M = data["wt%"].diff().fillna(data["wt%"]) / data["MW"]
+
+ M = M / sum(M)
+ data["M%"] = M.cumsum()
+
+ Ti = list(data["cuts_i"])
+ Tf = list(data["cuts_f"])
+ Wf = list(data["wt%"])
+ Vf = list(data["V%"])
+ Mf = list(data["M%"])
+ MW = list(data["MW"])
+ SG = list(data["SG"])
+ Tb = list(data["Tb"])
+
+ return [Ti, Tf, Wf, Vf, Mf, MW, SG, Tb]
+
+# uncomment the code to see use of function
+# SG = 0.809
+#
+# x = [ 7.68859754431644, 15.1538050381994, 31.5823352252608, 42.4062967988428, 52.8464767354692, 62.7377406502837, 71.2394217843979, 74.0267929538375, 83.4788183586731, 88.4543077863666, 92.486636460126]
+# y = [ 65, 100, 150, 200, 250, 300, 350, 370, 450, 500, 550]
+# SG_d = [0.647455170862764, 0.706398861451607, 0.749777780304995, 0.788281101028304, 0.819733528157335,
+# 0.84372915687493, 0.865974897719598, 0.882076096202821, 0.898995318013918, 0.913907839238595,
+# 0.924511278748632]
+# ti, tf, wf, vf, mf, mw, sg, tb = characterization_wt_SG(SG, x, y, SG_d)
+# print(ti)
+# print(tf)
+# print(wf)
+# print(vf)
+# print(mf)
+# print(mw)
+# print(sg)
+# print(tb)