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

WISDEM / WEIS / 9244539224

26 May 2024 04:03PM UTC coverage: 80.482% (+9.6%) from 70.847%
9244539224

push

github

web-flow
Merge pull request #279 from WISDEM/wisdem_315

5 of 7 new or added lines in 2 files covered. (71.43%)

689 existing lines in 18 files now uncovered.

21615 of 26857 relevant lines covered (80.48%)

0.8 hits per line

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

77.58
/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
                    
13

14
class WindTurbineOntologyPythonWEIS(WindTurbineOntologyPython):
1✔
15
    # Pure python class inheriting the class WindTurbineOntologyPython from WISDEM
16
    # and adding the WEIS options, namely the paths to the WEIS submodules
17
    # (OpenFAST, ROSCO, TurbSim, XFoil) and initializing the control parameters.
18

19
    def __init__(self, fname_input_wt, fname_input_modeling, fname_input_analysis):
1✔
20

21
        self.modeling_options = sch.load_modeling_yaml(fname_input_modeling)
1✔
22
        self.modeling_options['fname_input_modeling'] = fname_input_modeling
1✔
23
        self.wt_init          = sch.load_geometry_yaml(fname_input_wt)
1✔
24
        self.analysis_options = sch.load_analysis_yaml(fname_input_analysis)
1✔
25
        self.analysis_options['fname_input_analysis'] = fname_input_analysis
1✔
26

27
        self.set_run_flags()
1✔
28
        self.set_openmdao_vectors()
1✔
29
        self.set_openmdao_vectors_control()
1✔
30
        self.set_weis_data()
1✔
31
        self.set_opt_flags()
1✔
32

33
    def set_weis_data(self):
1✔
34

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

38
        # BEM dir, all levels
39
        base_run_dir = os.path.join(mod_opt_dir,self.modeling_options['General']['openfast_configuration']['OF_run_dir'])
1✔
40
        if MPI:
1✔
41
            rank    = MPI.COMM_WORLD.Get_rank()
×
42
            bemDir = osp.join(base_run_dir,'rank_%000d'%int(rank),'BEM')
×
43
        else:
44
            bemDir = osp.join(base_run_dir,'BEM')
1✔
45

46
        self.modeling_options["Level1"]['BEM_dir'] = bemDir
1✔
47
        if MPI:
1✔
48
            # If running MPI, RAFT won't be able to save designs in parallel
49
            self.modeling_options["Level1"]['save_designs'] = False
×
50

51

52
        # Openfast
53
        if self.modeling_options['Level2']['flag'] or self.modeling_options['Level3']['flag']:
1✔
54
            fast = InputReader_OpenFAST()
1✔
55
            self.modeling_options['General']['openfast_configuration']['fst_vt'] = {}
1✔
56
            self.modeling_options['General']['openfast_configuration']['fst_vt']['outlist'] = fast.fst_vt['outlist']
1✔
57

58
            # OpenFAST prefixes
59
            if self.modeling_options['General']['openfast_configuration']['OF_run_fst'] in ['','None','NONE','none']:
1✔
60
                self.modeling_options['General']['openfast_configuration']['OF_run_fst'] = 'weis_job'
1✔
61
                
62
            if self.modeling_options['General']['openfast_configuration']['OF_run_dir'] in ['','None','NONE','none']:
1✔
63
                self.modeling_options['General']['openfast_configuration']['OF_run_dir'] = osp.join(
1✔
64
                    self.analysis_options['general']['folder_output'], 
65
                    'openfast_runs'
66
                    )
67
                
68
            # User-defined control dylib (path2dll)
69
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
70
            if path2dll == 'none':   #Default option, use above
1✔
71
                self.modeling_options['General']['openfast_configuration']['path2dll'] = discon_lib_path
1✔
72
            else:
73
                if not osp.isabs(path2dll):  # make relative path absolute
×
74
                    self.modeling_options['General']['openfast_configuration']['path2dll'] = \
×
75
                        osp.join(osp.dirname(self.options['modeling_options']['fname_input_modeling']), path2dll)
76
            path2dll = self.modeling_options['General']['openfast_configuration']['path2dll']
1✔
77
            if not osp.exists( path2dll ):
1✔
78
                raise NameError("Cannot find DISCON library: "+path2dll)
