|
24 | 24 | "source": [ |
25 | 25 | "import capytaine as cpy\n", |
26 | 26 | "from capytaine.io.meshio import load_from_meshio\n", |
27 | | - "import autograd.numpy as np\n", |
| 27 | + "import numpy as np\n", |
| 28 | + "import jax.numpy as jnp\n", |
28 | 29 | "import matplotlib.pyplot as plt\n", |
29 | 30 | "from matplotlib import cm\n", |
30 | 31 | "from scipy.optimize import brute\n", |
|
376 | 377 | "source": [ |
377 | 378 | "def f_buoyancy(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
378 | 379 | " \"\"\"Only the zeroth order component (doesn't include linear stiffness)\"\"\"\n", |
379 | | - " return displacement * rho * g * np.ones([wec.ncomponents*nsubsteps, wec.ndof])\n", |
| 380 | + " return displacement * rho * g * jnp.ones([wec.ncomponents*nsubsteps, wec.ndof])\n", |
380 | 381 | "\n", |
381 | 382 | "def f_gravity(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
382 | | - " return -1 * wec.inertia_matrix.item() * g * np.ones([wec.ncomponents*nsubsteps, wec.ndof])\n", |
| 383 | + " return -1 * wec.inertia_matrix.item() * g * jnp.ones([wec.ncomponents*nsubsteps, wec.ndof])\n", |
383 | 384 | "\n", |
384 | 385 | "def f_pretension_wec(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
385 | 386 | " \"\"\"Pretension force as it acts on the WEC\"\"\"\n", |
|
389 | 390 | "\n", |
390 | 391 | "def f_pto_passive(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
391 | 392 | " pos = wec.vec_to_dofmat(x_wec)\n", |
392 | | - " vel = np.dot(wec.derivative_mat,pos)\n", |
393 | | - " acc = np.dot(wec.derivative_mat, vel)\n", |
| 393 | + " vel = jnp.dot(wec.derivative_mat,pos)\n", |
| 394 | + " acc = jnp.dot(wec.derivative_mat, vel)\n", |
394 | 395 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
395 | 396 | " spring = -(gear_ratios['spring']*airspring['gamma']*airspring['area']*\n", |
396 | 397 | " airspring['press_init']/airspring['vol_init']) * pos\n", |
397 | | - " f_spring = np.dot(time_matrix,spring)\n", |
| 398 | + " f_spring = jnp.dot(time_matrix,spring)\n", |
398 | 399 | " fric = -(friction_pto + \n", |
399 | 400 | " friction['Bpneumatic_spring_static1']*\n", |
400 | 401 | " gear_ratios['spring']) * vel\n", |
401 | | - " f_fric = np.dot(time_matrix,fric)\n", |
| 402 | + " f_fric = jnp.dot(time_matrix,fric)\n", |
402 | 403 | " inertia = inertia_pto * acc\n", |
403 | | - " f_inertia = np.dot(time_matrix,inertia)\n", |
| 404 | + " f_inertia = jnp.dot(time_matrix,inertia)\n", |
404 | 405 | " return f_spring + f_fric + f_inertia\n", |
405 | 406 | "\n", |
406 | 407 | "def f_pto_line(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
|
452 | 453 | "\n", |
453 | 454 | "def const_peak_torque_pto(wec, x_wec, x_opt, wave):\n", |
454 | 455 | " torque = pto.force(wec, x_wec, x_opt, wave, nsubsteps)\n", |
455 | | - " return torque_peak_max - np.abs(torque.flatten())\n", |
| 456 | + " return torque_peak_max - jnp.abs(torque.flatten())\n", |
456 | 457 | "\n", |
457 | 458 | "def const_speed_pto(wec, x_wec, x_opt, wave):\n", |
458 | 459 | " rot_vel = pto.velocity(wec, x_wec, x_opt, wave, nsubsteps)\n", |
459 | | - " return rot_speed_max - np.abs(rot_vel.flatten())\n", |
| 460 | + " return rot_speed_max - jnp.abs(rot_vel.flatten())\n", |
460 | 461 | "\n", |
461 | 462 | "def const_power_pto(wec, x_wec, x_opt, wave):\n", |
462 | 463 | " power_mech = (\n", |
463 | 464 | " pto.velocity(wec, x_wec, x_opt, wave, nsubsteps) *\n", |
464 | 465 | " pto.force(wec, x_wec, x_opt, wave, nsubsteps)\n", |
465 | 466 | " )\n", |
466 | | - " return power_max - np.abs(power_mech.flatten())\n", |
| 467 | + " return power_max - jnp.abs(power_mech.flatten())\n", |
467 | 468 | "\n", |
468 | 469 | "def constrain_min_tension(wec, x_wec, x_opt, wave):\n", |
469 | 470 | " total_tension = -1*f_pto_line(wec, x_wec, x_opt, wave, nsubsteps)\n", |
|
0 commit comments