Esempio n. 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
Esempio n. 2
0
    def poststep(self, t, dt):
        """
    Hook for doing stuff after advancing time step.
    """
        logEvent = "%spoststep" % self._loggingPrefix
        self._eventLogger.eventBegin(logEvent)

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

        # The velocity and acceleration at time t depends on the
        # displacement at time t+dt, we want to output BEFORE updating the
        # displacement fields so that the displacement, velocity, and
        # acceleration files are all at time t.
        if 0 == comm.rank:
            self._info.log("Writing solution fields.")
        for output in self.output.components():
            output.writeData(t, self.fields)
        self._writeData(t)

        # Update displacement field from time t to time t+dt.
        dispIncr = self.fields.get("dispIncr(t->t+dt)")
        dispT = self.fields.get("disp(t)")
        dispTmdt = self.fields.get("disp(t-dt)")

        dispTmdt.copy(dispT)
        dispT.add(dispIncr)
        dispIncr.zeroAll()

        # Complete post-step processing.
        Formulation.poststep(self, t, dt)

        self._eventLogger.eventEnd(logEvent)
        return
Esempio n. 3
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
Esempio n. 4
0
  def _setupBC(self, boundaryConditions):
    """
    Setup boundary conditions as integrators or constraints.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    from pylith.feassemble.Constraint import implementsConstraint
    from pylith.bc.PointForce import PointForce

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

    if 0 == comm.rank:
      self._info.log("Pre-initializing boundary conditions.")
    self._debug.log(resourceUsageString())
    for bc in boundaryConditions.components():
      bc.preinitialize(self.mesh())
      foundType = False
      if implementsIntegrator(bc):
        foundType = True
        self.integrators.append(bc)
        if 0 == comm.rank:
          self._info.log("Added boundary condition '%s' as an integrator." % \
                           bc.label())
      if implementsConstraint(bc):
        foundType = True
        self.constraints.append(bc)
        if 0 == comm.rank:
          self._info.log("Added boundary condition '%s' as a constraint." % \
                           bc.label())
      if not foundType:
        raise TypeError, \
              "Could not determine whether boundary condition '%s' is an " \
              "integrator or a constraint." % bc.name
    self._debug.log(resourceUsageString())    
    return
Esempio n. 5
0
  def poststep(self, t, dt):
    """
    Hook for doing stuff after advancing time step.
    """
    logEvent = "%spoststep" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)
    
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    # The velocity and acceleration at time t depends on the
    # displacement at time t+dt, we want to output BEFORE updating the
    # displacement fields so that the displacement, velocity, and
    # acceleration files are all at time t.
    if 0 == comm.rank:
      self._info.log("Writing solution fields.")
    for output in self.output.components():
      output.writeData(t, self.fields)
    self._writeData(t)

    # Update displacement field from time t to time t+dt.
    dispIncr = self.fields.get("dispIncr(t->t+dt)")
    dispT = self.fields.get("disp(t)")
    dispTmdt = self.fields.get("disp(t-dt)")

    dispTmdt.copy(dispT)
    dispT.add(dispIncr)
    dispIncr.zeroAll()

    # Complete post-step processing.
    Formulation.poststep(self, t, dt)

    self._eventLogger.eventEnd(logEvent)    
    return
Esempio n. 6
0
  def preinitialize(self, mesh):
    """
    Do pre-initialization setup.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Pre-initializing fault '%s'." % self.label())
    FaultCohesive.preinitialize(self, mesh)
    Integrator.preinitialize(self, mesh)

    ModuleFaultCohesiveKin.quadrature(self, self.faultQuadrature)

    for eqsrc in self.eqsrcs.components():
      eqsrc.preinitialize()
    ModuleFaultCohesiveKin.eqsrcs(self, self.eqsrcs.inventory.facilityNames(),
                                  self.eqsrcs.components())

    for name in self.eqsrcs.inventory.facilityNames():
      self.availableFields['vertex']['info'] += ["final_slip_%s" % name]
      self.availableFields['vertex']['info'] += ["slip_time_%s" % name]

    if mesh.dimension() == 2:
      self.availableFields['vertex']['info'] += ["strike_dir"]
    elif mesh.dimension() == 3:
      self.availableFields['vertex']['info'] += ["strike_dir",
                                                 "dip_dir"]
    return