×
79

80
            # Activate HAMS in Level1 if requested for Level 2 or 3
81
            if self.modeling_options["flags"]["offshore"] or self.modeling_options["Level3"]["from_openfast"]:
1✔
82
                if self.modeling_options["Level1"]["potential_model_override"] == 2:
1✔
83
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
1✔
84
                elif ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
85
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) > 0) ):
86
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 1
1✔
87
                elif self.modeling_options["Level1"]["potential_model_override"] == 1:
1✔
88
                    self.modeling_options["Level3"]["HydroDyn"]["PotMod"] = 0
×
89
                else:
90
                    # Keep user defined value of PotMod
91
                    pass
1✔
92

93
                if self.modeling_options["Level3"]["HydroDyn"]["PotMod"] == 1:
1✔
94

95
                    # If user requested PotMod but didn't specify any override or members, just run everything
96
                    if ( (self.modeling_options["Level1"]["potential_model_override"] == 0) and
1✔
97
                       (len(self.modeling_options["Level1"]["potential_bem_members"]) == 0) ):
98
                        self.modeling_options["Level1"]["potential_model_override"] == 2
×
99
                        
100
                    cwd = os.getcwd()
1✔
101
                    weis_dir = osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))
1✔
102
                    potpath = self.modeling_options["Level3"]["HydroDyn"]["PotFile"].replace('.hst','').replace('.12','').replace('.3','').replace('.1','')
1✔
103
                    if ( (len(potpath) == 0) or (potpath.lower() in ['unused','default','none']) ):
1✔
104
                        
105
                        self.modeling_options['Level1']['flag'] = True
1✔
106
                        self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.join(bemDir,'Output','Wamit_format','Buoy')
1✔
107
                        
108

109
                    else:
110
                        if self.modeling_options['Level1']['runPyHAMS']:
1✔
111
                            print('Found existing potential model: {}\n    - Trying to use this instead of running PyHAMS.'.format(potpath))
1✔
112
                            self.modeling_options['Level1']['runPyHAMS'] = False
1✔
113
                        if osp.exists( potpath+'.1' ):
1✔
114
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath(potpath)
1✔
115
                        elif osp.exists( osp.join(cwd, potpath+'.1') ):
×
116
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(cwd, potpath) )
×
117
                        elif osp.exists( osp.join(weis_dir, potpath+'.1') ):
×
118
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(weis_dir, potpath) )
×
119
                        elif osp.exists( osp.join(mod_opt_dir, potpath+'.1') ):
×
120
                            self.modeling_options["Level3"]["HydroDyn"]["PotFile"] = osp.realpath( osp.join(mod_opt_dir, potpath) )
×
121
                        else:
122
                            raise Exception(f'No valid Wamit-style output found for specified PotFile option, {potpath}.1')
×
123

124
        # OpenFAST dir
125
        if self.modeling_options["Level3"]["from_openfast"]:
1✔
126
            if not osp.isabs(self.modeling_options['Level3']['openfast_dir']):
1✔
127
                # Make relative to modeling options input
128
                self.modeling_options['Level3']['openfast_dir'] = osp.realpath(osp.join(
1✔
129
                    mod_opt_dir, self.modeling_options['Level3']['openfast_dir'] ))
130
        
131
        # RAFT
132
        if self.modeling_options["flags"]["floating"]:
1✔
133
            bool_init = True if self.modeling_options["Level1"]["potential_model_override"]==2 else False
1✔
134
            self.modeling_options["Level1"]["model_potential"] = [bool_init] * self.modeling_options["floating"]["members"]["n_members"]
1✔
135

136
            if self.modeling_options["Level1"]["potential_model_override"] == 0:
1✔
137
                for k in self.modeling_options["Level1"]["potential_bem_members"]:
1✔
138
                    idx = self.modeling_options["floating"]["members"]["name"].index(k)
1✔
139
                    self.modeling_options["Level1"]["model_potential"][idx] = True
1✔
140
        elif self.modeling_options["flags"]["offshore"]:
1✔
141
            self.modeling_options["Level1"]["model_potential"] = [False]*1000
1✔
142
            
143
        # ROSCO
144
        self.modeling_options['ROSCO']['flag'] = (self.modeling_options['Level1']['flag'] or
1✔
145
                                                  self.modeling_options['Level2']['flag'] or
146
                                                  self.modeling_options['Level3']['flag'])
