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

WISDEM / WEIS / 10910578615

17 Sep 2024 08:27PM UTC coverage: 79.167% (-0.5%) from 79.668%
10910578615

Pull #308

github

dzalkind
Tidy some docs pages
Pull Request #308: DLC Generation - Refactor and New Cases

423 of 568 new or added lines in 10 files covered. (74.47%)

171 existing lines in 7 files now uncovered.

21349 of 26967 relevant lines covered (79.17%)

0.79 hits per line

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

71.91
/weis/glue_code/gc_LoadInputs.py
1
import os
1✔
2
import os.path as osp
1✔
3
import shutil
1✔
4

5
from rosco import discon_lib_path
1✔
6
import weis.inputs as sch
1✔
7
from weis.aeroelasticse.FAST_reader import InputReader_OpenFAST
1✔
8
from wisdem.glue_code.gc_LoadInputs import WindTurbineOntologyPython
1✔
9
from weis.dlc_driver.dlc_generator    import DLCGenerator
1✔
10
from wisdem.commonse.mpi_tools              import MPI
1✔
11

12
def update_options(options,override):
1✔
UNCOV
13
    for key, value in override.items():
×
UNCOV
14
        if isinstance(value, dict) and key in options:
×
UNCOV
15
            update_options(options[key], value)
×
UNCOV
16
        elif key in options:
×
UNCOV
17
            options[key] = value
×
18
        else:
19
            raise Exception(f'Error updating option overrides. {key} is not part of {options.keys()}')
×
20

21
class WindTurbineOntologyPythonWEIS(WindTurbineOntologyPython):
1✔
22
    # Pure python class inheriting the class WindTurbineOntologyPython from WISDEM
23
    # and adding the WEIS options, namely the paths to the WEIS submodules
24
    # (OpenFAST, ROSCO, TurbSim, XFoil) and initializing the control parameters.
25

26
    def __init__(
1✔
27
            self, 
28
            fname_input_wt, 
29
            fname_input_modeling, 
30
            fname_input_analysis,
31
            modeling_override = None,
32
            analysis_override = None,
33
            ):
34

35
        self.modeling_options = sch.load_modeling_yaml(fname_input_modeling)
1✔
36
        self.modeling_options['fname_input_modeling'] = fname_input_modeling
1✔
37
        self.wt_init          = sch.load_geometry_yaml(fname_input_wt)
1✔
38
        self.analysis_options = sch.load_analysis_yaml(fname_input_analysis)
1✔
39
        self.analysis_options['fname_input_analysis'] = fname_input_analysis
1✔
40

41
        if modeling_override:
1✔
UNCOV
42
            update_options(self.modeling_options, modeling_override)
×
UNCOV
43
            sch.re_validate_modeling(self.modeling_options)
×
44
                
45
        
46
        if analysis_override:
1✔
47
            update_options(self.analysis_options, analysis_override)
×
48
            sch.re_validate_analysis(self.analysis_options)
×
49

50
        self.set_run_flags()
1✔
51
        self.set_openmdao_vectors()
1✔
52
        self.set_openmdao_vectors_control()
1✔
53
        self.set_weis_data()
1✔
54
        self.set_opt_flags()
1✔
55

56
    def set_weis_data(self):
1✔
57

58
        # Directory of modeling option input, if we want to use it for relative paths
59
        mod_opt_dir = osp.split(self.modeling_options['fname_input_modeling'])[0]
1✔
60

61

62

63

64
        # Openfast
65
        if self.modeling_options['Level2']['flag'] or self.modeling_options['Level3']['flag']:
1✔
66
            fast = InputReader_OpenFAST()
1✔
67
            self.modeling_options['General']['openfast_configuration']['fst_vt'] = {}
1✔
68
            self.modeling_options['General']['openfast_configuration']['fst_vt']['outlist'] = fast.fst_vt['outlist']
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
                    osp.dirname(self.analysis_options['fname_input_analysis']),
77
                    self.analysis_options['general']['folder_output'], 
78
                    'openfast_runs'
79
                    )
80
                
81
            # User-defined control dylib (path2dll)
82
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
83
            if path2dll == 'none':   #Default option, use above
1✔
84
                self.modeling_options['General']['openfast_configuration']['path2dll'] = discon_lib_path
1✔
85
            else:
86
                if not osp.isabs(path2dll):  # make relative path absolute
×
87
                    self.modeling_options['General']['openfast_configuration']['path2dll'] = \
×
88
                        osp.join(osp.dirname(self.options['modeling_options']['fname_input_modeling']), path2dll)