Esempio n. 7
0
  def _setupInterfaces(self, interfaceConditions):
    """
    Setup interfaces as integrators or constraints.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    from pylith.feassemble.Constraint import implementsConstraint

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

    if 0 == comm.rank:
      self._info.log("Pre-initializing interior interfaces.")
    for ic in interfaceConditions.components():
      ic.preinitialize(self.mesh())
      foundType = False
      if implementsIntegrator(ic):
        foundType = True
        self.integrators.append(ic)
        if 0 == comm.rank:
          self._info.log("Added interface condition '%s' as an integrator." % \
                           ic.label())
      if implementsConstraint(ic):
        foundType = True
        self.constraints.append(ic)
        if 0 == comm.rank:
          self._info.log("Added interface condition '%s' as a constraint." % \
                           ic.label())
      if not foundType:
        raise TypeError, \
              "Could not determine whether interface condition '%s' is an " \
              "integrator or a constraint." % ic.name
    self._debug.log(resourceUsageString())    
    return
    def preinitialize(self, mesh):
        """
    Do pre-initialization setup.
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        if 0 == comm.rank:
            self._info.log("Pre-initializing fault '%s'." % self.label())
        FaultCohesive.preinitialize(self, mesh)
        Integrator.preinitialize(self, mesh)

        ModuleFaultCohesiveDyn.quadrature(self, self.faultQuadrature)

        if mesh.dimension() == 2:
            self.availableFields['vertex']['info'] += ["strike_dir"]
        elif mesh.dimension() == 3:
            self.availableFields['vertex']['info'] += ["strike_dir", "dip_dir"]

        if not isinstance(self.tract, NullComponent):
            self.tract.preinitialize(mesh)
            self.availableFields['vertex'][
                'info'] += self.tract.availableFields['vertex']['info']

        self.availableFields['vertex']['info'] += \
            self.friction.availableFields['vertex']['info']
        self.availableFields['vertex']['data'] += \
            self.friction.availableFields['vertex']['data']
        return
Esempio n. 9
0
  def _setupBC(self, boundaryConditions):
    """
    Setup boundary conditions as integrators or constraints.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    from pylith.feassemble.Constraint import implementsConstraint
    from pylith.bc.PointForce import PointForce

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

    if 0 == comm.rank:
      self._info.log("Pre-initializing boundary conditions.")
    self._debug.log(resourceUsageString())
    for bc in boundaryConditions.components():
      bc.preinitialize(self.mesh())
      foundType = False
      if implementsIntegrator(bc):
        foundType = True
        self.integrators.append(bc)
        if 0 == comm.rank:
          self._info.log("Added boundary condition '%s' as an integrator." % \
                           bc.label())
      if implementsConstraint(bc):
        foundType = True
        self.constraints.append(bc)
        if 0 == comm.rank:
          self._info.log("Added boundary condition '%s' as a constraint." % \
                           bc.label())
      if not foundType:
        raise TypeError, \
              "Could not determine whether boundary condition '%s' is an " \
              "integrator or a constraint." % bc.name
    self._debug.log(resourceUsageString())    
    return
Esempio n. 10
0
  def _setupMaterials(self, materials):
    """
    Setup materials as integrators.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Pre-initializing materials.")
    self._debug.log(resourceUsageString())
    for material in materials.components():
      integrator = self.elasticityIntegrator()
      if not implementsIntegrator(integrator):
        raise TypeError, \
              "Could not use '%s' as an integrator for material '%s'. " \
              "Functionality missing." % (integrator.name, material.label())
      integrator.preinitialize(self.mesh(), material)
      self.integrators.append(integrator)
      self._debug.log(resourceUsageString())

      if 0 == comm.rank:
        self._info.log("Added elasticity integrator for material '%s'." % material.label())
    return
