# Improving the flowrate calculation

In the current state, CADET-Process uses sympy to solve the Flow Rates for every unit by creating symbols and generating general equations. This should be improvable by using numpy for solving this problem by generating a matrix and using numpy.linalg.solve.

Let us consider we have a Flow Sheet with n different units. Every unit has an equal total in- and outflow. For every unit we know the percentile w_{ji} of the flow Q_j \cdot w_{ji} from unit j to i (so Q_j is the total outflow of unit j). So we can assume the sum of every Q_j \cdot w_{ji} is equal to the total output Q_i of unit i:

\sum_{j=1}^{n_{units}} q_{ji} = \sum_{j=1}^{n_{units}} w_{ji} Q_j = Q_i

This equation is equivalent to

\left( w_{ii} - 1 \right) Q_i + \sum_{j\neq i}^{n_{units}} w_{ji} Q_j = 0

If the unit i is an Inlet or a Cstr with a given flow rate Q_i, Q_i does not depend on the other flows and by setting every w_{ji} with j\ne i to zero, the corresponding rows are simplified to

w_{ii} Q_i = Q_i

with w_{ii} = 1.

This generates a solvable system of equations (in this example the first row has a given flow rate, most others have not):

\begin{bmatrix} 1 & \dots & 0 \\ \vdots & \ddots & \\ w_{n1} & & w_{nn} - 1 \end{bmatrix} \begin{bmatrix} Q_1 \\ \vdots \\ Q_n \end{bmatrix} = \begin{bmatrix} Q_1 \\ \vdots \\ 0 \end{bmatrix}

By solving the total output Q_j for every unit we can calculate the flow rate for every connection by multiplying w_{ji} Q_j.

Thanks to Denis E.

2 Likes

Hi!

@daklauss , @j.schmoelder , you probably already found out the correct solution yourself, but just wanted to share here that in case of CSTR with given flow rate this system of equation needs to be modified. I found out this after our discussion as some tests were failing In this case the equation for CSTR is just Q_i = c_i, so what I did is to set all corresponding w_ji = 0, where i is the CSTR index. After that all tests passed.

2 Likes

Hey, thanks for your input! @daklauss has made good progress on this matter! You can track the progress here. Tests are already passing and AFAIK, we only need to clean up the code a bit. Daniel will also update this post later with the correct equations.

2 Likes

Hi,
thanks for your response. I’ve encountered the same issues with failing tests and modyfied my equations. I see i should have made more clear that simplifying an equation to w_{ii}Q_i = c_i meant to set every other w_{ji} to zero.

1 Like

I found another small mistake. w_{ii} is not necessary -1. If a unit is connected to itself with Outputstate \tilde{w}_{ii}, this component is w_{ii}=\tilde{w}_{ii} -1.

1 Like

This was just merged into dev! Thanks again to @daklauss and @dionis!

3 Likes