|  | 
| 3 | 3 | import operator | 
| 4 | 4 | import numpy as np | 
| 5 | 5 | import yaml | 
|  | 6 | +import sys | 
| 6 | 7 | from functools import reduce | 
| 7 | 8 | from deepdiff import DeepDiff | 
| 8 | 9 | try: | 
| @@ -137,6 +138,11 @@ def save_yaml(outdir, fname, data_out): | 
| 137 | 138 |     yaml.dump(data_out, f) | 
| 138 | 139 |     f.close() | 
| 139 | 140 | 
 | 
|  | 141 | +def print_yaml(data_struct): | 
|  | 142 | +    data_struct = remove_numpy(data_struct) | 
|  | 143 | +    yaml=ry.YAML() | 
|  | 144 | +    yaml.indent(mapping=4, sequence=6, offset=3) | 
|  | 145 | +    yaml.dump(data_struct,sys.stdout) | 
| 140 | 146 | 
 | 
| 141 | 147 | def select_cases(cases, var_sel, val_sel): | 
| 142 | 148 |     # Find a variable value from the AeroelasticSE case_matrix | 
| @@ -290,10 +296,83 @@ def remove_nested_keys(dictionary, keys_to_remove): | 
| 290 | 296 | 
 | 
| 291 | 297 |     return dictionary | 
| 292 | 298 | 
 | 
| 293 |  | -def cleanup_fstvt(fst_vt, ignoreVars=None, removeFileRef=False, removeArrayProps=False): | 
|  | 299 | +def removeDeactivatedModules(fst_vt): | 
|  | 300 | +    # Mapping of deactivated modules to their corresponding module names | 
|  | 301 | +    OFmodules = { | 
|  | 302 | +        'CompElast': { | 
|  | 303 | +            1: ['ElastoDyn', 'ElastoDynBlade', 'ElastoDynTower'], | 
|  | 304 | +            2: ['ElastoDyn', 'ElastoDynTower', 'BeamDyn', 'BeamDynBlade'], | 
|  | 305 | +            3: ['SimpleElastoDyn'] | 
|  | 306 | +        }, | 
|  | 307 | +        'CompInflow': { | 
|  | 308 | +            0: [], | 
|  | 309 | +            1: ['InflowWind'] | 
|  | 310 | +        }, | 
|  | 311 | +        'CompAero': { | 
|  | 312 | +            0: [], | 
|  | 313 | +            1: ['AeroDisk'],  | 
|  | 314 | +            2: ['AeroDyn', 'AeroDynBlade', 'AeroDynPolar'] | 
|  | 315 | +        }, | 
|  | 316 | +        'CompServo': { | 
|  | 317 | +            0: [], | 
|  | 318 | +            1: ['ServoDyn', 'DISCON_in'] | 
|  | 319 | +        },  | 
|  | 320 | +        'CompSeaSt': { | 
|  | 321 | +            0: [], | 
|  | 322 | +            1: ['SeaState'] | 
|  | 323 | +        }, | 
|  | 324 | +        'CompHydro': { | 
|  | 325 | +            0: [], | 
|  | 326 | +            1: ['HydroDyn'] | 
|  | 327 | +        }, | 
|  | 328 | +        'CompSub': { | 
|  | 329 | +            0: [], | 
|  | 330 | +            1: ['SubDyn'], | 
|  | 331 | +            2: ['read_ExtPtfm'] | 
|  | 332 | +        }, | 
|  | 333 | +        'CompMooring': { | 
|  | 334 | +            0: [], | 
|  | 335 | +            1: ['MAP'], | 
|  | 336 | +            2: [], | 
|  | 337 | +            3: ['MoorDyn', 'WaterKin'], | 
|  | 338 | +            4: [] | 
|  | 339 | +        }, | 
|  | 340 | +        'CompIce': { | 
|  | 341 | +            0: [], | 
|  | 342 | +            1: [], | 
|  | 343 | +            2: [] | 
|  | 344 | +        } | 
|  | 345 | +        # 'MHK': {0:[]}, # no special handling for MHK | 
|  | 346 | +    } | 
|  | 347 | + | 
|  | 348 | +    keys2keep = [] | 
|  | 349 | +    keys2remove = [] | 
|  | 350 | +    # loop throught the keys of OFmodules, and make two lists, one of the needed ones, | 
|  | 351 | +    # and one of the ones to remove, then remove the ones to remove | 
|  | 352 | +    for module, active in fst_vt['Fst'].items(): | 
|  | 353 | +        if module in OFmodules: | 
|  | 354 | +            if active in OFmodules[module]: | 
|  | 355 | +                # get the list of modules to keep | 
|  | 356 | +                keys2keep.extend(OFmodules[module][active]) | 
|  | 357 | + | 
|  | 358 | +                # get the list of modules to remove | 
|  | 359 | +                for key, value in OFmodules[module].items(): | 
|  | 360 | +                    if key != active: | 
|  | 361 | +                        keys2remove.extend(value) | 
|  | 362 | +     | 
|  | 363 | +    # remove the keys in keys2remove and NOT in keys2keep | 
|  | 364 | +    fst_vt = remove_nested_keys(fst_vt, [key for key in keys2remove if key not in keys2keep]) | 
|  | 365 | + | 
|  | 366 | +    return fst_vt | 
|  | 367 | + | 
|  | 368 | +def cleanup_fstvt(fst_vt, ignoreVars=None, removeFileRef=False, removeArrayProps=False, | 
|  | 369 | +                    removeDeactivatedModules=False): | 
| 294 | 370 |     # sanitize the dictionaries from numpy data types | 
| 295 | 371 |     fst_vt = remove_numpy(fst_vt) | 
| 296 | 372 | 
 | 
|  | 373 | +    if ignoreVars is not None: | 
|  | 374 | +        fst_vt = remove_nested_keys(fst_vt, ignoreVars) | 
|  | 375 | + | 
| 297 | 376 |     if removeFileRef: # not fair to compare file paths | 
| 298 | 377 |         fileVars = ['af_coord', 'Filename_Uni', 'FileName_BTS', 'FileName_u', 'FileName_v', 'FileName_w', # TODO: orgainze these logically | 
| 299 | 378 |                     'AFNames', 'ADBlFile1', 'ADBlFile2', 'ADBlFile3', 'NumCoords', | 
| @@ -333,11 +412,12 @@ def cleanup_fstvt(fst_vt, ignoreVars=None, removeFileRef=False, removeArrayProps | 
| 333 | 412 |     if removeArrayProps: # we can have different array properties, if run through different tools | 
| 334 | 413 |         arrayVars = ['BlSpn', 'BlCrvAC','BlSwpAC','BlCrvAng','BlTwist','BlChord','BlAFID', | 
| 335 | 414 |                     'ac','PC_GS_KP','PC_GS_KI','WE_FOPoles','beam_stiff','attr','units'] | 
| 336 |  | - | 
| 337 | 415 |         fst_vt = remove_nested_keys(fst_vt, arrayVars) | 
| 338 | 416 | 
 | 
| 339 |  | -    if ignoreVars is not None: | 
| 340 |  | -        fst_vt = remove_nested_keys(fst_vt, ignoreVars) | 
|  | 417 | + | 
|  | 418 | +    if removeDeactivatedModules: | 
|  | 419 | +        fst_vt = removeDeactivatedModules(fst_vt) | 
|  | 420 | + | 
| 341 | 421 | 
 | 
| 342 | 422 |     return fst_vt | 
| 343 | 423 | 
 | 
|  | 
0 commit comments