diff --git a/examples/foswec_capytaine.ipynb b/examples/foswec_capytaine.ipynb new file mode 100644 index 00000000..0b18b18d --- /dev/null +++ b/examples/foswec_capytaine.ipynb @@ -0,0 +1,2688 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# FOSWEC BEM and impedance\n", + "\n", + " - SAND report: https://doi.org/10.2172/1717884\n", + " - Journal paper: https://doi.org/10.1016/j.energy.2021.122485\n", + " - YouTube video: https://youtu.be/OUxbaEC2K6Y" + ] + }, + { + "cell_type": "code", + "execution_count": 372, + "metadata": {}, + "outputs": [], + "source": [ + "import autograd.numpy as np\n", + "import capytaine as cpy\n", + "import wecopttool as wot\n", + "wot.set_loglevel('INFO')\n", + "import gmsh\n", + "import pygmsh\n", + "import xarray as xr\n", + "import os\n", + "import matplotlib.pyplot as plt\n", + "from scipy.linalg import block_diag\n", + "import scipy.io as sio" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# BEM\n", + "## Set up geometry and Capytaine" + ] + }, + { + "cell_type": "code", + "execution_count": 373, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Warning: STL can only write triangle cells. Discarding vertex, tetra, line.\n", + "\n" + ], + "text/plain": [ + "\u001b[1;33mWarning:\u001b[0m\u001b[33m STL can only write triangle cells. Discarding vertex, tetra, line.\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:capytaine.bodies.bodies:Stored 804 triangle faces as quadrilaterals\n", + "INFO:capytaine.bodies.bodies:New floating body: fb_20230327214318897695.\n", + "INFO:capytaine.bodies.bodies:Clipping fb_20230327214318897695 with respect to Plane(normal=[0. 0. 1.], point=[0. 0. 0.])\n", + "INFO:capytaine.bodies.bodies:New floating body: 0_0+1_0.\n" + ] + } + ], + "source": [ + "def flap(thickness=0.1, width=1, draft=1.15, xloc=0, ofst=0.1, mesh_size_factor=1):\n", + "\n", + " with pygmsh.occ.Geometry() as geom:\n", + " gmsh.option.setNumber('Mesh.MeshSizeFactor', mesh_size_factor)\n", + " flap = geom.add_box([-1*thickness/2, 0, 0],\n", + " [1*thickness, width, -draft])\n", + " geom.translate(flap, [xloc, 0, 0])\n", + " geom.translate(flap, [0, 0, ofst])\n", + " mesh = geom.generate_mesh()\n", + " return mesh\n", + "\n", + "draft = 1.15\n", + "spacing = 1.44\n", + "\n", + "mesh = flap(mesh_size_factor=0.65)\n", + "mesh.write('foswec_capytaine_one_flap.stl')\n", + "fb = cpy.FloatingBody.from_meshio(mesh)\n", + "fb.keep_immersed_part()\n", + "my_axis = cpy.meshes.geometry.Axis((0, 1, 0), \n", + " point=(0, 0, -1*draft))\n", + "fb.add_rotation_dof(axis=my_axis, name='rot_about_shaft')\n", + "array = fb.assemble_regular_array(distance=spacing, nb_bodies=(2, 1))\n", + "\n", + "array.dofs['bow'] = array.dofs.pop('0_0__rot_about_shaft')\n", + "array.dofs['aft'] = array.dofs.pop('1_0__rot_about_shaft')\n", + "# array.show()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Animation to check DOFs" + ] + }, + { + "cell_type": "code", + "execution_count": 374, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:capytaine.ui.vtk.animation:Precompute motions of line_of_fb_20230327214318897695_mesh before animation.\n" + ] + } + ], + "source": [ + "animation = array.animate(motion={ i : 0.2 for i in array.dofs.keys() }, loop_duration=1.0)\n", + "animation.save('foswec_capytaine.ogv', camera_position=[-5, -5, 5], resolution=(int(10e2),int(10e2)))" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run Capytaine" + ] + }, + { + "cell_type": "code", + "execution_count": 375, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
<xarray.Dataset>\n", + "Dimensions: (radiating_dof: 2, influenced_dof: 2, omega: 60,\n", + " wave_direction: 1)\n", + "Coordinates:\n", + " * radiating_dof (radiating_dof) object 'bow' 'aft'\n", + " * influenced_dof (influenced_dof) object 'bow' 'aft'\n", + " * omega (omega) float64 0.07854 0.1571 0.2356 ... 4.634 4.712\n", + " * wave_direction (wave_direction) float64 0.0\n", + " g float64 9.81\n", + " rho float64 1.025e+03\n", + " body_name <U41 'array_of_fb_20230327210526733813_immersed'\n", + " water_depth float64 inf\n", + "Data variables:\n", + " impedance (radiating_dof, influenced_dof, omega) complex128 (1...\n", + " added_mass (omega, radiating_dof, influenced_dof) float64 365.4...\n", + " radiation_damping (omega, radiating_dof, influenced_dof) float64 1.383...\n", + " diffraction_force (omega, wave_direction, influenced_dof) complex128 (...\n", + " Froude_Krylov_force (omega, wave_direction, influenced_dof) complex128 0...
<xarray.DataArray 'impedance' (radiating_dof: 2, influenced_dof: 2, omega: 60)>\n", + "array([[[ 1.38297852e-09-8.37683745e+03j,\n", + " 1.74376185e-07-4.13789134e+03j,\n", + " 2.96521709e-06-2.70232756e+03j,\n", + " 2.21657352e-05-1.96768892e+03j,\n", + " 1.05494097e-04-1.51296421e+03j,\n", + " 3.77263150e-04-1.19800566e+03j,\n", + " 1.10819037e-03-9.63146311e+02j,\n", + " 2.81137820e-03-7.78117299e+02j,\n", + " 6.38405042e-03-6.26138358e+02j,\n", + " 1.32725690e-02-4.97437043e+02j,\n", + " 2.57477944e-02-3.85440416e+02j,\n", + " 4.69498290e-02-2.86004352e+02j,\n", + " 8.22056536e-02-1.96435265e+02j,\n", + " 1.36439813e-01-1.13547134e+02j,\n", + " 2.19076740e-01-3.67715099e+01j,\n", + " 3.41855978e-01+3.53556491e+01j,\n", + " 5.20218408e-01+1.03820766e+02j,\n", + " 7.67414957e-01+1.69725108e+02j,\n", + " 1.10876423e+00+2.32985294e+02j,\n", + " 1.57405265e+00+2.94343384e+02j,\n", + "...\n", + " 2.21592806e+02+1.65738121e+03j,\n", + " 2.71555540e+02+1.74320825e+03j,\n", + " 3.32798455e+02+1.82957919e+03j,\n", + " 4.04709668e+02+1.91419172e+03j,\n", + " 4.94982112e+02+1.99532844e+03j,\n", + " 6.06331215e+02+2.06473363e+03j,\n", + " 7.33191874e+02+2.11350569e+03j,\n", + " 8.68129561e+02+2.14097999e+03j,\n", + " 1.00990376e+03+2.13537946e+03j,\n", + " 1.14118805e+03+2.08768330e+03j,\n", + " 1.24733552e+03+2.01420755e+03j,\n", + " 1.32108723e+03+1.92844995e+03j,\n", + " 1.35524215e+03+1.83458486e+03j,\n", + " 1.35285503e+03+1.74831234e+03j,\n", + " 1.33071934e+03+1.68648299e+03j,\n", + " 1.29071091e+03+1.65109758e+03j,\n", + " 1.23607718e+03+1.63906578e+03j,\n", + " 1.18278323e+03+1.65279351e+03j,\n", + " 1.13533755e+03+1.69554956e+03j,\n", + " 1.09006251e+03+1.76629778e+03j]]])\n", + "Coordinates:\n", + " * radiating_dof (radiating_dof) object 'bow' 'aft'\n", + " * influenced_dof (influenced_dof) object 'bow' 'aft'\n", + " g float64 9.81\n", + " rho float64 1.025e+03\n", + " body_name <U41 'array_of_fb_20230327210526733813_immersed'\n", + " water_depth float64 inf\n", + " * omega (omega) float64 0.07854 0.1571 0.2356 ... 4.555 4.634 4.712