• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WISDEM / WEIS / 20352767729

18 Dec 2025 10:06PM UTC coverage: 58.335% (+0.2%) from 58.139%
20352767729

Pull #447

github

gbarter
adding trimesh
Pull Request #447: Rectangular update

607 of 891 new or added lines in 9 files covered. (68.13%)

38 existing lines in 4 files now uncovered.

8315 of 14254 relevant lines covered (58.33%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.2
/weis/glue_code/gc_LoadInputs.py
1
import os
1✔
2
import os.path as osp
1✔
3
import copy, logging
1✔
4
import numpy as np
1✔
5

6
from rosco import discon_lib_path
1✔
7
import weis.inputs as sch
1✔
8
from openfast_io.FAST_reader import InputReader_OpenFAST
1✔
9
from wisdem.glue_code.gc_LoadInputs import WindTurbineOntologyPython
1✔
10
from weis.dlc_driver.dlc_generator    import DLCGenerator
1✔
11
from openmdao.utils.mpi import MPI
1✔
12
from rosco.toolbox.inputs.validation import load_rosco_yaml
1✔
13
from wisdem.inputs import load_yaml
1✔
14
from weis.control.tune_rosco import update_rosco_options
1✔
15

16
logger = logging.getLogger("wisdem/weis")
1✔
17

18
def update_options(options,override):
1✔
19
    for key, value in override.items():
1✔
20
        if isinstance(value, dict) and key in options:
1✔
21
            update_options(options[key], value)
1✔
22
        elif key in options:
1✔
23
            options[key] = value
1✔
24
        else:
25
            raise Exception(f'Error updating option overrides. {key} is not part of {options.keys()}')
×
26

27
class WindTurbineOntologyPythonWEIS(WindTurbineOntologyPython):
1✔
28
    # Pure python class inheriting the class WindTurbineOntologyPython from WISDEM
29
    # and adding the WEIS options, namely the paths to the WEIS submodules
30
    # (OpenFAST, ROSCO, TurbSim, XFoil) and initializing the control parameters.
31

32
    def __init__(
1✔
33
            self, 
34
            fname_input_wt, 
35
            fname_input_modeling, 
36
            fname_input_analysis,
37
            modeling_override = None,
38
            analysis_override = None,
39
            ):
40

41
        self.modeling_options = sch.load_modeling_yaml(fname_input_modeling)
1✔
42
        self.modeling_options['fname_input_modeling'] = fname_input_modeling
1✔
43
        self.wt_init          = sch.load_geometry_yaml(fname_input_wt)
1✔
44
        self.analysis_options = sch.load_analysis_yaml(fname_input_analysis)
1✔
45
        self.analysis_options['fname_input_analysis'] = fname_input_analysis
1✔
46

47
        # Update options to maintain some backwards compatibility
48
        self.backwards_compatibility()
1✔
49

50
        if modeling_override:
1✔
51
            update_options(self.modeling_options, modeling_override)
1✔
52
            sch.load_modeling_yaml(self.modeling_options)
1✔
53
        
54
        if analysis_override:
1✔
55
            update_options(self.analysis_options, analysis_override)
1✔
56
            sch.load_analysis_yaml(self.analysis_options)
1✔
57

58
        self.set_run_flags()
1✔
59
        self.set_openmdao_vectors()
1✔
60
        self.set_openmdao_vectors_control()
1✔
61
        self.set_weis_data()
1✔
62
        self.set_opt_flags()
1✔
63

64
    def set_weis_data(self):
1✔
65

66
        # Directory of modeling option input, if we want to use it for relative paths
67
        mod_opt_dir = osp.dirname(self.modeling_options['fname_input_modeling'])
1✔
68
        ana_opt_dir = osp.dirname(self.analysis_options['fname_input_analysis'])
1✔
69

70
        # OpenFAST prefixes
71
        if self.modeling_options['General']['openfast_configuration']['OF_run_fst'] in ['','None','NONE','none']:
1✔
72
            self.modeling_options['General']['openfast_configuration']['OF_run_fst'] = 'weis_job'
1✔
73
            
74
        if self.modeling_options['General']['openfast_configuration']['OF_run_dir'] in ['','None','NONE','none']:
1✔
75
            self.modeling_options['General']['openfast_configuration']['OF_run_dir'] = osp.join(
1✔
76
                ana_opt_dir,        # If it's a relative path, will be relative to analysis folder_output directory
77
                self.analysis_options['general']['folder_output'], 
78
                'openfast_runs'
79
                )
80

81
        # BEM dir, all levels
82
        base_run_dir = os.path.join(mod_opt_dir,self.modeling_options['General']['openfast_configuration']['OF_run_dir'])
1✔
83
        if MPI:
1✔
84
            rank    = MPI.COMM_WORLD.Get_rank()
×
85
            bemDir = osp.join(base_run_dir,'rank_%000d'%int(rank),'BEM')
×
86
        else:
87
            bemDir = osp.join(base_run_dir,'BEM')
1✔
88

89
        self.modeling_options["RAFT"]['BEM_dir'] = bemDir
1✔
90
        if MPI:
1✔
91
            # If running MPI, RAFT won't be able to save designs in parallel
92
            self.modeling_options["RAFT"]['save_designs'] = False
×
93

94

95
        # Openfast
96
        if self.modeling_options['OpenFAST_Linear']['flag'] or self.modeling_options['OpenFAST']['flag']:
1✔
97
            fast = InputReader_OpenFAST()
1✔
98
            self.modeling_options['General']['openfast_configuration']['fst_vt'] = {}
1✔
99
            self.modeling_options['General']['openfast_configuration']['fst_vt']['outlist'] = fast.fst_vt['outlist']
1✔
100

101
                
102
            # User-defined control dylib (path2dll)
103
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
104
            if path2dll == 'none':   #Default option, use above
1✔
105
                self.modeling_options['General']['openfast_configuration']['path2dll'] = discon_lib_path
1✔
106
            else:
107
                if not osp.isabs(path2dll):  # make relative path absolute
×
108
                    self.modeling_options['General']['openfast_configuration']['path2dll'] = \
×
109
                        osp.join(osp.dirname(self.options['modeling_options']['fname_input_modeling']), path2dll)
110
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
111
            if not osp.exists( path2dll ):
1✔
112
                raise NameError("Cannot find DISCON library: "+path2dll)
×
113

114
        # Potential flow model logic (All Levels)
115
        if self.modeling_options["flags"]["offshore"] or self.modeling_options["OpenFAST"]["from_openfast"]:
1✔
116
            # RAFT option is equivalent to potential_flow_modeling, bem_method
117
            self.modeling_options["RAFT"]["potModMaster"] = self.modeling_options["General"]["potential_flow_modeling"]["bem_method"]
1✔
118
            
119
            # OpenFAST PotMod logic:
120

121
            # Model all members with BEM
122
            if self.modeling_options["General"]["potential_flow_modeling"]["bem_method"] in [2,3]:
1✔
NEW
123
                self.modeling_options["OpenFAST"]["HydroDyn"]["PotMod"] = 1
×
124
            
125
            # Modeling some members with BEM
126
            elif ( (self.modeling_options["General"]["potential_flow_modeling"]["bem_method"] == 0) and
1✔
127
                    (len(self.modeling_options["General"]["potential_flow_modeling"]["bem_members"]) > 0) ):
NEW
128
                self.modeling_options["OpenFAST"]["HydroDyn"]["PotMod"] = 1
×
129
            
130
            # Modeling no members with BEM
131
            elif self.modeling_options["General"]["potential_flow_modeling"]["bem_method"] == 1:
1✔
NEW
132
                self.modeling_options["OpenFAST"]["HydroDyn"]["PotMod"] = 0
×
133
            
134
            else:
135
                # Keep user defined value of PotMod
136
                pass
1✔
137

138
            # Set BEM directory in OpenFAST (PotFile) and RAFT
139
            if self.modeling_options["OpenFAST"]["HydroDyn"]["PotMod"] == 1:  # a good indicator of whether BEM is used, just above
1✔
140

141
                    
NEW
142
                cwd = os.getcwd()
×
NEW
143
                weis_dir = osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))