Esempio n. 11
0
  def finalize(self):
    """
    Cleanup after time stepping.
    """
    logEvent = "%sfinalize" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    if 0 == comm.rank:
      self._info.log("Formulation finalize.")
    self._debug.log(resourceUsageString())
    for integrator in self.integrators:
      integrator.finalize()
    for constraint in self.constraints:
      constraint.finalize()
    for output in self.output.components():
      output.close()
      output.finalize()
    self._debug.log(resourceUsageString())
    
    self._modelMemoryUse()

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 12
0
  def _setupInterfaces(self, interfaceConditions):
    """
    Setup interfaces as integrators or constraints.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    from pylith.feassemble.Constraint import implementsConstraint

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

    if 0 == comm.rank:
      self._info.log("Pre-initializing interior interfaces.")
    for ic in interfaceConditions.components():
      ic.preinitialize(self.mesh())
      foundType = False
      if implementsIntegrator(ic):
        foundType = True
        self.integrators.append(ic)
        if 0 == comm.rank:
          self._info.log("Added interface condition '%s' as an integrator." % \
                           ic.label())
      if implementsConstraint(ic):
        foundType = True
        self.constraints.append(ic)
        if 0 == comm.rank:
          self._info.log("Added interface condition '%s' as a constraint." % \
                           ic.label())
      if not foundType:
        raise TypeError, \
              "Could not determine whether interface condition '%s' is an " \
              "integrator or a constraint." % ic.name
    self._debug.log(resourceUsageString())    
    return
Esempio n. 13
0
    def preinitialize(self, problem, mesh):
        """Do minimal initialization of solution.
        """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Performing minimal initialization of solution.")

        from pylith.topology.Field import Field
        self.field = Field(mesh)
        self.field.setLabel("solution")
        spaceDim = mesh.getCoordSys().getSpaceDim()
        for subfield in self.subfields.components():
            subfield.initialize(problem.normalizer, spaceDim)
            if 0 == comm.rank:
                self._debug.log(
                    "Adding subfield '%s' as '%s' with components %s to solution."
                    % (subfield.fieldName, subfield.userAlias,
                       subfield.componentNames))
            descriptor = subfield.getTraitDescriptor("quadrature_order")
            if hasattr(descriptor.locator,
                       "source") and descriptor.locator.source == "default":
                quadOrder = problem.defaults.quadOrder
            else:
                quadOrder = subfield.quadOrder
            self.field.subfieldAdd(
                subfield.fieldName, subfield.userAlias,
                subfield.vectorFieldType, subfield.componentNames,
                subfield.scale.value, subfield.basisOrder, quadOrder,
                subfield.dimension, subfield.cellBasis,
                subfield.isBasisContinuous, subfield.feSpace)
        return
Esempio n. 14
0
  def finalize(self):
    """
    Cleanup after time stepping.
    """
    logEvent = "%sfinalize" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    if 0 == comm.rank:
      self._info.log("Formulation finalize.")
    self._debug.log(resourceUsageString())
    for integrator in self.integrators:
      integrator.finalize()
    for constraint in self.constraints:
      constraint.finalize()
    for output in self.output.components():
      output.close()
      output.finalize()
    self._debug.log(resourceUsageString())
    
    self._modelMemoryUse()

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 15
0
    def preinitialize(self, mesh):
        """
    Setup integrators for each element family (material/quadrature,
    bc/quadrature, etc.).
    """
        self._setupLogging()
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        if 0 == comm.rank:
            self._info.log("Pre-initializing problem.")
        import weakref
        self.mesh = weakref.ref(mesh)
        self.formulation.preinitialize(mesh, self.materials, self.bc,
                                       self.interfaces, self.gravityField)

        # Find fault for impulses
        found = False
        for fault in self.interfaces.components():
            if self.faultId == fault.id():
                self.source = fault
                found = True
                break
        if not found:
            raise ValueError("Could not find fault interface with id '%d' for "
                             "Green's function impulses." % self.faultId)
        return
Esempio n. 16
0
  def preinitialize(self, mesh, materials, boundaryConditions,
                    interfaceConditions, gravityField):
    """
    Create integrator for each element family.
    """
    self._setupLogging()
    logEvent = "%spreinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    self.timeStep.preinitialize()

    import weakref
    self.mesh = weakref.ref(mesh)
    self.integrators = []
    self.constraints = []
    self.gravityField = gravityField

    self.solver.preinitialize()
    self._setupMaterials(materials)
    self._setupBC(boundaryConditions)
    self._setupInterfaces(interfaceConditions)

    if 0 == comm.rank:
      self._info.log("Pre-initializing output.")
    for output in self.output.components():
      output.preinitialize()

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 17
0
  def step(self, t, dt):
    """
    Advance to next time step.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    dispIncr = self.fields.get("dispIncr(t->t+dt)")

    self._reformResidual(t+dt, dt)

    if 0 == comm.rank:
      self._info.log("Solving equations.")
    self._eventLogger.stagePush("Solve")

    residual = self.fields.get("residual")
    #self.jacobian.view() # TEMPORARY
    self.solver.solve(dispIncr, self.jacobian, residual)
    #dispIncr.view("DISP INCR") # TEMPORARY

    # DEBUGGING Verify solution makes residual 0
    #self._reformResidual(t+dt, dt)
    #residual.view("RESIDUAL")
    
    self._eventLogger.stagePop()

    return
Esempio n. 18
0
  def poststep(self, t, dt):
    """
    Hook for doing stuff after advancing time step.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    # Update displacement field from time t to time t+dt.
    dispIncr = self.fields.get("dispIncr(t->t+dt)")
    disp = self.fields.get("disp(t)")
    disp.add(dispIncr)
    dispIncr.zeroAll()

    # Complete post-step processing, then write data.
    Formulation.poststep(self, t, dt)

    # Write data. Velocity at time t will be based upon displacement
    # at time t-dt and t.
    if 0 == comm.rank:
      self._info.log("Writing solution fields.")
    for output in self.output.components():
      output.writeData(t+dt, self.fields)
    self._writeData(t+dt)

    return
Esempio n. 19
0
  def preinitialize(self, mesh):
    """
    Do pre-initialization setup.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()    

    if 0 == comm.rank:
      self._info.log("Pre-initializing fault '%s'." % self.label())
    FaultCohesive.preinitialize(self, mesh)
    Integrator.preinitialize(self, mesh)

    ModuleFaultCohesiveDyn.quadrature(self, self.faultQuadrature)

    if mesh.dimension() == 2:
      self.availableFields['vertex']['info'] += ["strike_dir"]
    elif mesh.dimension() == 3:
      self.availableFields['vertex']['info'] += ["strike_dir",
                                                 "dip_dir"]

    if not isinstance(self.tract, NullComponent):
      self.tract.preinitialize(mesh)
      self.availableFields['vertex']['info'] += self.tract.availableFields['vertex']['info']

    self.availableFields['vertex']['info'] += \
        self.friction.availableFields['vertex']['info']
    self.availableFields['vertex']['data'] += \
        self.friction.availableFields['vertex']['data']
    return
