Solution (source code)

= Solution

Follow a fluid element with position $\mathbf X(t)$ satisfying $\dot{\mathbf X}=\mathbf u(\mathbf X,t)$. The <chain rule> gives the <material derivative>
$$
\boxed{\frac{DQ}{Dt}=\frac d{dt}Q(\mathbf X(t),t)=\partial_tQ+\mathbf u\cdot\nabla Q.}
$$
Apply <Newton's second law> to a material element of <volume> $dV$ and <mass> $\rho dV$. The net <pressure> <force> is $-\nabla p\,dV$, and <gravity> gives $-\rho\nabla\phi\,dV$. Dividing by the element <mass>, neglecting <viscosity> and using the <chain rule> componentwise gives the <Euler equation>
$$
\partial_t\mathbf u+\mathbf u\cdot\nabla\mathbf u=-\frac1\rho\nabla p-\nabla\phi.
$$

For a static spherical isothermal gas, $p=c_s^2\rho$ and $dp/dr=-GM(r)\rho/r^2$. Trial <density> $\rho=A/r^2$ gives enclosed <mass> $M(r)=4\pi Ar$, so
$$
-\frac{2Ac_s^2}{r^3}=-\frac{4\pi GA^2}{r^3},\qquad
\boxed{A=\frac{c_s^2}{2\pi G}.}
$$
This is the <singular isothermal sphere>. Its central <density> diverges, although the enclosed <mass> tends to zero linearly and its total <mass> inside a finite radius is finite. It is not the finite-central-density regular isothermal solution.

Truncate at $r_0$ with boundary <pressure> $p_0$. Then $M=4\pi Ar_0=2c_s^2r_0/G$ and $p_0=c_s^2\rho(r_0)$, giving
$$
\boxed{r_0=\frac{GM}{2c_s^2},\qquad p_0=\frac{c_s^4}{2\pi G r_0^2}.}
$$
The external medium is being treated as a prescribed <pressure> boundary; its own gravitational field is excluded from the cloud self-energy calculation.

For a monatomic <perfect gas>, the equilibrium is isothermal but the internal-energy relation still uses its <adiabatic index> $\gamma=5/3$:
$$
U=\int\frac{p}{\gamma-1}\,dV=\frac32Mc_s^2.
$$
The gravitational self-energy follows by assembling shells:
$$
\Omega=-\int_0^{r_0}\frac{GM(r)}r\,dM(r)
=-16\pi^2GA^2r_0=-\frac{GM^2}{r_0}=-2Mc_s^2.
$$
Both <integrals> remain finite at the singular center. Consequently
$$
\boxed{2U+\Omega=Mc_s^2=4\pi r_0^3p_0=3p_0\mathcal V,\qquad\mathcal V=4\pi r_0^3/3.}
$$
The <pressure-confined singular isothermal gas sphere> therefore satisfies the <virial theorem> including the work of the confining surface <pressure>. One can see its origin directly by integrating $\mathbf r\cdot\nabla p$: <integration by parts> gives $\oint p\,\mathbf r\cdot d\mathbf S-3\int p\,dV$, whose surface term is $4\pi r_0^3p_0$. An isolated vacuum-boundary version would omit that term and could not truncate this same positive-temperature isothermal profile at finite radius. The equality expresses equilibrium <force> and <energy> balance, rather than proving <dynamical stability>.