{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "34ba7b7a",
   "metadata": {},
   "source": [
    "# Locate the load on a submerged viewing window\n",
    "\n",
    "Two circular windows have the same area and centre depth. One is more steeply inclined. Predict whether the net force and its position both stay the same. The circular face is completely submerged and the opposite face is at atmospheric pressure."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac242208",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "radius,depth=.18,.42   # m, circular radius and vertical centre depth\n",
    "tilt=60.               # degrees from horizontal\n",
    "rho,g=998.,9.81        # kg/m³, m/s²\n",
    "assert radius>0 and rho>0 and g>0 and 0<=tilt<=90\n",
    "sine=np.sin(np.deg2rad(tilt))\n",
    "assert depth>radius*sine, \"This worksheet assumes a fully submerged window.\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3c15020",
   "metadata": {},
   "source": [
    "## Calculate both the resultant and the moment\n",
    "The first moment of area about the centre is zero. The second moment about an in-plane diameter is pi times the fourth power of radius divided by four. Integrate horizontal chord strips to check the resulting force location independently."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2c2a0db",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=np.pi*radius**2\n",
    "force=rho*g*A*depth\n",
    "offset=radius**2*sine/(4*depth)\n",
    "edges=np.linspace(-radius,radius,3001)\n",
    "s=(edges[1:]+edges[:-1])/2\n",
    "area=2*np.sqrt(radius**2-s*s)*np.diff(edges)\n",
    "pressure=rho*g*(depth+s*sine)\n",
    "numerical=(pressure*area).sum()\n",
    "s_numeric=(pressure*s*area).sum()/numerical\n",
    "assert np.isclose(force,numerical,rtol=3e-5) and np.isclose(offset,s_numeric,atol=1e-5*radius)\n",
    "print(f\"Resultant {force:.2f} N, offset {1000*offset:.2f} mm down the slope.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce41ecd8",
   "metadata": {},
   "source": [
    "## Inspect which strips produce the moment\n",
    "Pressure rises linearly with depth but strip width vanishes at the rim. The right panel holds depth fixed as the angle varies and only draws submerged orientations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e62b9cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig,ax=plt.subplots(1,2,figsize=(9,3.5),layout=\"constrained\")\n",
    "ax[0].plot(s*1000,pressure*2*np.sqrt(radius**2-s*s),label=\"Force per unit slope distance\")\n",
    "ax[0].axvline(offset*1000,color=\"#ab532c\",ls=\"--\",label=\"Resultant location\")\n",
    "ax[0].set(xlabel=\"Distance down window from centre (mm)\",ylabel=\"Strip force density (N/m)\",title=\"Integrated hydrostatic load\")\n",
    "theta=np.linspace(0,90,120); valid=depth>radius*np.sin(np.deg2rad(theta))\n",
    "ax[1].plot(theta[valid],1000*radius**2*np.sin(np.deg2rad(theta[valid]))/(4*depth),label=\"Centre of pressure\")\n",
    "ax[1].set(xlabel=\"Tilt from horizontal (degrees)\",ylabel=\"Down-slope offset (mm)\",title=\"Location at fixed centre depth\")\n",
    "for p in ax: p.grid(alpha=.22);p.legend(fontsize=8)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69e216b2",
   "metadata": {},
   "source": [
    "Try a horizontal window. Double the centre depth at fixed tilt and predict both readings. If the gas on the other side is pressurised, work with the pressure difference across the window before locating its resultant."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