147
        
148
        if self.modeling_options['ROSCO']['tuning_yaml'] != 'none':  # default is empty
1✔
149
            # Make path absolute if not, relative to modeling options input
150
            if not osp.isabs(self.modeling_options['ROSCO']['tuning_yaml']):
1✔
151
                self.modeling_options['ROSCO']['tuning_yaml'] = osp.realpath(osp.join(
1✔
152
                    mod_opt_dir, self.modeling_options['ROSCO']['tuning_yaml'] ))
153
        
154
        # XFoil
155
        if not osp.isfile(self.modeling_options['Level3']["xfoil"]["path"]) and self.modeling_options['ROSCO']['Flp_Mode']:
1✔
156
            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")
×
157

158
        # Compute the number of DLCs that will be run
159
        DLCs = self.modeling_options['DLC_driver']['DLCs']
1✔
160
        # Initialize the DLC generator
161
        cut_in = self.wt_init['control']['supervisory']['Vin']
1✔
162
        cut_out = self.wt_init['control']['supervisory']['Vout']
1✔
163
        metocean = self.modeling_options['DLC_driver']['metocean_conditions']
1✔
164
        dlc_generator = DLCGenerator(cut_in, cut_out, metocean=metocean)
1✔
165
        # Generate cases from user inputs
166
        for i_DLC in range(len(DLCs)):
1✔
167
            DLCopt = DLCs[i_DLC]
1✔
168
            dlc_generator.generate(DLCopt['DLC'], DLCopt)
1✔
169
        self.modeling_options['DLC_driver']['n_cases'] = dlc_generator.n_cases
1✔
170
        if hasattr(dlc_generator,'n_ws_dlc11'):
1✔
171
            self.modeling_options['DLC_driver']['n_ws_dlc11'] = dlc_generator.n_ws_dlc11
1✔
172
        else:
173
            self.modeling_options['DLC_driver']['n_ws_dlc11'] = 0
×
174

175
        self.modeling_options['flags']['TMDs'] = False
1✔
176
        if 'TMDs' in self.wt_init:
1✔
177
            if self.modeling_options['Level3']['flag']:
1✔
178
                self.modeling_options['flags']['TMDs'] = True
1✔
179
            else:
180
                raise Exception("TMDs in Levels 1 and 2 are not supported yet")
×
181

182

183
    def set_openmdao_vectors_control(self):
1✔
184
        # Distributed aerodynamic control devices along blade
185
        self.modeling_options['WISDEM']['RotorSE']['n_te_flaps']      = 0
1✔
186
        if 'aerodynamic_control' in self.wt_init['components']['blade']:
1✔
187
            if 'te_flaps' in self.wt_init['components']['blade']['aerodynamic_control']:
×
188
                self.modeling_options['WISDEM']['RotorSE']['n_te_flaps'] = len(self.wt_init['components']['blade']['aerodynamic_control']['te_flaps'])
×
189
                self.modeling_options['WISDEM']['RotorSE']['n_tab']   = 3
×
190
            else:
191
                raise Exception('A distributed aerodynamic control device is provided in the yaml input file, but not supported by wisdem.')
×
192

193
        if 'TMDs' in self.wt_init:
1✔
194
            n_TMDs = len(self.wt_init['TMDs'])
1✔
195
            self.modeling_options['TMDs'] = {}
1✔
196
            self.modeling_options['TMDs']['n_TMDs']                 = n_TMDs
1✔
197
            # TODO: come back and check how many of these need to be modeling options
198
            self.modeling_options['TMDs']['name']                   = [tmd['name'] for  tmd in self.wt_init['TMDs']]
1✔
199
            self.modeling_options['TMDs']['component']              = [tmd['component'] for  tmd in self.wt_init['TMDs']]
1✔
200
            self.modeling_options['TMDs']['location']               = [tmd['location'] for  tmd in self.wt_init['TMDs']]
1✔
201
            self.modeling_options['TMDs']['mass']                   = [tmd['mass'] for  tmd in self.wt_init['TMDs']]
1✔
202
            self.modeling_options['TMDs']['stiffness']              = [tmd['stiffness'] for  tmd in self.wt_init['TMDs']]