×
NEW
144
                potpath = self.modeling_options["General"]["potential_flow_modeling"]["bem_file_base"].replace('.hst','').replace('.12','').replace('.3','').replace('.1','')
×
NEW
145
                if ( (len(potpath) == 0) or (potpath.lower() in ['unused','default','none']) ):
×
146
                    
NEW
147
                    self.modeling_options['RAFT']['flag'] = True
×
NEW
148
                    self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"] = osp.join(bemDir,'Output','Wamit_format','Buoy')
×
149
                    
150

151
                else:
NEW
152
                    if self.modeling_options['RAFT']['runPyHAMS']:
×
NEW
153
                        print('Found existing potential model: {}\n    - Trying to use this instead of running PyHAMS.'.format(potpath))
×
NEW
154
                        self.modeling_options['RAFT']['runPyHAMS'] = False
×
NEW
155
                    if osp.exists( potpath+'.1' ):
×
NEW
156
                        self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"] = osp.realpath(potpath)
×
NEW
157
                    elif osp.exists( osp.join(cwd, potpath+'.1') ):
×
NEW
158
                        self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(cwd, potpath) )
×
NEW
159
                    elif osp.exists( osp.join(weis_dir, potpath+'.1') ):
×
NEW
160
                        self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(weis_dir, potpath) )
