Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom control structures #64

Open
mdbartos opened this issue Jul 27, 2023 · 0 comments
Open

Add custom control structures #64

mdbartos opened this issue Jul 27, 2023 · 0 comments

Comments

@mdbartos
Copy link
Owner

mdbartos commented Jul 27, 2023

Taking pumps as an example, analogous functions for the following are needed:

operator_flow_coefficients

def pump_flow_coefficients(self, u=None):
"""
Compute pump flow coefficients: alpha_up, beta_up, chi_up,
alpha_dp, beta_dp, chi_dp.
"""
# Import instance variables
H_j = self.H_j # Head at superjunction j
_z_inv_j = self._z_inv_j # Invert elevation at superjunction j
_J_up = self._J_up # Index of superjunction upstream of pump p
_J_dp = self._J_dp # Index of superjunction downstream of pump p
_z_p = self._z_p # Offset of pump inlet above upstream invert elevation
_dHp_max = self._dHp_max # Maximum pump head difference
_dHp_min = self._dHp_min # Minimum pump head difference
_a_p = self._a_p # Pump curve parameter `a`
_b_p = self._b_p # Pump curve parameter `b`
_c_p = self._c_p # Pump curve parameter `c`
_Qp = self._Qp # Current flow rate through pump p
_alpha_p = self._alpha_p # Pump flow coefficient alpha_p
_beta_p = self._beta_p # Pump flow coefficient beta_p
_chi_p = self._chi_p # Pump flow coefficient chi_p
# If no input signal, assume pump is closed
if u is None:
u = np.zeros(self.n_p, dtype=np.float64)
# Check max/min head differences
assert (_dHp_min <= _dHp_max).all()
# Compute pump flow coefficients
numba_pump_flow_coefficients(_alpha_p, _beta_p, _chi_p, H_j, _z_inv_j, _Qp, u,
_z_p, _dHp_max, _dHp_min, _a_p, _b_p, _c_p, _J_up, _J_dp)
# Export instance variables
self._alpha_p = _alpha_p
self._beta_p = _beta_p
self._chi_p = _chi_p

solve_operator_flows

def solve_pump_flows(self, u=None):
"""
Solve for pump discharges given superjunction heads at time t + dt.
"""
# Import instance variables
H_j = self.H_j # Head at superjunction j
_z_inv_j = self._z_inv_j # Invert elevation of superjunction j
_J_up = self._J_up # Index of superjunction upstream of pump p
_J_dp = self._J_dp # Index of superjunction downstream of pump p
_z_p = self._z_p # Offset of pump inlet above upstream invert
_dHp_max = self._dHp_max # Maximum pump head difference
_dHp_min = self._dHp_min # Minimum pump head difference
_a_p = self._a_p # Pump curve parameter `a`
_b_p = self._b_p # Pump curve parameter `b`
_c_p = self._c_p # Pump curve parameter `c`
_Qp = self._Qp # Current flow rate through pump p
# If no input signal, assume pump is closed
if u is None:
u = np.zeros(self.n_p, dtype=np.float64)
# Compute pump flows
_Qp_next = numba_solve_pump_flows(H_j, u, _z_inv_j, _z_p, _dHp_max,
_dHp_min, _a_p, _b_p, _c_p, _J_up, _J_dp)
self._Qp = _Qp_next

In sparse_matrix_equations, analogous lines for the following are needed:

if n_p:
P = self.P
_J_up = self._J_up # Index of superjunction upstream of pump p
_J_dp = self._J_dp # Index of superjunction downstream of pump p
_alpha_p = self._alpha_p # Pump flow coefficient
_beta_p = self._beta_p # Pump flow coefficient
_chi_p = self._chi_p # Pump flow coefficient
_alpha_upm = self._alpha_upm # Summation of pump flow coefficients
_beta_dpl = self._beta_dpl # Summation of pump flow coefficients
_chi_upl = self._chi_upl # Summation of pump flow coefficients
_chi_dpm = self._chi_dpm # Summation of pump flow coefficients
_P_diag = self._P_diag # Diagonal elements of matrix P

if n_p:
_alpha_up = _alpha_p
_alpha_dp = _alpha_p
_beta_up = _beta_p
_beta_dp = _beta_p
_chi_up = _chi_p
_chi_dp = _chi_p
_P_diag.fill(0)
numba_clear_off_diagonals(P, bc, _J_up, _J_dp, n_p)
# Set diagonal
numba_create_OWP_matrix(P, _P_diag, bc, _J_up, _J_dp, _alpha_up,
_alpha_dp, _beta_up, _beta_dp, M, n_p)
# Set right-hand side
numba_add_at(D, _J_up, -_chi_up)
numba_add_at(D, _J_dp, _chi_dp)

In solve_sparse_matrix, a new matrix must be added to the sum:

l = A + O + W + P

And same goes for solve_banded_matrix:

l = A + O + W + P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant