Skip to content

Running casegeneration with a table (e.g. Moordyn line inputs) error with "AUTO" not found #81

@ogrootes

Description

@ogrootes

When I running the case generation for Moordyn, I encountered the following error. With the MoorDyn v2, NType is not given separately. Based on line 511: NUMTAB_FROM_LAB_DIM_VAR += ['NTypes:AUTO','NConnects' ,'NLines:AUTO' , 'AUTO'], the tabDimVar will be split on the ':'.
The code searches for AUTO and this value is not found. The proposed fix ensures that the code search for the correct variable and not for AUTO

File "c:\Users\0035513\Documents_PC\Code_base_Thesis_FOWT\Python_scripts_mooring_DLC\Floater_mooring_DLC_runs_case_generation.py", line 601, in <module>       
    fastFiles = case_gen.templateReplace(
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\case_generation\case_gen.py", line 313, in templateReplace
    return templateReplaceGeneral(PARAMS, templateDir, outputDir=outputDir, main_file=main_file,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\case_generation\case_gen.py", line 265, in templateReplaceGeneral
    new_mainFile, Files = replaceRecurse(main_file_base, '', k, v, Files, strID, wd, TemplateFiles)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\case_generation\case_gen.py", line 198, in replaceRecurse
    newchildFilename, Files = replaceRecurse(child_templatefilename, NewFileKey, ChildrenKey, ParamValue, Files, strID, workDir, TemplateFiles)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\case_generation\case_gen.py", line 186, in replaceRecurse
    f[Key] = ParamValue
    ~^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\io\fast_input_file.py", line 152, in __setitem__
    return self.fixedfile.__setitem__(key, item)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\io\fast_input_file.py", line 331, in __setitem__
    iDimVar = self.getID(dimVar)
              ^^^^^^^^^^^^^^^^^^
  File "c:\Users\0035513\Documents_PC\OpenFAST_PC\openfast_toolbox\openfast_toolbox\io\fast_input_file.py", line 278, in getID
    raise KeyError('Variable `' + str(label) +'` not found in FAST file:'+str(self.filename))
KeyError: 'Variable `AUTO` not found in FAST file:c:\\Users\\0035513\\Documents_PC\\Data_mooring_DLC_Runs\\no_shear_Reference_TLP_4.2.0\\IEA-15-240-RWT-Reference_TLP_MoorDyn_DLC_mooring_ws_EA1_5p98e08_09p500_hs_01p53_tp_07p40_mean.dat'

Lines 826-841 in fast_input_file.py:

else:
                    # We either use a variable name or "AUTO" to find the number of rows
                    tabDimVars = tabDimVar.split(':')
                    for tabDimVar in tabDimVars:
                        d['tabDimVar'] = tabDimVar
                        if tabDimVar=='AUTO':
                            # Determine table dimension automatically
                            nTabLines = findNumberOfTableLines(lines[i+nHeaders:], break_chars=['---','!','#'])
                            break
                        else:
                            try:
                                nTabLines = self[tabDimVar+labOffset]
                                break
                            except KeyError:
                                print('Cannot determine table dimension using {}'.format(tabDimVar))
                                # Hopefully this table has AUTO as well
                                pass

Can be replaced with the following code to prevent this error:

                else:
                    # We either use a variable name or "AUTO" to find the number of rows
                    tabDimVars = tabDimVar.split(':')
                    primaryDimVar = tabDimVars[0] if len(tabDimVars) > 0 else tabDimVar
                    for tabDimVar in tabDimVars:
                        d['tabDimVar'] = tabDimVar
                        if tabDimVar=='AUTO':
                            # Determine table dimension automatically
                            nTabLines = findNumberOfTableLines(lines[i+nHeaders:], break_chars=['---','!','#'])
                            # If split syntax was used (e.g. "NTypes:AUTO"),
                            # bind AUTO-detected size back to the variable before ':'.
                            if len(tabDimVars) > 1:
                                dimKey = primaryDimVar + labOffset
                                d['tabDimVar'] = primaryDimVar
                                iDim = self.getIDSafe(dimKey)
                                if iDim >= 0:
                                    self.data[iDim]['value'] = nTabLines
                                else:
                                    self.addKeyVal(dimKey, nTabLines)
                            break
                        else:
                            try:
                                nTabLines = self[tabDimVar+labOffset]
                                break
                            except KeyError:
                                print('Cannot determine table dimension using {}'.format(tabDimVar))
                                # Hopefully this table has AUTO as well
                                pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions