_h2lib

h2lib._h2lib.H2Lib(suppress_output=False, subprocess=True, cwd='.', filename=None) H2LibThread[source]
class h2lib._h2lib.H2LibProcess(suppress_output, filename=None, cwd='.')[source]

Bases: ProcessClass, H2LibThread

class h2lib._h2lib.H2LibThread(suppress_output=True, filename=None, cwd='.')[source]

Bases: DLLWrapper, H2Lib_DistributedSections, H2LibSignatures

add_sensor(sensor_line)[source]

Add sensor to hawc2. The sensor will be accessible from h2lib but will not show up in the output file of HAWC2 Note, that some sensors consist of multiple HAWC2 sensors, e.g. “wind free_wind” which has a Vx, Vy and Vz sensors

Parameters:

Sensor_line (str) – Sensor line as used in the output sections in HAWC2. See How2Hawc2

Returns:

index_lst – List of sensor index(es). These index(es) can be used to call get_sensor_info or get_sensor_values

Return type:

list

aero_sections_data_shape(rotor)[source]
body_output_element(ibdy, ielem)[source]

Compute element matrices. Wrapper of HAWC2 command new_htc_structure / element_matrix_output.

Parameters:
  • ibdy (int) – Body index, starting from 0.

  • ielem (int) – Element index, starting from 0.

Raises:
  • RuntimeError – If the structure is confidential.

  • IndexError – If the body or the element do not exist.

Returns:

  • mass ((12, 12) ndarray of float) – Mass matrix.

  • stiffness ((12, 12) ndarray of float) – Mass matrix.

  • damping ((12, 12) ndarray of float) – Mass matrix.

body_output_mass(ibdy)[source]

Compute body mass properties. Wrapper of HAWC2 command new_htc_structure / body_output_file_name.

Parameters:

ibdy (int) – Body index, starting from 0.

Raises:
  • RuntimeError – If the structure is confidential.

  • IndexError – If the body does not exist.

Returns:

  • body_mass (float) – Body mass [kg].

  • body_inertia ((6,) ndarray) – Body inertia [Ixx, Iyy, Izz, Ixy, Ixz, Iyz] in [kg*m^2].

  • cog_global_frame ((3,) ndarray) – Body center of gravity in the global frame [m].

  • cog_body_frame ((3,) ndarray) – Body center of gravity in the body frame [m].

check_convergence()[source]

Check the convergence of the simulation. Typically, after a time step or a call to the static solver.

Returns:

  • bconv (bool) – True if the solution has converged.

  • resq (real) – Residual on internal-external forces.

  • resg (real) – Residual on constraint equations.

  • resd (real) – Residual on increment.

close()[source]
correct()[source]

Temporary functions to reproduce results from old cpl coupling

do_system_eigenanalysis(n_modes, include_damping=True)[source]

Do the system eigen-analysis.

Parameters:
  • n_modes (int) – Number of modes to output.

  • include_damping (bool, optional) – True to include damping, False otherwise. The default is True.

Raises:
  • RuntimeError – Call linearize first.

  • ValueError – If too many modes are requested.

Returns:

  • natural_frequencies ((n_modes,) ndarray) – Natural frequencies, in Hz.

  • damping_ratios ((n_modes,) ndarray) – Damping ratios (nondimensional). Only returned if include_damping=True.

getState()[source]
get_aerosections_forces(rotor=0)[source]
get_aerosections_moments(rotor=0)[source]
get_aerosections_position(rotor=0)[source]

