Ejemplo n.º 1
0
def construct_mesh(input, filename, verbose=False):
    """
    The following function is taking parsed values from the XML to:
        - build model grids & meshes,
        - initialise Finite Volume discretisation,
        - define the partitioning when parallelisation is enable.
    """

    rank = mpi.COMM_WORLD.rank
    size = mpi.COMM_WORLD.size
    comm = mpi.COMM_WORLD

    cumflex = None
    flex = None
    wave = None
    tinFlex = None
    strata = None
    mapero = None

    # Get DEM regular grid and create Badlands TIN.
    recGrid = raster2TIN.raster2TIN(filename, areaDelFactor=input.Afactor)

    fixIDs = recGrid.boundsPt + recGrid.edgesPt

    force = forceSim.forceSim(
        input.seafile, input.seapos, input.rainMap, input.rainTime,
        input.rainVal, input.orographic, input.orographiclin, input.rbgd,
        input.rmin, input.rmax, input.rzmax, input.windx, input.windy,
        input.tauc, input.tauf, input.nm, input.cw, input.hw, input.ortime,
        input.tectFile, input.tectTime, recGrid.regX, recGrid.regY,
        input.riverPos, input.riverTime, input.riverQws, input.riverRck,
        input.riverNb, input.rockNb, input.tDisplay)

    if input.disp3d:
        force.time3d = input.time3d
        if input.merge3d == 0. or input.merge3d > recGrid.resEdges:
            force.merge3d = input.Afactor * recGrid.resEdges * 0.5
        else:
            force.merge3d = input.merge3d

    # Partition the TIN
    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]

    # Build Finite Volume discretisation
    # Define overlapping partitions
    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'])

    if rank == 0 and size > 1 and verbose:
        print " - partition TIN amongst processors and create local TINs", time.clock(
        ) - walltime

    # Define Finite Volume parameters
    walltime = time.clock()
    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 " - FV mesh ", time.clock() - walltime

    # Define TIN parameters
    if input.flexure:
        elevation, cumdiff, cumhill, cumflex, inIDs, parentIDs = _define_TINparams(
            totPts, input, FVmesh, recGrid, verbose)
    else:
        elevation, cumdiff, cumhill, inIDs, parentIDs = _define_TINparams(
            totPts, input, FVmesh, recGrid, verbose)

    # Build stratigraphic and erodibility meshes
    if input.laytime > 0 and input.erolays >= 0:
        strata, mapero = _build_strateroMesh(input, FVmesh, recGrid, cumdiff,
                                             rank, verbose)
    elif input.laytime > 0:
        strata = _build_strateroMesh(input, FVmesh, recGrid, cumdiff, rank,
                                     verbose)
    elif input.erolays >= 0:
        mapero = _build_strateroMesh(input, FVmesh, recGrid, cumdiff, rank,
                                     verbose)

    # Set default to no rain
    force.update_force_TIN(FVmesh.node_coords[:, :2])

    # Flexural isostasy initialisation
    if input.flexure:
        flex, tinFlex, cumflex = _init_flexure(FVmesh, input, recGrid, force,
                                               elevation, cumdiff, cumflex,
                                               totPts, rank, verbose)

    # Wave grid initialisation
    if input.waveOn:
        wave = _init_wave(input, recGrid, force, rank, verbose)

    # Stratigraphic TIN initialisation
    if input.rockNb > 0:
        layNb = int((input.tEnd - input.tStart) / input.laytime) + 2
        bPts = recGrid.boundsPt
        ePts = recGrid.edgesPt
        if input.restart:
            straTIN = stratiWedge.stratiWedge(
                layNb, input.initlayers, FVmesh.node_coords[:, :2], bPts, ePts,
                input.layersData, input.actlay, input.outDir,
                input.strath5file, input.rockNb, recGrid.regX, recGrid.regY,
                elevation, input.rockCk, cumdiff, input.rfolder, input.rstep)
        else:
            straTIN = stratiWedge.stratiWedge(
                layNb, input.initlayers, FVmesh.node_coords[:, :2], bPts, ePts,
                input.layersData, input.actlay, input.outDir,
                input.strath5file, input.rockNb, recGrid.regX, recGrid.regY,
                elevation, input.rockCk)
    else:
        straTIN = None

    # Stratigraphic grid in case of carbonate and/or pelagic growth functions
    if input.carbonate or input.pelagic:
        layNb = int((input.tEnd - input.tStart) / input.tDisplay) + 2
        bPts = recGrid.boundsPt
        ePts = recGrid.edgesPt
        if input.restart:
            carbTIN = carbMesh.carbMesh(layNb, input.initlayers,
                                        FVmesh.node_coords[:, :2], bPts, ePts,
                                        input.layersData, input.outDir,
                                        input.strath5file, recGrid.regX,
                                        recGrid.regY, elevation, input.rfolder,
                                        input.rstep)
        else:
            carbTIN = carbMesh.carbMesh(layNb, input.initlayers,
                                        FVmesh.node_coords[:, :2], bPts, ePts,
                                        input.layersData, input.outDir,
                                        input.strath5file, recGrid.regX,
                                        recGrid.regY, elevation)
    else:
        carbTIN = None

    return recGrid, FVmesh, force, tMesh, lGIDs, fixIDs, \
        inIDs, parentIDs, inGIDs, totPts, elevation, cumdiff, \
        cumhill, cumflex, strata, mapero, tinFlex, flex, wave, \
        straTIN, carbTIN
