forked from HughMungous/ENGSCI263_PROJECT1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
84 lines (67 loc) · 2.49 KB
/
helper.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
from typing import List
def improved_euler_step(f, tk: float, yk: float, h: float, pars: List[float])->float:
""" Compute a single Improved Euler step.
Parameters
----------
f : callable
Derivative function.
tk : float
Independent variable at beginning of step.
yk : float
Solution at beginning of step.
h : float
Step size.
pars : iterable
Optional parameters to pass to derivative function.
Returns
-------
yk1 : float
Solution at end of the Improved Euler step.
"""
f0 = f(tk, yk, *pars)
f1 = f(tk + h, yk + h*f0, *pars)
yk1 = yk + h*0.5*(f0 + f1)
return yk1
def pressureModel(t: float, P: float, P0: float, q: float, dqdt: float, a: float, b: float, c: float)->float:
"""Returns the first derivative of pressure with respect to time.
parameters: (all floats)
-----------
t : time, seconds
P : pressure, MPA
q : net sink rate, kg/s
dqdt : first derivative of net sink rate, kg/s^2
a, b, c : arbitrary coefficient for each term
returns:
--------
dPdt : first derivative of pressure with respect to time, MPA/s
"""
return -a*q - b*(P-P0) - c*dqdt
def soluteModel(t: float, C: float, C0: float, P: float, P0: float, q: float, M0: float, a: float, b: float, d: float)->float:
''' Return the Solute derivative dC/dt at time, t, for given parameters.
Parameters:
-----------
t : time, seconds
Independent variable.
C : CO2 concentration, weight %
Dependent variable. (Current CO2 concentration)
qCO2 : CO2 injection rate, kg/s
Source/sink rate. (injection rate of CO2)
a : float
Source/sink strength parameter.
b : float
Recharge strength parameter.
d : float
Recharge strength parameter
P : float
Pressure at time point t
Returns:
--------
dCdt : float
Derivative of Pressure variable with respect to independent variable.
'''
CPrime = C0 if P <= P0 else C
return ((1 - C) * (q / M0)) - ((b / (a * M0)) * (P - P0) * (CPrime - C)) - (d * (C - C0))
def qLossModel(dt: float, C: float, P: float, P0: float, a: float, b: float)->float:
"""DOCSTRING NEEDED
"""
return (b / a) * (P - P0) * C * dt if P > P0 else 0