Esempio n. 20
0
  def run(self, app):
    """
    Compute Green's functions associated with fault slip.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Computing Green's functions.")
    self.checkpointTimer.toplevel = app # Set handle for saving state

    # Limit material behavior to linear regime
    for material in self.materials.components():
      material.useElasticBehavior(True)

    nimpulses = self.source.numImpulses()
    if nimpulses > 0:
      self.progressMonitor.open()
    
    ipulse = 0;
    dt = 1.0
    while ipulse < nimpulses:
      self.progressMonitor.update(ipulse, 0, nimpulses)

      self._eventLogger.stagePush("Prestep")
      if 0 == comm.rank:
        self._info.log("Main loop, impulse %d of %d." % (ipulse+1, nimpulses))
      
      # Implicit time stepping computes solution at t+dt, so set
      # t=ipulse-dt, so that t+dt corresponds to the impulse
      t = float(ipulse)-dt

      # Checkpoint if necessary
      self.checkpointTimer.update(t)

      if 0 == comm.rank:
        self._info.log("Preparing impulse %d of %d." % \
                         (ipulse+1, nimpulses))
      self.formulation.prestep(t, dt)
      self._eventLogger.stagePop()

      if 0 == comm.rank:
        self._info.log("Computing response to impulse %d of %d." %
                         (ipulse+1, nimpulses))
      self._eventLogger.stagePush("Step")
      self.formulation.step(t, dt)
      self._eventLogger.stagePop()

      if 0 == comm.rank:
        self._info.log("Finishing impulse %d of %d." % \
                         (ipulse+1, nimpulses))
      self._eventLogger.stagePush("Poststep")
      self.formulation.poststep(t, dt)
      self._eventLogger.stagePop()

      # Update time/impulse
      ipulse += 1

    self.progressMonitor.close()      
    return
Esempio n. 21
0
  def preinitialize(self, mesh):
    """
    Setup integrators for each element family (material/quadrature,
    bc/quadrature, etc.).
    """
    self._setupLogging()
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    
    if 0 == comm.rank:
      self._info.log("Pre-initializing problem.")
    import weakref
    self.mesh = weakref.ref(mesh)
    self.formulation.preinitialize(mesh, self.materials, self.bc, self.interfaces, self.gravityField)

    # Find fault for impulses
    found = False
    for fault in self.interfaces.components():
      if self.faultId == fault.id():
        self.source = fault
        found = True
        break
    if not found:
      raise ValueError("Could not find fault interface with id '%d' for "
                       "Green's function impulses." % self.faultId)
    return
Esempio n. 22
0
  def preinitialize(self, mesh, materials, boundaryConditions,
                    interfaceConditions, gravityField):
    """
    Create integrator for each element family.
    """
    self._setupLogging()
    logEvent = "%spreinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    self.timeStep.preinitialize()

    import weakref
    self.mesh = weakref.ref(mesh)
    self.integrators = []
    self.constraints = []
    self.gravityField = gravityField

    self.solver.preinitialize()
    self._setupMaterials(materials)
    self._setupBC(boundaryConditions)
    self._setupInterfaces(interfaceConditions)

    if 0 == comm.rank:
      self._info.log("Pre-initializing output.")
    for output in self.output.components():
      output.preinitialize()

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 23
0
  def main(self, *args, **kwds):
    """
    Run the application.
    """
    if self.pdbOn:
          import pdb
          pdb.set_trace()
        
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Running on %d process(es)." % comm.size)

    from pylith.utils.profiling import resourceUsageString    
    self._debug.log(resourceUsageString())

    self._setupLogging()

    # Create mesh (adjust to account for interfaces (faults) if necessary)
    self._eventLogger.stagePush("Meshing")
    interfaces = None
    if "interfaces" in dir(self.problem):
      interfaces = self.problem.interfaces.components()
    mesh = self.mesher.create(self.problem.normalizer, interfaces)
    del interfaces
    del self.mesher
    self._debug.log(resourceUsageString())
    self._eventLogger.stagePop()

    # Setup problem, verify configuration, and then initialize
    self._eventLogger.stagePush("Setup")
    self.problem.preinitialize(mesh)
    self._debug.log(resourceUsageString())

    self.problem.verifyConfiguration()

    self.problem.initialize()
    self._debug.log(resourceUsageString())

    self._eventLogger.stagePop()

    # If initializing only, stop before running problem
    if self.initializeOnly:
      return

    # Run problem
    self.problem.run(self)
    self._debug.log(resourceUsageString())

    # Cleanup
    self._eventLogger.stagePush("Finalize")
    self.problem.finalize()
    self._eventLogger.stagePop()

    self.perfLogger.logMesh('Mesh', mesh)
    self.compilePerformanceLog()
    if self.perfLogger.verbose:
      self.perfLogger.show()

    return
Esempio n. 24
0
  def _setupMaterials(self, materials):
    """
    Setup materials as integrators.
    """
    from pylith.feassemble.Integrator import implementsIntegrator
    
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Pre-initializing materials.")
    self._debug.log(resourceUsageString())
    for material in materials.components():
      integrator = self.elasticityIntegrator()
      if not implementsIntegrator(integrator):
        raise TypeError, \
              "Could not use '%s' as an integrator for material '%s'. " \
              "Functionality missing." % (integrator.name, material.label())
      integrator.preinitialize(self.mesh(), material)
      self.integrators.append(integrator)
      self._debug.log(resourceUsageString())

      if 0 == comm.rank:
        self._info.log("Added elasticity integrator for material '%s'." % material.label())
    return
Esempio n. 25
0
    def preinitialize(self, mesh):
        """
    Do pre-initialization setup.
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        if 0 == comm.rank:
            self._info.log("Pre-initializing fault '%s'." % self.label())
        FaultCohesive.preinitialize(self, mesh)
        Integrator.preinitialize(self, mesh)

        ModuleFaultCohesiveKin.quadrature(self, self.faultQuadrature)

        for eqsrc in self.eqsrcs.components():
            eqsrc.preinitialize()
        ModuleFaultCohesiveKin.eqsrcs(self,
                                      self.eqsrcs.inventory.facilityNames(),
                                      self.eqsrcs.components())

        for name in self.eqsrcs.inventory.facilityNames():
            self.availableFields['vertex']['info'] += ["final_slip_%s" % name]
            self.availableFields['vertex']['info'] += ["slip_time_%s" % name]

        if mesh.dimension() == 2:
            self.availableFields['vertex']['info'] += ["strike_dir"]
        elif mesh.dimension() == 3:
            self.availableFields['vertex']['info'] += ["strike_dir", "dip_dir"]
        return
Esempio n. 26
0
    def main(self, *args, **kwds):
        """Run the application.
        """
        if self.pdbOn:
            import pdb
            pdb.set_trace()

        # Dump parameters and version information
        self.parameters.preinitialize()
        self.parameters.write(self)

        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Running on %d process(es)." % comm.size)

        from pylith.utils.profiling import resourceUsageString
        self._debug.log(resourceUsageString())

        self._setupLogging()

        # Create mesh (adjust to account for interfaces (faults) if necessary)
        self._eventLogger.stagePush("Meshing")
        interfaces = None
        if "interfaces" in dir(self.problem):
            interfaces = self.problem.interfaces.components()
        self.mesher.preinitialize(self.problem)
        mesh = self.mesher.create(self.problem, interfaces)
        del interfaces
        self.mesher = None
        self._debug.log(resourceUsageString())
        self._eventLogger.stagePop()

        # Setup problem, verify configuration, and then initialize
        self._eventLogger.stagePush("Setup")
        self.problem.preinitialize(mesh)
        self._debug.log(resourceUsageString())

        self.problem.verifyConfiguration()

        self.problem.initialize()
        self._debug.log(resourceUsageString())

        self._eventLogger.stagePop()

        # If initializing only, stop before running problem
        if self.initializeOnly:
            return

        # Run problem
        self.problem.run(self)
        self._debug.log(resourceUsageString())

        # Cleanup
        self._eventLogger.stagePush("Finalize")
        self.problem.finalize()
        self._eventLogger.stagePop()

        return
Esempio n. 27
0
  def initialize(self, dimension, normalizer):
    """
    Initialize problem for implicit time integration.
    """
    logEvent = "%sinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    self._initialize(dimension, normalizer)

    #from pylith.utils.petsc import MemoryLogger
    #memoryLogger = MemoryLogger.singleton()
    #memoryLogger.setDebug(0)
    #memoryLogger.stagePush("Problem")

    # Allocate other fields, reusing layout from dispIncr
    if 0 == comm.rank:
      self._info.log("Creating other fields.")
    self.fields.add("velocity(t)", "velocity")
    self.fields.copyLayout("dispIncr(t->t+dt)")

    # Setup fields and set to zero
    dispT = self.fields.get("disp(t)")
    dispT.zeroAll()
    residual = self.fields.get("residual")
    residual.zeroAll()
    residual.createScatter(residual.mesh())

    lengthScale = normalizer.lengthScale()
    timeScale = normalizer.timeScale()
    velocityScale = lengthScale / timeScale
    velocityT = self.fields.get("velocity(t)")
    velocityT.scale(velocityScale.value)
    velocityT.zeroAll()

    self._debug.log(resourceUsageString())
    #memoryLogger.stagePop()

    # Allocates memory for nonzero pattern and Jacobian
    if 0 == comm.rank:
      self._info.log("Creating Jacobian matrix.")
    self._setJacobianMatrixType()
    from pylith.topology.Jacobian import Jacobian
    self.jacobian = Jacobian(self.fields.solution(),
                             self.matrixType, self.blockMatrixOkay)
    self.jacobian.zero() # TEMPORARY, to get correct memory usage
    self._debug.log(resourceUsageString())

    #memoryLogger.stagePush("Problem")
    if 0 == comm.rank:
      self._info.log("Initializing solver.")
    self.solver.initialize(self.fields, self.jacobian, self)
    self._debug.log(resourceUsageString())

    #memoryLogger.stagePop()
    #memoryLogger.setDebug(0)
    return
Esempio n. 28
0
 def finalize(self):
     """Cleanup after running problem.
     """
     from pylith.mpi.Communicator import mpi_comm_world
     comm = mpi_comm_world()
     if 0 == comm.rank:
         self._info.log("Finalizing problem.")
     return
Esempio n. 29
0
def resourceUsageString():
    """Get CPU time and memory usage as a string.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    (cputime, memory) = resourceUsage()
    return "[%d] CPU time: %s, Memory usage: %.2f MB" % \
        (comm.rank, cputime, memory)
Esempio n. 30
0
def resourceUsageString():
  """
  Get CPU time and memory usage as a string.
  """
  from pylith.mpi.Communicator import mpi_comm_world
  comm = mpi_comm_world()
  (cputime, memory) = resourceUsage()
  return "[%d] CPU time: %s, Memory usage: %.2f MB" % \
      (comm.rank, cputime, memory)
Esempio n. 31
0
    def preinitialize(self, problem):
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Performing minimal initialization of poroelasticity rheology '%s'." %
                           self.aliases[-1])

        self._createModuleObj()
        return
Esempio n. 32
0
    def initialize(self):
        """Initialize integrators and constraints.
        """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Initializing {} problem.".format(self.formulation))

        ModuleProblem.initialize(self)
        return
Esempio n. 33
0
    def write(self, mesh):
        """Write finite-element mesh.stored in Sieve mesh object.

        @param mesh 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("Writing finite-element mesh")
        ModuleMeshIO.write(self, mesh)
        return
Esempio n. 34
0
    def run(self, app):
        """Solve time dependent problem.
        """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        if 0 == comm.rank:
            self._info.log("Solving problem.")

        ModuleTimeDependent.solve(self)
        return
Esempio n. 35
0
  def write(self, mesh):
    """
    Write finite-element mesh.stored in Sieve mesh object.

    @param mesh 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("Writing finite-element mesh")
    ModuleMeshIO.write(self, mesh)
    return
Esempio n. 36
0
    def verifyConfiguration(self):
        """Verify compatibility of configuration.
        """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Verifying compatibility of problem configuration.")

        ModuleProblem.verifyConfiguration(self)

        self._printInfo()
        return
Esempio n. 37
0
  def initialize(self):
    """
    Setup integrators for each element family (material/quadrature,
    bc/quadrature, etc.).
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Initializing problem.")
    self.checkpointTimer.initialize(self.normalizer)
    self.formulation.initialize(self.dimension, self.normalizer)
    return
Esempio n. 38
0
    def initialize(self):
        """
    Setup integrators for each element family (material/quadrature,
    bc/quadrature, etc.).
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        if 0 == comm.rank:
            self._info.log("Initializing problem.")
        self.checkpointTimer.initialize(self.normalizer)
        self.formulation.initialize(self.dimension, self.normalizer)
        return
Esempio n. 39
0
    def mkpath(self, filename):
        """Create path for output file.
        """
        self._info.log("Creating path for output file '{}'".format(filename))
        relpath = os.path.dirname(filename)

        if relpath and not os.path.exists(relpath):
            # Only create directory on proc 0
            from pylith.mpi.Communicator import mpi_comm_world
            comm = mpi_comm_world()
            if not comm.rank:
                os.makedirs(relpath)
        return
Esempio n. 40
0
    def _createPath(self, filename):
        """Create path for filename if it doesn't exist.
        """
        import os
        relpath = os.path.dirname(filename)

        if len(relpath) > 0 and not os.path.exists(relpath):
            # Only create directory on proc 0
            from pylith.mpi.Communicator import mpi_comm_world
            comm = mpi_comm_world()
            if 0 == comm.rank:
                os.makedirs(relpath)
        return
Esempio n. 41
0
 def _createPath(self, filename):
     """Create path for filename if it doesn't exist.
     """
     import os
     relpath = os.path.dirname(filename)
 
     if len(relpath) > 0 and not os.path.exists(relpath):
         # Only create directory on proc 0
         from pylith.mpi.Communicator import mpi_comm_world
         comm = mpi_comm_world()
         if 0 == comm.rank:
             os.makedirs(relpath)
     return
Esempio n. 42
0
  def close(self):
    """
    Close writer.
    """
    ModuleDataWriterHDF5Ext.close(self)

    # Only write Xdmf file on proc 0
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if not comm.rank:
      from Xdmf import Xdmf
      xdmf = Xdmf()
      xdmf.write(ModuleDataWriterHDF5Ext.hdf5Filename(self), verbose=False)
    return
Esempio n. 43
0
    def close(self):
        """
    Close writer.
    """
        ModuleDataWriterHDF5.close(self)

        # Only write Xdmf file on proc 0
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if not comm.rank:
            from Xdmf import Xdmf
            xdmf = Xdmf()
            xdmf.write(ModuleDataWriterHDF5.hdf5Filename(self), verbose=False)
        return
Esempio n. 44
0
    def verifyConfiguration(self):
        """
    Verify compatibility of configuration.
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Verifying compatibility of problem configuration.")
        if self.dimension != self.mesh().dimension():
            raise ValueError, \
                  "Spatial dimension of problem is '%d' but mesh contains cells " \
                  "for spatial dimension '%d'." % \
                  (self.dimension, self.mesh().dimension())

        if self.dimension != self.mesh().coordsys().spaceDim():
            raise ValueError, \
                  "Spatial dimension of problem is '%d' but mesh coordinate system " \
                  "is  for spatial dimension '%d'." % \
                  (self.dimension, self.mesh().coordsys().spaceDim())

        # Check to make sure ids of materials and interfaces are unique
        materialIds = {}
        for material in self.materials.components():
            if material.quadrature.spaceDim() != self.dimension:
                raise ValueError, \
                      "Spatial dimension of problem is '%d' but quadrature " \
                      "for material '%s' is for spatial dimension '%d'." % \
                      (self.dimension, material.label(), material.quadrature.spaceDim())
            if material.id() in materialIds.keys():
                raise ValueError, \
                    "ID values for materials '%s' and '%s' are both '%d'. " \
                    "Material id values must be unique." % \
                    (material.label(), materialIds[material.id()], material.id())
            materialIds[material.id()] = material.label()

        for interface in self.interfaces.components():
            if interface.id() in materialIds.keys():
                raise ValueError, \
                    "ID values for material '%s' and interface '%s' are both '%d'. " \
                    "Material and interface id values must be unique." % \
                    (materialIds[interface.id()], interface.label(), interface.id())
            materialIds[interface.id()] = interface.label()

        # Check to make sure material-id for each cell matches the id of a material
        import numpy
        idValues = numpy.array(materialIds.keys(), dtype=numpy.int32)
        self.mesh().checkMaterialIds(idValues)

        return
Esempio n. 45
0
  def verifyConfiguration(self):
    """
    Verify compatibility of configuration.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Verifying compatibility of problem configuration.")
    if self.dimension != self.mesh().dimension():
      raise ValueError, \
            "Spatial dimension of problem is '%d' but mesh contains cells " \
            "for spatial dimension '%d'." % \
            (self.dimension, self.mesh().dimension())

    if self.dimension != self.mesh().coordsys().spaceDim():
      raise ValueError, \
            "Spatial dimension of problem is '%d' but mesh coordinate system " \
            "is  for spatial dimension '%d'." % \
            (self.dimension, self.mesh().coordsys().spaceDim())

    # Check to make sure ids of materials and interfaces are unique
    materialIds = {}
    for material in self.materials.components():
      if material.quadrature.spaceDim() != self.dimension:
        raise ValueError, \
              "Spatial dimension of problem is '%d' but quadrature " \
              "for material '%s' is for spatial dimension '%d'." % \
              (self.dimension, material.label(), material.quadrature.spaceDim())
      if material.id() in materialIds.keys():
        raise ValueError, \
            "ID values for materials '%s' and '%s' are both '%d'. " \
            "Material id values must be unique." % \
            (material.label(), materialIds[material.id()], material.id())
      materialIds[material.id()] = material.label()
    
    for interface in self.interfaces.components():
      if interface.id() in materialIds.keys():
        raise ValueError, \
            "ID values for material '%s' and interface '%s' are both '%d'. " \
            "Material and interface id values must be unique." % \
            (materialIds[interface.id()], interface.label(), interface.id())
      materialIds[interface.id()] = interface.label()

    # Check to make sure material-id for each cell matches the id of a material
    import numpy
    idValues = numpy.array(materialIds.keys(), dtype=numpy.int32)
    self.mesh().checkMaterialIds(idValues)

    return
Esempio n. 46
0
  def writeData(self, t, fields):
    """
    Hook for writing data at time t.
    """
    logEvent = "%swrite" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Writing material data.")
    self.output.writeData(t, fields)

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 47
0
 def preinitialize(self, mesh):
   """
   Setup integrators for each element family (material/quadrature,
   bc/quadrature, etc.).
   """
   self._setupLogging()
   from pylith.mpi.Communicator import mpi_comm_world
   comm = mpi_comm_world()
   
   if 0 == comm.rank:
     self._info.log("Pre-initializing problem.")
   import weakref
   self.mesh = weakref.ref(mesh)
   self.formulation.preinitialize(mesh, self.materials, self.bc, self.interfaces, self.gravityField)
   return
Esempio n. 48
0
    def writeData(self, t, fields):
        """
    Hook for writing data at time t.
    """
        logEvent = "%swrite" % self._loggingPrefix
        self._eventLogger.eventBegin(logEvent)

        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Writing material data.")
        self.output.writeData(t, fields)

        self._eventLogger.eventEnd(logEvent)
        return
Esempio n. 49
0
  def initialize(self, normalizer, filename):
    """
    Initialize writer.
    """

    import os
    relpath = os.path.dirname(filename)
    
    if len(relpath) > 0 and not os.path.exists(relpath):
      # Only create directory on proc 0
      from pylith.mpi.Communicator import mpi_comm_world
      comm = mpi_comm_world()
      if not comm.rank:
        os.makedirs(relpath)
    return
Esempio n. 50
0
 def preinitialize(self, mesh):
   """
   Setup integrators for each element family (material/quadrature,
   bc/quadrature, etc.).
   """
   self._setupLogging()
   from pylith.mpi.Communicator import mpi_comm_world
   comm = mpi_comm_world()
   
   if 0 == comm.rank:
     self._info.log("Pre-initializing problem.")
   import weakref
   self.mesh = weakref.ref(mesh)
   self.formulation.preinitialize(mesh, self.materials, self.bc, self.interfaces, self.gravityField)
   return
Esempio n. 51
0
    def preinitialize(self, spaceDim):
        """
    Setup quadrature object.
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Initializing reference cell.")
        cell = self.cell
        cell.initialize(spaceDim)

        if 0 == comm.rank:
            self._info.log("Initializing C++ quadrature.")
        self._initialize(cell)
        self.refGeometry(cell.geometry)
        return
Esempio n. 52
0
  def preinitialize(self, spaceDim):
    """
    Setup quadrature object.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Initializing reference cell.")
    cell = self.cell
    cell.initialize(spaceDim)

    if 0 == comm.rank:
      self._info.log("Initializing C++ quadrature.")
    self._initialize(cell)
    self.refGeometry(cell.geometry)
    return
Esempio n. 53
0
  def _reformResidual(self, t, dt):
    """
    Reform residual vector for operator.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    if 0 == comm.rank:
      self._info.log("Integrating residual term in operator.")
    self._eventLogger.stagePush("Reform Residual")

    self.updateSettings(self.jacobian, self.fields, t, dt)
    self.reformResidual()

    self._eventLogger.stagePop()
    self._debug.log(resourceUsageString())
    return
Esempio n. 54
0
    def preinitialize(self, problem):
        """Do pre-initialization setup.
        """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Pre-initializing fault '%s'." % self.label)

        FaultCohesive.preinitialize(self, problem)

        for eqsrc in self.eqRuptures.components():
            eqsrc.preinitialize()
        ModuleFaultCohesiveKin.setEqRuptures(
            self, self.eqRuptures.inventory.facilityNames(),
            self.eqRuptures.components())

        return
Esempio n. 55
0
    def step(self, t, dt):
        """
    Advance to next time step.
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()

        self._reformResidual(t, dt)

        if 0 == comm.rank:
            self._info.log("Solving equations.")

        residual = self.fields.get("residual")
        dispIncr = self.fields.get("dispIncr(t->t+dt)")
        self.solver.solve(dispIncr, self.jacobian, residual)

        return
Esempio n. 56
0
  def initialize(self, totalTime, numTimeSteps, normalizer):
    """
    Initialize material properties.
    """
    logEvent = "%sinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Initializing integrator for material '%s'." % \
                       self.materialObj.label())
    Integrator.initialize(self, totalTime, numTimeSteps, normalizer)
    self.materialObj.normalizer(normalizer)

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 57
0
  def step(self, t, dt):
    """
    Advance to next time step.
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()

    self._reformResidual(t, dt)
    
    if 0 == comm.rank:
      self._info.log("Solving equations.")

    residual = self.fields.get("residual")
    dispIncr = self.fields.get("dispIncr(t->t+dt)")
    self.solver.solve(dispIncr, self.jacobian, residual)

    return
Esempio n. 58
0
  def initialize(self, totalTime, numTimeSteps, normalizer):
    """
    Initialize cohesive elements.
    """
    logEvent = "%sinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    if 0 == comm.rank:
      self._info.log("Initializing fault '%s'." % self.label())

    Integrator.initialize(self, totalTime, numTimeSteps, normalizer)
    FaultCohesive.initialize(self, totalTime, numTimeSteps, normalizer)

    self._eventLogger.eventEnd(logEvent)
    return
Esempio n. 59
0
  def initialize(self, totalTime, numTimeSteps, normalizer):
    """
    Initialize PointForce boundary condition.
    """
    logEvent = "%sinit" % self._loggingPrefix
    self._eventLogger.eventBegin(logEvent)

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

    if 0 == comm.rank:
      self._info.log("Initializing point forces '%s'." % self.label())

    Integrator.initialize(self, totalTime, numTimeSteps, normalizer)
    BoundaryCondition.initialize(self, totalTime, numTimeSteps, normalizer)

    self._eventLogger.eventEnd(logEvent)    
    return