89
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
90
            if not osp.exists( path2dll ):
1✔
91
                raise NameError("Cannot find DISCON library: "+path2dll)
×
92

93
            # Activate HAMS in Level1 if requested for Level 2 or 3
94
            if self.modeling_options["flags"]["offshore"] or self.modeling_options["Level3"]["from_openfast"]:
1✔
95
                if self.modeling_options["Level1"]["potential_model_override"] == 2:
1✔
96
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
1✔
97
                elif ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
98
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) > 0) ):
99
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
×
100
                elif self.modeling_options["Level1"]["potential_model_override"] == 1:
1✔
101
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 0
×
102
                else:
103
                    # Keep user defined value of PotMod
104
                    pass
1✔
105

106
                if self.modeling_options["Level3"]["HydroDyn"]["PotMod"] == 1:
1✔
107

108
                    # If user requested PotMod but didn't specify any override or members, just run everything
109
                    if ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
110
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) == 0) ):
111
                        self.modeling_options["Level1"]["potential_model_override"] == 2
×
112
                        
113
                    cwd = os.getcwd()
1✔
114
                    weis_dir = osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))
1✔
115
                    potpath = self.modeling_options["Level3"]["HydroDyn"]["PotFile"].replace('.hst','').replace('.12','').replace('.3','').replace('.1','')
1✔
116
                    if ( (len(potpath) == 0) or (potpath.lower() in ['unused','default','none']) ):
1✔
117
                        
118
                        self.modeling_options['Level1']['flag'] = True
×
119
                        self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.join(bemDir,'Output','Wamit_format','Buoy')
×
120
                        
121

122
                    else:
123
                        if self.modeling_options['Level1']['runPyHAMS']:
1✔
124
                            print('Found existing potential model: {}\n    - Trying to use this instead of running PyHAMS.'.format(potpath))
1✔
125
                            self.modeling_options['Level1']['runPyHAMS'] = False
1✔
126
                        if osp.exists( potpath+'.1' ):
1✔
127
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath(potpath)
1✔
128
                        elif osp.exists( osp.join(cwd, potpath+'.1') ):
×
129
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(cwd, potpath) )
×
130
                        elif osp.exists( osp.join(weis_dir, potpath+'.1') ):
×
131
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(weis_dir, potpath) )
×
132
                        elif osp.exists( osp.join(mod_opt_dir, potpath+'.1') ):
×
133
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(mod_opt_dir, potpath) )
×
134
                        else:
135
                            raise Exception(f'No valid Wamit-style output found for specified PotFile option, {potpath}.1')
×
136

137
        # OpenFAST dir
138
        if self.modeling_options["Level3"]["from_openfast"]:
1✔
139
            if not osp.isabs(self.modeling_options['Level3']['openfast_dir']):
1✔
140
                # Make relative to modeling options input
141
                self.modeling_options['Level3']['openfast_dir'] = osp.realpath(osp.join(
1✔
142
                    mod_opt_dir, self.modeling_options['Level3']['openfast_dir'] ))
143
        
144
        # BEM dir, all levels
145
        base_run_dir = os.path.join(mod_opt_dir,self.modeling_options['General']['openfast_configuration']['OF_run_dir'])
1✔
146
        if MPI:
1✔
NEW
147
            rank    = MPI.COMM_WORLD.Get_rank()
×
NEW
148
            bemDir = osp.join(base_run_dir,'rank_%000d'%int(rank),'BEM')
×
149
        else:
150
            bemDir = osp.join(base_run_dir,'BEM')
1✔
151

152
        self.modeling_options["Level1"]['BEM_dir'] = bemDir
1✔
153
        if MPI:
1✔
154
            # If running MPI, RAFT won't be able to save designs in parallel
NEW
155
            self.modeling_options["Level1"]['save_designs'] = False
×
156
        
157
        # RAFT
158
        if self.modeling_options["flags"]["floating"]:
1✔
159
            bool_init = True if self.modeling_options["Level1"]["potential_model_override"]==2 else False
1✔
160
            self.modeling_options["Level1"]["model_potential"] = [bool_init] * self.modeling_options["floating"]["members"]["n_members"]
1✔
161

162
            if self.modeling_options["Level1"]["potential_model_override"] == 0:
1✔
163
                for k in self.modeling_options["Level1"]["potential_bem_members"]:
1✔
164
                    idx = self.modeling_options["floating"]["members"]["name"].index(k)
1✔
165
                    self.modeling_options["Level1"]["model_potential"][idx] = True
