示例#1
0
  def read(self, debug, interpolate):
    """
    Read finite-element mesh and store in Sieve mesh object.

    @returns PETSc mesh object containing finite-element mesh
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Reading finite-element mesh")

    # Set flags
    self.debug(debug)
    self.interpolate(interpolate)

    # Initialize coordinate system
    if self.coordsys is None:
      raise ValueError, "Coordinate system for mesh is unknown."

    from pylith.mpi.Communicator import petsc_comm_world
    from pylith.topology.Mesh import Mesh    
    mesh = Mesh(dim=self.coordsys.spaceDim(), comm=petsc_comm_world())
    mesh.coordsys(self.coordsys)

    # Read mesh
    ModuleMeshIO.read(self, mesh)
    return mesh
示例#2
0
    def read(self, debug, interpolate):
        """
    Read finite-element mesh and store in Sieve mesh object.

    @returns PETSc mesh object containing finite-element mesh
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Reading finite-element mesh")

        # Set flags
        self.debug(debug)
        self.interpolate(interpolate)

        # Initialize coordinate system
        if self.coordsys is None:
            raise ValueError, "Coordinate system for mesh is unknown."

        from pylith.mpi.Communicator import petsc_comm_world
        from pylith.topology.Mesh import Mesh
        mesh = Mesh(dim=self.coordsys.spaceDim(), comm=petsc_comm_world())
        mesh.coordsys(self.coordsys)

        # Read mesh
        ModuleMeshIO.read(self, mesh)
        return mesh
示例#3
0
    def create(self, normalizer, faults=None):
        """
    Hook for creating mesh.
    """
        from pylith.utils.profiling import resourceUsageString
        from pylith.mpi.Communicator import petsc_comm_world
        comm = petsc_comm_world()

        self._setupLogging()
        logEvent = "%screate" % self._loggingPrefix
        self._eventLogger.eventBegin(logEvent)

        # Read mesh
        mesh = self.reader.read(self.debug, self.interpolate)
        if self.debug:
            mesh.view()

        # Reorder mesh
        if self.reorderMesh:
            logEvent2 = "%sreorder" % self._loggingPrefix
            self._eventLogger.eventBegin(logEvent2)
            self._debug.log(resourceUsageString())
            if 0 == comm.rank:
                self._info.log("Reordering cells and vertices.")
            from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee
            ordering = ReverseCuthillMcKee()
            ordering.reorder(mesh)
            self._eventLogger.eventEnd(logEvent2)

        # Adjust topology
        self._debug.log(resourceUsageString())
        if 0 == comm.rank:
            self._info.log("Adjusting topology.")
        self._adjustTopology(mesh, faults)

        # Distribute mesh
        if comm.size > 1:
            if 0 == comm.rank:
                self._info.log("Distributing mesh.")
            mesh = self.distributor.distribute(mesh, normalizer)
            if self.debug:
                mesh.view()
            mesh.memLoggingStage = "DistributedMesh"

        # Refine mesh (if necessary)
        newMesh = self.refiner.refine(mesh)
        if not newMesh == mesh:
            mesh.cleanup()
            newMesh.memLoggingStage = "RefinedMesh"

        # Can't reorder mesh again, because we do not have routine to
        # unmix normal and hybrid cells.

        # Nondimensionalize mesh (coordinates of vertices).
        from pylith.topology.topology import MeshOps_nondimensionalize
        MeshOps_nondimensionalize(newMesh, normalizer)

        self._eventLogger.eventEnd(logEvent)
        return newMesh
