示例#1
0
def reconstruct_mesh(recGrid, input, verbose=False):
    """
    The following function is used after 3D displacements to:

    * rebuild model grids & meshes,
    * reinitialise Finite Volume discretisation,
    * redefine the partitioning when parallelisation is enable.

    Args:
        recGrid: class describing the regular grid characteristics.
        input: class containing XML input file parameters.
        verbose : (bool) when :code:`True`, output additional debug information (default: :code:`False`).

    Returns
    -------
    FVmesh
        class describing the finite volume mesh.
    lGIDs
        numpy 1D array containing the node indices.
    inIDs
        numpy 1D array containing the local node indices inside the mesh.
    inGIDs
        numpy 1D array containing the node indices inside the mesh.
    totPts
        total number of points in the mesh.
    """

    walltime = time.process_time()
    FVmesh = FVmethod.FVmethod(
        recGrid.tinMesh["vertices"],
        recGrid.tinMesh["triangles"],
        recGrid.tinMesh["edges"],
    )

    # Define Finite Volume parameters
    totPts = len(recGrid.tinMesh["vertices"][:, 0])
    lGIDs = np.arange(totPts)
    inGIDs = lGIDs
    FVmesh.neighbours = np.zeros((totPts, 20), dtype=np.int32, order="F")
    FVmesh.neighbours.fill(-2)
    FVmesh.edge_length = np.zeros((totPts, 20), dtype=np.float, order="F")
    FVmesh.vor_edges = np.zeros((totPts, 20), dtype=np.float, order="F")
    FVmesh.control_volumes = np.zeros(totPts, dtype=np.float)

    # Compute Finite Volume parameters
    FVmesh.construct_FV(lGIDs, verbose)

    if verbose:
        print(" - reconstructed FV mesh ", time.process_time() - walltime)

    inIDs = lGIDs[recGrid.boundsPt:]
    elevationTIN.assign_parameter_pit(
        FVmesh.neighbours,
        FVmesh.control_volumes,
        input.diffnb,
        input.diffprop,
        input.propa,
        input.propb,
        recGrid.boundsPt,
        input.fillmax,
    )

    return FVmesh, lGIDs, inIDs, inGIDs, totPts
示例#2
0
def _define_TINparams(totPts, inIDs, input, FVmesh, recGrid, verbose=False):
    """
    This function is defining the main values declared on the TIN.
    """

    walltime = time.process_time()
    local_elev = np.zeros(totPts)
    local_elev.fill(-1.0e6)

    # In case of a restart read values from HDF5 files
    if input.restart:
        local_cum = np.zeros(totPts)
        local_cum.fill(-1.0e6)
        local_hill = np.zeros(totPts)
        local_hill.fill(-1.0e6)
        local_fail = np.zeros(totPts)
        local_fail.fill(-1.0e6)
        if input.flexure:
            local_cumflex = np.zeros(totPts)
            local_cumflex.fill(-1.0e6)
            (
                local_elev[inIDs],
                local_cum[inIDs],
                local_hill[inIDs],
                local_fail[inIDs],
                local_cumflex[inIDs],
            ) = recGrid.load_hdf5_flex(input.rfolder, input.rstep,
                                       FVmesh.node_coords[inIDs, :2])
        else:
            (
                local_elev[inIDs],
                local_cum[inIDs],
                local_hill[inIDs],
                local_fail[inIDs],
            ) = recGrid.load_hdf5(input.rfolder, input.rstep,
                                  FVmesh.node_coords[inIDs, :2])

        # Get cumulative erosion/deposition values
        cumdiff = local_cum
        cumdiff[:recGrid.boundsPt] = 0.0
        cumhill = local_hill
        cumhill[:recGrid.boundsPt] = 0.0
        cumfail = local_hill
        cumfail[:recGrid.boundsPt] = 0.0
        if input.flexure:
            # Get cumulative flexural values
            cumflex = local_cumflex
            cumflex[:recGrid.boundsPt] = 0.0

    # Otherwise interpolate elevation from DEM to TIN
    else:
        local_elev[inIDs] = elevationTIN.getElevation(
            recGrid.regX, recGrid.regY, recGrid.regZ,
            FVmesh.node_coords[inIDs, :2])
        # Initialise TIN parameters
        cumdiff = np.zeros(totPts)
        cumhill = np.zeros(totPts)
        cumfail = np.zeros(totPts)
        if input.flexure:
            cumflex = np.zeros(totPts)

    # Assign boundary values
    elevation, parentIDs = elevationTIN.update_border_elevation(
        local_elev,
        FVmesh.neighbours,
        FVmesh.edge_length,
        recGrid.boundsPt,
        btype=input.btype,
    )

    # Define pit filling algorithm
    elevationTIN.assign_parameter_pit(
        FVmesh.neighbours,
        FVmesh.control_volumes,
        input.diffnb,
        input.diffprop,
        input.propa,
        input.propb,
        recGrid.boundsPt,
        input.fillmax,
    )

    if verbose:
        print(" - define paramters on TIN grid ",
              time.process_time() - walltime)

    if input.flexure:
        return elevation, cumdiff, cumhill, cumfail, cumflex, inIDs, parentIDs
    else:
        return elevation, cumdiff, cumhill, cumfail, inIDs, parentIDs
