Exemplo 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
Exemplo n.º 2
0
 def test_dimension(self):
   """
   Test debug().
   """
   mesh = Mesh()
   self.assertEqual(0, mesh.dimension())
   return
Exemplo n.º 3
0
 def test_dimension(self):
     """
 Test debug().
 """
     mesh = Mesh()
     self.assertEqual(0, mesh.dimension())
     return
Exemplo n.º 4
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
Exemplo n.º 5
0
 def test_coordsys(self):
     """
 Test coordsys().
 """
     mesh = self._getMesh()
     submesh = Mesh(mesh=mesh, label="bc")
     self.assertEqual(2, submesh.coordsys().spaceDim())
     return
Exemplo n.º 6
0
 def test_constructorA(self):
   """
   Test constructor.
   """
   mesh = Mesh()
   self.assertEqual(0, mesh.dimension())
   self.assertEqual(False, mesh.debug())
   return
Exemplo n.º 7
0
 def test_coordsys(self):
   """
   Test coordsys().
   """
   mesh = self._getMesh()
   submesh = Mesh(mesh=mesh, label="bc")
   self.assertEqual(2, submesh.coordsys().spaceDim())
   return
Exemplo n.º 8
0
 def test_constructorA(self):
     """
 Test constructor.
 """
     mesh = Mesh()
     self.assertEqual(0, mesh.dimension())
     self.assertEqual(False, mesh.debug())
     return
Exemplo n.º 9
0
 def test_constructorB(self):
   """
   Test constructor.
   """
   mesh = self._getMesh()
   submesh = Mesh(mesh=mesh, label="bc")
   self.assertEqual(1, submesh.dimension())
   self.assertEqual(False, mesh.debug())
   return
Exemplo n.º 10
0
  def test_dimension(self):
    """
    Test debug().
    """
    mesh = self._getMesh()
    submesh = Mesh(mesh=mesh, label="bc")

    self.assertEqual(1, submesh.dimension())
    return
Exemplo n.º 11
0
 def test_constructorB(self):
     """
 Test constructor.
 """
     dim = 2
     mesh = Mesh(dim=dim)
     self.assertEqual(dim, mesh.dimension())
     self.assertEqual(False, mesh.debug())
     return
Exemplo n.º 12
0
    def test_dimension(self):
        """
    Test debug().
    """
        mesh = self._getMesh()
        submesh = Mesh(mesh=mesh, label="bc")

        self.assertEqual(1, submesh.dimension())
        return
Exemplo n.º 13
0
 def test_constructorB(self):
   """
   Test constructor.
   """
   dim = 2
   mesh = Mesh(dim=dim)
   self.assertEqual(dim, mesh.dimension())
   self.assertEqual(False, mesh.debug())
   return
Exemplo n.º 14
0
 def test_constructorB(self):
     """
 Test constructor.
 """
     mesh = self._getMesh()
     submesh = Mesh(mesh=mesh, label="bc")
     self.assertEqual(1, submesh.dimension())
     self.assertEqual(False, mesh.debug())
     return
Exemplo n.º 15
0
 def test_comm(self):
     """
 Test comm().
 """
     from pylith.mpi.Communicator import petsc_comm_self
     mesh = Mesh(dim=3, comm=petsc_comm_self())
     comm = mesh.comm()
     self.assertEqual(0, comm.rank)
     self.assertEqual(1, comm.size)
     return
Exemplo n.º 16
0
 def test_constructorC(self):
     """
 Test constructor.
 """
     dim = 2
     from pylith.mpi.Communicator import mpi_comm_self
     mesh = Mesh(dim=dim, comm=mpi_comm_self())
     self.assertEqual(dim, mesh.dimension())
     self.assertEqual(False, mesh.debug())
     return
Exemplo n.º 17
0
 def test_comm(self):
   """
   Test comm().
   """
   from pylith.mpi.Communicator import petsc_comm_self
   mesh = Mesh(dim=3, comm=petsc_comm_self())
   comm = mesh.comm()
   self.assertEqual(0, comm.rank)
   self.assertEqual(1, comm.size)
   return
Exemplo n.º 18
0
 def test_constructorC(self):
   """
   Test constructor.
   """
   dim = 2
   from pylith.mpi.Communicator import mpi_comm_self
   mesh = Mesh(dim=dim, comm=mpi_comm_self())
   self.assertEqual(dim, mesh.dimension())
   self.assertEqual(False, mesh.debug())
   return
Exemplo n.º 19
0
  def test_debug(self):
    """
    Test debug().
    """
    mesh = Mesh()

    self.assertEqual(False, mesh.debug())

    mesh.debug(True)
    self.assertEqual(True, mesh.debug())
    return