示例#4
0
  def create(self, normalizer, faults=None):
    """
    Hook for creating mesh.
    """
    from pylith.utils.profiling import resourceUsageString
    from pylith.mpi.Communicator import petsc_comm_world
    comm = petsc_comm_world()

    self._setupLogging()
    logEvent = "%screate" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)    

    # Read mesh
    mesh = self.reader.read(self.debug, self.interpolate)
    if self.debug:
      mesh.view()

    # Reorder mesh
    if self.reorderMesh:
      logEvent2 = "%sreorder" % self._loggingPrefix
      self._eventLogger.eventBegin(logEvent2)
      self._debug.log(resourceUsageString())
      if 0 == comm.rank:
        self._info.log("Reordering cells and vertices.")
      from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee
      ordering = ReverseCuthillMcKee()
      ordering.reorder(mesh)
      self._eventLogger.eventEnd(logEvent2)

    # Adjust topology
    self._debug.log(resourceUsageString())
    if 0 == comm.rank:
      self._info.log("Adjusting topology.")
    self._adjustTopology(mesh, faults)

    # Distribute mesh
    if comm.size > 1:
      if 0 == comm.rank:
        self._info.log("Distributing mesh.")
      mesh = self.distributor.distribute(mesh, normalizer)
      if self.debug:
        mesh.view()
      mesh.memLoggingStage = "DistributedMesh"

    # Refine mesh (if necessary)
    newMesh = self.refiner.refine(mesh)
    if not newMesh == mesh:
      mesh.cleanup()
      newMesh.memLoggingStage = "RefinedMesh"

    # Can't reorder mesh again, because we do not have routine to
    # unmix normal and hybrid cells.

    # Nondimensionalize mesh (coordinates of vertices).
    from pylith.topology.topology import MeshOps_nondimensionalize
    MeshOps_nondimensionalize(newMesh, normalizer)

    self._eventLogger.eventEnd(logEvent)    
    return newMesh
示例#5
0
 def finalize(self):
     """Finalize PETSc.
     """
     from pylith.mpi.Communicator import petsc_comm_world
     comm = petsc_comm_world()
     if 0 == comm.rank:
         self._info.log("Finalizing PETSc.")
     petsc.finalize()
     return
示例#6
0
 def finalize(self):
   """
   Finalize PETSc.
   """
   from pylith.mpi.Communicator import petsc_comm_world
   comm = petsc_comm_world()
   if 0 == comm.rank:
     self._info.log("Finalizing PETSc.")
   petsc.finalize()
   return
示例#7
0
 def initialize(self):
     """Initialize PETSc.
     """
     import sys
     args = [sys.executable]
     options = self._getOptions()
     if len(options) > 0:
         for arg in options:
             args.append(arg)
     petsc.initialize(args)
     from pylith.mpi.Communicator import petsc_comm_world
     comm = petsc_comm_world()
     if 0 == comm.rank:
         self._info.log("Initialized PETSc.")
     return
示例#8
0
 def initialize(self):
   """
   Initialize PETSc.
   """
   import sys
   args = [sys.executable]
   options = self._getOptions()
   if len(options) > 0:
     for arg in options:
       args.append(arg)
   petsc.initialize(args)
   from pylith.mpi.Communicator import petsc_comm_world
   comm = petsc_comm_world()
   if 0 == comm.rank:
     self._info.log("Initialized PETSc.")
   return
示例#9
0
  def _showStatus(self, stage):
    import sys
    from pylith.utils.profiling import resourceUsageString
    from pylith.mpi.Communicator import petsc_comm_world
    comm = petsc_comm_world()

    if comm.rank == 0:
      print "\n----------------------------------------------------------------------"
      print "STAGE: %s" % stage
      print "----------------------------------------------------------------------"
    for irank in xrange(comm.size):
      comm.barrier()
      if comm.rank == irank:
        print "\nPROCESSOR %d" % comm.rank
        print "\nStatus from ps: %s\n" % resourceUsageString()
        self.logger.show()
        sys.stdout.flush()

      comm.barrier()
    return
示例#10
0
    def refine(self, mesh):
        """Refine mesh.
        """
        self._setupLogging()
        logEvent = "%srefine" % self._loggingPrefix
        self._eventLogger.eventBegin(logEvent)

        from pylith.mpi.Communicator import petsc_comm_world
        comm = petsc_comm_world()
        if 0 == comm.rank:
            self._info.log("Refining mesh using uniform refinement.")

        from .Mesh import Mesh
        newMesh = Mesh()
        newMesh.debug(mesh.debug())
        newMesh.setCoordSys(mesh.getCoordSys())
        ModuleRefineUniform.refine(self, newMesh, mesh, self.levels)
        mesh.cleanup()

        self._eventLogger.eventEnd(logEvent)
        return newMesh
