Integrating formula for gas flow into a fixed volume The rate of gas flow into a pressure vessel can be expressed as:
${\frac{dp}{dt}}=K\sqrt{S(S-p)}\qquad p\leq S$
I want to find $p(t)$ where $K, S$ (source pressure), and initial pressure $P_0$ are constants. My atrophied calculus skills could only come up with nonsense solutions, failing the simple test that $p$ rises asymptotically to $S$.
 A: This is a seperable ODE . I assume you want $p(t_0) = P_0$ for some $t_0 \in \mathbb{R}$.
$$p'(t) = K \sqrt{S(S-p(t))} = K \sqrt{S} \sqrt{S-p(t)}$$
$$\stackrel{(\star)}{\Leftrightarrow} \frac{p'(t)}{\sqrt{S-p(t)}} = K \sqrt S $$
$$\Leftrightarrow \int\limits_{t_0}^t \frac{p'(x)}{\sqrt{S-p(x)}} dx = \int\limits_{t_0}^t K \sqrt S\ dx = K \sqrt{S} (t-t_0)$$
By substitution $u = S-p(x)$ we get
$$\int\limits_{t_0}^t \frac{p'(x)}{\sqrt{S-p(x)}} dx = - \int\limits_{S-p(t_0)}^{S-p(t)} \frac{1}{\sqrt u} du = \Big[- 2\sqrt{u} \Big]_{u=S-p(t_0)}^{u=S-p(t)} = -2\sqrt{S-p(t)} + 2\sqrt{S-p(t_0)}$$
$$ = -2\sqrt{S-p(t)} + 2\sqrt{S-P_0}$$
Therefore continuing our deduction above:
$$-2\sqrt{S-p(t)} = K\sqrt{S}(t-t_0) - 2\sqrt{S-P_0}$$
for a constant $c_1 \in \Bbb R$.
Squaring both sides leads us to
$$4 (S-p(t)) = K^2S (t-t_0)^2 - 4K\sqrt{S}\sqrt{S-P_0}(t-t_0) + 4(S-P_0)$$
$$\Leftrightarrow S-p(t) = \frac{1}{4} K^2S (t-t_0)^2 - K\sqrt{S}\sqrt{S-P_0}(t-t_0) + (S-P_0) $$
$$\Leftrightarrow p(t) = -\frac{1}{4} K^2S (t-t_0)^2 + K\sqrt{S}\sqrt{S-P_0}(t-t_0) - (S-P_0)  + S $$
$$= -\frac{1}{4} K^2S (t-t_0)^2 + K\sqrt{S(S-P_0)}(t-t_0) + P_0$$
This should solve the problem, atlhough you have to pay attention to where the solution is defined, since you can't take the squareroot of a negative number in $\Bbb R$, therefore this solution only makes sense in an interval $I$ with $t_0 \in I$ and $S-p(t) > 0\ (\forall t \in I)$. If $P_0 = S$ then $p(t) = P_0\ (\forall t\in \Bbb R)$ would also be a valid solution, since $p'(t) = 0 = K\sqrt{S\cdot 0}$ [this happens because while finding the solution (look at $\star$) we divided by $\sqrt{S-p(t)}$ assuming this would'nt equal 0].
If you find any mistakes please let me know.

EDIT: (follow up to your second question)
The reason why this mathematical model doesn't fit is that, if you get in the theory of ODE's, the way I solved it only gives you a solution on an interval.
You can also easily see this if you look at $p(t)$. Since it's a polynomial with a negative leading coefficient, $p(t) \to -\infty$, contradicting your real-life physics.
But there is a way to fix this
If you use the simplified version $t_0 = 0$ you get
$$p(t_1) = S \Leftrightarrow t_1 = \frac{2\sqrt{S(S-P_0)}}{KS}$$
If you plug this $t_1$ into your derivative, you get $p'(t_1) = 0$.
This is good, because you now can define:
$$q(t) := \begin{cases} p(t) & \ \text{if}\ t\in\ [0, t_1] \\ S & \ \text{if}\ t \in\ ]t_1, \infty[ \end{cases}$$
Now you have 
$$\lim\limits_{t \uparrow t_1} p(t) = S = \lim\limits_{t \downarrow t_1} S = q(t_1) $$
but also [since S is a constant and therefore $\frac{d}{dt}S = 0$]
$$\lim\limits_{t \uparrow t_1} p'(t) = 0 = \lim\limits_{t \downarrow t_1} \frac{d}{dt}S = q'(t_1)$$
This means your new defined $q(t)$ is a differentiable function that not only solves the ODE but also fits your physics. [well, at least I hope it fits the physics; I'm a math guy not a physics guy]
A: GhostAmarth, thanks so much for your help, but you flipped the sign on the second term of the last step. Correcting that, the final answer would be:
$p(t)= -\frac{1}{4} K^2S (t-t_0)^2 + K\sqrt{S(S-P_0)}(t-t_0) + P_0$
For practical purposes, $t_0=0$, so this simplifies to:
$p(t)= -\frac{1}{4} K^2S t^2 + K\sqrt{S(S-P_0)} t + P_0$
I did some numerical analysis and verified the results are correct up until the time $t$ when $p=S$. After that, the pressure drops. In the physical world, once $p=S$ all flow stops. I am stumped trying to understand why the mathematical model does not match real world, but I guess that's not a topic for this forum...
