diff --git a/ogstools/fe2vtu/_cli.py b/ogstools/fe2vtu/_cli.py index 2b156323bf95ccc94983837b056621f5f601b1d6..aa442192708ba40bbccb7936fe0472bf7f64c97e 100644 --- a/ogstools/fe2vtu/_cli.py +++ b/ogstools/fe2vtu/_cli.py @@ -71,73 +71,57 @@ def cli(): mesh = get_geo_mesh(doc) - if args.case == "geometry" or args.case == "geo_surface": - if args.case == "geo_surface": - # surface - surf = mesh.extract_surface() - pv.save_meshio(args.output, surf, file_format="vtu") - # log feflow version - log.info( - "The surface of the input mesh has been successfully converted." - ) - else: - pv.save_meshio(args.output, mesh, file_format="vtu") - log.info( - "The geometry of the input mesh has been successfully converted." - ) - elif args.case == "properties" or args.case == "properties_surface": + if "properties" in args.case: update_geo_mesh(mesh, doc) - if args.case == "properties_surface": - surf = mesh.extract_surface() - pv.save_meshio(args.output, surf, file_format="vtu") - log.info( - "The surface with properties of the input mesh have been successfully converted." - ) - else: - pv.save_meshio(args.output, mesh, file_format="vtu") - log.info("The input mesh has been successfully converted.") - if args.BC == "BC": - BC_mesh = mesh.copy() - for cd in [ - cell_data - for cell_data in BC_mesh.cell_data - if cell_data not in ["P_SOUF", "P_IOFLOW"] - ]: - BC_mesh.cell_data.remove(cd) - # Only cell data are needed - BC_mesh.point_data.clear() - # get the topsurface since there are the cells of interest - topsurf = get_specific_surface( - BC_mesh.extract_surface(), lambda normals: normals[:, 2] > 0 - ) - topsurf.save("topsurface_" + args.output) - # create the xml-file - write_xml( - "topsurface_" + args.output, - "Neumann", - topsurf.cell_data, - "MeshElement", - ) - - # remove all the point data that are not of interest - for point_data in mesh.point_data: - if not all(["_BC_" in point_data]): - mesh.point_data.remove(point_data) - - # Only selected point data is needed -> clear all cell data - mesh.cell_data.clear() - - # remove all points with point data that are of "nan"-value - for point_data in mesh.point_data: - filtered_points = mesh.extract_points( - [not np.isnan(x) for x in mesh[point_data]], - include_cells=False, - ) - # Only "BULK_NODE_ID" can be read by ogs - filtered_points.rename_array( - "vtkOriginalPointIds", "BULK_NODE_ID" - ) - filtered_points.save(point_data + ".vtu") - - # create the xml-file - write_xml("", "Dirichlet", filtered_points.point_data, "MeshNode") + mesh = mesh.extract_surface() if "surface" in args.case else mesh + msg = { + "geo_surface": "surface", + "geometry": "geometry", + "properties_surface": "surface with properties", + "properties": "", + } + pv.save_meshio(args.output, mesh, file_format="vtu") + log.info( + "The %s of the input mesh has been successfully converted.", + msg[args.case], + ) + if "properties" not in args.case or args.BC != "BC": + return + BC_mesh = mesh.copy() + for cd in [ + cell_data + for cell_data in BC_mesh.cell_data + if cell_data not in ["P_SOUF", "P_IOFLOW"] + ]: + BC_mesh.cell_data.remove(cd) + # Only cell data are needed + BC_mesh.point_data.clear() + # get the topsurface since there are the cells of interest + topsurf = get_specific_surface( + BC_mesh.extract_surface(), lambda normals: normals[:, 2] > 0 + ) + topsurf.save("topsurface_" + args.output) + # create the xml-file + write_xml( + "topsurface_" + args.output, + "Neumann", + topsurf.cell_data, + "MeshElement", + ) + # remove all the point data that are not of interest + for point_data in mesh.point_data: + if not all(["_BC_" in point_data]): + mesh.point_data.remove(point_data) + # Only selected point data is needed -> clear all cell data + mesh.cell_data.clear() + # remove all points with point data that are of "nan"-value + for point_data in mesh.point_data: + filtered_points = mesh.extract_points( + [not np.isnan(x) for x in mesh[point_data]], + include_cells=False, + ) + # Only "BULK_NODE_ID" can be read by ogs + filtered_points.rename_array("vtkOriginalPointIds", "BULK_NODE_ID") + filtered_points.save(point_data + ".vtu") + # create the xml-file + write_xml("", "Dirichlet", filtered_points.point_data, "MeshNode")