def getFieldDict(classname, finfoType=""): """Get dictionary of field names and types for specified class. Parameters ---------- className : str MOOSE class to find the fields of. finfoType : str (default '') Finfo type of the fields to find. If empty or not specified, allfields will be retrieved. Returns ------- dict field names and their respective types as key-value pair. Notes ----- This behaviour is different from `getFieldNames` where only `valueFinfo`s are returned when `finfoType` remains unspecified. Examples -------- List all the source fields on class Neutral >>> moose.getFieldDict('Neutral', 'srcFinfo') {'childMsg': 'int'} """ return _moose.getFieldDict(classname, finfoType)
def showfields(el, field="*", showtype=False): """Show the fields of the element `el`, their data types and values in human readable format. Convenience function for GENESIS users. Parameters ---------- el : melement/str Element or path of an existing element. field : str Field to be displayed. If '*' (default), all fields are displayed. showtype : bool If True show the data type of each field. False by default. Returns ------- string """ if isinstance(el, str): if not _moose.exists(el): raise ValueError("no such element: %s" % el) el = _moose.element(el) result = [] if field == "*": value_field_dict = _moose.getFieldDict(el.className, "valueFinfo") max_type_len = max(len(dtype) for dtype in value_field_dict.values()) max_field_len = max(len(dtype) for dtype in value_field_dict.keys()) result.append("\n[" + el.path + "]\n") for key, dtype in sorted(value_field_dict.items()): if (dtype == "bad" or key == "this" or key == "dummy" or key == "me" or dtype.startswith("vector") or "ObjId" in dtype): continue value = el.getField(key) if showtype: typestr = dtype.ljust(max_type_len + 4) ## The following hack is for handling both Python 2 and ## 3. Directly putting the print command in the if/else ## clause causes syntax error in both systems. result.append(typestr + " ") result.append( key.ljust(max_field_len + 4) + "=" + str(value) + "\n") else: try: result.append(field + "=" + el.getField(field)) except AttributeError: pass # Genesis silently ignores non existent fields print("".join(result)) return "".join(result)
def showfield(el, field='*', showtype=False): """Show the fields of the element `el`, their data types and values in human readable format. Convenience function for GENESIS users. Parameters ---------- el : melement/str Element or path of an existing element. field : str Field to be displayed. If '*' (default), all fields are displayed. showtype : bool If True show the data type of each field. False by default. Returns ------- string """ if isinstance(el, str): if not _moose.exists(el): raise ValueError('no such element: %s' % el) el = _moose.element(el) result = [] if field == '*': value_field_dict = _moose.getFieldDict(el.className, 'valueFinfo') max_type_len = max(len(dtype) for dtype in value_field_dict.values()) max_field_len = max(len(dtype) for dtype in value_field_dict.keys()) result.append('\n[' + el.path + ']\n') for key, dtype in sorted(value_field_dict.items()): if dtype == 'bad' or key == 'this' or key == 'dummy' \ or key == 'me' or dtype.startswith('vector') \ or 'ObjId' in dtype: continue value = el.getField(key) if showtype: typestr = dtype.ljust(max_type_len + 4) # The following hack is for handling both Python 2 and # 3. Directly putting the print command in the if/else # clause causes syntax error in both systems. result.append(typestr + ' ') result.append( key.ljust(max_field_len + 4) + '=' + str(value) + '\n') else: try: result.append(field + '=' + el.getField(field)) except AttributeError: pass # Genesis silently ignores non existent fields print(''.join(result)) return ''.join(result)
def showfield(el, field='*', showtype=False): """Show the fields of the element `el`, their data types and values in human readable format. Convenience function for GENESIS users. Parameters ---------- el : melement/str Element or path of an existing element. field : str Field to be displayed. If '*' (default), all fields are displayed. showtype : bool If True show the data type of each field. False by default. Returns ------- None """ if isinstance(el, str): if not _moose.exists(el): raise ValueError('no such element') el = _moose.element(el) if field == '*': value_field_dict = _moose.getFieldDict(el.className, 'valueFinfo') max_type_len = max(len(dtype) for dtype in value_field_dict.values()) max_field_len = max(len(dtype) for dtype in value_field_dict.keys()) print('\n[', el.path, ']') for key, dtype in sorted(value_field_dict.items()): if dtype == 'bad' or key == 'this' or key == 'dummy' or key == 'me' or dtype.startswith( 'vector') or 'ObjId' in dtype: continue value = el.getField(key) if showtype: typestr = dtype.ljust(max_type_len + 4) # The following hack is for handling both Python 2 and # 3. Directly putting the print command in the if/else # clause causes syntax error in both systems. print(typestr, end=' ') print(key.ljust(max_field_len + 4), '=', value) else: try: print(field, '=', el.getField(field)) except AttributeError: pass # Genesis silently ignores non existent fields