1✔
166
        elif self.modeling_options["flags"]["offshore"]:
1✔
167
            self.modeling_options["Level1"]["model_potential"] = [False]*1000
1✔
168
            
169
        # ROSCO
170
        self.modeling_options['ROSCO']['flag'] = (self.modeling_options['Level1']['flag'] or
1✔
171
                                                  self.modeling_options['Level2']['flag'] or
172
                                                  self.modeling_options['Level3']['flag'])
173
        
174
        if self.modeling_options['ROSCO']['tuning_yaml'] != 'none':  # default is empty
1✔
175
            # Make path absolute if not, relative to modeling options input
176
            if not osp.isabs(self.modeling_options['ROSCO']['tuning_yaml']):
1✔
177
                self.modeling_options['ROSCO']['tuning_yaml'] = osp.realpath(osp.join(
1✔
178
                    mod_opt_dir, self.modeling_options['ROSCO']['tuning_yaml'] ))
179
        
180
        # XFoil
181
        if not osp.isfile(self.modeling_options['Level3']["xfoil"]["path"]) and self.modeling_options['ROSCO']['Flp_Mode']:
1✔
182
            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")
×
183

184
        # Compute the number of DLCs that will be run
185
        DLCs = self.modeling_options['DLC_driver']['DLCs']
1✔
186
        # Initialize the DLC generator
187
        cut_in = self.wt_init['control']['supervisory']['Vin']
1✔
188
        cut_out = self.wt_init['control']['supervisory']['Vout']
1✔
189
        metocean = self.modeling_options['DLC_driver']['metocean_conditions']
1✔
190
        dlc_generator = DLCGenerator(cut_in, cut_out, metocean=metocean)
1✔
191
        # Generate cases from user inputs
192
        for i_DLC in range(len(DLCs)):
1✔
193
            DLCopt = DLCs[i_DLC]
1✔
194
            dlc_generator.generate(DLCopt['DLC'], DLCopt)
1✔
195
        self.modeling_options['DLC_driver']['n_cases'] = dlc_generator.n_cases
1✔
196
        if hasattr(dlc_generator,'n_ws_dlc11'):
1✔
197
            self.modeling_options['DLC_driver']['n_ws_dlc11'] = dlc_generator.n_ws_dlc11
1✔
198
        else:
199
            self.modeling_options['DLC_driver']['n_ws_dlc11'] = 0
×
200

201
        self.modeling_options['flags']['TMDs'] = False
1✔
202
        if 'TMDs' in self.wt_init:
1✔
203
            if self.modeling_options['Level3']['flag']:
1✔
204
                self.modeling_options['flags']['TMDs'] = True
1✔
205
            else:
206
                raise Exception("TMDs in Levels 1 and 2 are not supported yet")
×
207

208

209
    def set_openmdao_vectors_control(self):
1✔
210
        # Distributed aerodynamic control devices along blade
211
        self.modeling_options['WISDEM']['RotorSE']['n_te_flaps']      = 0
1✔
212
        if 'aerodynamic_control' in self.wt_init['components']['blade']:
1✔
213
            if 'te_flaps' in self.wt_init['components']['blade']['aerodynamic_control']:
×
214
                self.modeling_options['WISDEM']['RotorSE']['n_te_flaps'] = len(self.wt_init['components']['blade']['aerodynamic_control']['te_flaps'])
×
215
                self.modeling_options['WISDEM']['RotorSE']['n_tab']   = 3
×
216
            else:
217
                raise Exception('A distributed aerodynamic control device is provided in the yaml input file, but not supported by wisdem.')
×
218

219
        if 'TMDs' in self.wt_init:
1✔
220
            n_TMDs = len(self.wt_init['TMDs'])
1✔
221
            self.modeling_options['TMDs'] = {}
1✔
222
            self.modeling_options['TMDs']['n_TMDs']                 = n_TMDs
1✔
223
            # TODO: come back and check how many of these need to be modeling options
224
            self.modeling_options['TMDs']['name']                   = [tmd['name'] for  tmd in self.wt_init['TMDs']]
1✔
225
            self.modeling_options['TMDs']['component']              = [tmd['component'] for  tmd in self.wt_init['TMDs']]
1✔
226
            self.modeling_options['TMDs']['location']               = [tmd['location'] for  tmd in self.wt_init['TMDs']]
1✔
227
            self.modeling_options['TMDs']['mass']                   = [tmd['mass'] for  tmd in self.wt_init['TMDs']]
