Пример #1
0
def write_fenics_mesh_codim_xdmf(fem_mesh_obj,
                                 topologynode,
                                 nodes_dict,
                                 codim=0,
                                 encoding=ENCODING_ASCII):
    mesh_dimension = get_FemMeshObjectDimension(fem_mesh_obj)

    element_types = get_FemMeshObjectElementTypes(
        fem_mesh_obj, remove_zero_element_entries=True)
    element_order = get_FemMeshObjectOrder(fem_mesh_obj)
    # we get all elements from mesh to decide which one to write by selection of codim
    # nodeindices = [(nodes_dict[ind] for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_volume_ind)) for (fen_ind, fc_volume_ind) in enumerate(fc_cells)]
    writeout_element_dimension = mesh_dimension - codim

    (num_topo, name_topo, dim_topo) = (0, "", 0)
    for (num, name, dim) in element_types:
        if writeout_element_dimension == dim:
            (num_topo, name_topo, dim_topo) = (num, name, dim)

    (topology_type,
     nodes_per_element) = FreeCAD_to_Fenics_XDMF_dict[(name_topo,
                                                       element_order)]

    topologynode.set("TopologyType", topology_type)
    topologynode.set("NumberOfElements", str(num_topo))
    topologynode.set("NodesPerElement", str(nodes_per_element))

    if dim_topo == 3:
        fc_topo = fem_mesh_obj.FemMesh.Volumes
    elif dim_topo == 2:
        fc_topo = fem_mesh_obj.FemMesh.Faces
    elif dim_topo == 1:
        fc_topo = fem_mesh_obj.FemMesh.Edges
    elif dim_topo == 0:
        fc_topo = fem_mesh_obj.FemMesh.Nodes
    else:
        fc_topo = []
        print("Dimension of mesh incompatible with export XDMF function: %d" %
              (dim_topo, ))

    nodeindices = [
        (nodes_dict[ind]
         for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_topo_ind))
        for (fen_ind, fc_topo_ind) in enumerate(fc_topo)
    ]

    if encoding == ENCODING_ASCII:
        dataitem = ET.SubElement(topologynode,
                                 "DataItem",
                                 NumberType="UInt",
                                 Dimensions="%d %d" %
                                 (num_topo, nodes_per_element),
                                 Format="XML")
        dataitem.text = numpy_array_to_str(
            tuples_to_numpy(nodeindices, nodes_per_element))
    elif encoding == ENCODING_HDF5:
        pass

    return fc_topo
Пример #2
0
def write_fenics_mesh_volumes_xdmf(fem_mesh_obj,
                                   topologynode,
                                   rd,
                                   encoding=ENCODING_ASCII):
    (num_cells, name_cell, dim_cell) = get_MaxDimElementFromList(
        get_FemMeshObjectElementTypes(fem_mesh_obj))
    element_order = get_FemMeshObjectOrder(fem_mesh_obj)

    FreeCAD_to_Fenics_XDMF_dict = {
        ("Node", 1): ("polyvertex", 1),
        ("Edge", 1): ("polyline", 2),
        ("Edge", 2): ("edge_3", 3),
        ("Triangle", 1): ("triangle", 3),
        ("Triangle", 2): ("tri_6", 6),
        ("Tetra", 1): ("tetrahedron", 4),
        ("Tetra", 2): ("tet_10", 10)
    }

    (topology_type,
     nodes_per_element) = FreeCAD_to_Fenics_XDMF_dict[(name_cell,
                                                       element_order)]

    topologynode.set("TopologyType", topology_type)
    topologynode.set("NumberOfElements", str(num_cells))
    topologynode.set("NodesPerElement", str(nodes_per_element))

    if dim_cell == 3:
        fc_cells = fem_mesh_obj.FemMesh.Volumes
    elif dim_cell == 2:
        fc_cells = fem_mesh_obj.FemMesh.Faces
    elif dim_cell == 1:
        fc_cells = fem_mesh_obj.FemMesh.Edges
    elif dim_cell == 0:
        fc_cells = fem_mesh_obj.FemMesh.Nodes
    else:
        fc_cells = []
        print("Dimension of mesh incompatible with export XDMF function: %d" %
              (dim_cell, ))

    nodeindices = [
        (rd[ind]
         for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_volume_ind))
        for (fen_ind, fc_volume_ind) in enumerate(fc_cells)
    ]
    # FC starts after all other entities, fenics start from 0 to size-1
    # write nodeindices into dict to access them later

    if encoding == ENCODING_ASCII:
        dataitem = etree.SubElement(topologynode,
                                    "DataItem",
                                    NumberType="UInt",
                                    Dimensions="%d %d" %
                                    (num_cells, nodes_per_element),
                                    Format="XML")
        dataitem.text = numpy_array_to_str(tuples_to_numpy(nodeindices))
    elif encoding == ENCODING_HDF5:
        pass
Пример #3
0
def write_fenics_mesh_codim_xdmf(fem_mesh_obj,
                                 topologynode,
                                 nodes_dict,
                                 codim=0,
                                 encoding=ENCODING_ASCII):
    mesh_dimension = get_FemMeshObjectDimension(fem_mesh_obj)

    element_types = get_FemMeshObjectElementTypes(fem_mesh_obj, remove_zero_element_entries=True)
    element_order = get_FemMeshObjectOrder(fem_mesh_obj)
    # we get all elements from mesh to decide which one to write by selection of codim
    # nodeindices = [(nodes_dict[ind] for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_volume_ind)) for (fen_ind, fc_volume_ind) in enumerate(fc_cells)]
    writeout_element_dimension = mesh_dimension - codim

    (num_topo, name_topo, dim_topo) = (0, "", 0)
    for (num, name, dim) in element_types:
        if writeout_element_dimension == dim:
            (num_topo, name_topo, dim_topo) = (num, name, dim)

    (topology_type, nodes_per_element) = FreeCAD_to_Fenics_XDMF_dict[(name_topo, element_order)]

    topologynode.set("TopologyType", topology_type)
    topologynode.set("NumberOfElements", str(num_topo))
    topologynode.set("NodesPerElement", str(nodes_per_element))

    if dim_topo == 3:
        fc_topo = fem_mesh_obj.FemMesh.Volumes
    elif dim_topo == 2:
        fc_topo = fem_mesh_obj.FemMesh.Faces
    elif dim_topo == 1:
        fc_topo = fem_mesh_obj.FemMesh.Edges
    elif dim_topo == 0:
        fc_topo = fem_mesh_obj.FemMesh.Nodes
    else:
        fc_topo = []
        print("Dimension of mesh incompatible with export XDMF function: %d" % (dim_topo,))

    nodeindices = [(nodes_dict[ind] for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_topo_ind)) for (fen_ind, fc_topo_ind) in enumerate(fc_topo)]

    if encoding == ENCODING_ASCII:
        dataitem = ET.SubElement(topologynode, "DataItem", NumberType="UInt", Dimensions="%d %d" % (num_topo, nodes_per_element), Format="XML")
        dataitem.text = numpy_array_to_str(tuples_to_numpy(nodeindices, nodes_per_element))
    elif encoding == ENCODING_HDF5:
        pass

    return fc_topo
Пример #4
0
def write_fenics_mesh_volumes_xdmf(fem_mesh_obj, topologynode, rd, encoding=ENCODING_ASCII):
    (num_cells, name_cell, dim_cell) = get_MaxDimElementFromList(get_FemMeshObjectElementTypes(fem_mesh_obj))
    element_order = get_FemMeshObjectOrder(fem_mesh_obj)

    FreeCAD_to_Fenics_XDMF_dict = {
        ("Node", 1): ("polyvertex", 1),
        ("Edge", 1): ("polyline", 2),
        ("Edge", 2): ("edge_3", 3),
        ("Triangle", 1): ("triangle", 3),
        ("Triangle", 2): ("tri_6", 6),
        ("Tetra", 1): ("tetrahedron", 4),
        ("Tetra", 2): ("tet_10", 10)
    }

    (topology_type, nodes_per_element) = FreeCAD_to_Fenics_XDMF_dict[(name_cell, element_order)]

    topologynode.set("TopologyType", topology_type)
    topologynode.set("NumberOfElements", str(num_cells))
    topologynode.set("NodesPerElement", str(nodes_per_element))

    if dim_cell == 3:
        fc_cells = fem_mesh_obj.FemMesh.Volumes
    elif dim_cell == 2:
        fc_cells = fem_mesh_obj.FemMesh.Faces
    elif dim_cell == 1:
        fc_cells = fem_mesh_obj.FemMesh.Edges
    elif dim_cell == 0:
        fc_cells = fem_mesh_obj.FemMesh.Nodes
    else:
        fc_cells = []
        print("Dimension of mesh incompatible with export XDMF function: %d" % (dim_cell,))

    nodeindices = [(rd[ind] for ind in fem_mesh_obj.FemMesh.getElementNodes(fc_volume_ind)) for (fen_ind, fc_volume_ind) in enumerate(fc_cells)]
    # FC starts after all other entities, fenics start from 0 to size-1
    # write nodeindices into dict to access them later

    if encoding == ENCODING_ASCII:
        dataitem = etree.SubElement(topologynode, "DataItem", NumberType="UInt", Dimensions="%d %d" % (num_cells, nodes_per_element), Format="XML")
        dataitem.text = numpy_array_to_str(tuples_to_numpy(nodeindices))
    elif encoding == ENCODING_HDF5:
        pass