コード例 #1
0
ファイル: Solution.py プロジェクト: thearagon/pylith
    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
コード例 #2
0
    def test_cloneSectionField(self):
        """
    Test newSection(field).
    """
        fieldB = Field(self.mesh)
        fieldB.cloneSection(self.field)

        # No test of result
        return
コード例 #3
0
ファイル: TestMeshField.py プロジェクト: rishabhdutta/pylith
  def test_cloneSectionField(self):
    """
    Test newSection(field).
    """
    fieldB = Field(self.mesh)
    fieldB.cloneSection(self.field)

    # No test of result
    return
コード例 #4
0
ファイル: TestMeshField.py プロジェクト: rishabhdutta/pylith
  def test_operatorAdd(self):
    """
    Test add().
    """
    fieldB = Field(self.mesh)
    fieldB.allocate()
    self.field.add(fieldB)

    # No test of result
    return
コード例 #5
0
ファイル: TestMeshField.py プロジェクト: rishabhdutta/pylith
  def test_copy(self):
    """
    Test newSection(field).
    """
    fieldB = Field(self.mesh)
    fieldB.allocate()
    fieldB.copy(self.field)

    # No test of result
    return
コード例 #6
0
    def test_operatorAdd(self):
        """
    Test add().
    """
        fieldB = Field(self.mesh)
        fieldB.allocate()
        self.field.add(fieldB)

        # No test of result
        return
コード例 #7
0
  def _initialize(self):
    """
    Initialize DirichletBoundary boundary condition.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    db = SimpleDB()
    db.inventory.label = "TestDirichletBoundary tri3"
    db.inventory.iohandler.inventory.filename = "data/tri3_disp.spatialdb"
    db.inventory.iohandler._configure()
    db._configure()

    from spatialdata.spatialdb.SimpleDB import SimpleDB
    dbRate = SimpleDB()
    dbRate.inventory.label = "TestDirichletBoundary tri3"
    dbRate.inventory.iohandler.inventory.filename = "data/tri3_vel.spatialdb"
    dbRate.inventory.iohandler._configure()
    dbRate._configure()

    from pylith.bc.DirichletBoundary import DirichletBoundary
    bc = DirichletBoundary()
    bc.inventory.output._configure()
    bc.inventory.output.writer._configure()
    bc.inventory.label = "bc"
    bc.inventory.bcDOF = [1]
    bc.inventory.dbInitial = db
    bc.inventory.dbRate = dbRate
    bc._configure()

    bc.preinitialize(mesh)
    bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)

    # Setup field
    from pylith.topology.Field import Field
    field = Field(mesh)
    field.newSection(field.VERTICES_FIELD, cs.spaceDim())
    
    return (mesh, bc, field)
コード例 #8
0
ファイル: TestDirichletBoundary.py プロジェクト: jjle/pylith
  def _initialize(self):
    """
    Initialize DirichletBoundary boundary condition.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    db = SimpleDB()
    db.inventory.label = "TestDirichletBoundary tri3"
    db.inventory.iohandler.inventory.filename = "data/tri3_disp.spatialdb"
    db.inventory.iohandler._configure()
    db._configure()

    from spatialdata.spatialdb.SimpleDB import SimpleDB
    dbRate = SimpleDB()
    dbRate.inventory.label = "TestDirichletBoundary tri3"
    dbRate.inventory.iohandler.inventory.filename = "data/tri3_vel.spatialdb"
    dbRate.inventory.iohandler._configure()
    dbRate._configure()

    from pylith.bc.DirichletBoundary import DirichletBoundary
    bc = DirichletBoundary()
    bc.inventory.output._configure()
    bc.inventory.output.writer._configure()
    bc.inventory.label = "bc"
    bc.inventory.bcDOF = [1]
    bc.inventory.dbInitial = db
    bc.inventory.dbRate = dbRate
    bc._configure()

    bc.preinitialize(mesh)
    bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)

    # Setup field
    from pylith.topology.Field import Field
    field = Field(mesh)
    field.newSection(field.VERTICES_FIELD, cs.spaceDim())
    
    return (mesh, bc, field)
コード例 #9
0
ファイル: TestMeshField.py プロジェクト: jjle/pylith
    def setUp(self):
        """
    Setup mesh and associated field.
    """
        from spatialdata.geocoords.CSCart import CSCart

        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        from spatialdata.units.Nondimensional import Nondimensional

        normalizer = Nondimensional()
        normalizer._configure()

        from pylith.meshio.MeshIOAscii import MeshIOAscii

        importer = MeshIOAscii()
        importer.inventory.filename = "data/tri3.mesh"
        importer.inventory.coordsys = cs
        importer._configure()
        self.mesh = importer.read(debug=False, interpolate=False)

        self.field = Field(self.mesh)
        self.field.allocate()
        return
コード例 #10
0
    def setUp(self):
        """
    Setup mesh and associated field.
    """
        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        from spatialdata.units.Nondimensional import Nondimensional
        normalizer = Nondimensional()
        normalizer._configure()

        from pylith.meshio.MeshIOAscii import MeshIOAscii
        importer = MeshIOAscii()
        importer.inventory.filename = "data/tri3.mesh"
        importer.inventory.coordsys = cs
        importer._configure()
        self.mesh = importer.read(debug=False, interpolate=False)

        self.field = Field(self.mesh)
        self.field.allocate()
        return
コード例 #11
0
    def test_copy(self):
        """
    Test newSection(field).
    """
        fieldB = Field(self.mesh)
        fieldB.allocate()
        fieldB.copy(self.field)

        # No test of result
        return
コード例 #12
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)
    jacobian.newSection(jacobian.VERTICES_FIELD, mesh.coordsys().spaceDim())
    jacobian.allocate()
    jacobian.zero()

    t = 7.3
    self.assertEqual(True, integrator.needNewJacobian())
    integrator.integrateJacobian(jacobian, t, fields)
    self.assertEqual(False, integrator.needNewJacobian())
    
    # No test of result.
    return
