def test_distribute(self): """ Test distribute() """ generator = MeshGenSimple() generator.interpolate = True generator.setBoundary(generator.createCubeBoundary()) mesh = generator.create() from pylith.meshio.OutputManager import OutputManager io = OutputManager() io._configure() io.writer._configure() io.writer.filename = 'mesh.vtk' from spatialdata.geocoords.CSCart import CSCart io.coordsys = CSCart() mesh.coordsys = CSCart() self.mesh = mesh from pyre.units.time import s io.preinitialize(self) io.initialize() io.writeInfo() from pylith.topology.Distributor import Distributor distributor = Distributor() distributor.partitioner = "chaco" newMesh = distributor.distribute(mesh) self.mesh = newMesh io.writer.filename = 'newMesh.vtk' io.writeInfo() return
def _runTest(self): """ Run test. """ #filenameIn = "data/tet4.exo" #filenameIn = "tri3_200m_gradient.exo" filenameIn = "tet4_150m.exo" from pylith.perf.MemoryLogger import MemoryLogger self.logger = MemoryLogger() self.logger._configure() from pylith.utils.petsc import MemoryLogger sieveLogger = MemoryLogger.singleton() from pylith.topology.topology import MeshOps_numMaterialCells from pylith.mpi.Communicator import petsc_comm_world comm = petsc_comm_world() self._showStatus("Before reading mesh") # ------------------------------------------------------------ # Read mesh from pylith.meshio.MeshIOCubit import MeshIOCubit io = MeshIOCubit() io.inventory.filename = filenameIn io.inventory.useNames = False io._configure() from pylith.materials.ElasticIsotropic3D import ElasticIsotropic3D material = ElasticIsotropic3D() material.inventory.label = "Elastic material" material.inventory.id = 1 material._configure() mesh = io.read(debug=False, interpolate=False) self.logger.logMesh(mesh.memLoggingStage, mesh) material.ncells = MeshOps_numMaterialCells(mesh, material.id()) self.logger.logMaterial(mesh.memLoggingStage, material) self._showStatus("After reading mesh") # ------------------------------------------------------------ # Reorder mesh from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee ordering = ReverseCuthillMcKee() ordering.reorder(mesh) # Expect no memory allocation self.logger.memory["MeshReordering"] = 0 self._showStatus("After reordering mesh") # ------------------------------------------------------------ # Distribute mesh if comm.size > 1: from pylith.topology.Distributor import Distributor from spatialdata.units.Nondimensional import Nondimensional distributor = Distributor() normalizer = Nondimensional() dmesh = distributor.distribute(mesh, normalizer) dmesh.memLoggingStage = "DistributedMesh" self.logger.logMesh(mesh.memLoggingStage, mesh) material.ncells = MeshOps_numMaterialCells(mesh, material.id()) self.logger.logMaterial(mesh.memLoggingStage, material) self.logger.logMesh(dmesh.memLoggingStage, dmesh) material.ncells = MeshOps_numMaterialCells(dmesh, material.id()) self.logger.logMaterial(dmesh.memLoggingStage, material) self._showStatus("After distributing mesh") mesh = dmesh if False: # Refine mesh (if necessary) from pylith.topology.RefineUniform import RefineUniform refiner = RefineUniform() rmesh = refiner.refine(mesh) rmesh.memLoggingStage = "RefinedMesh" print "Unrefined mesh logging stage",mesh.memLoggingStage self.logger.logMesh(mesh.memLoggingStage, mesh) material.ncells = MeshOps_numMaterialCells(mesh, material.id()) self.logger.logMaterial(mesh.memLoggingStage, material) self.logger.logMesh(rmesh.memLoggingStage, rmesh) material.ncells = MeshOps_numMaterialCells(rmesh, material.id()) self.logger.logMaterial(rmesh.memLoggingStage, material) self._showStatus("After refining mesh") return