Exemplo n.º 20
0
  def test_comm(self):
    """
    Test comm().
    """
    mesh = self._getMesh()
    submesh = Mesh(mesh=mesh, label="bc")

    comm = submesh.comm()
    self.assertEqual(0, comm.rank)
    self.assertEqual(1, comm.size)
    return
Exemplo n.º 21
0
    def test_comm(self):
        """
    Test comm().
    """
        mesh = self._getMesh()
        submesh = Mesh(mesh=mesh, label="bc")

        comm = submesh.comm()
        self.assertEqual(0, comm.rank)
        self.assertEqual(1, comm.size)
        return
Exemplo n.º 22
0
  def test_debug(self):
    """
    Test debug().
    """
    mesh = self._getMesh()
    submesh = Mesh(mesh=mesh, label="bc")

    self.assertEqual(False, submesh.debug())

    submesh.debug(True)
    self.assertEqual(True, submesh.debug())
    return
Exemplo n.º 23
0
  def test_coordsys(self):
    """
    Test coordsys().
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    mesh = Mesh()
    mesh.coordsys(cs)
    self.assertEqual(cs.spaceDim(), mesh.coordsys().spaceDim())
    return
Exemplo n.º 24
0
    def test_coordsys(self):
        """
    Test coordsys().
    """
        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        mesh = Mesh()
        mesh.coordsys(cs)
        self.assertEqual(cs.spaceDim(), mesh.coordsys().spaceDim())
        return
Exemplo n.º 25
0
    def test_timeStep(self):
        """
    Test timeStep().
    """
        tstep = self.tstep

        integrators = [Integrator(4.0), Integrator(8.0)]

        from pylith.topology.Mesh import Mesh
        mesh = Mesh()

        self.assertEqual(1.0, tstep.timeStep(mesh, integrators))

        tstep.dtN = 0.5
        self.assertEqual(0.5, tstep.timeStep(mesh, integrators))

        caught = False
        try:
            tstep.dtN = 10.0
            tstep.timeStep(mesh, integrators)
        except RuntimeError:
            caught = True
        self.failUnless(caught)

        return
Exemplo n.º 26
0
    def distribute(self, mesh, normalizer):
        """
    Distribute a Mesh
    """
        self._setupLogging()
        logEvent = "%sdistribute" % self._loggingPrefix
        self._eventLogger.eventBegin(logEvent)

        from pylith.topology.Mesh import Mesh
        newMesh = Mesh(mesh.dimension())
        if self.partitioner == "metis":
            partitionerName = "parmetis"
        else:
            partitionerName = self.partitioner
        ModuleDistributor.distribute(newMesh, mesh, partitionerName)

        #from pylith.utils.petsc import MemoryLogger
        #memoryLogger = MemoryLogger.singleton()

        #memoryLogger.stagePush(mesh.memLoggingStage)
        mesh.cleanup()
        #memoryLogger.stagePop()

        if self.writePartition:
            self.dataWriter.initialize(normalizer)
            ModuleDistributor.write(self.dataWriter, newMesh)

        self._eventLogger.eventEnd(logEvent)
        return newMesh
Exemplo n.º 27
0
 def testStableTimeStepImplicit(self):
     """
 Test stableTimeStepImplicit().
 """
     from pylith.topology.Mesh import Mesh
     mesh = Mesh()
     dt = self.material.stableTimeStepImplicit(mesh)
     from pylith.utils.utils import maxdouble
     self.assertAlmostEqual(1.0, dt / maxdouble())
Exemplo n.º 28
0
    def test_timeStep(self):
        """
    Test timeStep().
    """
        tstep = self.tstep

        tstep.adaptSkip = 2
        integrators = [Integrator(2.0), Integrator(0.5)]

        from pylith.topology.Mesh import Mesh
        mesh = Mesh()

        # Set time step
        dt = 0.5 / 2.0
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Increase stable time step, but time step should not change (skipped)
        integrators[1].dt = 0.8
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Reduce time step even if though should have skipped
        integrators[1].dt = 0.2
        dt = 0.2 / 2.0
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Skip adjusting time step
        integrators[1].dt = 0.8
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Skip adjusting time step
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Adjust time step and stability factor
        tstep.stabilityFactor = 3.0
        dt = 0.8 / 3.0
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Skip adjusting time step
        integrators[1].dt = 2.0
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Skip adjusting time step
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        # Adjust time step with value bigger than max
        dt = 0.5
        self.assertEqual(dt, tstep.timeStep(mesh, integrators))

        return
Exemplo n.º 29
0
    def test_debug(self):
        """
    Test debug().
    """
        mesh = Mesh()

        self.assertEqual(False, mesh.debug())

        mesh.debug(True)
        self.assertEqual(True, mesh.debug())
        return
Exemplo n.º 30
0
    def test_currentStep(self):
        """
    Test currentStep().
    """
        tstep = self.tstep

        integrators = [Integrator(4.0), Integrator(8.0)]

        from pylith.topology.Mesh import Mesh
        from pylith.mpi.Communicator import petsc_comm_world
        mesh = Mesh()
        #mesh.setComm(petsc_comm_world())

        tstep.timeStep(mesh, integrators)
        stepE = 1.0 / 0.5  # Nondimensionalize
        self.assertEqual(stepE, tstep.currentStep())
        return
Exemplo n.º 31
0
    def test_debug(self):
        """
    Test debug().
    """
        mesh = self._getMesh()
        submesh = Mesh(mesh=mesh, label="bc")

        self.assertEqual(False, submesh.debug())

        submesh.debug(True)
        self.assertEqual(True, submesh.debug())
        return
Exemplo n.º 32
0
    def test_currentStep(self):
        """
    Test currentStep().
    """
        tstep = self.tstep
        tstep.maxDtN = 10.0
        tstep.dtN = tstep.maxDtN

        self.assertEqual(10.0, tstep.currentStep())

        integrators = [Integrator(3.0), Integrator(2.4)]

        from pylith.topology.Mesh import Mesh
        mesh = Mesh()

        dt = 2.4 / 2.0
        tstep.timeStep(mesh, integrators)
        self.assertEqual(dt, tstep.currentStep())

        return
Exemplo n.º 33
0
    def test_timeStep(self):
        """
    Test timeStep().
    """
        tstep = self.tstep

        step1 = 1.0 / 0.5  # nondimensionalize
        step2 = 2.0 / 0.5  # nondimensionalize
        step3 = 3.0 / 0.5  # nondimensionalize

        integrators = [Integrator(40.0), Integrator(80.0)]

        from pylith.topology.Mesh import Mesh
        mesh = Mesh()

        self.assertEqual(step1, tstep.timeStep(mesh, integrators))
        self.assertEqual(step2, tstep.timeStep(mesh, integrators))
        self.assertEqual(step3, tstep.timeStep(mesh, integrators))
        self.assertEqual(step3, tstep.timeStep(mesh, integrators))
        self.assertEqual(step3, tstep.timeStep(mesh, integrators))

        tstep.index = 0
        tstep.loopSteps = True
        self.assertEqual(step1, tstep.timeStep(mesh, integrators))
        self.assertEqual(step2, tstep.timeStep(mesh, integrators))
        self.assertEqual(step3, tstep.timeStep(mesh, integrators))
        self.assertEqual(step1, tstep.timeStep(mesh, integrators))
        self.assertEqual(step2, tstep.timeStep(mesh, integrators))

        integrators = [Integrator(0.01), Integrator(8.0)]
        caught = False
        try:
            tstep.timeStep(mesh, integrators)
        except RuntimeError:
            caught = True
        self.failUnless(caught)

        return
Exemplo n.º 34
0
    def __init__(self):
        """
    Constructor.
    """
        self.availableFields = \
            {'vertex': \
               {'info': ["vertex info"],
                'data': ["vertex data 1",
                         "vertex data 2"]},
             'cell': \
               {'info': ["cell info"],
                'data': ["cell data"]}}

        filename = "data/twohex8.txt"

        from pylith.meshio.MeshIOAscii import MeshIOAscii
        iohandler = MeshIOAscii()
        iohandler.inventory.filename = filename
        from spatialdata.geocoords.CSCart import CSCart
        iohandler.inventory.coordsys = CSCart()
        iohandler._configure()

        from spatialdata.units.Nondimensional import Nondimensional
        normalizer = Nondimensional()
        normalizer._configure()
        mesh = iohandler.read(debug=False, interpolate=False)

        from pylith.topology.Mesh import Mesh
        submesh = Mesh(mesh=mesh, label="4")

        from pylith.topology.Fields import Fields
        fields = Fields(submesh)

        self.mesh = mesh
        self.submesh = submesh
        self.fields = fields
        return
Exemplo n.º 35
0
 def test_constructor(self):
     mesh = Mesh()
     field = Field(mesh)
     self.assertTrue(not field is None)
Exemplo n.º 36
0
 def test_constructor(self):
     mesh = Mesh()
     self.assertTrue(not mesh is None)