示例#3
0
def reconstruct_mesh(recGrid, input, verbose=False):
    """
    The following function is used after 3D displacements to:

    * rebuild model grids & meshes,
    * reinitialise Finite Volume discretisation,
    * redefine the partitioning when parallelisation is enable.

    Args:
        recGrid: class describing the regular grid characteristics.
        input: class containing XML input file parameters.
        verbose : (bool) when :code:`True`, output additional debug information (default: :code:`False`).

    Returns
    -------
    FVmesh
        class describing the finite volume mesh.
    tMesh
        class describing the TIN mesh.
    lGIDs
        numpy 1D array containing the node indices.
    inIDs
        numpy 1D array containing the local node indices inside the mesh.
    inGIDs
        numpy 1D array containing the node indices inside the mesh.
    totPts
        total number of points in the mesh.
    """

    walltime = time.clock()
    FVmesh = FVmethod.FVmethod(recGrid.tinMesh['vertices'],
                               recGrid.tinMesh['triangles'],
                               recGrid.tinMesh['edges'])

    # Perform partitioning by equivalent domain splitting
    partitionIDs, RowProc, ColProc = partitionTIN.simple(
        recGrid.tinMesh['vertices'][:, 0], recGrid.tinMesh['vertices'][:, 1])
    FVmesh.partIDs = partitionIDs

    # Get each partition global node ID
    inGIDs = np.where(partitionIDs == 0)[0]

    if verbose:
        print(" - partition TIN amongst processors ", time.clock() - walltime)

    # Define overlapping partitions
    walltime = time.clock()
    lGIDs, localTIN = partitionTIN.overlap(recGrid.tinMesh['vertices'][:, 0],
                                           recGrid.tinMesh['vertices'][:, 1],
                                           RowProc, ColProc,
                                           2 * recGrid.resEdges, verbose)

    # Set parameters of the finite volume mesh
    tMesh = FVmethod.FVmethod(localTIN['vertices'], localTIN['triangles'],
                              localTIN['edges'])

    # Define Finite Volume parameters
    totPts = len(recGrid.tinMesh['vertices'][:, 0])
    FVmesh.neighbours = np.zeros((totPts, 20), dtype=np.int32, order='F')
    FVmesh.neighbours.fill(-2)
    FVmesh.edge_length = np.zeros((totPts, 20), dtype=np.float, order='F')
    FVmesh.vor_edges = np.zeros((totPts, 20), dtype=np.float, order='F')
    FVmesh.control_volumes = np.zeros(totPts, dtype=np.float)

    # Compute Finite Volume parameters
    tGIDs, tNgbh, tEdgs, tVors, tVols = tMesh.construct_FV(
        inGIDs, lGIDs, totPts, recGrid.resEdges * input.Afactor, verbose)

    FVmesh.neighbours[tGIDs, :tMesh.maxNgbh] = tNgbh
    FVmesh.edge_length[tGIDs, :tMesh.maxNgbh] = tEdgs
    FVmesh.vor_edges[tGIDs, :tMesh.maxNgbh] = tVors
    FVmesh.control_volumes[tGIDs] = tVols

    if verbose:
        print(" - reconstructed FV mesh ", time.clock() - walltime)

    inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == 0)[0]
    inIDs += recGrid.boundsPt
    elevationTIN.assign_parameter_pit(FVmesh.neighbours,
                                      FVmesh.control_volumes, input.diffnb,
                                      input.diffprop, recGrid.boundsPt,
                                      input.fillmax)

    return FVmesh, tMesh, lGIDs, inIDs, inGIDs, totPts