예제 #1
0
파일: xdmf_utils.py 프로젝트: pyfsi/Kratos
def CreateXdmfSpatialGrid(h5_model_part):
    """Return an XDMF Grid object corresponding to a mesh in an HDF5 file.

    Keyword arguments:
    h5_model_part -- the HDF5 group containing the model part

    Expects:
    - element connectivities in h5_model_part["Xdmf/Elements/<element-name>"].
      Each connectivities has attributes "Dimension" and "NumberOfNodes".  For
      example, "Element2D3N" has "Dimension" 2 and "NumberOfNodes" 3.  The
      connectivities differ from the normal mdpa connectivities in that they
      directly index the array of nodal coordinates.  Currently there is
      no other way to post-process the mesh with Xdmf.

    See:
    - core.operations.ModelPartOutput,
    - core.operations.PartitionedModelPartOutput,
    - RenumberConnectivitiesForXdmf.
    """
    sgrid = SpatialGrid()
    geom = Geometry(HDF5UniformDataItem(
        h5_model_part["Nodes/Local/Coordinates"]))
    for name, value in h5_model_part["Xdmf/Elements"].items():
        cell_type = TopologyCellType(
            value.attrs["Dimension"], value.attrs["NumberOfNodes"])
        connectivities = HDF5UniformDataItem(value["Connectivities"])
        topology = UniformMeshTopology(cell_type, connectivities)
        sgrid.add_grid(UniformGrid(name, geom, topology))
    return sgrid
예제 #2
0
def CreateXdmfSpatialGrid(h5_model_part):
    """Return an XDMF Grid object corresponding to a mesh in an HDF5 file.

    Keyword arguments:
    h5_model_part -- the HDF5 group containing the model part

    Expects:
    - element connectivities in h5_model_part["Xdmf/Elements/<element-name>"].
      Each connectivities has attributes "Dimension" and "NumberOfNodes".  For
      example, "Element2D3N" has "Dimension" 2 and "NumberOfNodes" 3.  The
      connectivities differ from the normal mdpa connectivities in that they
      directly index the array of nodal coordinates.  Currently there is
      no other way to post-process the mesh with Xdmf.

    See:
    - core.operations.ModelPartOutput,
    - core.operations.PartitionedModelPartOutput,
    - RenumberConnectivitiesForXdmf.
    """
    sgrid = SpatialGrid()
    geom = Geometry(
        HDF5UniformDataItem(h5_model_part["Nodes/Local/Coordinates"]))

    spatial_grids_list = []
    GetListOfSpatialGrids(spatial_grids_list, h5_model_part["Xdmf"],
                          "RootModelPart")

    for spatial_grid in spatial_grids_list:
        spatial_grid_location = spatial_grid[0]
        spatial_grid_name = spatial_grid[1]
        current_h5_item = h5_model_part[spatial_grid_location]
        if (isinstance(current_h5_item, h5py.Dataset)):
            cell_type = TopologyCellType(3, 1)
            points = HDF5UniformDataItem(current_h5_item)
            topology = UniformMeshTopology(cell_type, points)
            sgrid.add_grid(
                UniformGrid(spatial_grid_name + "." + name, geom, topology))
            KratosMultiphysics.Logger.PrintInfo(
                "XDMF", "Added " + spatial_grid_name + " spatial grid.")
        else:
            for name, value in current_h5_item.items():
                cell_type = TopologyCellType(value.attrs["Dimension"],
                                             value.attrs["NumberOfNodes"])
                connectivities = HDF5UniformDataItem(value["Connectivities"])
                topology = UniformMeshTopology(cell_type, connectivities)
                sgrid.add_grid(
                    UniformGrid(spatial_grid_name + "." + name, geom,
                                topology))
                KratosMultiphysics.Logger.PrintInfo(
                    "XDMF", "Added " + spatial_grid_name + "." + name +
                    " spatial grid.")

    return sgrid
예제 #3
0
def XdmfNodalFlags(h5_results):
    """Return a list of XDMF Attribute objects for nodal flags in an HDF5 file.

    Keyword arguments:
    h5_results -- the HDF5 group containing the flags

    Checks for flags stored in data sets by variable name in:
    - h5_flags["NodalFlagValues/<flag-name>"]

    Expects:
    - each flag variable occurs only once

    If no flags are found, returns an empty list.

    See:
    - core.operations.NodalFlagsValueOutput.
    """

    results_path = "NodalFlagValues"
    results = []
    try:
        grp = h5_results[results_path]
    except KeyError:
        return results
    for variable, data in filter(Has_dtype, grp.items()):
        r = NodalData(variable, HDF5UniformDataItem(data))
        results.append(r)
    return results
예제 #4
0
def XdmfNodalResults(h5_results):
    """Return a list of XDMF Attribute objects for nodal results in an HDF5 file.

    Keyword arguments:
    h5_results -- the HDF5 group containing the results

    Checks for results stored in data sets by variable name in:
    - h5_results["NodalSolutionStepData/<variable-name>"]
    - h5_results["NodalDataValues/<variable-name>"]

    Expects:
    - each result variable occurs only once

    If no results are found, returns an empty list.

    See:
    - core.operations.NodalSolutionStepDataOutput,
    - core.operations.NodalDataValueOutput.
    """
    results = {}
    for path in ["NodalSolutionStepData", "NodalDataValues"]:
        try:
            grp = h5_results[path]
        except KeyError:
            continue
        for variable, data in filter(Has_dtype, grp.items()):
            if variable in results:
                # A variable can exist in the nodal solution step data or
                # non-historical nodal data value container, but not both.
                raise RuntimeError('Nodal result variable "' + variable +
                                   '" already exists.')
            results[variable] = NodalData(variable, HDF5UniformDataItem(data))
    return list(results.values())
예제 #5
0
def XdmfConditionGaussPointValues(h5_results):
    """Return a list of XDMF Attribute objects for element integration point values in an HDF5 file.

    Keyword arguments:
    h5_results -- the HDF5 group containing the results

    Checks for results stored by variable name in:
    - h5_results["ConditionGaussPointValues/<variable>"]

    If no results are found, returns an empty list.

    See:
    - core.operations.ConditionGaussPointOutput.
    """
    results_path = "ConditionGaussPointValues"
    results = []
    try:
        grp = h5_results[results_path]
    except KeyError:
        return results
    for variable, data in filter(Has_dtype, grp.items()):
        r = ElementData(variable, HDF5UniformDataItem(data))
        results.append(r)
    return results
예제 #6
0
def XdmfElementFlags(h5_results):
    """Return a list of XDMF Attribute objects for element flags in an HDF5 file.

    Keyword arguments:
    h5_flags -- the HDF5 group containing the flags

    Checks for flags stored by variable name in:
    - h5_flags["ElementFlagValues/<flag-name>"]

    If no flags are found, returns an empty list.

    See:
    - core.operations.ElementFlagValueOutput.
    """
    results_path = "ElementFlagValues"
    results = []
    try:
        grp = h5_results[results_path]
    except KeyError:
        return results
    for variable, data in filter(Has_dtype, grp.items()):
        r = ElementData(variable, HDF5UniformDataItem(data))
        results.append(r)
    return results