コード例 #13
0
ファイル: TestMeshField.py プロジェクト: rishabhdutta/pylith
class TestMeshField(unittest.TestCase):
  """
  Unit testing of Field object.
  """

  def setUp(self):
    """
    Setup mesh and associated field.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()    

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    self.mesh = importer.read(debug=False, interpolate=False)
    
    self.field = Field(self.mesh)
    self.field.allocate()
    return


  def test_constructorA(self):
    """
    Test constructor.
    """
    return


  def test_mesh(self):
    """
    Test mesh().
    """
    mesh = self.field.mesh()
    
    self.assertEqual(2, mesh.dimension())
    return


  def test_label(self):
    """
    Test label().
    """
    label = "field A"

    self.field.label(label)
    self.assertEqual(label, self.field.label())
    return


  def test_vectorFieldType(self):
    """
    Test vectorFieldType().
    """
    fieldType = Field.MULTI_SCALAR

    self.field.vectorFieldType(fieldType)
    self.assertEqual(fieldType, self.field.vectorFieldType())
    return


  def test_scale(self):
    """
    Test scale().
    """
    scale = 2.0

    self.field.scale(scale)
    self.assertEqual(scale, self.field.scale())
    return


  def test_dimensionalizeOkay(self):
    """
    Test dimensionalizeOkay().
    """
    self.assertEqual(False, self.field.dimensionalizeOkay())

    self.field.dimensionalizeOkay(True)
    self.assertEqual(True, self.field.dimensionalizeOkay())
    return


  def test_spaceDim(self):
    """
    Test spaceDim().
    """
    self.assertEqual(2, self.field.spaceDim())
    return


  def test_newSectionDomain(self):
    """
    Test newSection(domain).
    """
    self.field.newSection(Field.VERTICES_FIELD, 4)

    # No test of result
    return


  def test_cloneSectionField(self):
    """
    Test newSection(field).
    """
    fieldB = Field(self.mesh)
    fieldB.cloneSection(self.field)

    # No test of result
    return

  def test_operatorAdd(self):
    """
    Test add().
    """
    fieldB = Field(self.mesh)
    fieldB.allocate()
    self.field.add(fieldB)

    # No test of result
    return


  def test_copy(self):
    """
    Test newSection(field).
    """
    fieldB = Field(self.mesh)
    fieldB.allocate()
    fieldB.copy(self.field)

    # No test of result
    return
コード例 #14
0
ファイル: TestField.py プロジェクト: thearagon/pylith
 def test_constructor(self):
     mesh = Mesh()
     field = Field(mesh)
     self.assertTrue(not field is None)
コード例 #15
0
ファイル: Explicit.py プロジェクト: jjle/pylith
  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.newSection(jacobian.VERTICES_FIELD, dimension)
    jacobian.allocate()
    jacobian.label("jacobian")
    jacobian.vectorFieldType(jacobian.VECTOR)
    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
コード例 #16
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
コード例 #17
0
ファイル: Solution.py プロジェクト: thearagon/pylith
class Solution(PetscComponent):
    """Python abstract base class for solution field for problem.

    FACTORY: solution.
    """

    import pythia.pyre.inventory

    from .SolnDisp import SolnDisp
    from .SolutionSubfield import subfieldFactory
    subfields = pythia.pyre.inventory.facilityArray(
        "subfields",
        family="soln_subfields",
        itemFactory=subfieldFactory,
        factory=SolnDisp)
    subfields.meta['tip'] = "Subfields in solution."

    # PUBLIC METHODS /////////////////////////////////////////////////////

    def __init__(self, name="solution"):
        """Constructor.
        """
        PetscComponent.__init__(self, name, facility="solution")
        self.field = None
        return

    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

    # PRIVATE METHODS ////////////////////////////////////////////////////

    def _configure(self):
        """Set members based using inventory.
        """
        PetscComponent._configure(self)
        return

    def _cleanup(self):
        if self.field:
            self.field.deallocate()
        return
コード例 #18
0
ファイル: Explicit.py プロジェクト: geodynamics/pylith
  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
コード例 #19
0
class TestMeshField(unittest.TestCase):
    """
  Unit testing of Field object.
  """
    def setUp(self):
        """
    Setup mesh and associated field.
    """
        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        from spatialdata.units.Nondimensional import Nondimensional
        normalizer = Nondimensional()
        normalizer._configure()

        from pylith.meshio.MeshIOAscii import MeshIOAscii
        importer = MeshIOAscii()
        importer.inventory.filename = "data/tri3.mesh"
        importer.inventory.coordsys = cs
        importer._configure()
        self.mesh = importer.read(debug=False, interpolate=False)

        self.field = Field(self.mesh)
        self.field.allocate()
        return

    def test_constructorA(self):
        """
    Test constructor.
    """
        return

    def test_mesh(self):
        """
    Test mesh().
    """
        mesh = self.field.mesh()

        self.assertEqual(2, mesh.dimension())
        return

    def test_label(self):
        """
    Test label().
    """
        label = "field A"

        self.field.label(label)
        self.assertEqual(label, self.field.label())
        return

    def test_vectorFieldType(self):
        """
    Test vectorFieldType().
    """
        fieldType = Field.MULTI_SCALAR

        self.field.vectorFieldType(fieldType)
        self.assertEqual(fieldType, self.field.vectorFieldType())
        return

    def test_scale(self):
        """
    Test scale().
    """
        scale = 2.0

        self.field.scale(scale)
        self.assertEqual(scale, self.field.scale())
        return

    def test_dimensionalizeOkay(self):
        """
    Test dimensionalizeOkay().
    """
        self.assertEqual(False, self.field.dimensionalizeOkay())

        self.field.dimensionalizeOkay(True)
        self.assertEqual(True, self.field.dimensionalizeOkay())
        return

    def test_spaceDim(self):
        """
    Test spaceDim().
    """
        self.assertEqual(2, self.field.spaceDim())
        return

    def test_newSectionDomain(self):
        """
    Test newSection(domain).
    """
        self.field.newSection(Field.VERTICES_FIELD, 4)

        # No test of result
        return

    def test_cloneSectionField(self):
        """
    Test newSection(field).
    """
        fieldB = Field(self.mesh)
        fieldB.cloneSection(self.field)

        # No test of result
        return

    def test_operatorAdd(self):
        """
    Test add().
    """
        fieldB = Field(self.mesh)
        fieldB.allocate()
        self.field.add(fieldB)

        # No test of result
        return

    def test_copy(self):
        """
    Test newSection(field).
    """
        fieldB = Field(self.mesh)
        fieldB.allocate()
        fieldB.copy(self.field)

        # No test of result
        return
コード例 #20
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
コード例 #21
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