h2lib 13.2.702__py3-none-win_amd64.whl → 13.2.901__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  from h2lib.h2lib_signatures import H2LibSignatures
2
2
  import numpy as np
3
3
  from enum import Enum
4
+ import sys
4
5
 
5
6
 
6
7
  class DistributedSections():
@@ -45,9 +46,9 @@ class H2Lib_DistributedSections(H2LibSignatures):
45
46
  assert mainbody_name in mbdy_name_dict, f"'{mainbody_name}' does not exist. Valid names are {list(mbdy_name_dict.keys())}."
46
47
  mbdy_nr = mbdy_name_dict[mainbody_name]
47
48
  nsec = len(section_relative_position)
48
- link_id = H2LibSignatures.add_distributed_sections(
49
+ link_id = H2LibSignatures._add_distributed_sections(
49
50
  self,
50
- mainbody_nr=int(mbdy_nr),
51
+ mainbody_nr=mbdy_nr,
51
52
  nsec=nsec,
52
53
  sec_rel_pos=np.asfortranarray(section_relative_position, dtype=float),
53
54
  link_id=0)[0][-1]
@@ -60,11 +61,12 @@ class H2Lib_DistributedSections(H2LibSignatures):
60
61
  add_distributed_sections and before first call to get_distributed_sections,
61
62
  get_distributed_section_position_orientation and set_distributed_section_force_and_moment
62
63
  """
63
- return H2LibSignatures.initialize_distributed_sections(self)
64
+ self.distributed_sections_initialized = True
65
+ return H2LibSignatures._initialize_distributed_sections(self)
64
66
 
65
67
  def get_distributed_sections(self, link_type: LinkType, link_id):
66
68
  """Return a DistributedSections link object (needed for get_distributed_section_position_orientation
67
- and set_distributed_section_force_and_moment).
69
+ get_distributed_section_force_and_moment and set_distributed_section_force_and_moment).
68
70
 
69
71
  To obtain the aerodynamic load sections at blade 3 (only rotor=1 can be accessed):
70
72
  h2.get_distributed_sections(LinkType.BLADE, 3)
@@ -73,23 +75,35 @@ class H2Lib_DistributedSections(H2LibSignatures):
73
75
  ----------
74
76
  link_type : LinkType
75
77
  Specifies the link type. See enum LinkType
76
- link_id : integer
78
+ link_id : int
77
79
  index of link. link_id=1 will reference the first added sections, e.g. blade1
78
80
  Returns
79
81
  -------
80
82
  DistributedSections object
81
83
  """
82
- mbdy_nr, nsec = H2LibSignatures.get_distributed_sections(
84
+ if link_type == LinkType.BODY:
85
+ err_msg = "Call initialize_distributed_sections before get_distributed_sections(link_type=LinkType.BODY,...)"
86
+ assert getattr(self, 'distributed_sections_initialized', False) is True, err_msg
87
+ mbdy_nr, nsec = H2LibSignatures._get_distributed_sections(
83
88
  self, link_type.value, link_id, mainbody_nr=0, nsec=0)[0][2:]
84
89
  mbdy_name_dict = self.get_mainbody_name_dict()
85
90
  mbdy_name = {nr: name for name, nr in mbdy_name_dict.items()}[mbdy_nr]
86
91
  return DistributedSections(mbdy_name, link_type, link_id, nsec)
87
92
 
88
93
  def get_distributed_section_position_orientation(self, ds: DistributedSections, mainbody_coo_nr=0):
89
- """
94
+ """Computes the position and orientation of a set of distributed sections.
95
+ Note, the distributed sections are located on the c2def (aeroload/blade sections have a twisted 1/4 chord offset
96
+ relative to c2def)
97
+
90
98
  Parameters
91
99
  ----------
92
100
  ds : DistributedSections
101
+ reference to distributed sections as returned from add_distributed_sections or get_distributed_sections
102
+ mainbody_coo_nr : int, optional
103
+ Specifies the coodinate system of the returned position and orientation.
104
+ If 0 (default), the output is in global coordinates
105
+ Otherwise the output is transformed to the coordinate system of the mainbody with the specified index.
106
+ The index can be obtained from get_mainbody_name_dict
93
107
 
94
108
  Returns
95
109
  -------
@@ -98,13 +112,16 @@ class H2Lib_DistributedSections(H2LibSignatures):
98
112
  Orientation of section in specified coordinates.
99
113
  For mainbody_coo_nr=0, default, the orientation is in global coordinates, i.e. Tsg
100
114
  """