1✔
203
            self.modeling_options['TMDs']['damping']                = [tmd['damping'] for  tmd in self.wt_init['TMDs']]
1✔
204
            self.modeling_options['TMDs']['natural_frequency']      = [tmd['natural_frequency'] for  tmd in self.wt_init['TMDs']]
1✔
205
            self.modeling_options['TMDs']['damping_ratio']          = [tmd['damping_ratio'] for  tmd in self.wt_init['TMDs']]
1✔
206
            self.modeling_options['TMDs']['X_DOF']                  = [tmd['X_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
207
            self.modeling_options['TMDs']['Y_DOF']                  = [tmd['Y_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
208
            self.modeling_options['TMDs']['Z_DOF']                  = [tmd['Z_DOF'] for  tmd in self.wt_init['TMDs']]
1✔
209
            self.modeling_options['TMDs']['preload_spring']         = [tmd['preload_spring'] for  tmd in self.wt_init['TMDs']]
1✔
210

211
            # Check that TMD locations map to somewhere valid (tower or platform member)
212
            self.modeling_options['TMDs']['num_tower_TMDs'] = 0
1✔
213
            self.modeling_options['TMDs']['num_ptfm_TMDs']  = 0
1✔
214
            
215
            for i_TMD, component in enumerate(self.modeling_options['TMDs']['component']):
1✔
216
                if self.modeling_options['flags']['floating'] and component in self.modeling_options['floating']['members']['name']:
1✔
217
                    self.modeling_options['TMDs']['num_ptfm_TMDs'] += 1
1✔
218
                elif component == 'tower':
×
219
                    self.modeling_options['TMDs']['num_tower_TMDs'] += 1
×
220
                else:
UNCOV
221
                    raise Exception('Invalid TMD component mapping for {} on {}'.format(
×
222
                        self.modeling_options['TMDs']['name'][i_TMD],component))      
223

224
            # Set TMD group  mapping: list of length n_groups, with i_TMDs in each group
225
            # Loop through TMD names, assign to own group if not in an analysis group
226
            if 'TMDs' in self.analysis_options['design_variables']:
1✔
227
                tmd_group_map = []
1✔
228
                tmd_names = self.modeling_options['TMDs']['name']
1✔
229
                
230
                for i_group, tmd_group in enumerate(self.analysis_options['design_variables']['TMDs']['groups']):
1✔
231
                    tmds_in_group_i = [tmd_names.index(tmd_name) for tmd_name in tmd_group['names']]
1✔
232

233
                    tmd_group_map.append(tmds_in_group_i)
1✔
234
                
235
                self.modeling_options['TMDs']['group_mapping'] = tmd_group_map
1✔
236

237
    def update_ontology_control(self, wt_opt):
1✔
238
        # Update controller
239
        if self.modeling_options['flags']['control']:
×
240
            self.wt_init['control']['pitch']['omega_pc'] = wt_opt['tune_rosco_ivc.omega_pc']
×
241
            self.wt_init['control']['pitch']['zeta_pc']  = wt_opt['tune_rosco_ivc.zeta_pc']
×
242
            self.wt_init['control']['torque']['omega_vs'] = float(wt_opt['tune_rosco_ivc.omega_vs'])
×
243
            self.wt_init['control']['torque']['zeta_vs']  = float(wt_opt['tune_rosco_ivc.zeta_vs'])
×
244
            self.wt_init['control']['pitch']['Kp_float']  = float(wt_opt['tune_rosco_ivc.Kp_float'])
×
245
            self.wt_init['control']['pitch']['ptfm_freq']  = float(wt_opt['tune_rosco_ivc.ptfm_freq'])
×
246
            self.wt_init['control']['IPC']['IPC_Ki_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Kp1p'])
×
247
            self.wt_init['control']['IPC']['IPC_Kp_1P'] = float(wt_opt['tune_rosco_ivc.IPC_Ki1p'])
×
248
            if self.modeling_options['ROSCO']['Flp_Mode'] > 0:
×
249
                self.wt_init['control']['dac']['flp_kp_norm']= float(wt_opt['tune_rosco_ivc.flp_kp_norm'])
×
250
                self.wt_init['control']['dac']['flp_tau'] = float(wt_opt['tune_rosco_ivc.flp_tau'])
×
251

252

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