Ejemplo n.º 2
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.
    """

    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
Ejemplo n.º 3
0
    def load_dem(self, filename, verbose=False):
        """
        Load a DEM input file.
        """

        # 1. Get DEM regular grid and create Badlands TIN.

        recGrid = raster2TIN.raster2TIN(filename,
                                        areaDelFactor=self.input.Afactor)

        self.fixIDs = recGrid.boundsPt + recGrid.edgesPt

        force = forceSim.forceSim(
            self.input.seafile, self.input.seapos, self.input.rainMap,
            self.input.rainTime, self.input.rainVal, self.input.orographic,
            self.input.rbgd, self.input.rmin, self.input.rmax,
            self.input.windx, self.input.windy, self.input.tauc,
            self.input.tauf, self.input.nm, self.input.cw, self.input.hw,
            self.input.ortime, self.input.tectFile, self.input.tectTime,
            recGrid.regX, recGrid.regY, self.input.tDisplay)

        if self.input.disp3d:
            force.time3d = self.input.time3d
            if self.input.merge3d == 0. or self.input.merge3d > recGrid.resEdges:
                force.merge3d = self.input.Afactor * recGrid.resEdges * 0.5
            else:
                force.merge3d = self.input.merge3d

        # 2. Partition the TIN
        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 == self._rank)[0]

        if self._rank == 0 and self._size > 1 and verbose:
            print " - partition TIN amongst processors ", time.clock(
            ) - walltime

        # 3. Build Finite Volume discretisation

        # Define overlapping partitions
        allIDs, 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'])

        walltime = time.clock()

        # 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)
        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, allIDs, totPts, recGrid.resEdges * self.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 self._rank == 0 and verbose:
            print " - FV mesh ", time.clock() - walltime

        # 4. Interpolate elevation
        walltime = time.clock()

        inIDs = np.where(FVmesh.partIDs[recGrid.boundsPt:] == self._rank)[0]
        inIDs += recGrid.boundsPt

        local_elev = np.zeros(totPts)
        local_elev.fill(-1.e6)

        if self.input.restart:
            local_cum = np.zeros(totPts)
            local_cum.fill(-1.e6)
            if self.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(
                        self.input.rfolder, self.input.rstep,
                        FVmesh.node_coords[inIDs, :2])
            else:
                local_elev[inIDs], local_cum[inIDs] = recGrid.load_hdf5(
                    self.input.rfolder, self.input.rstep,
                    FVmesh.node_coords[inIDs, :2])
            self._comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX)
            self._comm.Allreduce(mpi.IN_PLACE, local_cum, op=mpi.MAX)
            self.cumdiff = local_cum
            self.cumdiff[:recGrid.boundsPt] = 0.
            if self.input.flexure:
                self._comm.Allreduce(mpi.IN_PLACE, local_cumflex, op=mpi.MAX)
                self.cumflex = local_cumflex
                self.cumflex[:recGrid.boundsPt] = 0.
        else:
            local_elev[inIDs] = elevationTIN.getElevation(
                recGrid.regX, recGrid.regY, recGrid.regZ,
                FVmesh.node_coords[inIDs, :2])
            self._comm.Allreduce(mpi.IN_PLACE, local_elev, op=mpi.MAX)
            self.cumdiff = np.zeros(totPts)
            if self.input.flexure:
                self.cumflex = np.zeros(totPts)

        elevation = elevationTIN.update_border_elevation(
            local_elev,
            FVmesh.neighbours,
            FVmesh.edge_length,
            recGrid.boundsPt,
            btype=self.input.btype)
        # Set default to no rain
        force.update_force_TIN(FVmesh.node_coords[:, :2])
        self.rain = np.zeros(totPts, dtype=float)

        # Define variables
        self.hillslope = diffLinear()
        self.hillslope.CDaerial = self.input.CDa
        self.hillslope.CDmarine = self.input.CDm

        self.flow = flowNetwork()
        self.flow.erodibility = self.input.SPLero
        self.flow.m = self.input.SPLm
        self.flow.n = self.input.SPLn
        self.flow.mindt = self.input.minDT
        self.flow.bedrock = self.input.bedrock
        self.flow.alluvial = self.input.alluvial
        self.flow.esmooth = self.input.esmooth
        self.flow.dsmooth = self.input.dsmooth
        self.flow.xycoords = FVmesh.node_coords[:, :2]
        self.flow.spl = self.input.spl
        self.flow.capacity = self.input.capacity
        self.flow.filter = self.input.filter
        self.flow.depo = self.input.depo

        if self._rank == 0 and verbose:
            print " - interpolate elevation on grid ", time.clock() - walltime

        # Flexural isostasy initialisation
        if self.input.flexure:
            walltime = time.clock()
            nx = self.input.fnx
            ny = self.input.fny
            if nx == 0:
                nx = recGrid.nx
            if ny == 0:
                ny = recGrid.ny
            if self.input.elasticH is None:
                elasticT = str(self.input.elasticGrid)
            else:
                elasticT = self.input.elasticH

            self.flex = isoFlex.isoFlex()
            self.flex.buildGrid(nx, ny, self.input.youngMod,
                                self.input.dmantle, self.input.dsediment,
                                elasticT, self.input.flexbounds,
                                FVmesh.node_coords[:, :2])

            self.tinFlex = np.zeros(totPts, dtype=float)
            force.getSea(self.tNow)
            self.tinFlex = self.flex.get_flexure(elevation,
                                                 self.cumdiff,
                                                 force.sealevel,
                                                 recGrid.boundsPt,
                                                 initFlex=True)
            self.tinFlex = force.disp_border(self.tinFlex, FVmesh.neighbours,
                                             FVmesh.edge_length,
                                             recGrid.boundsPt)
            self.cumflex += self.tinFlex
            if self._rank == 0:
                print "   - Compute flexural isostasy ", time.clock(
                ) - walltime

        # Save state for subsequent calls
        # TODO: there is a lot of stuff here. Can we reduce it?
        self.recGrid = recGrid
        self.elevation = elevation
        self.FVmesh = FVmesh
        self.allIDs = allIDs
        self.inIDs = inIDs
        self.inGIDs = inGIDs
        self.tMesh = tMesh
        self.force = force
        self.totPts = totPts
Ejemplo n.º 4
0
    def rebuildMesh(self, verbose=False):
        """
        Build TIN after 3D displacements.
        """

        # Build the Finite Volume representation
        self.fixIDs = self.recGrid.boundsPt + self.recGrid.edgesPt
        walltime = time.clock()

        FVmesh = FVmethod.FVmethod(self.recGrid.tinMesh['vertices'],
                                   self.recGrid.tinMesh['triangles'],
                                   self.recGrid.tinMesh['edges'])

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

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

        if self._rank == 0 and verbose:
            print " - partition TIN amongst processors ", time.clock(
            ) - walltime

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

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

        walltime = time.clock()

        # Define Finite Volume parameters
        totPts = len(self.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, allIDs, totPts, self.recGrid.resEdges * self.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 self._rank == 0 and verbose:
            print " - FV mesh ", time.clock() - walltime

        inIDs = np.where(
            FVmesh.partIDs[self.recGrid.boundsPt:] == self._rank)[0]
        inIDs += self.recGrid.boundsPt

        # Set default with no rain
        self.force.update_force_TIN(FVmesh.node_coords[:, :2])
        self.rain = np.zeros(totPts, dtype=float)
        self.rain[inIDs] = self.force.get_Rain(self.tNow, self.elevation,
                                               inIDs)

        # Update flexural isostasy
        if self.input.flexure:
            self.tinFlex = np.zeros(totPts, dtype=float)
            self.flex.update_flexure_parameters(FVmesh.node_coords[:, :2])

        # Save state for subsequent calls
        # TODO: there is a lot of stuff here. Can we reduce it?
        self.flow.xycoords = FVmesh.node_coords[:, :2]
        self.FVmesh = FVmesh
        self.allIDs = allIDs
        self.inIDs = inIDs
        self.inGIDs = inGIDs
        self.tMesh = tMesh
        self.totPts = totPts
Ejemplo n.º 5
0
def construct_mesh(input, filename, verbose=False):
    """
    The following function is taking parsed values from the XML to:
        - build model grids & meshes,
        - initialise Finite Volume discretisation,
        - define the partitioning when parallelisation is enable.
    """

    rank = mpi.COMM_WORLD.rank
    size = mpi.COMM_WORLD.size
    comm = mpi.COMM_WORLD

    cumflex = None
    flex = None
    tinFlex = None
    strata = None
    mapero = None

    # Get DEM regular grid and create Badlands TIN.
    recGrid = raster2TIN.raster2TIN(filename, areaDelFactor=input.Afactor)

    fixIDs = recGrid.boundsPt + recGrid.edgesPt

    force = forceSim.forceSim(input.seafile, input.seapos, input.rainMap,
                input.rainTime, input.rainVal, input.orographic,
                input.rbgd, input.rmin, input.rmax , input.windx,
                input.windy, input.tauc, input.tauf, input.nm,
                input.cw, input.hw, input.ortime, input.tectFile,
                input.tectTime, recGrid.regX, recGrid.regY, input.riverPos,
                input.riverTime, input.riverQws, input.riverWidth, input.riverNb,
                input.tDisplay)

    if input.disp3d:
        force.time3d = input.time3d
        if input.merge3d == 0. or input.merge3d > recGrid.resEdges:
            force.merge3d = input.Afactor * recGrid.resEdges * 0.5
        else:
            force.merge3d = input.merge3d

    # Partition the TIN
    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]

    # Build Finite Volume discretisation
    # Define overlapping partitions
    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'])

    if rank == 0 and size > 1 and verbose:
        print " - partition TIN amongst processors and create local TINs", time.clock() - walltime

    # Define Finite Volume parameters
    walltime = time.clock()
    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)
    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 " - FV mesh ", time.clock() - walltime

    # Define TIN parameters
    if input.flexure:
        elevation, cumdiff, cumflex, inIDs = _define_TINparams(totPts, input, FVmesh, recGrid, verbose)
    else:
        elevation, cumdiff, inIDs = _define_TINparams(totPts, input, FVmesh, recGrid, verbose)

    # Build stratigraphic and erodibility meshes
    if input.laytime > 0 and input.erolays >= 0:
        strata, mapero = _build_strateroMesh(input, FVmesh, recGrid, cumdiff, rank, verbose)
    elif input.laytime > 0:
        strata = _build_strateroMesh(input, FVmesh, recGrid, cumdiff, rank, verbose)
    elif input.erolays >= 0:
        mapero = _build_strateroMesh(input, FVmesh, recGrid, cumdiff, rank, verbose)

    # Set default to no rain
    force.update_force_TIN(FVmesh.node_coords[:,:2])

    # Flexural isostasy initialisation
    if input.flexure:
        flex, tinFlex, cumflex = _init_flexure(FVmesh, input, recGrid, force, elevation,
                                                cumdiff, cumflex, totPts, rank, verbose)

    return recGrid, FVmesh, force, tMesh, lGIDs, fixIDs, \
        inIDs, inGIDs, totPts, elevation, cumdiff, \
        cumflex, strata, mapero, tinFlex, flex
Ejemplo n.º 6
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.
    """

    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