示例#1
0
 def MS_Delete(self):
     OOF.Microstructure.Create_From_ImageFile(filenames=ThreeDImagePattern(
         directory=reference_file("ms_data", "5color"),
         pattern="slice(0|([1-9][0-9]*))\\.tif",
         sort=NumericalOrder()),
                                              microstructure_name="deltest",
                                              height=20.0,
                                              width=20.0,
                                              depth=20.0)
     OOF.Image.AutoGroup(image="deltest:5color")
     OOF.Skeleton.New(
         name="skeleton",
         microstructure="deltest",
         x_elements=3,
         y_elements=3,
         z_elements=3,
         skeleton_geometry=TetraSkeleton(arrangement='moderate'))
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 1)
     OOF.Microstructure.Delete(microstructure="deltest")
     self.assertEqual(microstructure.microStructures.nActual(), 0)
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 0)
     self.assertEqual(imagecontext.imageContexts.nActual(), 0)
     self.assertEqual(cskeletonnode2.get_globalNodeCount(), 0)
     self.assertEqual(cskeletonelement.get_globalElementCount(), 0)
     self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
示例#2
0
 def Skeleton_Delete(self):
     from ooflib.engine import mesh
     from ooflib.engine import skeletoncontext
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="deltest",
         height=20.0, width=20.0)
     OOF.Image.AutoGroup(image="deltest:small.ppm")
     OOF.Skeleton.New(
         name="skeleton",
         microstructure="deltest",
         x_elements=8, y_elements=8,
         skeleton_geometry=QuadSkeleton(left_right_periodicity=False,
                                        top_bottom_periodicity=False))
     OOF.Mesh.New(name="test", skeleton="deltest:skeleton",
                  element_types=['T3_3', 'Q4_4'])
     #
     OOF.Skeleton.Delete(skeleton="deltest:skeleton")
     self.assertEqual(mesh.meshes.nActual(), 0)
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 0)
     self.assertEqual(femesh.get_globalFEMeshCount(), 0)
     self.assertEqual(cskeleton.get_globalNodeCount(), 0)
     self.assertEqual(cskeleton.get_globalElementCount(), 0)
     OOF.Microstructure.Delete(microstructure="deltest")
     self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
示例#3
0
        def checktest(self, *args, **kwargs):
            # Run the test function.
            val = func(self, *args, **kwargs)
            # After running the function, delete the microstructures.
            from ooflib.common.IO.mainmenu import OOF
            for msname in _microstructures:
                OOF.Microstructure.Delete(microstructure=msname)
            # Exceptions can hold references to data.  Since this file
            # tests for exceptions as well as memory leaks, it's
            # important to clear the exception state before checking
            # for leaks.
            sys.exc_clear()
            gc.collect()

            from ooflib.common.worker import allWorkers, allWorkerCores
            from ooflib.common.IO import whoville
            from ooflib.SWIG.common import cmicrostructure
            from ooflib.SWIG.common import threadstate
            from ooflib.SWIG.engine import cskeleton
            from ooflib.SWIG.engine import csubproblem
            from ooflib.SWIG.engine import femesh
            from ooflib.SWIG.engine import linearizedsystem

            self.assertEqual(whoville.getClass("Microstructure").nActual(), 0)
            self.assertEqual(whoville.getClass("Image").nActual(), 0)
            self.assertEqual(whoville.getClass("Skeleton").nActual(), 0)
            self.assertEqual(whoville.getClass("Mesh").nActual(), 0)
            self.assertEqual(whoville.getClass("SubProblem").nActual(), 0)
            self.assertEqual(linearizedsystem.get_globalLinSysCount(), 0)
            self.assertEqual(cmicrostructure.get_globalMicrostructureCount(),
                             0)
            self.assertEqual(femesh.get_globalFEMeshCount(), 0)
            self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0)
            self.assertEqual(cskeleton.get_globalNodeCount(), 0)
            self.assertEqual(cskeleton.get_globalElementCount(), 0)
            self.assertEqual(len(allWorkers), 0)
            ## TODO: For some reason, on some systems there is
            ## occasionally a leftover WorkerCore when this check is
            ## run.  It doesn't seem to have any references,
            ## though... Since there are no extra ThreadStates, we're
            ## ignoring the leftover WorkerCore for now.
            #             if len(allWorkerCores) > 0:
            #                 from ooflib.common import debug
            #                 debug.set_debug_mode()
            #                 print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\
            #                     "id=", id(allWorkerCores.keys()[0])
            #                 debug.dumpReferrers(allWorkerCores.keys()[0], 2)
            #             self.assertEqual(len(allWorkerCores), 0)

            # The main thread still exists, but all subthreads should
            # have finished.
            self.assertEqual(threadstate.nThreadStates(), 1)
            print >> sys.stderr, "Memory leak check passed."
            return val
示例#4
0
文件: generics.py 项目: song2001/OOF2
def objectInventory(microstructures=0, nodes=0, elements=0, meshes=0):
    counts = (cmicrostructure.get_globalMicrostructureCount(),
              cskeleton.get_globalNodeCount(),
              cskeleton.get_globalElementCount(),
              femesh.get_globalFEMeshCount())
    expected = (microstructures, nodes, elements, meshes)
    if counts != expected:
        print >> sys.stderr, \
            "objectInventory failed. Expected (micro, nodes, elems, meshes) =",\
            expected, "Got", counts
    return counts == expected
