def test_filename(self): """ Test filename(). """ value = "hi.txt" io = MeshIOCubit() io.filename(value) self.assertEqual(value, io.filename()) return
def test_readwrite(self): """ Test read(). """ filenameIn = "data/twohex8.exo" filenameOut = "data/twohex8_test.txt" filenameE = "data/twohex8.txt" from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs._configure() # For now, we only test reading the file. io = MeshIOCubit() io.inventory.filename = filenameIn io.inventory.useNames = False io._configure() from spatialdata.units.Nondimensional import Nondimensional normalizer = Nondimensional() mesh = io.read(debug=False, interpolate=False) testhandler = MeshIOAscii() testhandler.filename(filenameOut) testhandler.coordsys = cs testhandler.write(mesh) fileE = open(filenameE, "r") linesE = fileE.readlines() fileE.close() fileT = open(filenameOut, "r") linesT = fileT.readlines() fileT.close() self.assertEqual(len(linesE), len(linesT)) for (lineE, lineT) in zip(linesE, linesT): self.assertEqual(lineE, lineT) return
def test_readwrite(self): """ Test read(). """ filenameIn = "data/twohex8.exo" filenameOut = "data/twohex8_test.txt" filenameE = "data/twohex8.txt" from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs._configure() # For now, we only test reading the file. io = MeshIOCubit() io.inventory.filename = filenameIn io.inventory.useNames = False io._configure() from spatialdata.units.Nondimensional import Nondimensional normalizer = Nondimensional() mesh = io.read(debug=False, interpolate=True) testhandler = MeshIOAscii() testhandler.filename(filenameOut) testhandler.coordsys = cs testhandler.write(mesh) fileE = open(filenameE, "r") linesE = fileE.readlines() fileE.close() fileT = open(filenameOut, "r") linesT = fileT.readlines() fileT.close() self.assertEqual(len(linesE), len(linesT)) for (lineE, lineT) in zip(linesE, linesT): self.assertEqual(lineE, lineT) return
#!/usr/bin/env nemesis import sys if len(sys.argv) != 2: raise ValueError("usage: exotoascii.py EXODUS_MESH") filenameEXO = sys.argv[1] filenameASCII = filenameEXO.replace(".exo", ".mesh") from pylith.meshio.MeshIOAscii import MeshIOAscii from pylith.meshio.MeshIOCubit import MeshIOCubit import pylith.utils.petsc as petsc petsc.initialize(sys.argv) cubit = MeshIOCubit() cubit.inventory.filename = filenameEXO cubit._configure() mesh = cubit.read(debug=False, interpolate=True) ascii = MeshIOAscii() ascii.inventory.filename = filenameASCII ascii._configure() ascii.write(mesh) del cubit del ascii del mesh petsc.finalize()
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
def test_constructor(self): """ Test constructor. """ io = MeshIOCubit() return