1✔
228
            self.modeling_options['TMDs']['stiffness']              = [tmd['stiffness'] for  tmd in self.wt_init['TMDs']]
1✔
229
            self.modeling_options['TMDs']['damping']                = [tmd['damping'] for  tmd in self.wt_init['TMDs']]
1✔
230
            self.modeling_options['TMDs']['natural_frequency']      = [tmd['natural_frequency'] for  tmd in self.wt_init['TMDs']]
1✔
231
            self.modeling_options['TMDs']['damping_ratio']          = [tmd['damping_ratio'] for  tmd in self.wt_init['TMDs']]
1✔
232
            self.modeling_options['TMDs']['X_DOF']                  = [tmd['X_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
233
            self.modeling_options['TMDs']['Y_DOF']                  = [tmd['Y_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
234
            self.modeling_options['TMDs']['Z_DOF']                  = [tmd['Z_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
235
            self.modeling_options['TMDs']['preload_spring']         = [tmd['preload_spring'] for  tmd in self.wt_init['TMDs']]
1✔
236

237
            # Check that TMD locations map to somewhere valid (tower or platform member)
238
            self.modeling_options['TMDs']['num_tower_TMDs'] = 0
1✔
239
            self.modeling_options['TMDs']['num_ptfm_TMDs']  = 0
1✔
240
            
241
            for i_TMD, component in enumerate(self.modeling_options['TMDs']['component']):
1✔
242
                if self.modeling_options['flags']['floating'] and component in self.modeling_options['floating']['members']['name']:
1✔
243
                    self.modeling_options['TMDs']['num_ptfm_TMDs'] += 1
1✔
244
                elif component == 'tower':
×
245
                    self.modeling_options['TMDs']['num_tower_TMDs'] += 1
×
246
                else:
247
                    raise Exception('Invalid TMD component mapping for {} on {}'.format(
×
248
                        self.modeling_options['TMDs']['name'][i_TMD],component))      
249

250
            # Set TMD group  mapping: list of length n_groups, with i_TMDs in each group
251
            # Loop through TMD names, assign to own group if not in an analysis group
252
            if 'TMDs' in self.analysis_options['design_variables']:
1✔
253
                tmd_group_map = []
1✔
254
                tmd_names = self.modeling_options['TMDs']['name']
1✔
255
                
256
                for i_group, tmd_group in enumerate(self.analysis_options['design_variables']['TMDs']['groups']):
1✔
257
                    tmds_in_group_i = [tmd_names.index(tmd_name) for tmd_name in tmd_group['names']]
1✔
258

259
                    tmd_group_map.append(tmds_in_group_i)
1✔
260
                
261
                self.modeling_options['TMDs']['group_mapping'] = tmd_group_map
1✔
262

263
    def update_ontology_control(self, wt_opt):
1✔
264
        # Update controller
265
        if self.modeling_options['flags']['control']:
×
266
            self.wt_init['control']['pitch']['omega_pc'] = wt_opt['tune_rosco_ivc.omega_pc']
×
267
            self.wt_init['control']['pitch']['zeta_pc']  = wt_opt['tune_rosco_ivc.zeta_pc']
×
268
            self.wt_init['control']['torque']['omega_vs'] = float(wt_opt['tune_rosco_ivc.omega_vs'])
×
269
            self.wt_init['control']['torque']['zeta_vs']  = float(wt_opt['tune_rosco_ivc.zeta_vs'])
×
270
            self.wt_init['control']['pitch']['Kp_float']  = float(wt_opt['tune_rosco_ivc.Kp_float'])
×
271
            self.wt_init['control']['pitch']['ptfm_freq']  = float(wt_opt['tune_rosco_ivc.ptfm_freq'])
×
272
            self.wt_init['control']['IPC']['IPC_Ki_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Kp1p'])
×
273
            self.wt_init['control']['IPC']['IPC_Kp_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Ki1p'])
×
274
            if self.modeling_options['ROSCO']['Flp_Mode'] > 0:
×
275
                self.wt_init['control']['dac']['flp_kp_norm']= float(wt_opt['tune_rosco_ivc.flp_kp_norm'])
×
276
                self.wt_init['control']['dac']['flp_tau'] = float(wt_opt['tune_rosco_ivc.flp_tau'])
×
277

278

279
    def write_options(self, fname_output):
1✔
280
        # Override the WISDEM version to ensure that the WEIS options files are written instead
281
        sch.write_modeling_yaml(self.modeling_options, fname_output)
1✔
282
        sch.write_analysis_yaml(self.analysis_options, fname_output)
1✔
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