コード例 #1
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)
コード例 #2
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)
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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