×
NEW
161
                    elif osp.exists( osp.join(mod_opt_dir, potpath+'.1') ):
×
NEW
162
                        self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(mod_opt_dir, potpath) )
×
163
                    else:
NEW
164
                        raise Exception(f'No valid Wamit-style output found for specified PotFile option, {potpath}.1')
×
165

166
                    
167
                # Update RAFT BEM dir
NEW
168
                if not self.modeling_options['RAFT']['runPyHAMS']:
×
NEW
169
                    self.modeling_options["RAFT"]['BEM_dir'] = self.modeling_options["OpenFAST"]["HydroDyn"]["PotFile"]
×
170
    
171

172
        # OpenFAST dir
173
        if self.modeling_options["OpenFAST"]["from_openfast"]:
1✔
174
            if not osp.isabs(self.modeling_options['OpenFAST']['openfast_dir']):
1✔
175
                # Make relative to modeling options input
176
                self.modeling_options['OpenFAST']['openfast_dir'] = osp.realpath(osp.join(
1✔
177
                    mod_opt_dir, self.modeling_options['OpenFAST']['openfast_dir'] ))
178
        
179
        if MPI:
1✔
180
            # If running MPI, RAFT won't be able to save designs in parallel
NEW
181
            self.modeling_options["RAFT"]['save_designs'] = False
×
182
        
183
        # RAFT
184
        if self.modeling_options["flags"]["floating"]:
1✔
185
            bool_init = True if self.modeling_options["General"]["potential_flow_modeling"]["bem_method"]==2 else False
1✔
186
            self.modeling_options["RAFT"]["model_potential"] = [bool_init] * self.modeling_options["floating"]["members"]["n_members"]
1✔
187

188
            if self.modeling_options["General"]["potential_flow_modeling"]["bem_method"] == 0:
1✔
189
                for k in self.modeling_options["General"]["potential_flow_modeling"]["bem_members"]:
1✔
UNCOV
190
                    idx = self.modeling_options["floating"]["members"]["name"].index(k)
×
UNCOV
191
                    self.modeling_options["RAFT"]["model_potential"][idx] = True
×
192
        elif self.modeling_options["flags"]["offshore"]:
1✔
193
            self.modeling_options["RAFT"]["model_potential"] = [False]*1000
×
194
            
195
        # ROSCO
