FEM: XML/XDMF: Console.Print* strings to F-strings (where necessary) and reformated them to avoid long lines

This commit is contained in:
joha2
2023-04-15 09:57:55 +02:00
committed by Bernd Hahnebach
parent 5d30b30c5e
commit 1e49852fa8
4 changed files with 30 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
# ***************************************************************************
# * Copyright (c) 2017 Johannes Hartung <j.hartung@gmx.net> *
# * Copyright (c) 2017-2023 Johannes Hartung <j.hartung@gmx.net> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
@@ -174,11 +174,11 @@ def export(objectslist, fileString, group_values_dict_nogui=None):
if fileString != "":
fileName, fileExtension = os.path.splitext(fileString)
if fileExtension.lower() == ".xml":
Console.PrintWarning(
"XML is not designed to save higher order elements.\n")
Console.PrintWarning(
"Reducing order for second order mesh.\n")
Console.PrintWarning("Tri6 -> Tri3, Tet10 -> Tet4, etc.\n")
if obj.ElementOrder != "1st":
Console.PrintWarning(
"XML is not designed to save higher order elements.\n" +
"Reducing order for second order mesh.\n" +
"Tri6 -> Tri3, Tet10 -> Tet4, etc.\n")
writeFenicsXML.write_fenics_mesh_xml(obj, fileString)
elif fileExtension.lower() == ".xdmf":
mesh_groups = importToolsFem.get_FemMeshObjectMeshGroups(obj)

View File