115
+ if ds.link_type == LinkType.BODY:
116
+ err_msg = "Call initialize_distributed_sections before get_distributed_section_position_orientation"
117
+ assert getattr(self, 'distributed_sections_initialized', False) is True, err_msg
101
118
  sec_pos = np.zeros((ds.nsec, 3), dtype=np.float64, order="F")
102
119
  sec_ori = np.zeros((ds.nsec, 3, 3), dtype=np.float64, order="F")
103
- return H2LibSignatures.get_distributed_section_position_orientation(
104
- self, int(ds.link_type.value), int(ds.link_id), int(ds.nsec), sec_pos, sec_ori,
105
- int(mainbody_coo_nr))[0][3:-1]
120
+ return H2LibSignatures._get_distributed_section_position_orientation(
121
+ self, ds.link_type.value, ds.link_id, ds.nsec, sec_pos, sec_ori,
122
+ mainbody_coo_nr)[0][3:-1]
106
123
 
107
- def set_distributed_section_force_and_moment(self, ds: DistributedSections, sec_frc, sec_mom):
124
+ def set_distributed_section_force_and_moment(self, ds: DistributedSections, sec_frc, sec_mom, mainbody_coo_nr=0):
108
125
  """Set forces and moments at distributed sections
109
126
 
110
127
  Parameters
@@ -115,15 +132,51 @@ class H2Lib_DistributedSections(H2LibSignatures):
115
132
  Section forces pr. length [N/m] in global coordinates, shape=(nsec,3)
116
133
  sec_momc : array_like
117
134
  Section moments pr. length [Nm/m] in global coordinates, shape=(nsec,3)
135
+ mainbody_coo_nr : int, optional
136
+ Specifies the coodinate system of the provided forces and moments.
137
+ If 0 (default), the forces and moments are in global coordinates
138
+ Otherwise the index of the mainbody in which coordinate system, the forces and moments are provided
139
+ The index can be obtained from get_mainbody_name_dict
118
140
  """
141
+ if ds.link_type == LinkType.BODY:
142
+ err_msg = "Call initialize_distributed_sections before set_distributed_section_force_and_moment"
143
+ assert getattr(self, 'distributed_sections_initialized', False) is True, err_msg
119
144
  sec_frc = np.asfortranarray(sec_frc, dtype=np.float64)
120
145
  sec_mom = np.asfortranarray(sec_mom, dtype=np.float64)
121
146
  assert sec_frc.shape == (ds.nsec, 3)
122
147
  assert sec_mom.shape == (ds.nsec, 3)
148
+ return H2LibSignatures._set_distributed_section_force_and_moment(
149
+ self, link_type=int(ds.link_type.value), link_id=int(ds.link_id), nsec=int(ds.nsec),
150
+ frc=sec_frc, mom=sec_mom, mainbody_coo_nr=int(mainbody_coo_nr))
151
+
152
+ def get_distributed_section_force_and_moment(self, ds: DistributedSections, mainbody_coo_nr=0):
153
+ """Set forces and moments at distributed sections
123
154
 
124
- return H2LibSignatures.set_distributed_section_force_and_moment(
155
+ Parameters
156
+ ----------
157
+ ds : DistributedSections object
158
+ object returned by add_distributed_sections or get_distributed_sections
159
+ mainbody_coo_nr : int, optional
160
+ Specifies the coodinate system of the provided forces and moments.
161
+ If 0 (default), the forces and moments are in global coordinates
162
+ Otherwise the index of the mainbody in which coordinate system, the forces and moments are provided
163
+ The index can be obtained from get_mainbody_name_dict
164
+
165
+ Returns
166
+ -------
167
+ sec_frc : array_like
168
+ Section forces pr. length [N/m] in global coordinates, shape=(nsec,3)
169
+ sec_momc : array_like
170
+ Section moments pr. length [Nm/m] in global coordinates, shape=(nsec,3)
171
+ """
172
+ if ds.link_type == LinkType.BODY:
173
+ err_msg = "Call initialize_distributed_sections before get_distributed_section_force_and_moment"
174
+ assert getattr(self, 'distributed_sections_initialized', False) is True, err_msg
175
+ sec_frc = np.zeros((ds.nsec, 3), order='F', dtype=np.float64)
176
+ sec_mom = np.zeros((ds.nsec, 3), order='F', dtype=np.float64)
177
+ return H2LibSignatures._get_distributed_section_force_and_moment(
125
178
  self, link_type=int(ds.link_type.value), link_id=int(ds.link_id), nsec=int(ds.nsec),
126
- frc_g=sec_frc, mom_g=sec_mom)
179
+ frc=sec_frc, mom=sec_mom, mainbody_coo_nr=int(mainbody_coo_nr))[0][3:5]
127
180
 