196
        self.modeling_options['ROSCO']['flag'] = (self.modeling_options['RAFT']['flag'] or
1✔
197
                                                  self.modeling_options['OpenFAST_Linear']['flag'] or
198
                                                  self.modeling_options['OpenFAST']['flag'])
199
        
200
        if self.modeling_options['ROSCO']['tuning_yaml'] != 'none':  # default is empty
1✔
201
            # Make path absolute if not, relative to modeling options input
202
            if not osp.isabs(self.modeling_options['ROSCO']['tuning_yaml']):
1✔
203
                self.modeling_options['ROSCO']['tuning_yaml'] = osp.realpath(osp.join(
1✔
204
                    mod_opt_dir, self.modeling_options['ROSCO']['tuning_yaml'] ))
205
                
206
        # Apply tuning yaml input if available, this needs to be here for sizing tune_rosco_ivc
207
        if os.path.split(self.modeling_options['ROSCO']['tuning_yaml'])[1] != 'none':  # default is none
1✔
208
            update_rosco_options(self.modeling_options)
1✔
209
        
210
        # XFoil
211
        if not osp.isfile(self.modeling_options['OpenFAST']["xfoil"]["path"]) and self.modeling_options['ROSCO']['Flp_Mode']:
1✔
212
            raise Exception("A distributed aerodynamic control device is defined in the geometry yaml, but the path to XFoil in the modeling options is not defined correctly")
×
213

214
        # Compute the number of DLCs that will be run
215
        DLCs = self.modeling_options['DLC_driver']['DLCs']
1✔
216
        # Initialize the DLC generator
217
        cut_in = self.wt_init['control']['supervisory']['Vin']
1✔
218
        cut_out = self.wt_init['control']['supervisory']['Vout']
1✔
219
        metocean = self.modeling_options['DLC_driver']['metocean_conditions']
1✔
220
        dlc_driver_options = self.modeling_options['DLC_driver']
1✔
221
        dlc_generator = DLCGenerator(cut_in, cut_out, dlc_driver_options=dlc_driver_options, metocean=metocean)
1✔
222
        # Generate cases from user inputs
223
        for i_DLC in range(len(DLCs)):
1✔
224
            DLCopt = DLCs[i_DLC]
1✔
225
            DLCopt['fname_input_modeling'] = self.modeling_options['fname_input_modeling'] # pass this for relative paths
1✔
226
            dlc_generator.generate(DLCopt['DLC'], DLCopt)
1✔
227
        self.modeling_options['DLC_driver']['n_cases'] = dlc_generator.n_cases
1✔
228
        
229
        # Determine wind speeds that will be used to calculate AEP (using DLC AEP or 1.1)
230
        DLCs = [i_dlc['DLC'] for i_dlc in self.modeling_options['DLC_driver']['DLCs']]
1✔
231
        if 'AEP' in DLCs:
1✔
232
            DLC_label_for_AEP = 'AEP'
×
233
        else:
234
            DLC_label_for_AEP = '1.1'
1✔
235
        dlc_aep_ws = [c.URef for c in dlc_generator.cases if c.label == DLC_label_for_AEP]
1✔
236
        self.modeling_options['DLC_driver']['n_ws_aep'] = len(np.unique(dlc_aep_ws))
1✔
237

238
        # TMD modeling
239
        self.modeling_options['flags']['TMDs'] = False
1✔
240
        if 'TMDs' in self.wt_init:
1✔
241
            if self.modeling_options['OpenFAST']['flag']:
×
242
                self.modeling_options['flags']['TMDs'] = True
×
243
            else:
244
                raise Exception("TMDs in Levels 1 and 2 are not supported yet")
×
245

246

247
    def set_openmdao_vectors_control(self):
1✔
248
        # Distributed aerodynamic control devices along blade
249
        self.modeling_options['WISDEM']['RotorSE']['n_te_flaps']      = 0
1✔
250
        if 'aerodynamic_control' in self.wt_init['components']['blade']:
