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

WISDEM / WEIS / 9919956665

13 Jul 2024 12:34PM UTC coverage: 79.574% (+8.7%) from 70.904%
9919956665

Pull #289

github

gbarter
use the OpenMDAO approach to the problem_vars.json output
Pull Request #289: Release with improved installation

163 of 521 new or added lines in 17 files covered. (31.29%)

707 existing lines in 19 files now uncovered.

21618 of 27167 relevant lines covered (79.57%)

0.8 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✔
NEW
13
    for key, value in override.items():
×
NEW
14
        if isinstance(value, dict) and key in options:
×
NEW
15
            update_options(options[key], value)
×
NEW
16
        elif key in options:
×
NEW
17
            options[key] = value
×
18
        else:
NEW
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✔
NEW
42
            update_options(self.modeling_options, modeling_override)
×
NEW
43
            sch.re_validate_modeling(self.modeling_options)
×
44
                
45
        
46
        if analysis_override:
1✔
NEW
47
            update_options(self.analysis_options, analysis_override)
×
NEW
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
        # BEM dir, all levels
62
        base_run_dir = os.path.join(mod_opt_dir,self.modeling_options['General']['openfast_configuration']['OF_run_dir'])
1✔
63
        if MPI:
1✔
64
            rank    = MPI.COMM_WORLD.Get_rank()
×
65
            bemDir = osp.join(base_run_dir,'rank_%000d'%int(rank),'BEM')
×
66
        else:
67
            bemDir = osp.join(base_run_dir,'BEM')
1✔
68

69
        self.modeling_options["Level1"]['BEM_dir'] = bemDir
1✔
70
        if MPI:
1✔
71
            # If running MPI, RAFT won't be able to save designs in parallel
72
            self.modeling_options["Level1"]['save_designs'] = False
×
73

74

75
        # Openfast
76
        if self.modeling_options['Level2']['flag'] or self.modeling_options['Level3']['flag']:
1✔
77
            fast = InputReader_OpenFAST()
1✔
78
            self.modeling_options['General']['openfast_configuration']['fst_vt'] = {}
1✔
79
            self.modeling_options['General']['openfast_configuration']['fst_vt']['outlist'] = fast.fst_vt['outlist']
1✔
80

81
            # OpenFAST prefixes
82
            if self.modeling_options['General']['openfast_configuration']['OF_run_fst'] in ['','None','NONE','none']:
1✔
83
                self.modeling_options['General']['openfast_configuration']['OF_run_fst'] = 'weis_job'
1✔
84
                
85
            if self.modeling_options['General']['openfast_configuration']['OF_run_dir'] in ['','None','NONE','none']:
1✔
86
                self.modeling_options['General']['openfast_configuration']['OF_run_dir'] = osp.join(
1✔
87
                    self.analysis_options['general']['folder_output'], 
88
                    'openfast_runs'
89
                    )
90
                
91
            # User-defined control dylib (path2dll)
92
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
93
            if path2dll == 'none':   #Default option, use above
1✔
94
                self.modeling_options['General']['openfast_configuration']['path2dll'] = discon_lib_path
1✔
95
            else:
96
                if not osp.isabs(path2dll):  # make relative path absolute
×
97
                    self.modeling_options['General']['openfast_configuration']['path2dll'] = \
×
98
                        osp.join(osp.dirname(self.options['modeling_options']['fname_input_modeling']), path2dll)
99
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
100
            if not osp.exists( path2dll ):
1✔
101
                raise NameError("Cannot find DISCON library: "+path2dll)
×
102

103
            # Activate HAMS in Level1 if requested for Level 2 or 3
104
            if self.modeling_options["flags"]["offshore"] or self.modeling_options["Level3"]["from_openfast"]:
1✔
105
                if self.modeling_options["Level1"]["potential_model_override"] == 2:
1✔
106
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
1✔
107
                elif ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
108
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) > 0) ):
UNCOV
109
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
×
110
                elif self.modeling_options["Level1"]["potential_model_override"] == 1:
1✔
111
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 0
×
112
                else:
113
                    # Keep user defined value of PotMod
114
                    pass
1✔
115

116
                if self.modeling_options["Level3"]["HydroDyn"]["PotMod"] == 1:
1✔
117

118
                    # If user requested PotMod but didn't specify any override or members, just run everything
119
                    if ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
120
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) == 0) ):
121
                        self.modeling_options["Level1"]["potential_model_override"] == 2
×
122
                        
123
                    cwd = os.getcwd()
1✔
124
                    weis_dir = osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))
1✔
125
                    potpath = self.modeling_options["Level3"]["HydroDyn"]["PotFile"].replace('.hst','').replace('.12','').replace('.3','').replace('.1','')
1✔
126
                    if ( (len(potpath) == 0) or (potpath.lower() in ['unused','default','none']) ):
1✔
127
                        
128
                        self.modeling_options['Level1']['flag'] = True
×
NEW
129
                        self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.join(bemDir,'Output','Wamit_format','Buoy')
×
130
                        
131

132
                    else:
133
                        if self.modeling_options['Level1']['runPyHAMS']:
1✔
134
                            print('Found existing potential model: {}\n    - Trying to use this instead of running PyHAMS.'.format(potpath))
1✔
135
                            self.modeling_options['Level1']['runPyHAMS'] = False
1✔
136
                        if osp.exists( potpath+'.1' ):
1✔
137
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath(potpath)
1✔
UNCOV
138
                        elif osp.exists( osp.join(cwd, potpath+'.1') ):
×
139
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(cwd, potpath) )
×
UNCOV
140
                        elif osp.exists( osp.join(weis_dir, potpath+'.1') ):
×
UNCOV
141
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(weis_dir, potpath) )
×
142
                        elif osp.exists( osp.join(mod_opt_dir, potpath+'.1') ):
×
143
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(mod_opt_dir, potpath) )
×
144
                        else:
145
                            raise Exception(f'No valid Wamit-style output found for specified PotFile option, {potpath}.1')
×
146

147
        # OpenFAST dir
148
        if self.modeling_options["Level3"]["from_openfast"]:
1✔
149
            if not osp.isabs(self.modeling_options['Level3']['openfast_dir']):
1✔
150
                # Make relative to modeling options input
151
                self.modeling_options['Level3']['openfast_dir'] = osp.realpath(osp.join(
1✔
152
                    mod_opt_dir, self.modeling_options['Level3']['openfast_dir'] ))
153
        
154
        # RAFT
155
        if self.modeling_options["flags"]["floating"]:
1✔
156
            bool_init = True if self.modeling_options["Level1"]["potential_model_override"]==2 else False
1✔
157
            self.modeling_options["Level1"]["model_potential"] = [bool_init] * self.modeling_options["floating"]["members"]["n_members"]
1✔
158

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

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

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

205

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

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

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

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

256
                    tmd_group_map.append(tmds_in_group_i)
1✔
257
                
258
                self.modeling_options['TMDs']['group_mapping'] = tmd_group_map
1✔
259

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

275

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