def _define_TINparams(totPts, input, FVmesh, recGrid, verbose=False): """ This function is defining the main values declared on the TIN. """ # Initialise MPI communications comm = mpi.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() walltime = time.clock() inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == rank)[0] inIDs += recGrid.boundsPt local_elev = np.zeros(totPts) local_elev.fill(-1.e6) # In case of a restart read values from HDF5 files if input.restart: local_cum = np.zeros(totPts) local_cum.fill(-1.e6) local_hill = np.zeros(totPts) local_hill.fill(-1.e6) if input.flexure: local_cumflex = np.zeros(totPts) local_cumflex.fill(-1.e6) local_elev[inIDs], local_cum[inIDs], local_hill[ 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] = recGrid.load_hdf5(input.rfolder, input.rstep, FVmesh.node_coords[inIDs, :2]) comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX) comm.Allreduce(mpi.IN_PLACE, local_cum, op=mpi.MAX) comm.Allreduce(mpi.IN_PLACE, local_hill, op=mpi.MAX) # Get cumulative erosion/deposition values cumdiff = local_cum cumdiff[:recGrid.boundsPt] = 0. cumhill = local_hill cumhill[:recGrid.boundsPt] = 0. if input.flexure: # Get cumulative flexural values comm.Allreduce(mpi.IN_PLACE, local_cumflex, op=mpi.MAX) cumflex = local_cumflex cumflex[:recGrid.boundsPt] = 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]) comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX) # Initialise TIN parameters cumdiff = np.zeros(totPts) cumhill = 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, recGrid.boundsPt, input.fillmax) if rank == 0 and verbose: print " - define paramters on TIN grid ", time.clock() - walltime if input.flexure: return elevation, cumdiff, cumhill, cumflex, inIDs, parentIDs else: return elevation, cumdiff, cumhill, inIDs, parentIDs
def _define_TINparams(totPts, input, FVmesh, recGrid, verbose=False): """ This function is defining the main values declared on the TIN. """ # Initialise MPI communications comm = mpi.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() walltime = time.clock() inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == rank)[0] inIDs += recGrid.boundsPt local_elev = np.zeros(totPts) local_elev.fill(-1.e6) # In case of a restart read values from HDF5 files if input.restart: local_cum = np.zeros(totPts) local_cum.fill(-1.e6) if input.flexure: local_cumflex = np.zeros(totPts) local_cumflex.fill(-1.e6) local_elev[inIDs],local_cum[inIDs],local_cumflex[inIDs] = recGrid.load_hdf5_flex(input.rfolder, input.rstep,FVmesh.node_coords[inIDs, :2]) else: local_elev[inIDs],local_cum[inIDs] = recGrid.load_hdf5(input.rfolder,input.rstep, FVmesh.node_coords[inIDs, :2]) comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX) comm.Allreduce(mpi.IN_PLACE, local_cum, op=mpi.MAX) # Get cumulative erosion/deposition values cumdiff = local_cum cumdiff[:recGrid.boundsPt] = 0. if input.flexure: # Get cumulative flexural values comm.Allreduce(mpi.IN_PLACE, local_cumflex, op=mpi.MAX) cumflex = local_cumflex cumflex[:recGrid.boundsPt] = 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]) comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX) # Initialise TIN parameters cumdiff = np.zeros(totPts) if input.flexure: cumflex = np.zeros(totPts) # Assign boundary values elevation = 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,recGrid.boundsPt,input.fillmax) if rank == 0 and verbose: print " - define paramters on TIN grid ", time.clock() - walltime if input.flexure: return elevation, cumdiff, cumflex, inIDs else: return elevation, cumdiff, inIDs
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. """ rank = mpi.COMM_WORLD.rank size = mpi.COMM_WORLD.size comm = mpi.COMM_WORLD 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 == rank)[0] if rank == 0 and 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 rank == 0 and verbose: print " - reconstructed FV mesh ", time.clock() - walltime inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == rank)[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
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. """ rank = mpi.COMM_WORLD.rank size = mpi.COMM_WORLD.size comm = mpi.COMM_WORLD 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 == rank)[0] if rank == 0 and 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) FVmesh.neighbours.fill(-2) FVmesh.edge_length = np.zeros((totPts, 20), dtype=np.float) FVmesh.vor_edges = np.zeros((totPts, 20), dtype=np.float) 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 rank == 0 and verbose: print " - reconstructed FV mesh ", time.clock() - walltime inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == rank)[0] inIDs += recGrid.boundsPt elevationTIN.assign_parameter_pit(FVmesh.neighbours, recGrid.boundsPt, input.fillmax) return FVmesh, tMesh, lGIDs, inIDs, inGIDs, totPts