Global xyz position of aero sections. Shape=(#blades, #sections, 3)

get_bem_grid(rotor=0)[source]

returns azi, rad

get_bem_grid_dim(rotor=0)[source]

returns (nazi, nrad)

get_body_rotation_tensor(ibdy)[source]

Get the rotation tensor of the requested body, that transforms from local to global base.

Parameters:

ibdy (int) – Body index, starting from 0.

Raises:
  • RuntimeError – If the structure is confidential.

  • IndexError – If the body does not exist.

Returns:

amat – Rotation tensor.

Return type:

(3, 3) ndarray

get_diameter(rotor=0)[source]
get_induction_axisymmetric(rotor=0)[source]
get_induction_polargrid(rotor=0)[source]
get_induction_rotoravg(rotor=0)[source]
get_mainbody_name_dict()[source]
get_mainbody_nodes_state(mainbody_nr, state, mainbody_coo_nr=0)[source]

Return the state (pos, vel or acc) of mainbody nodes Note, the state refers to the structural nodes at the elastic axis

Parameters:
  • mainbody_nr (int) – Index of mainbody (can be obtained from get_mainbody_name_dict())

  • state ({'pos','vel','acc'}) – state type (position, velocity, acceleration) to compute

  • mainbody_coo_nr (int, optional) – Specifies the coodinate system of the returned position and orientation. If 0 (default), the output is in global coordinates Otherwise the output is transformed to the coordinate system of the mainbody with the specified index. The index can be obtained from get_mainbody_name_dict

Returns:

state – state data shape=(no_nodes,3) containing the (x,y,z) position, velocity or acceleration of the nodes

Return type:

array_like

get_mainbody_position_orientation(mainbody_nr, mainbody_coo_nr=0)[source]
get_nSections(rotor=0, blade=0)[source]
get_nblades(rotor=0)[source]
get_no_mainbodies()[source]
get_nrotors()[source]
get_number_of_bodies_and_constraints()[source]

Get number of bodies and constraints.

Raises:

RuntimeError – If the structure is confidential.

Returns:

  • nbdy (int) – Number of bodies.

  • ncst (int) – Number of constraints.

get_number_of_elements()[source]

Get the number of elements for each body.

Raises:

RuntimeError – If the structure is confidential.

Returns:

nelem – Number of elements for each body.

Return type:

(nbdy) ndarray, int

get_rotor_avg_uvw(rotor=0)[source]
get_rotor_avg_wsp(coo=1, rotor=0)[source]

Returns the rotor averaged wind speed in global(coo=1, default) or rotor(coo=2) coordinates.

get_rotor_dims()[source]
get_rotor_orientation(rotor=0, deg=False)[source]

return yaw, tilt, azi(of first blade) in rad(default) or deg

get_rotor_position(rotor=0)[source]
get_sensor_info(id)[source]

return name, unit, description

get_sensor_values(id_lst)[source]

Get sensor values from HAWC2

Parameters:

id_lst (array_like or int) – list of sensor ids

Returns:

values

Return type:

array_like or float

get_system_eigenvalues_and_eigenvectors(n_modes, n_rdofs, include_damping=True)[source]

Get the system eigenvalues and eigenvectors from system_eigenanalysis.

This function must be called after do_system_eigenanalysis, with the same value of include_damping.

Parameters:
  • n_modes (int) – Number of modes to output.

  • n_rdofs (int) – Number of degrees of freedom in the reduced order system. As returned by linearize.

  • include_damping (bool, optional) – True to include damping, False otherwise. The default is True.

Raises:
  • RuntimeError – If the structure is confidential or if linearize and do_system_eigenanalysis have not been called first.

  • ValueError – Either n_modes or n_rdofs is wrong.

Returns:

  • eigenvalues ((n_modes,) ndarray) – Eigenvalues. Real array without damping and complex array otherwise.

  • eigenvectors ((n_modes, ny)) – Eigenvectors. Real array without damping and complex array otherwise. Only returned if the structure is not confidential.

get_system_matrices(n_tdofs, n_rdofs)[source]

Get the system structural matrices computed during the system_eigenanalysis.

This function must be called after linearize().

Parameters:
  • n_tdofs (int) – Total number of degrees of freedom in the system.

  • n_rdofs (int) – Number of degrees of freedom in the reduced order system.

Raises:
  • RuntimeError – If the linearizetion has not been done or the structure is confidential.

  • ValueError – If the total or reduced number of degrees of freedom is wrong.

Returns:

  • M ((n_rdofs, n_rdofs) ndarray) – Mass matrix.

  • C ((n_rdofs, n_rdofs) ndarray) – Damping matrix.

  • K ((n_rdofs, n_rdofs) ndarray) – Stiffness matrix.

  • R ((n_tdofs, n_rdofs) ndarray) – Transformation between reduced and all DOFs.

get_time()[source]
get_timoshenko_location(ibdy, ielem)[source]

Get the location and orientation of an element.

Parameters:
  • ibdy (int) – Body index, starting from 0.

  • ielem (int) – Element index, starting from 0.

Raises:
  • RuntimeError – If the structure is confidential.

  • IndexError – If the body or the element do not exist.

Returns:

  • l (float) – Element length.

  • r1 ((3) ndarray) – Location of node 1.

  • r12 ((3) ndarray) – Vector from node 1 to node 2.

  • tes ((3, 3) ndarray) – Transformation matrix describing orientation.

get_uvw(pos_g)[source]
get_version()[source]
get_wind_speed(pos_g)[source]
init(htc_path=None, model_path='.')[source]
init_AD(htc_path=None, model_path='.', tiploss_method=2, tiploss2_shen_c2=21, tiploss2_shen_h=0, rotor=0)[source]

Initialize HAWC2 for Actuator Disc workflow, where wind speeds including induction at the aerodynamic sections are passed from e.g. CFD to HAWC2 via set_aerosections_windspeed. This function will: - Disable wind speed update at blade sections (wind speeds must be set via set_aerosections_windspeed) - Disable HAWC2 induction (induction_method=0). - set GetWindSpeedData%u_mean=nan to avoid unintended use of the free wind module in HAWC2 - set the tiploss_method. The default method is 2, which works with the AD workflow,

but the tiploss2_shen_c2 and tiploss2_shen_h parameters must be tuned to give sensible results, see tiploss_method in the HAWC2 manual

init_AL(epsilon_smearing, htc_path=None, model_path='.', rotor=0)[source]

Initialize HAWC2 for Actuator Line workflow, where wind speeds including induction at the aerodynamic sections are passed from e.g. CFD to HAWC2 via set_aerosections_windspeed. This function will: - Disable wind speed update at blade sections (wind speeds must be set via set_aerosections_windspeed) - Enable viscous core correction which compensates for the missing induction due to smearing of the forces.

The method calculates the missing induction as a smearing factor times the normal near wake induction (induction_method=2) while disregarding the BEM farwake contribution. The smearing factor is based on the smearing size given by epsilon_smearing [m].

  • set GetWindSpeedData%u_mean=nan to avoid unintended use of the free wind module in HAWC2

  • set the tiploss_method to 0, to avoid unintended additional tiploss correction

init_windfield(Nxyz, dxyz, box_offset_yz, transport_speed)[source]

Initialize wind field which afterwards can be set using set_windfield

x: direction of wind y: horizontal to the left when looking along x z: vertical up

Parameters:
  • Nxyz ((int, int, int)) – Number of points in wind field

  • dxyz ((float, float, float)) – Distance between wind field points

  • box_offset_yz ((float, float)) – Box offset in y and z, relative to hawc2 origo. Note this is in met coordinates as described above To set a wind field of size 200x80x80, such that the center is located at hawc2 coordinate (0,0,-70), box_offset_yz must be (-40,30) Note that the wind field size is (Nxyz)-1*dxyz

  • transport_speed (float) – Box transport speed

Notes

The wind field will be transported in the hawc2 global y-direction with the transport speed, In HAWC2: - shear format is set to 0 (which also means that the mean wind (transport speed) is not added) - turbformat is set to 1 (mann), but the buffer should be filled manually via set_windfield - center_pos0 is set such that the lower right corner (when looking along global y) is located at box_offset_yz - windfield_rotations is set to (0,0,0), i.e. the wind is aligned with y, and w points up (opposite global z) - scaling is disabled - the buffer is interpolated in the standard way, i.e. it is mirrored in the lateral and vertical direction and

repeated in the longitudinal direction

linearize()[source]

Linearize the system, as done by the system eigen-analysis.

Returns:

  • n_tdofs (int) – Total number of degrees of freedom in the system.

  • n_rdofs (int) – Number of degrees of freedom in the reduced order system.

loop(N)[source]

Return time to compute N loops

property model_path
predict()[source]

Temporary functions to reproduce results from old cpl coupling

read_input(htc_path, model_path='.')[source]
run(time)[source]
set_aerosections_windspeed(uvw, rotor=0)[source]

Update wind speed at aero sections. uvw shape=(#blades, #sections, 3)

set_c2_def(main_body_nr, c2_def, twist_in_deg=True, check_length=True, update_structure=True)[source]

Set c2_def or cx_def for the specified main body.

Parameters:
  • main_body_nr (int) – Number of main body that must be updated. The mapping between main body name and number can be obtained with get_mainbody_name_dict.

  • c2_def ((:, 4) or (:, 5) ndarray) – New c2_def/cx_def. It is an array with at least 2 rows and 4 columns for x, y, z and twist. Optionally, the 5th column can be used for dx (default is 0.) The number of rows, i.e. sections, must match the ones in the original c2_def.

  • twist_in_deg (bool, optional) – True if the twist (last column in c2_def) is given in [deg]. False if it is given in [rad]. The default is True.

  • check_length (bool, optional) – True if the new beam length needs to be checked, False otherwise. The default is False.

  • update_structure (bool, optional) – If True (default) triggers the recomputation of the element matrices, constraints and so on. It is required for the changes to c2_def to take effect. If the user updates both c2_def/cx_def and st, only 1 structure update is required.

Raises:
  • ValueError – Can be due to: - MAIN_BODY_NOT_FOUND: none of the main bodies is called main_body_name. - WRONG_NUMBER_OF_COLUMNS: cx_def must have 4 or 5 columns. - TOO_FEW_SECTIONS_IN_C2DEF: c2_def must have at least 2 sections, i.e. rows. - BEAM_TOO_SHORT: the minimum beam length is 1.0e-7. - DIFFERENT_NSEC: this command does not allow to add or remove sections, therefore c2_def must have the same number of sections as in the HAWC2 model.

  • NotImplementedError – Only the c2_def node distribution is supported.

Return type:

None.

set_orientation_base(main_body, mbdy_eulerang_table=None, angles_in_deg=True, reset_orientation=False, mbdy_ini_rotvec_d1=None)[source]

Set an orientation / base command.

Function equivalent to the HAWC2 command orientation / base. For further details see the HAWC2 documentation. We assume that this base orientation is already present in the htc file, and therefore modify it here instead of creating a new one.

Parameters:
  • main_body (str) – Main body name. Same as HAWC2 mbdy parameter.

  • mbdy_eulerang_table ((:, 3) ndarray, optional) – A sequence of Euler angles, one per row. Equivalent to HAWC2 command mbdy_eulerang. A 1D array with 3 elements will be interpreted as 1 row. This table is additive with respect to the orientation / base command in the htc file, unless the flag reset_orientation is used. The default is [0, 0, 0], which means that no rotation is applied.

  • angles_in_deg (bool, optional) – True if the angles in mbdy_eulerang_table are provided in degrees. False if they are in radians. The default is True.

  • reset_orientation (bool, optional,) – If True this function will reset the orientation to the global frame before applying mbdy_eulerang_table. The default is False.

  • mbdy_ini_rotvec_d1 – Angular velocity. First 3 elements for the direction and last for the magnitude. Equivalent to HAWC2 command mbdy_ini_rotvec_d1. The default is 0 speed.

Raises:

ValueError – If the orientation / base command cannot be found.

Return type:

None.

set_orientation_relative(main_body_1, node_1, main_body_2, node_2, mbdy2_eulerang_table=None, angles_in_deg=True, reset_orientation=False, mbdy2_ini_rotvec_d1=None)[source]

Set an orientation / relative command.

Function equivalent to the HAWC2 command orientation / relative. For further details see the HAWC2 documentation. We assume that this relative orientation is already present in the htc file, and therefore modify it here instead of creating a new one.

Parameters:
  • main_body_1 (str) – Main body name to which the next main body is attached.

  • node_1 (int, str) – Node number of main_body_1 that is used for connection, starting from 0. “last” can be specified which ensures that the last node on the main_body is used, and -1 refers to the origin of the main body coordinate system.

  • main_body_2 (str) – Main_body name of the main_body that is positioned in space by the relative command.

  • node_2 (int, str) – Node number of main_body_2 that is used for connection, starting from 0. “last” can be specified which ensures that the last node on the main_body is used, and -1 refers to the origin of the main body coordinate system.

  • mbdy2_eulerang_table (: (:, 3) ndarray, optional) – A sequence of Euler angles, one per row. Equivalent to HAWC2 command mbdy2_eulerang. A 1D array with 3 elements will be interpreted as 1 row. This table is additive with respect to the orientation / relative command in the htc file, unless the flag reset_orientation is used. The default is [0, 0, 0], which means that no rotation is applied.

  • angles_in_deg (bool, optional) – True if the angles in mbdy2_eulerang_table are provided in degrees. False if they are in radians. The default is True.

  • reset_orientation (bool, optional,) – If True this function will reset the orientation to no rotation before applying mbdy2_eulerang_table. The default is False.

  • mbdy2_ini_rotvec_d1 – Angular velocity. First 3 elements for the direction and last for the magnitude. Equivalent to HAWC2 command mbdy2_ini_rotvec_d1. The default is 0 speed.

Raises:

ValueError – If the orientation / relative command cannot be found, or if the main bodies do not exist.

Return type:

None.

set_st(main_body_nr, st, update_structure=True)[source]

Set STructural data for the specified main body.

Parameters:
  • main_body_nr (int) – Number of main body that must be updated. The mapping between main body name and number can be obtained with get_mainbody_name_dict.

  • st ((:, :) ndarray) – New ST. It is an array with an arbitrary number of rows and 19 or 30 columns. Both the classical Timoshenko and the FPM model are supported.

  • update_structure (bool, optional) – If True (default) triggers the recomputation of the element matrices, constraints and so on. It is required for the changes to st to take effect. If the user updates both c2_def/cx_def and st, only 1 structure update is required.

Raises:
  • ValueError – Can be due to: - MAIN_BODY_NOT_FOUND: none of the main bodies is called main_body_name. - WRONG_NUMBER_OF_COLUMNS: st must have 19 or 30 columns. - ST_Z_NOT_CONTINUOUSLY_INCREASING: The z coordinate must always increase.

  • NotImplementedError – Only the c2_def node distribution is supported.

Return type:

None.

set_variable_sensor_value(id, value)[source]
set_windfield(uvw, box_offset_x, time=None)[source]

Set wind field, must be called after init_windfield and init

Parameters:
  • uvw (array_like, dims=(3,Nx,Ny,Nz)) – wind field components including mean wind speed, shear etc.

  • box_offset_x (float) – Offset in x direction at the <time> To set a wind field of size 200x80x80, such that the front plane (largest x) is located at hawc2 coordinate (0,20,-70), i.e. 20m downstream of origo, set box_offset_x=-180 Note that the wind field size is (Nxyz)-1*dxyz Note also that the end plane (x=0) will be located in -180 and repeated in 20+dx

  • time (float, optional) – Time at which the the last plane (x=0) is at x=box_offset_x If None, default, time is set to the current time in HAWC2

Notes

uvw must be scaled in advance to the right turbulence level and should contain mean wind, shear, gusts, direction change etc. and uvw(:,1) is the back plane of the turbulence box, while uvw(:,Nx) is the front plane

solver_static_delete()[source]

Delete the static solver.

Return type:

None.

solver_static_init()[source]

Initialize the static solver.

Return type:

None.

solver_static_run(reset_structure=False, max_state=None, max_lambda=None, use_cstr_stiffness=False)[source]

Run the complete static solver algorithm.

When the calls to the static solver are independent, it may be convenient to set reset_structure = True, so that the static solver will run from the undeflected configuration, as specified in the htc file. On the other hand, if the static solver is obtained for increasing wind speeds, then it is convenient to start from the last converged solution, thus setting reset_structure = False, as done by HAWCStab2.

Parameters:
  • reset_structure (bool, optional) – If True this function will reset the structure deflection and orientation before running the static solver. The default is False.

  • max_state (float, optional) – Maximum step length in static solver for state variable. If None (default) the value from the htc file is used. If the htc file does not specify it, it is set to unlimited.

  • max_lambda (float, optional) – Maximum step length in static solver for constraint forces. If None (default) the value from the htc file is used. If the htc file does not specify it, it is set to unlimited.

  • use_cstr_stiffness (bool, optional) – Flag to include constraint stiffness when using the static solver. Including the constraint stiffness is sometimes necessary when external systems are present (e.g. ESYSMooring). The default is False.

Raises:

RuntimeError – If the static solver has not converged.

Return type:

None.

solver_static_solve(binit, max_state=None, max_lambda=None)[source]

Solve static equilibrium.

Parameters:
  • binit (bool) – The first time that this subroutine is called, binit must be set to True to trigger the factorization of the A matrix. This should be done only once. On exit, binit is set to False, because only the linear system needs to be solved.

  • max_state (float, optional) – Maximum step length in static solver for state variable. If None (default) the value from the htc file is used. If the htc file does not specify it, it is set to unlimited.

  • max_lambda (float, optional) – Maximum step length in static solver for constraint forces. If None (default) the value from the htc file is used. If the htc file does not specify it, it is set to unlimited.

Raises:

RuntimeError – If the static solver has not been initialized. Call solver_static_init() first.

Returns:

binit – Must be False.

Return type:

bool

solver_static_update_residual()[source]

Update the static solver force vector.

Raises:

RuntimeError – If the static solver has not been initialized. Call solver_static_init() first.

Return type:

None.

solver_static_update_system()[source]

Update the static solver system matrix.

Raises:

RuntimeError – If the static solver has not been initialized. Call solver_static_init() first.

Return type:

None.

step()[source]
stop_on_error(flag)[source]

Control if HAWC2 will terminate the execution upon encountering an error. The default HAWC2 behavior is to stop.

Parameters:

flag (bool) – If set to True an error will cause HAWC2 to terminate the execution with status code 1. If set to False HAWC2 will still print a log message but not stop.

Return type:

None.

structure_reset()[source]

Reset the structure deflection and orientation.

work(time)[source]

Return number of loops

h2lib._h2lib.MultiH2Lib(N, filename=None, cwd='.', suppress_output=False)[source]
h2lib._h2lib.set_LD_LIBRARY_PATH()[source]