1✔
251
            if 'te_flaps' in self.wt_init['components']['blade']['aerodynamic_control']:
×
252
                self.modeling_options['WISDEM']['RotorSE']['n_te_flaps'] = len(self.wt_init['components']['blade']['aerodynamic_control']['te_flaps'])
×
253
                self.modeling_options['WISDEM']['RotorSE']['n_tab']   = 3
×
254
            else:
255
                raise Exception('A distributed aerodynamic control device is provided in the yaml input file, but not supported by wisdem.')
×
256

257
        if 'TMDs' in self.wt_init:
1✔
258
            n_TMDs = len(self.wt_init['TMDs'])
×
259
            self.modeling_options['TMDs'] = {}
×
260
            self.modeling_options['TMDs']['n_TMDs']                 = n_TMDs
×
261
            # TODO: come back and check how many of these need to be modeling options
262
            self.modeling_options['TMDs']['name']                   = [tmd['name'] for  tmd in self.wt_init['TMDs']]
×
263
            self.modeling_options['TMDs']['component']              = [tmd['component'] for  tmd in self.wt_init['TMDs']]
×
264
            self.modeling_options['TMDs']['location']               = [tmd['location'] for  tmd in self.wt_init['TMDs']]
×
265
            self.modeling_options['TMDs']['mass']                   = [tmd['mass'] for  tmd in self.wt_init['TMDs']]
×
266
            self.modeling_options['TMDs']['stiffness']              = [tmd['stiffness'] for  tmd in self.wt_init['TMDs']]
×
267
            self.modeling_options['TMDs']['damping']                = [tmd['damping'] for  tmd in self.wt_init['TMDs']]
×
268
            self.modeling_options['TMDs']['natural_frequency']      = [tmd['natural_frequency'] for  tmd in self.wt_init['TMDs']]
×
269
            self.modeling_options['TMDs']['damping_ratio']          = [tmd['damping_ratio'] for  tmd in self.wt_init['TMDs']]
×
270
            self.modeling_options['TMDs']['X_DOF']                  = [tmd['X_DOF'] for  tmd in self.wt_init['TMDs']]
×
271
            self.modeling_options['TMDs']['Y_DOF']                  = [tmd['Y_DOF'] for  tmd in self.wt_init['TMDs']]
×
272
            self.modeling_options['TMDs']['Z_DOF']                  = [tmd['Z_DOF'] for  tmd in self.wt_init['TMDs']]
×
273
            self.modeling_options['TMDs']['preload_spring']         = [tmd['preload_spring'] for  tmd in self.wt_init['TMDs']]
×
274

275
            # Check that TMD locations map to somewhere valid (tower or platform member)
276
            self.modeling_options['TMDs']['num_tower_TMDs'] = 0
×
277
            self.modeling_options['TMDs']['num_ptfm_TMDs']  = 0
×
278
            
279
            for i_TMD, component in enumerate(self.modeling_options['TMDs']['component']):
×
280
                if self.modeling_options['flags']['floating'] and component in self.modeling_options['floating']['members']['name']:
×
281
                    self.modeling_options['TMDs']['num_ptfm_TMDs'] += 1
×
282
                elif component == 'tower':
×
283
                    self.modeling_options['TMDs']['num_tower_TMDs'] += 1
×
284
                else:
285
                    raise Exception('Invalid TMD component mapping for {} on {}'.format(
×
286
                        self.modeling_options['TMDs']['name'][i_TMD],component))      
287

288
            # Set TMD group  mapping: list of length n_groups, with i_TMDs in each group
289
            # Loop through TMD names, assign to own group if not in an analysis group
290
            if 'TMDs' in self.analysis_options['design_variables']:
×
291
                tmd_group_map = []
×
292
                tmd_names = self.modeling_options['TMDs']['name']
×
293
                
294
                for i_group, tmd_group in enumerate(self.analysis_options['design_variables']['TMDs']['groups']):
