Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Moved dA calculation in initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kandread committed Oct 15, 2019
1 parent 7f70563 commit b4418f0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions confluence/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def __init__(self, n, A0, H, W, S, dA, routing_table):
self.nreaches = len(A0)
self.A0 = np.array(A0)
self.n = np.array(n)
w = np.mean(W, axis=0)
h = np.mean(H, axis=0)
if dA is None:
dA = np.array([(w[r] + W[np.argmin(H[:, r]), r]) / 2 * (h[r] - H[np.argmin(H[:, r]), r])
for r in range(self.nreaches)]).T
self.data = (H, W, S, dA)
self.rivs = self._riverTopology(routing_table)

Expand All @@ -55,12 +60,8 @@ def objective(self, x):
H, W, S, dA = self.data
w = np.mean(W, axis=0)
h = np.mean(H, axis=0)
if dA is None:
dA = np.array([(w[r] + W[np.argmin(H[:, r]), r]) / 2 * (h[r] - H[np.argmin(H[:, r]), r])
for r in range(self.nreaches)]).T
else:
dA = np.mean(dA, axis=0)
Q = 1 / n * (A0 + dA)**(5 / 3) * w**(-2 / 3) * np.mean(S,
da = np.mean(dA, axis=0)
Q = 1 / n * (A0 + da)**(5 / 3) * w**(-2 / 3) * np.mean(S,
axis=0)**(1 / 2)
error = [np.sqrt((Q[i] - np.sum(Q[j] for j in self.rivs[i]))**2) for i in self.rivs]
return np.sum(error)
Expand All @@ -72,12 +73,8 @@ def constraint(self, i, x):
H, W, S, dA = self.data
w = np.mean(W, axis=0)
h = np.mean(H, axis=0)
if dA is None:
dA = np.array([(w[r] + W[np.argmin(H[:, r]), r]) / 2 * (h[r] - H[np.argmin(H[:, r]), r])
for r in range(self.nreaches)]).T
else:
dA = np.mean(dA, axis=0)
Q = 1 / n * (A0 + dA)**(5 / 3) * w**(-2 / 3) * np.mean(S,
da = np.mean(dA, axis=0)
Q = 1 / n * (A0 + da)**(5 / 3) * w**(-2 / 3) * np.mean(S,
axis=0)**(1 / 2)
return Q[i] - np.sum([Q[j] for j in self.rivs[i]])

Expand Down

0 comments on commit b4418f0

Please sign in to comment.