|
442 | 442 | " pos_fw = wec.vec_to_dofmat(x_opt[nstate_pto:])\n", |
443 | 443 | " return pos_wec - pos_fw\n", |
444 | 444 | "\n", |
445 | | - "def rel_position(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
| 445 | + "def rel_position(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
446 | 446 | " pos_rel = x_rel(wec, x_wec, x_opt)\n", |
447 | 447 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
448 | 448 | " return np.dot(time_matrix, pos_rel)\n", |
449 | 449 | "\n", |
450 | | - "def rel_velocity(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
| 450 | + "def rel_velocity(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
451 | 451 | " pos_rel = x_rel(wec, x_wec, x_opt)\n", |
452 | 452 | " vel_rel = np.dot(wec.derivative_mat, pos_rel)\n", |
453 | 453 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
|
468 | 468 | "metadata": {}, |
469 | 469 | "outputs": [], |
470 | 470 | "source": [ |
471 | | - "def force_from_generator(wec, x_wec, x_opt, waves=None, nsubsteps=1):\n", |
| 471 | + "def force_from_generator(wec, x_wec, x_opt, wave=None, nsubsteps=1):\n", |
472 | 472 | " f_fd = np.reshape(x_opt[:nstate_pto], (-1, ndof), order='F')\n", |
473 | 473 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
474 | 474 | " torque = np.dot(time_matrix, f_fd) * flywheel_properties['motor_gear_ratio']\n", |
|
525 | 525 | "metadata": {}, |
526 | 526 | "outputs": [], |
527 | 527 | "source": [ |
528 | | - "def mechanical_power(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
529 | | - " force_td = force_from_generator(wec, x_wec, x_opt, waves, nsubsteps)\n", |
530 | | - " vel_td = rel_velocity(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 528 | + "def mechanical_power(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
| 529 | + " force_td = force_from_generator(wec, x_wec, x_opt, wave, nsubsteps)\n", |
| 530 | + " vel_td = rel_velocity(wec, x_wec, x_opt, wave, nsubsteps)\n", |
531 | 531 | " return vel_td * force_td\n", |
532 | 532 | "\n", |
533 | | - "def electrical_power(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
534 | | - " q1_td = rel_velocity(wec, x_wec, x_opt, waves)\n", |
535 | | - " e1_td = force_from_generator(wec, x_wec, x_opt, waves)\n", |
| 533 | + "def electrical_power(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
| 534 | + " q1_td = rel_velocity(wec, x_wec, x_opt, wave)\n", |
| 535 | + " e1_td = force_from_generator(wec, x_wec, x_opt, wave)\n", |
536 | 536 | " q1 = wot.complex_to_real(wec.td_to_fd(q1_td, False))\n", |
537 | 537 | " e1 = wot.complex_to_real(wec.td_to_fd(e1_td, False))\n", |
538 | 538 | " vars_1 = np.hstack([q1, e1])\n", |
|
546 | 546 | " e2_td = np.dot(time_mat, e2)\n", |
547 | 547 | " return q2_td * e2_td\n", |
548 | 548 | "\n", |
549 | | - "def energy(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
550 | | - " power_td = electrical_power(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 549 | + "def energy(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
| 550 | + " power_td = electrical_power(wec, x_wec, x_opt, wave, nsubsteps)\n", |
551 | 551 | " return np.sum(power_td) * wec.dt/nsubsteps\n", |
552 | 552 | "\n", |
553 | | - "def average_electrical_power(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
554 | | - " e = energy(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 553 | + "def average_electrical_power(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
| 554 | + " e = energy(wec, x_wec, x_opt, wave, nsubsteps)\n", |
555 | 555 | " return e / wec.tf" |
556 | 556 | ] |
557 | 557 | }, |
|
575 | 575 | "max_generator_torque = 25.8 # N*m\n", |
576 | 576 | "nsubsteps_constraints = 5\n", |
577 | 577 | "\n", |
578 | | - "def constraint_max_generator_torque(wec, x_wec, x_opt, waves, nsubsteps=nsubsteps_constraints):\n", |
579 | | - " torque = force_from_generator(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 578 | + "def constraint_max_generator_torque(wec, x_wec, x_opt, wave, nsubsteps=nsubsteps_constraints):\n", |
| 579 | + " torque = force_from_generator(wec, x_wec, x_opt, wave, nsubsteps)\n", |
580 | 580 | " return max_generator_torque - np.abs(torque.flatten())" |
581 | 581 | ] |
582 | 582 | }, |
|
607 | 607 | "metadata": {}, |
608 | 608 | "outputs": [], |
609 | 609 | "source": [ |
610 | | - "def force_from_friction(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
611 | | - " rel_vel = rel_velocity(wec, x_wec, x_opt, waves, nsubsteps) * flywheel_properties['motor_gear_ratio']\n", |
| 610 | + "def force_from_friction(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
| 611 | + " rel_vel = rel_velocity(wec, x_wec, x_opt, wave, nsubsteps) * flywheel_properties['motor_gear_ratio']\n", |
612 | 612 | " fric = -1*(\n", |
613 | 613 | " np.tanh(rel_vel)*flywheel_properties['coulomb_friction'] +\n", |
614 | 614 | " rel_vel*flywheel_properties['viscous_friction']\n", |
|
618 | 618 | "def linear_spring(pos):\n", |
619 | 619 | " return spring_properties['gear_ratio'] * -spring_properties['stiffness'] * pos\n", |
620 | 620 | "\n", |
621 | | - "def force_from_lin_spring(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
622 | | - " pos = rel_position(wec, x_wec, x_opt, waves, nsubsteps) * spring_properties['gear_ratio']\n", |
| 621 | + "def force_from_lin_spring(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
| 622 | + " pos = rel_position(wec, x_wec, x_opt, wave, nsubsteps) * spring_properties['gear_ratio']\n", |
623 | 623 | " return linear_spring(pos)\n", |
624 | 624 | "\n", |
625 | 625 | "def nonlinear_spring(pos):\n", |
|
635 | 635 | " new_pos = new_pos - coeffs*np.sin(k*spring_eq_pos_td)\n", |
636 | 636 | " return spring_properties['gear_ratio'] * -spring_properties['stiffness'] * scale * new_pos\n", |
637 | 637 | "\n", |
638 | | - "def force_from_nl_spring(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
639 | | - " pos = rel_position(wec, x_wec, x_opt, waves, nsubsteps) * spring_properties['gear_ratio']\n", |
| 638 | + "def force_from_nl_spring(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
| 639 | + " pos = rel_position(wec, x_wec, x_opt, wave, nsubsteps) * spring_properties['gear_ratio']\n", |
640 | 640 | " return nonlinear_spring(pos)\n", |
641 | 641 | "\n", |
642 | 642 | "spring_angle_rad = np.arange(-2*np.pi, 2*np.pi, np.pi/200)\n", |
|
674 | 674 | "metadata": {}, |
675 | 675 | "outputs": [], |
676 | 676 | "source": [ |
677 | | - "def flywheel_inertia(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
| 677 | + "def flywheel_inertia(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
678 | 678 | " pos_fw = wec.vec_to_dofmat(x_opt[nstate_pto:])\n", |
679 | 679 | " acc_fw = np.dot(wec.derivative2_mat, pos_fw)\n", |
680 | 680 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
681 | 681 | " acc_fw = np.dot(time_matrix, acc_fw)\n", |
682 | 682 | " return flywheel_properties['MOI'] * acc_fw\n", |
683 | 683 | "\n", |
684 | | - "def flywheel_residual_lin_spring(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
| 684 | + "def flywheel_residual_lin_spring(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
685 | 685 | " resid = (\n", |
686 | | - " flywheel_inertia(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
687 | | - " force_from_lin_spring(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
688 | | - " force_from_friction(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
689 | | - " force_from_generator(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 686 | + " flywheel_inertia(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 687 | + " force_from_lin_spring(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 688 | + " force_from_friction(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 689 | + " force_from_generator(wec, x_wec, x_opt, wave, nsubsteps)\n", |
690 | 690 | " )\n", |
691 | 691 | " return resid.flatten()\n", |
692 | 692 | "\n", |
693 | | - "def flywheel_residual_nl_spring(wec, x_wec, x_opt, waves = None, nsubsteps = 1):\n", |
| 693 | + "def flywheel_residual_nl_spring(wec, x_wec, x_opt, wave = None, nsubsteps = 1):\n", |
694 | 694 | " resid = (\n", |
695 | | - " flywheel_inertia(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
696 | | - " force_from_nl_spring(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
697 | | - " force_from_friction(wec, x_wec, x_opt, waves, nsubsteps) +\n", |
698 | | - " force_from_generator(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 695 | + " flywheel_inertia(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 696 | + " force_from_nl_spring(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 697 | + " force_from_friction(wec, x_wec, x_opt, wave, nsubsteps) +\n", |
| 698 | + " force_from_generator(wec, x_wec, x_opt, wave, nsubsteps)\n", |
699 | 699 | " )\n", |
700 | 700 | " return resid.flatten()" |
701 | 701 | ] |
|
967 | 967 | "outputs": [], |
968 | 968 | "source": [ |
969 | 969 | "\n", |
970 | | - "def fw_velocity(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
| 970 | + "def fw_velocity(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
971 | 971 | " pos_fw = wec.vec_to_dofmat(x_opt[nstate_pto:])\n", |
972 | 972 | " vel_fw = np.dot(wec.derivative_mat, pos_fw)\n", |
973 | 973 | " time_matrix = wec.time_mat_nsubsteps(nsubsteps)\n", |
974 | 974 | " return np.dot(time_matrix, vel_fw)\n", |
975 | 975 | "\n", |
976 | | - "def fw_friction_power(wec, x_wec, x_opt, waves, nsubsteps=1):\n", |
977 | | - " force_td = force_from_friction(wec, x_wec, x_opt, waves, nsubsteps)\n", |
978 | | - " vel_td = fw_velocity(wec, x_wec, x_opt, waves, nsubsteps)\n", |
| 976 | + "def fw_friction_power(wec, x_wec, x_opt, wave, nsubsteps=1):\n", |
| 977 | + " force_td = force_from_friction(wec, x_wec, x_opt, wave, nsubsteps)\n", |
| 978 | + " vel_td = fw_velocity(wec, x_wec, x_opt, wave, nsubsteps)\n", |
979 | 979 | " return vel_td * force_td\n", |
980 | 980 | "\n", |
981 | | - "fw_fric_power = fw_friction_power(wec_nl, x_wec, x_opt, waves_regular, nsubsteps)\n", |
| 981 | + "fw_fric_power = fw_friction_power(wec_nl, x_wec, x_opt, waves_regular.sel(realization=0), nsubsteps)\n", |
982 | 982 | "avg_fw_fric_power = np.mean(fw_fric_power)" |
983 | 983 | ] |
984 | 984 | }, |
|
0 commit comments