×
295
                    tmds_in_group_i = [tmd_names.index(tmd_name) for tmd_name in tmd_group['names']]
×
296

297
                    tmd_group_map.append(tmds_in_group_i)
×
298
                
299
                self.modeling_options['TMDs']['group_mapping'] = tmd_group_map
×
300

301
    def update_ontology(self, wt_opt):
1✔
302
        # Call the WISDEM version first
303
        super(WindTurbineOntologyPythonWEIS, self).update_ontology(wt_opt)
1✔
304

305
        '''
1✔
306
        # Likely outdated
307
        if self.modeling_options['flags']['control']:
308
            self.wt_init['control']['pitch']['omega_pc'] = wt_opt['tune_rosco_ivc.omega_pc']
309
            self.wt_init['control']['pitch']['zeta_pc']  = wt_opt['tune_rosco_ivc.zeta_pc']
310
            self.wt_init['control']['torque']['omega_vs'] = float(wt_opt['tune_rosco_ivc.omega_vs'])
311
            self.wt_init['control']['torque']['zeta_vs']  = float(wt_opt['tune_rosco_ivc.zeta_vs'])
312
            self.wt_init['control']['pitch']['Kp_float']  = float(wt_opt['tune_rosco_ivc.Kp_float'])
313
            self.wt_init['control']['pitch']['ptfm_freq']  = float(wt_opt['tune_rosco_ivc.ptfm_freq'])
314
            self.wt_init['control']['IPC']['IPC_Ki_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Kp1p'])
315
            self.wt_init['control']['IPC']['IPC_Kp_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Ki1p'])
316
            if self.modeling_options['ROSCO']['Flp_Mode'] > 0:
317
                self.wt_init['control']['dac']['flp_kp_norm']= float(wt_opt['tune_rosco_ivc.flp_kp_norm'])
318
                self.wt_init['control']['dac']['flp_tau'] = float(wt_opt['tune_rosco_ivc.flp_tau'])
319
        '''
320

321
        if self.modeling_options['flags']['TMDs']:
1✔
322
            for k in range( self.modeling_options['TMDs']['n_TMDs'] ):
×
323
                for m in ['mass', 'stiffness', 'damping']: #, 'natural_frequency', 'damping_ratio']:
×
324
                    self.wt_init['TMDs'][k][m] = float(wt_opt[f'TMDs.{m}'][k])
×
325

326

327
    def write_outputs(self, fname_output):
1✔
328
        # Override the WISDEM version to ensure that the WEIS options files are written instead
329
        sch.write_geometry_yaml(self.wt_init, fname_output)
1✔
330
        sch.write_modeling_yaml(self.modeling_options, fname_output)
1✔
331
        sch.write_analysis_yaml(self.analysis_options, fname_output)
1✔
332

333

334
    def backwards_compatibility(self):
1✔
335

336
        modopts_no_defaults = load_yaml(self.modeling_options['fname_input_modeling'])
1✔
337

338
        if 'Level1' in modopts_no_defaults:
1✔
339
            self.modeling_options['RAFT'] = copy.deepcopy(self.modeling_options['Level1'])
×
340
            logger.warning('Level1 is no longer a WEIS modeling option.  Please use RAFT instead.  Level1 will be depreciated in a future release.')
×
341

342
        if 'Level2' in modopts_no_defaults:
1✔
343
            self.modeling_options['OpenFAST_Linear'] = copy.deepcopy(self.modeling_options['Level2'])
×
344
            logger.warning('Level2 is no longer a WEIS modeling option.  Please use OpenFAST_Linear instead.  Level2 will be depreciated in a future release.')
×
345

346
        if 'Level3' in modopts_no_defaults:
1✔
347
            self.modeling_options['OpenFAST'] = copy.deepcopy(self.modeling_options['Level3'])
×
348
            logger.warning('Level3 is no longer a WEIS modeling option.  Please use OpenFAST instead.  Level3 will be depreciated in a future release.')
×
349

350

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc