def test_integrateJacobian(self):
    """
    Test integrateJacobian().

    WARNING: This is not a rigorous test of integrateJacobian()
    because we neither set the input fields or verify the results.
    """
    (mesh, integrator) = self._preinitialize()
    fields = self._initialize(mesh, integrator)

    from pylith.topology.Field import Field
    jacobian = Field(mesh)
    spaceDim = mesh.coordsys().spaceDim()
    jacobian.subfieldAdd("displacement", spaceDim, jacobian.VECTOR);
    jacobian.subfieldAdd("lagrange_multiplier", spaceDim, jacobian.VECTOR);

    jacobian.subfieldsSetup();
    jacobian.setupSolnChart();
    jacobian.setupSolnDof(spaceDim);
    jacobian.allocate();
    jacobian.zeroAll();

    t = 7.3
    self.assertEqual(True, integrator.needNewJacobian())
    integrator.integrateJacobian(jacobian, t, fields)
    self.assertEqual(False, integrator.needNewJacobian())
    
    # No test of result.
    return
Example #2
0
  def test_integrateJacobian(self):
    """
    Test integrateJacobian().

    WARNING: This is not a rigorous test of integrateJacobian()
    because we neither set the input fields or verify the results.
    """
    (mesh, integrator) = self._preinitialize()
    fields = self._initialize(mesh, integrator)

    from pylith.topology.Field import Field
    jacobian = Field(mesh)
    spaceDim = mesh.coordsys().spaceDim()
    jacobian.subfieldAdd("displacement", spaceDim, jacobian.VECTOR);
    jacobian.subfieldAdd("lagrange_multiplier", spaceDim, jacobian.VECTOR);

    jacobian.subfieldsSetup();
    jacobian.setupSolnChart();
    jacobian.setupSolnDof(spaceDim);
    jacobian.allocate();
    jacobian.zeroAll();

    t = 7.3
    self.assertEqual(True, integrator.needNewJacobian())
    integrator.integrateJacobian(jacobian, t, fields)
    self.assertEqual(False, integrator.needNewJacobian())
    
    # No test of result.
    return
Example #3
0
  def initialize(self, dimension, normalizer):
    """
    Initialize problem for explicit 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("disp(t-dt)", "displacement")
    self.fields.add("velocity(t)", "velocity")
    self.fields.add("acceleration(t)", "acceleration")
    self.fields.copyLayout("dispIncr(t->t+dt)")
    self._debug.log(resourceUsageString())

    # Setup fields and set to zero
    dispTmdt = self.fields.get("disp(t-dt)")
    dispTmdt.zeroAll()
    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()

    accelerationScale = velocityScale / timeScale
    accelerationT = self.fields.get("acceleration(t)")
    accelerationT.scale(accelerationScale.value)
    accelerationT.zeroAll()

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

    if 0 == comm.rank:
      self._info.log("Creating lumped Jacobian matrix.")
    from pylith.topology.Field import Field
    jacobian = Field(self.mesh())
    jacobian.label("jacobian")

    # Setup section manually. Cloning the solution field includes
    # constraints which messes up the solve for constrained DOF.
    pressureScale = normalizer.pressureScale()
    jacobian.subfieldAdd("displacement", dimension, jacobian.VECTOR, lengthScale.value)
    jacobian.subfieldAdd("lagrange_multiplier", dimension, jacobian.VECTOR, pressureScale.value)
    jacobian.subfieldsSetup()
    jacobian.setupSolnChart()
    jacobian.setupSolnDof(dimension)
    # Loop over integrators to adjust DOF layout
    for integrator in self.integrators:
      integrator.setupSolnDof(jacobian)
    jacobian.vectorFieldType(jacobian.VECTOR)
    jacobian.allocate()
    jacobian.zeroAll()
    self.jacobian = jacobian
    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)
    self._eventLogger.eventEnd(logEvent)
    return
Example #4
0
    def initialize(self, dimension, normalizer):
        """
    Initialize problem for explicit 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("disp(t-dt)", "displacement")
        self.fields.add("velocity(t)", "velocity")
        self.fields.add("acceleration(t)", "acceleration")
        self.fields.copyLayout("dispIncr(t->t+dt)")
        self._debug.log(resourceUsageString())

        # Setup fields and set to zero
        dispTmdt = self.fields.get("disp(t-dt)")
        dispTmdt.zeroAll()
        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()

        accelerationScale = velocityScale / timeScale
        accelerationT = self.fields.get("acceleration(t)")
        accelerationT.scale(accelerationScale.value)
        accelerationT.zeroAll()

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

        if 0 == comm.rank:
            self._info.log("Creating lumped Jacobian matrix.")
        from pylith.topology.Field import Field
        jacobian = Field(self.mesh())
        jacobian.label("jacobian")

        # Setup section manually. Cloning the solution field includes
        # constraints which messes up the solve for constrained DOF.
        pressureScale = normalizer.pressureScale()
        jacobian.subfieldAdd("displacement", dimension, jacobian.VECTOR,
                             lengthScale.value)
        jacobian.subfieldAdd("lagrange_multiplier", dimension, jacobian.VECTOR,
                             pressureScale.value)
        jacobian.subfieldsSetup()
        jacobian.setupSolnChart()
        jacobian.setupSolnDof(dimension)
        # Loop over integrators to adjust DOF layout
        for integrator in self.integrators:
            integrator.setupSolnDof(jacobian)
        jacobian.vectorFieldType(jacobian.VECTOR)
        jacobian.allocate()
        jacobian.zeroAll()
        self.jacobian = jacobian
        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)
        self._eventLogger.eventEnd(logEvent)
        return