示例#11
0
  def refine(self, mesh):
    """
    Refine mesh.
    """
    self._setupLogging()
    logEvent = "%srefine" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

    from pylith.mpi.Communicator import petsc_comm_world
    comm = petsc_comm_world()
    if 0 == comm.rank:
      self._info.log("Refining mesh using uniform refinement.")

    from Mesh import Mesh
    newMesh = Mesh()
    newMesh.debug(mesh.debug())
    newMesh.coordsys(mesh.coordsys())
    ModuleRefineUniform.refine(self, newMesh, mesh, self.levels)
    mesh.cleanup()

    self._eventLogger.eventEnd(logEvent)
    return newMesh
示例#12
0
  def _runTest(self):
    """
    Run test.
    """

    #filenameIn = "data/tet4.exo"
    #filenameIn = "tri3_200m_gradient.exo"
    filenameIn = "tet4_150m.exo"

    from pylith.perf.MemoryLogger import MemoryLogger
    self.logger = MemoryLogger()
    self.logger._configure()

    from pylith.utils.petsc import MemoryLogger
    sieveLogger =  MemoryLogger.singleton()

    from pylith.topology.topology import MeshOps_numMaterialCells

    from pylith.mpi.Communicator import petsc_comm_world
    comm = petsc_comm_world()

    self._showStatus("Before reading mesh")

    # ------------------------------------------------------------
    # Read mesh
    from pylith.meshio.MeshIOCubit import MeshIOCubit
    io = MeshIOCubit()
    io.inventory.filename = filenameIn
    io.inventory.useNames = False
    io._configure()

    from pylith.materials.ElasticIsotropic3D import ElasticIsotropic3D
    material = ElasticIsotropic3D()
    material.inventory.label = "Elastic material"
    material.inventory.id = 1
    material._configure()

    mesh = io.read(debug=False, interpolate=False)

    self.logger.logMesh(mesh.memLoggingStage, mesh)
    material.ncells = MeshOps_numMaterialCells(mesh, material.id())
    self.logger.logMaterial(mesh.memLoggingStage, material)
    

    self._showStatus("After reading mesh")    

    # ------------------------------------------------------------
    # Reorder mesh
    from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee
    ordering = ReverseCuthillMcKee()
    ordering.reorder(mesh)

    # Expect no memory allocation
    self.logger.memory["MeshReordering"] = 0

    self._showStatus("After reordering mesh")


    # ------------------------------------------------------------
    # Distribute mesh
    if comm.size > 1:
      from pylith.topology.Distributor import Distributor
      from spatialdata.units.Nondimensional import Nondimensional
      distributor = Distributor()
      normalizer = Nondimensional()
      dmesh = distributor.distribute(mesh, normalizer)
      dmesh.memLoggingStage = "DistributedMesh"

      self.logger.logMesh(mesh.memLoggingStage, mesh)
      material.ncells = MeshOps_numMaterialCells(mesh, material.id())
      self.logger.logMaterial(mesh.memLoggingStage, material)
    
      self.logger.logMesh(dmesh.memLoggingStage, dmesh)
      material.ncells = MeshOps_numMaterialCells(dmesh, material.id())
      self.logger.logMaterial(dmesh.memLoggingStage, material)

      self._showStatus("After distributing mesh")

      mesh = dmesh
      

    if False: # Refine mesh (if necessary)
      from pylith.topology.RefineUniform import RefineUniform
      refiner = RefineUniform()
      rmesh = refiner.refine(mesh)
      rmesh.memLoggingStage = "RefinedMesh"

      print "Unrefined mesh logging stage",mesh.memLoggingStage
      self.logger.logMesh(mesh.memLoggingStage, mesh)
      material.ncells = MeshOps_numMaterialCells(mesh, material.id())
      self.logger.logMaterial(mesh.memLoggingStage, material)
    
      self.logger.logMesh(rmesh.memLoggingStage, rmesh)
      material.ncells = MeshOps_numMaterialCells(rmesh, material.id())
      self.logger.logMaterial(rmesh.memLoggingStage, material)

      self._showStatus("After refining mesh")


    return