Skip to content

Commit

Permalink
Capytaine v2 Hydrostatics (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtgrasb authored Oct 26, 2023
1 parent 63660d6 commit 8d383e3
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 633 deletions.
Binary file modified examples/data/bem.nc
Binary file not shown.
37 changes: 4 additions & 33 deletions examples/tutorial_1_WaveBot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,6 @@
"ndof = fb.nb_dofs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we will add the mass and hydrostatic stiffness properties. \n",
"If these values are known they can be added directly.\n",
"Here we will use the fact that the WaveBot is free floating and assume constant density to calculate these properties, which Capytaine can natively perform with the `FloatingBody` created above. For convenience, this functionality has been wrapped in `wecopttool.hydrostatics`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stiffness = wot.hydrostatics.stiffness_matrix(fb).values\n",
"mass = wot.hydrostatics.inertia_matrix(fb).values"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -145,7 +126,9 @@
"\n",
"We will analyze 50 frequencies with a spacing of 0.05 Hz. These frequencies will be used for the Fourier representation of both the wave and the desired PTO force in the pseudo-spectral problem. See the Theory section of the Documentation for more details on the pseudo-spectral problem formulation.\n",
"\n",
"If you would like to save our BEM data to a NetCDF file for future use, see the `wecopttool.write_netcdf` function."
"If you would like to save our BEM data to a NetCDF file for future use, see the `wecopttool.write_netcdf` function.\n",
"\n",
"The run_bem() function now calculates the hydrostatics and stores them as part of bem_data. The inertia and stiffness can still be defined manually as part of the `FloatingBody` if desired."
]
},
{
Expand Down Expand Up @@ -236,8 +219,6 @@
"source": [
"wec = wot.WEC.from_bem(\n",
" bem_data,\n",
" inertia_matrix=mass,\n",
" hydrostatic_stiffness=stiffness,\n",
" constraints=constraints,\n",
" friction=None,\n",
" f_add=f_add,\n",
Expand Down Expand Up @@ -512,8 +493,6 @@
"# Update WEC\n",
"\n",
"wec_2 = wot.WEC.from_bem(bem_data,\n",
" inertia_matrix=mass,\n",
" hydrostatic_stiffness=stiffness,\n",
" constraints=constraints_2,\n",
" friction=None,\n",
" f_add=f_add_2\n",
Expand Down Expand Up @@ -558,8 +537,6 @@
"source": [
"wec_2_nocon = wot.WEC.from_bem(\n",
" bem_data,\n",
" inertia_matrix=mass,\n",
" hydrostatic_stiffness=stiffness,\n",
" constraints=None,\n",
" friction=None,\n",
" f_add=f_add_2)\n",
Expand Down Expand Up @@ -712,10 +689,6 @@
" nfreq = 50\n",
" bem_data = wot.run_bem(fb, freq)\n",
"\n",
" # Mass & hydrostatic stiffness\n",
" stiffness_3 = wot.hydrostatics.stiffness_matrix(fb).values\n",
" mass_3 = wot.hydrostatics.inertia_matrix(fb).values\n",
"\n",
" # Impedance definition\n",
" omega = bem_data.omega.values\n",
" gear_ratio = 12.0\n",
Expand Down Expand Up @@ -764,8 +737,6 @@
"\n",
" # Create WEC\n",
" wec = wot.WEC.from_bem(bem_data,\n",
" inertia_matrix=mass_3,\n",
" hydrostatic_stiffness=stiffness_3,\n",
" constraints=constraints,\n",
" friction=None, \n",
" f_add=f_add,\n",
Expand Down Expand Up @@ -874,7 +845,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.10.9"
},
"vscode": {
"interpreter": {
Expand Down
67 changes: 27 additions & 40 deletions examples/tutorial_2_AquaHarmonics.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -29,12 +28,15 @@
"import matplotlib.pyplot as plt\n",
"from matplotlib import cm\n",
"from scipy.optimize import brute\n",
"import xarray as xr\n",
"import logging\n",
"logging.basicConfig()\n",
"logging.getLogger().setLevel(logging.DEBUG)\n",
"\n",
"import wecopttool as wot"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -62,7 +64,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -83,14 +84,12 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hydrostatics and mass\n",
"The AquaHarmonics device is positively buoyant (i.e., the buoyancy force is greater than the force due to gravity).\n",
"Therefore, we'll calculate the hydrostatic stiffness from the mesh, but set the rigid-body mass manually. \n",
"We will also calculate the displaced volume and mass from the mesh, which we will need later for defining forces and constraints."
"Therefore, we'll set the rigid-body mass manually, but allow the hydrostatic stiffness to be set automatically by run_bem() based on the mesh. We will also calculate the displaced volume and mass from the mesh (before manually defining the mass of the FloatingBody), which we will need later for defining forces and constraints."
]
},
{
Expand All @@ -99,17 +98,17 @@
"metadata": {},
"outputs": [],
"source": [
"mass = np.atleast_2d(5e3) # [kg]\n",
"stiffness = wot.hydrostatics.stiffness_matrix(fb).values\n",
"\n",
"g = 9.81\n",
"rho = 1025\n",
"displaced_mass = wot.hydrostatics.inertia_matrix(fb, rho).values # [kg]\n",
"displacement = displaced_mass/rho # [m^3] "
"fb.center_of_mass = [0, 0, 0]\n",
"fb.rotation_center = fb.center_of_mass\n",
"displaced_mass = fb.compute_rigid_body_inertia(rho=rho).values # [kg]\n",
"displacement = displaced_mass/rho # [m^3] \n",
"\n",
"fb.mass = np.atleast_2d(5e3) # [kg]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -134,7 +133,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -167,7 +165,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -233,7 +230,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -257,7 +253,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -281,7 +276,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -321,7 +315,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -349,7 +342,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -410,7 +402,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -474,36 +465,33 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### WEC object\n",
"Finally, we can use all the different components we've developed thus far to construct a `WEC` object:\n",
"\n",
" * **BEM data** - defines the hydrodynamics of the hull\n",
" * **Inertia and hydrostatics** - rigid-body inertia and hydrostatic stiffness\n",
" * **BEM data** - defines the hydrodynamics of the hull and includes hydrostatics\n",
" * **Constraints** - limitations on the hardware (max power, max torque, etc.) and the constraint to prevent the tether from going slack\n",
" * **Additional forces** - this captures all of the forces on the WEC that are not due to the interaction between the hull and water (PTO, etc.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"wec = wot.WEC.from_bem(\n",
" bem_data,\n",
" inertia_matrix = mass,\n",
" hydrostatic_stiffness = stiffness,\n",
" constraints = constraints,\n",
" f_add = f_add,\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -526,7 +514,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -544,7 +531,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -558,7 +544,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"scale_x_wec = 1e1\n",
Expand All @@ -583,7 +571,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -603,7 +590,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -621,7 +607,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -719,7 +704,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -747,7 +731,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -783,12 +766,11 @@
" # Unpack geometry variables\n",
" mass_ratio = x[0]\n",
" mass_var = mass_ratio * max_mass\n",
"\n",
" bem_data['inertia_matrix'] = mass_var\n",
" \n",
" # update WEC \n",
" wec_mass = wot.WEC.from_bem(\n",
" bem_data,\n",
" inertia_matrix = mass_var,\n",
" hydrostatic_stiffness = stiffness,\n",
" constraints = constraints,\n",
" friction = None,\n",
" f_add = f_add,\n",
Expand Down Expand Up @@ -819,7 +801,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -853,7 +834,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -912,6 +892,13 @@
"ax3.set_yticks([1, 5, 10, 15, 20, 25])\n",
"ax3.legend(loc=9)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 8d383e3

Please sign in to comment.