128
181
  def set_fsi_loads_h2lib(self, fx, fy, fz, mx, my, mz): # pragma: no cover
129
182
  """Temporary function needed to replicate results of the cpl coupling framework"""
h2lib/dll_wrapper.py CHANGED
@@ -17,8 +17,9 @@ import sys
17
17
  from pathlib import Path
18
18
  import atexit
19
19
 
20
- c_int_p = POINTER(ctypes.c_long)
21
- c_long_p = POINTER(ctypes.c_longlong)
20
+ c_int_p = POINTER(ctypes.c_int)
21
+ c_long_p = POINTER(ctypes.c_long)
22
+ c_longlong_p = POINTER(ctypes.c_longlong)
22
23
  c_double_p = POINTER(ctypes.c_double)
23
24
  c_float_p = POINTER(ctypes.c_float)
24
25
  c_bool_p = POINTER(ctypes.c_bool)
@@ -113,19 +114,21 @@ def wrap(self, f, *args, check_stop=True, **kwargs):
113
114
  for arg in args:
114
115
  if isinstance(arg, bool):
115
116
  c_args.append(c_bool_p(c_bool(arg)))
116
- elif isinstance(arg, int):
117
- c_args.append(c_long_p(c_longlong(arg)))
118
- elif isinstance(arg, float):
117
+ elif isinstance(arg, np.int32):
118
+ c_args.append(c_long_p(c_long(arg)))
119
+ elif isinstance(arg, (int, np.int64)):
120
+ c_args.append(c_longlong_p(c_longlong(arg)))
121
+ elif isinstance(arg, (float, np.float64)):
119
122
  c_args.append(c_double_p(c_double(arg)))
120
123
  elif isinstance(arg, str):
121
124
  c_args.append(c_char_p(arg.encode('cp1252')))
122
- # c_args.append(c_int_p(c_int(len(arg))))
125
+ # c_args.append(c_long_p(c_int(len(arg))))
123
126
 
124
127
  elif isinstance(arg, np.ndarray):
125
128
  if arg.dtype in [np.int32]:
126
- c_args.append(arg.ctypes.data_as(c_int_p))
127
- elif arg.dtype in [np.int64]:
128
129
  c_args.append(arg.ctypes.data_as(c_long_p))
130
+ elif arg.dtype in [np.int64]:
131
+ c_args.append(arg.ctypes.data_as(c_longlong_p))
129
132
  elif arg.dtype == np.float64:
130
133
  c_args.append(arg.ctypes.data_as(c_double_p))
131
134
  elif arg.dtype == np.float32:
@@ -158,7 +161,7 @@ def wrap(self, f, *args, check_stop=True, **kwargs):
158
161
  ret_args = []
159
162
  for arg in args:
160
163
  c_arg = c_args.pop(0)
161
- if isinstance(arg, (int, float, bool)):
164
+ if isinstance(arg, (int, float, bool, np.int64, np.float64)):
162
165
  ret_args.append(c_arg.contents.value)
163
166
  elif isinstance(arg, (str)):
164
167
  ret_args.append(c_arg.value.decode('cp1252'))
@@ -184,7 +187,7 @@ class DLLWrapper(object):
184
187
 
185
188
  def check_stop(self):
186
189
  stop_code = 0
187
- cstop_code = c_long_p(c_longlong(stop_code))
190
+ cstop_code = c_longlong_p(c_longlong(stop_code))
188
191
  getattr(self.lib, 'get_stop_code')(cstop_code)
189
192
  if cstop_code.contents.value:
190
193
  stop_msg = (" " * 1024).encode('cp1252')