@@ -59,8 +59,8 @@ def read_fenics_mesh_xml(xmlfilename):
vertex_size = 0
Console.PrintLog("Mesh dimension: %d\n" % (dim,))
Console.PrintLog("Mesh cell type: %s\n" % (cell_type,))
Console.PrintLog(f"Mesh dimension: {dim}\n")
Console.PrintLog(f"Mesh cell type: {cell_type}\n")
# every cell type contains a dict with key=dimension and value=number
@@ -81,7 +81,7 @@ def read_fenics_mesh_xml(xmlfilename):
Console.PrintWarning("No vertices found!\n")
else:
vertex_size = int(find_vertices.attrib.get("size"))
Console.PrintLog("Reading %d vertices\n" % (vertex_size,))
Console.PrintLog(f"Reading {vertex_size} vertices\n")
for vertex in find_vertices:
ind = int(vertex.get("index"))
@@ -95,20 +95,19 @@ def read_fenics_mesh_xml(xmlfilename):
# increase node index by one, since fenics starts at 0, FreeCAD at 1
# print("%d %f %f %f" % (ind, node_x, node_y, node_z))
else:
Console.PrintWarning("found strange vertex tag: %s\n" % (vertex.tag,))
Console.PrintWarning(f"found strange vertex tag: {vertex.tag}\n")
if find_cells is None:
Console.PrintWarning("No cells found!\n")
else:
Console.PrintLog("Reading %d cells\n" % (int(find_cells.attrib.get("size")),))
Console.PrintLog(f"Reading {int(find_cells.attrib.get('size'))} cells\n")
for cell in find_cells:
ind = int(cell.get("index"))
if cell.tag.lower() != cell_type.lower():
Console.PrintWarning(
"Strange mismatch between cell type {} and cell tag {}\n"
.format(cell_type, cell.tag.lower())
)
Console.PrintWarning("Strange mismatch between cell type " +
f"{cell_type} and " +
f"cell tag {cell.tag.lower()}\n")
num_vertices = cells_parts_dim[cell_type][0]
vtupel = tuple([
@@ -244,7 +243,7 @@ def read_fenics_mesh_xml(xmlfilename):
for (elm, numbers) in list(element_dict.items()):
lst = sorted(list(numbers.items()), key=lambda x: x[0])
if lst != []:
Console.PrintWarning("{} min: {} max: {}\n".format(elm, lst[0], lst[-1]))
Console.PrintMessage(f"{elm} min: {lst[0]} max: {lst[-1]}\n")
else:
Console.PrintError("No mesh found\n")

View File

@@ -171,10 +171,8 @@ def write_fenics_mesh_codim_xdmf(
fc_topo = fem_mesh_obj.FemMesh.Nodes
else:
fc_topo = []
Console.PrintError(
"Dimension of mesh incompatible with export XDMF function: %d\n"
% (dim_topo,)
)
Console.PrintError("Dimension of mesh incompatible with export" +
f" XDMF function: {dim_topo}\n")
nodeindices = [(
nodes_dict[ind] for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_topo_ind)
@@ -265,11 +263,11 @@ def write_fenics_mesh_xdmf(
For the export of xdmf.
"""
Console.PrintMessage("Converting " + fem_mesh_obj.Label + " to fenics XDMF File\n")
Console.PrintMessage("Dimension of mesh: %d\n" % (get_FemMeshObjectDimension(fem_mesh_obj),))
Console.PrintMessage(f"Converting {fem_mesh_obj.Label} to fenics XDMF File\n")
Console.PrintMessage(f"Dimension of mesh: {get_FemMeshObjectDimension(fem_mesh_obj)}\n")
elements_in_mesh = get_FemMeshObjectElementTypes(fem_mesh_obj)
Console.PrintMessage("Elements appearing in mesh: %s\n" % (str(elements_in_mesh),))
Console.PrintMessage(f"Elements appearing in mesh: {str(elements_in_mesh)}\n")
celltype_in_mesh = get_MaxDimElementFromList(elements_in_mesh)
(num_cells, cellname_fc, dim_cell) = celltype_in_mesh
@@ -309,10 +307,9 @@ def write_fenics_mesh_xdmf(
mesh_function_codim = dim_cell - FreeCAD_Group_Dimensions[mesh_function_type]
mesh_function_name = fem_mesh.getGroupName(g)
Console.PrintMessage(
"group id: %d (label: %s) with element type %s and codim %d\n"
% (g, mesh_function_name, mesh_function_type, mesh_function_codim)
)
Console.PrintMessage(f"group id: {g} (label: {mesh_function_name})" +
f" with element type {mesh_function_type} and" +
" codim {mesh_function_codim}\n")
mesh_function_grid = ET.SubElement(
domain, "Grid",
@@ -328,7 +325,8 @@ def write_fenics_mesh_xdmf(
codim=mesh_function_codim, encoding=encoding
)
mesh_function_geometry = ET.SubElement(mesh_function_grid, "Geometry", Reference="XML")
mesh_function_geometry = ET.SubElement(mesh_function_grid, "Geometry",
Reference="XML")
mesh_function_geometry.text = "/Xdmf/Domain/Grid/Geometry"
mesh_function_attribute = ET.SubElement(mesh_function_grid, "Attribute")

View File

@@ -71,19 +71,17 @@ def write_fenics_mesh_xml(fem_mesh_obj, outputfile):
"hexahedron": 8
}
Console.PrintMessage("Converting {} to fenics XML File\n".format(fem_mesh_obj.Label))
Console.PrintMessage("Dimension of mesh: %d\n" % (get_FemMeshObjectDimension(fem_mesh_obj),))
Console.PrintMessage(f"Converting {fem_mesh_obj.Label} to fenics XML File\n")
Console.PrintMessage(f"Dimension of mesh: {get_FemMeshObjectDimension(fem_mesh_obj)}\n")
elements_in_mesh = get_FemMeshObjectElementTypes(fem_mesh_obj)
Console.PrintMessage("Elements appearing in mesh: %s" % (str(elements_in_mesh),))
Console.PrintMessage(f"Elements appearing in mesh: {str(elements_in_mesh)}\n")
celltype_in_mesh = get_MaxDimElementFromList(elements_in_mesh)
(num_cells, cellname_fc, dim_cell) = celltype_in_mesh
cellname_fenics = FreeCAD_to_Fenics_dict[cellname_fc]
num_verts_cell = XML_Number_of_Nodes_dict[cellname_fenics]
Console.PrintMessage(
u"Celltype in mesh -> %s and its Fenics name: %s\n"
% (str(celltype_in_mesh), cellname_fenics)
)
Console.PrintMessage(f"Celltype in mesh -> {str(celltype_in_mesh)} " +
f"and its Fenics name: {cellname_fenics}\n")
root = ET.Element("dolfin", dolfin="http://fenicsproject.org")
meshchild = ET.SubElement(root, "mesh", celltype=cellname_fenics, dim=str(dim_cell))