示例#5
0
def objectInventory(microstructures=0, nodes=0, elements=0, meshes=0):
    counts = (cmicrostructure.get_globalMicrostructureCount(),
              cskeleton.get_globalNodeCount(),
              cskeleton.get_globalElementCount(),
              femesh.get_globalFEMeshCount())
    expected = (microstructures, nodes, elements, meshes)
    if counts != expected:
        print >> sys.stderr, \
            "objectInventory failed. Expected (micro, nodes, elems, meshes) =",\
            expected, "Got", counts
    return counts == expected
示例#6
0
        def checktest(self, *args, **kwargs):
            # Run the test function.
            val = func(self, *args, **kwargs)
            # After running the function, delete the microstructures.
            from ooflib.common.IO.mainmenu import OOF
            for msname in _microstructures:
                OOF.Microstructure.Delete(microstructure=msname)
            # Exceptions can hold references to data.  Since this file
            # tests for exceptions as well as memory leaks, it's
            # important to clear the exception state before checking
            # for leaks.
            sys.exc_clear()
            gc.collect()

            from ooflib.common.worker import allWorkers, allWorkerCores
            from ooflib.common.IO import whoville
            from ooflib.SWIG.common import cmicrostructure
            from ooflib.SWIG.common import threadstate
            from ooflib.SWIG.engine import cskeleton
            from ooflib.SWIG.engine import csubproblem
            from ooflib.SWIG.engine import femesh
            from ooflib.SWIG.engine import linearizedsystem

            self.assertEqual(whoville.getClass("Microstructure").nActual(), 0)
            self.assertEqual(whoville.getClass("Image").nActual(), 0)
            self.assertEqual(whoville.getClass("Skeleton").nActual(), 0)
            self.assertEqual(whoville.getClass("Mesh").nActual(), 0)
            self.assertEqual(whoville.getClass("SubProblem").nActual(), 0)
            self.assertEqual(linearizedsystem.get_globalLinSysCount(),0)
            self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
            self.assertEqual(femesh.get_globalFEMeshCount(), 0)
            self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0)
            self.assertEqual(cskeleton.get_globalNodeCount(), 0)
            self.assertEqual(cskeleton.get_globalElementCount(), 0)
            self.assertEqual(len(allWorkers), 0)
            ## TODO: For some reason, on some systems there is
            ## occasionally a leftover WorkerCore when this check is
            ## run.  It doesn't seem to have any references,
            ## though... Since there are no extra ThreadStates, we're
            ## ignoring the leftover WorkerCore for now.
#             if len(allWorkerCores) > 0:
#                 from ooflib.common import debug
#                 debug.set_debug_mode()
#                 print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\
#                     "id=", id(allWorkerCores.keys()[0])
#                 debug.dumpReferrers(allWorkerCores.keys()[0], 2)
#             self.assertEqual(len(allWorkerCores), 0)

            # The main thread still exists, but all subthreads should
            # have finished.
            self.assertEqual(threadstate.nThreadStates(), 1)
            print >> sys.stderr, "Memory leak check passed."
            return val
示例#7
0
 def Delete(self):
     ms_count=microstructure.microStructures.nActual()
     self.assertEqual(ms_count,1)
     self.assertRaises(KeyError,
                       OOF.Microstructure.Delete, microstructure="two")
     ms_count=microstructure.microStructures.nActual()
     self.assertEqual(ms_count,1)
     OOF.Microstructure.Delete(microstructure="one")
     labeltree_count=microstructure.microStructures.members.__len__()
     ms_and_proxies=microstructure.microStructures.nmembers
     # There should only be the proxy left.
     self.assertEqual(ms_and_proxies,2)
     # The labeltree object's len function counts the root and the proxy.
     self.assertEqual(labeltree_count,3)
     ms_count=microstructure.microStructures.nActual()
     # There should be no non-proxy objects.
     self.assertEqual(ms_count,0)
     self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
示例#8
0
 def Delete(self):
     ms_count = microstructure.microStructures.nActual()
     self.assertEqual(ms_count, 1)
     self.assertRaises(KeyError,
                       OOF.Microstructure.Delete,
                       microstructure="two")
     ms_count = microstructure.microStructures.nActual()
     self.assertEqual(ms_count, 1)
     OOF.Microstructure.Delete(microstructure="one")
     labeltree_count = microstructure.microStructures.members.__len__()
     ms_and_proxies = microstructure.microStructures.nmembers
     # There should only be the proxy left.
     self.assertEqual(ms_and_proxies, 2)
     # The labeltree object's len function counts the root and the proxy.
     self.assertEqual(labeltree_count, 3)
     ms_count = microstructure.microStructures.nActual()
     # There should be no non-proxy objects.
     self.assertEqual(ms_count, 0)
     self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
示例#9
0
 def MS_Delete(self):
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="deltest",
         height=20.0, width=20.0)
     OOF.Image.AutoGroup(image="deltest:small.ppm")
     OOF.Skeleton.New(
         name="skeleton", microstructure="deltest",
         x_elements=8, y_elements=8,
         skeleton_geometry=QuadSkeleton(left_right_periodicity=True,
                                        top_bottom_periodicity=True))
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 1)
     OOF.Microstructure.Delete(microstructure="deltest")
     self.assertEqual(microstructure.microStructures.nActual(), 0)
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 0)
     self.assertEqual(imagecontext.imageContexts.nActual(), 0)
     self.assertEqual(cskeleton.get_globalNodeCount(), 0)
     self.assertEqual(cskeleton.get_globalElementCount(), 0)
     self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)