コード例 #1
0
    def doModify(self, registration, startfile, compfile, kwargs):
        import os, random
        from ooflib.SWIG.common import crandom

        # Loaded skeleton must be named "modtest".
        OOF.File.Load.Data(filename=reference_file("skeleton_data", startfile))
        mod = registration(**kwargs)
        random.seed(17)
        crandom.rndmseed(17)
        OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
        skelc = skeletoncontext.skeletonContexts["skeltest:modtest"]
        self.assert_(skelc.getObject().sanity_check())
        # Saving and reloading the Skeleton guarantees that node
        # indices match up with the reference skeleton.  Nodes are
        # re-indexed when a skeleton is saved.
        OOF.File.Save.Skeleton(filename="skeleton_mod_test", mode="w", format="ascii", skeleton="skeltest:modtest")
        OOF.Skeleton.Delete(skeleton="skeltest:modtest")
        OOF.File.Load.Data(filename="skeleton_mod_test")
        # Saved skeleton is named "skelcomp:reference".
        OOF.File.Load.Data(filename=reference_file("skeleton_data", compfile))
        sk1 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
        sk2 = skeletoncontext.skeletonContexts["skelcomp:reference"].getObject()
        # Tolerance is 1.0e-13, 100x double-precision noise.
        self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
        os.remove("skeleton_mod_test")
        OOF.Skeleton.Delete(skeleton="skeltest:modtest")
        OOF.Skeleton.Delete(skeleton="skelcomp:reference")
        OOF.Microstructure.Delete(microstructure="skelcomp")
コード例 #2
0
 def Create_From_ImageFile(self):
     from ooflib.SWIG.image import oofimage
     from ooflib.common import primitives
     from ooflib.SWIG.common.IO import stringimage
     self.assertRaises(
         oofimage.ImageMagickError, 
         OOF.Microstructure.Create_From_ImageFile,
         filename="nosuchfile", microstructure_name="nosuchfile",
         height=automatic, width=automatic)
     self.assertRaises(
         ooferror.ErrUserError,
         OOF.Microstructure.Create_From_ImageFile,
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="oops",
         height=-1.0, width=-1.0)
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="small.ms",
         height=20.0, width=20.0)
     ms = getMicrostructure("small.ms")
     self.assertEqual(ms.size(), primitives.Point(20.0, 20.0))
     self.assertEqual(ms.sizeInPixels(), primitives.iPoint(150,150))
     self.assertEqual(ms.sizeOfPixels(), (20.0/150, 20.0/150))
     ms_images = ms.imageNames()
     self.assertEqual(len(ms_images), 1)
     self.assert_("small.ppm" in ms_images)
     img = oofimage.getImage("small.ms:small.ppm")
     strimg = stringimage.StringImage(ms.sizeInPixels(), ms.size())
     img.fillstringimage(strimg)
     outfile = file('hexstringimage.dat','w')
     print >> outfile, strimg.hexstringimage()
     outfile.close()
     assert filecmp.cmp('hexstringimage.dat',
                        reference_file('ms_data','smallppm.hex'))
     os.remove("hexstringimage.dat")
コード例 #3
0
ファイル: image_test.py プロジェクト: shkeshavarz/OOF2
    def Save(self):
        import filecmp, os

        OOF.Microstructure.Create_From_ImageFile(
            filename=reference_file("ms_data", "rectangle.ppm"),
            microstructure_name="save_test",
            height=automatic,
            width=automatic,
        )
        OOF.File.Save.Image(filename="image_save_test", image="save_test:rectangle.ppm")
        self.assert_(filecmp.cmp("image_save_test", reference_file("image_data", "saved_rectangle")))
        os.remove("image_save_test")
コード例 #4
0
def compare_mesh(meshpath, filename, tolerance):
    microname, relativemeshpath = string.split(meshpath, ':', 1)
    referencemeshpath = "reference:" + relativemeshpath
    datafile = reference_file("mesh_data", filename)
    if generate and not os.path.exists(datafile):
        OOF.Microstructure.Rename(microstructure=microname, name="reference")
        OOF.File.Save.Mesh(filename=datafile,
                           mode="w",
                           format="ascii",
                           mesh=referencemeshpath)
        OOF.Microstructure.Rename(microstructure="reference", name=microname)
        return 0
    else:
        OOF.File.Load.Data(filename=datafile)
        mesh1 = mesh.meshes[meshpath]
        mesh2 = mesh.meshes[referencemeshpath]
        result = mesh1.compare(mesh2, tolerance)
        OOF.Microstructure.Delete(microstructure="reference")
        if result != 0:
            print >> sys.stderr, ("Mesh comparison failed.  Saving mesh as"
                                  " subproblem_test_extra_failed.mesh")
            OOF.File.Save.Mesh(filename='subproblem_test_extra_failed.mesh',
                               mode="w",
                               format='ascii',
                               mesh=meshpath)
        return result
コード例 #5
0
ファイル: skeleton_bdy_test.py プロジェクト: song2001/OOF2
    def setUp(self):
        global skeletoncontext
        from ooflib.engine import skeletoncontext
        global cskeleton
        from ooflib.SWIG.engine import cskeleton
        global cmicrostructure
        from ooflib.SWIG.common import cmicrostructure
        OOF.Microstructure.Create_From_ImageFile(
            filename=reference_file("ms_data", "small.ppm"),
            microstructure_name="skeltest",
            height=20.0,
            width=20.0)
        OOF.Image.AutoGroup(image="skeltest:small.ppm")
        global gfxmanager
        from ooflib.common.IO import gfxmanager
        OOF.Skeleton.New(name="bdytest",
                         microstructure="skeltest",
                         x_elements=8,
                         y_elements=8,
                         skeleton_geometry=QuadSkeleton(
                             top_bottom_periodicity=False,
                             left_right_periodicity=False))

        # Need a graphics window so we can do the direct selection.
        OOF.Windows.Graphics.New()
        self.sk_context = skeletoncontext.skeletonContexts["skeltest:bdytest"]
コード例 #6
0
    def setUp(self):
        global skeletoncontext
        from ooflib.engine import skeletoncontext
        OOF.Microstructure.Create_From_ImageFile(
            filename=reference_file("ms_data", "small.ppm"),
            microstructure_name="skeltest",
            height=20.0,
            width=20.0)
        OOF.Image.AutoGroup(image="skeltest:small.ppm")
        global gfxmanager
        from ooflib.common.IO import gfxmanager
        OOF.Skeleton.New(name="bdytest",
                         microstructure="skeltest",
                         x_elements=8,
                         y_elements=8,
                         skeleton_geometry=TriSkeleton(
                             arrangement="middling",
                             left_right_periodicity=True,
                             top_bottom_periodicity=True))

        # Need a graphics window so we can do the direct selection.
        OOF.Windows.Graphics.New()
        graphics_name = gfxmanager.gfxManager.windows[-1].name
        self.g_window_menu = OOF.__getattr__(graphics_name)
        self.sk_context = skeletoncontext.skeletonContexts["skeltest:bdytest"]
コード例 #7
0
    def FloatAndFixed2(self):
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<3>', mesh='bc_test:skeleton:mesh',
            condition=DirichletBC(
                field=Temperature,field_component='',
                equation=Heat_Eqn,eqn_component='',
                profile=ContinuumProfileXTd(
                    function='0',timeDerivative='0',timeDerivative2='0'),
                boundary='top'))
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<4>', mesh='bc_test:skeleton:mesh',
            condition=FloatBC(field=Temperature,field_component='',
                              equation=Heat_Eqn,eqn_component='',
                              profile=ContinuumProfile(function='alpha+1.234'),
                              boundary='left'))

        OOF.Subproblem.Set_Solver(
            subproblem='bc_test:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                nonlinear_solver=NoNonlinearSolver(),
                time_stepper=StaticDriver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='bc_test:skeleton:mesh',
                       endtime=0.0)


        OOF.File.Load.Data(filename=reference_file("bc_data", "floatandfixed"))
        from ooflib.engine import mesh
        saved = mesh.meshes["floatandfixed:skeleton:mesh"]
        damned = mesh.meshes["bc_test:skeleton:mesh"]
        self.assertEqual(saved.compare(damned, 1.0e-12), 0)
コード例 #8
0
    def Periodic1(self):
        OOF.Mesh.Boundary_Conditions.New(name='bc<3>',
                                         mesh='bc_test:skeleton:mesh',
                                         condition=PeriodicBC(
                                             field=Temperature,
                                             equation=Heat_Eqn,
                                             boundary='top bottom'))
        OOF.Subproblem.Set_Solver(subproblem='bc_test:skeleton:mesh:default',
                                  solver_mode=AdvancedSolverMode(
                                      nonlinear_solver=NoNonlinearSolver(),
                                      time_stepper=StaticDriver(),
                                      symmetric_solver=ConjugateGradient(
                                          preconditioner=ILUPreconditioner(),
                                          tolerance=1e-13,
                                          max_iterations=1000)))
        OOF.Mesh.Solve(mesh='bc_test:skeleton:mesh', endtime=0.0)

        fname = reference_file("bc_data", "periodic_1")
        if generate and not os.path.exists(fname):
            OOF.Microstructure.Rename(microstructure="bc_test",
                                      name="periodic_1")
            OOF.File.Save.Mesh(filename=fname,
                               mode="w",
                               format="ascii",
                               mesh="periodic_1:skeleton:mesh")
            OOF.Microstructure.Rename(microstructure="periodic_1",
                                      name="bc_test")

        OOF.File.Load.Data(filename=fname)
        from ooflib.engine import mesh
        saved = mesh.meshes["periodic_1:skeleton:mesh"]
        damned = mesh.meshes["bc_test:skeleton:mesh"]
        self.assertEqual(saved.compare(damned, 1.0e-13), 0)
コード例 #9
0
    def Periodic2(self):
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<3>', mesh='bc_test:skeleton:mesh',
            condition=PeriodicBC(field=Temperature,
                                 equation=Heat_Eqn,
                                 boundary='top bottom'))
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<4>', mesh='bc_test:skeleton:mesh',
            condition=PeriodicBC(field=Temperature,
                                 equation=Heat_Eqn,
                                 boundary='left right'))
        OOF.Subproblem.Set_Solver(
            subproblem='bc_test:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                nonlinear_solver=NoNonlinearSolver(),
                time_stepper=StaticDriver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='bc_test:skeleton:mesh',
                       endtime=0.0)

        OOF.File.Load.Data(filename=reference_file("bc_data", "periodic_2"))
        from ooflib.engine import mesh
        saved = mesh.meshes["periodic_2:skeleton:mesh"]
        damned = mesh.meshes["bc_test:skeleton:mesh"]
        self.assertEqual(saved.compare(damned, 1.0e-13), 0)
コード例 #10
0
 def SimpleSolve(self):
     OOF.Subproblem.Set_Solver(subproblem='bc_test:skeleton:mesh:default',
                               solver_mode=AdvancedSolverMode(
                                   nonlinear_solver=NoNonlinearSolver(),
                                   time_stepper=StaticDriver(),
                                   symmetric_solver=ConjugateGradient(
                                       preconditioner=ILUPreconditioner(),
                                       tolerance=1e-13,
                                       max_iterations=1000)))
     OOF.Mesh.Solve(mesh='bc_test:skeleton:mesh', endtime=0.0)
     fname = reference_file("bc_data", "simple_solution_test")
     if generate and not os.path.exists(fname):
         OOF.Microstructure.Rename(microstructure="bc_test",
                                   name="saved_data")
         OOF.File.Save.Mesh(filename=fname,
                            mode="w",
                            format="ascii",
                            mesh="saved_data:skeleton:mesh")
         OOF.Microstructure.Rename(microstructure="saved_data",
                                   name="bc_test")
     OOF.File.Load.Data(filename=fname)
     from ooflib.engine import mesh
     saved = mesh.meshes["saved_data:skeleton:mesh"]
     damned = mesh.meshes["bc_test:skeleton:mesh"]
     self.assertEqual(saved.compare(damned, 1.0e-13), 0)
コード例 #11
0
ファイル: subproblem_test.py プロジェクト: anilkunwar/OOF2
    def setUp(self):
        global mesh
        global subproblemcontext
        from ooflib.engine import subproblemcontext
        from ooflib.engine import mesh
        global femesh, cskeleton, cmicrostructure
        from ooflib.SWIG.engine import cskeleton
        from ooflib.SWIG.engine import femesh
        from ooflib.SWIG.common import cmicrostructure

        OOF.Microstructure.Create_From_ImageFile(
            filename=reference_file('ms_data', 'small.ppm'),
            microstructure_name='small.ppm', height=automatic, width=automatic)
        OOF.Windows.Graphics.New()
        OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
            source='small.ppm:small.ppm',
            points=[Point(37.4416,59.9125), Point(81.0992,45.7879)],
            shift=0, ctrl=0)
        OOF.PixelGroup.New(name='spot1', microstructure='small.ppm')
        OOF.PixelGroup.AddSelection(microstructure='small.ppm', group='spot1')
        OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
            source='small.ppm:small.ppm',
            points=[Point(84.3093,56.7023), Point(125.399,41.2938)],
            shift=0, ctrl=0)
        OOF.PixelGroup.New(name='spot2', microstructure='small.ppm')
        OOF.PixelGroup.AddSelection(microstructure='small.ppm', group='spot2')
        OOF.Graphics_1.File.Close()
        OOF.Skeleton.New(
            name='skeleton', microstructure='small.ppm',
            x_elements=20, y_elements=20,
            skeleton_geometry=QuadSkeleton(top_bottom_periodicity=False,
                                           left_right_periodicity=False))
        OOF.Mesh.New(name='mesh', skeleton='small.ppm:skeleton',
                     element_types=['T3_3', 'Q4_4'])
コード例 #12
0
ファイル: skeleton_bdy_test.py プロジェクト: anilkunwar/OOF2
    def setUp(self):
        global skeletoncontext
        from ooflib.engine import skeletoncontext
        global cskeleton
        from ooflib.SWIG.engine import cskeleton
        global cmicrostructure
        from ooflib.SWIG.common import cmicrostructure
        OOF.Microstructure.Create_From_ImageFile(
            filename=reference_file("ms_data","small.ppm"),
            microstructure_name="skeltest",
            height=20.0, width=20.0)
        OOF.Image.AutoGroup(image="skeltest:small.ppm")
        global gfxmanager
        from ooflib.common.IO import gfxmanager
        OOF.Skeleton.New(
            name="bdytest",
            microstructure="skeltest", 
            x_elements=8, y_elements=8,
            skeleton_geometry=QuadSkeleton(top_bottom_periodicity=False,
                                           left_right_periodicity=False))

        # Need a graphics window so we can do the direct selection.
        OOF.Windows.Graphics.New()
        self.sk_context = skeletoncontext.skeletonContexts[
            "skeltest:bdytest"]
コード例 #13
0
 def Create_From_Image(self):
     from ooflib.common import primitives
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name=automatic,
         height=20.0, width=20.0)
     OOF.Microstructure.Create_From_Image(
         name="new", width=automatic, height=automatic,
         image="small.ppm:small.ppm")
     ms_0 = getMicrostructure("small.ppm")
     ms_1 = getMicrostructure("new")
     # Ensure images are separate objects.
     imageclass = whoville.getClass('Image')
     ms_1_image_id = id(ms_1.getImageContexts()[0])
     # Make sure the image wasn't copied in the source microstructure.
     self.assertEqual(len(ms_0.imageNames()), 1)
     # Make sure the newly constructed microstructure is the right size.
     self.assertEqual(ms_1.sizeInPixels(), primitives.iPoint(150,150))
     self.assertEqual(ms_1.size(), primitives.Point(20.0, 20.0))
     self.assertEqual(ms_1.sizeOfPixels(), (20.0/150, 20.0/150))
     OOF.Microstructure.Delete(microstructure="small.ppm")
     # Ensure that after the originating microstructure has been
     # deleted, the derived one still has the same image.
     self.assert_("small.ppm" in ms_1.imageNames())
     self.assertEqual(ms_1_image_id, id(ms_1.getImageContexts()[0]))
コード例 #14
0
ファイル: pixel_extra_test.py プロジェクト: anilkunwar/OOF2
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="skeltest",
         height=20.0, width=20.0)
     OOF.Image.AutoGroup(image="skeltest:small.ppm")
コード例 #15
0
ファイル: fundamental_test.py プロジェクト: pk-organics/OOF3D
 def ScriptSyntaxErr1(self):
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "nestedsyntaxerr.py"))
     self.assertRaises(NameError, utils.OOFeval, "bandersnatch")
     self.assertRaises(NameError, utils.OOFeval, "borogoves")
     self.assertEqual(utils.OOFeval('teststring'), 'ok')
コード例 #16
0
 def MatLoad(self):
     OOF.File.Load.Data(filename=reference_file("matprop_data","matload"))
     mat = self.mat_manager["load"]
     prop = self.allprops["Color:check"]
     self.assertEqual(prop.name().split(':')[-1], "check")
     self.assertEqual(mat.name, "load")
     OOF.Material.Delete(name="load")
     OOF.Property.Delete(property="Color:check")
コード例 #17
0
ファイル: fundamental_test.py プロジェクト: pk-organics/OOF3D
 def ScriptException1(self):
     # This script is the same, but it raises the exception by
     # running a menu command.
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "errorcmd.py"))
     self.assertEqual(utils.OOFeval('teststring'), "ok")
コード例 #18
0
 def MatLoad(self):
     OOF.File.Load.Data(filename=reference_file("matprop_data","matload"))
     mat = self.mat_manager["load"]
     prop = self.allprops["Color:check"]
     self.assertEqual(prop.name().split(':')[-1], "check")
     self.assertEqual(mat.name, "load")
     OOF.Material.Delete(name="load")
     OOF.Property.Delete(property="Color:check")
コード例 #19
0
ファイル: fundamental_test.py プロジェクト: anilkunwar/OOF2
 def ScriptException1(self):
     # This script is the same, but it raises the exception by
     # running a menu command.
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "errorcmd.py"))
     self.assertEqual(utils.OOFeval('teststring'), "ok")
コード例 #20
0
ファイル: fundamental_test.py プロジェクト: anilkunwar/OOF2
 def ScriptSyntaxErr1(self):
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "nestedsyntaxerr.py"))
     self.assertRaises(NameError, utils.OOFeval, "bandersnatch")
     self.assertRaises(NameError, utils.OOFeval, "borogoves")
     self.assertEqual(utils.OOFeval('teststring'), 'ok')
コード例 #21
0
ファイル: amr_test.py プロジェクト: song2001/OOF2
    def RefineSubproblem(self):
        from ooflib.engine import mesh
        OOF.File.Load.Data(
            filename=reference_file("mesh_data", "el_shape2.mesh"))
        meshctxt = mesh.meshes['el_shape.png:skeleton:mesh']
        skelctxt = meshctxt.getParent()
        OOF.Windows.Graphics.New()
        OOF.Graphics_1.Toolbox.Pixel_Select.Rectangle(
            source='el_shape.png:el_shape.png',
            points=[Point(0.222, 9.736),
                    Point(2.728, 3.110)],
            shift=0,
            ctrl=0)
        OOF.PixelGroup.New(name='upperpixels', microstructure='el_shape.png')
        OOF.PixelGroup.AddSelection(microstructure='el_shape.png',
                                    group='upperpixels')
        OOF.Subproblem.New(
            name='subproblem',
            mesh='el_shape.png:skeleton:mesh',
            subproblem=PixelGroupSubProblem(group='upperpixels'))
        OOF.Subproblem.Set_Solver(
            subproblem='el_shape.png:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                nonlinear_solver=NoNonlinearSolver(),
                time_stepper=StaticDriver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1.e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='el_shape.png:skeleton:mesh', endtime=0.0)
        OOF.Subproblem.Copy_Field_State(
            source='el_shape.png:skeleton:mesh:default',
            target='el_shape.png:skeleton:mesh:subproblem')
        OOF.Subproblem.Copy_Equation_State(
            source='el_shape.png:skeleton:mesh:default',
            target='el_shape.png:skeleton:mesh:subproblem')
        OOF.Skeleton.Modify(
            skeleton='el_shape.png:skeleton',
            modifier=Refine(targets=AdaptiveMeshRefine(
                subproblem='el_shape.png:skeleton:mesh:subproblem',
                estimator=ZZ_Estimator(norm=L2ErrorNorm(),
                                       flux=Stress,
                                       threshold=10)),
                            criterion=Unconditionally(),
                            degree=Trisection(rule_set='conservative'),
                            alpha=0.29999999999999999))
        self.assertEqual(meshctxt.nelements(), 400)
        newNel = len(skelctxt.getObject().elements)
        self.assert_(newNel > 400)

        OOF.Mesh.Modify(mesh='el_shape.png:skeleton:mesh',
                        modifier=RebuildMesh())
        self.assertEqual(meshctxt.nelements(), newNel)

        OOF.Graphics_1.File.Close()
        OOF.Material.Delete(name="green-material")
        OOF.Property.Delete(
            property="Mechanical:Elasticity:Isotropic:green_elasticity")
コード例 #22
0
 def doModify(self, registration, startfile, compfile, kwargs):
     import os, random
     from ooflib.SWIG.common import crandom
     OOF.File.Load.Data(filename=reference_file("skeleton_data",
                                                "periodic_mods", startfile))
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     mod = registration(**kwargs)
     random.seed(17)
     crandom.rndmseed(17)
     OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     self.assert_(sk0.sanity_check())
     fname = reference_file("skeleton_data", "periodic_mods", compfile)
     if generate and not os.path.exists(fname):
         # Save the new Skeleton under a different name
         OOF.Microstructure.Rename(microstructure="skeltest",
                                   name="reference")
         OOF.File.Save.Skeleton(filename=fname,
                                mode="w",
                                format="ascii",
                                skeleton="reference:modtest")
         # Change the name back, so that tearDown won't complain.
         OOF.Microstructure.Rename(microstructure="reference",
                                   name="skeltest")
     else:
         # Saving and reloading the Skeleton guarantees that node
         # indices match up with the reference skeleton.  Nodes are
         # re-indexed when a skeleton is saved.
         OOF.File.Save.Skeleton(filename="skeleton_mod_test",
                                mode="w",
                                format="ascii",
                                skeleton="skeltest:modtest")
         OOF.Microstructure.Delete(microstructure="skeltest")
         OOF.File.Load.Data(filename="skeleton_mod_test")
         # Load the reference Skeleton.
         OOF.File.Load.Data(filename=fname)
         # Compare the two Skeletons
         sk1 = skeletoncontext.skeletonContexts[
             "skeltest:modtest"].getObject()
         sk2 = skeletoncontext.skeletonContexts[
             "reference:modtest"].getObject()
         # Tolerance is 1.0e-13, 100x double-precision noise.
         self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
         os.remove("skeleton_mod_test")
         OOF.Microstructure.Delete(microstructure="reference")
コード例 #23
0
 def Load(self):
     OOF.File.Load.Data(filename=reference_file("skeleton_data", "savetest"))
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 1)
     self.assert_(["skeltest", "savetest"] in skeletoncontext.skeletonContexts.keys())
     skelctxt = skeletoncontext.skeletonContexts["skeltest:savetest"]
     skel = skelctxt.getObject()
     self.assertEqual(skel.nnodes(), 81)
     self.assertEqual(skel.nelements(), 64)
     self.assert_(skel.sanity_check())
コード例 #24
0
 def Load(self):
     from ooflib.common import primitives
     # The MS in this file is named "load_test", and is the same
     # as the "save_test" one, except for the name.
     OOF.File.Load.Data(filename=reference_file("ms_data","saved_ms"))
     ms_0 = getMicrostructure("save_test")
     self.assertEqual(ms_0.sizeInPixels(), primitives.iPoint(10,10))
     self.assertEqual(ms_0.size(), primitives.Point(2.5, 3.5))
     self.assertEqual(ms_0.sizeOfPixels(), (2.5/10, 3.5/10 ))
コード例 #25
0
 def Load(self):
     from ooflib.common import primitives
     # The MS in this file is named "load_test", and is the same
     # as the "save_test" one, except for the name.
     OOF.File.Load.Data(filename=reference_file("ms_data", "saved_ms"))
     ms_0 = getMicrostructure("save_test")
     self.assertEqual(ms_0.sizeInPixels(), primitives.iPoint(10, 10))
     self.assertEqual(ms_0.size(), primitives.Point(2.5, 3.5))
     self.assertEqual(ms_0.sizeOfPixels(), (2.5 / 10, 3.5 / 10))
コード例 #26
0
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "small.ppm"),
         microstructure_name="skeltest",
         height=20.0,
         width=20.0)
     OOF.Image.AutoGroup(image="skeltest:small.ppm")
コード例 #27
0
    def FloatAndFixedLoop2(self):
        OOF.Mesh.Boundary_Conditions.New(name='bc<3>',
                                         mesh='bc_test:skeleton:mesh',
                                         condition=DirichletBC(
                                             field=Temperature,
                                             field_component='',
                                             equation=Heat_Eqn,
                                             eqn_component='',
                                             profile=ContinuumProfileXTd(
                                                 function='0',
                                                 timeDerivative='0',
                                                 timeDerivative2='0'),
                                             boundary='top'))
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<4>',
            mesh='bc_test:skeleton:mesh',
            condition=FloatBC(field=Temperature,
                              field_component='',
                              equation=Heat_Eqn,
                              eqn_component='',
                              profile=ContinuumProfile(function='alpha+1.234'),
                              boundary='left'))
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<5>',
            mesh='bc_test:skeleton:mesh',
            condition=FloatBC(field=Temperature,
                              field_component='',
                              equation=Heat_Eqn,
                              eqn_component='',
                              profile=ContinuumProfile(function='-17'),
                              boundary='bottom'))
        OOF.Mesh.Boundary_Conditions.New(
            name='bc<6>',
            mesh='bc_test:skeleton:mesh',
            condition=FloatBC(field=Temperature,
                              field_component='',
                              equation=Heat_Eqn,
                              eqn_component='',
                              profile=ContinuumProfile(function='-alpha-3.14'),
                              boundary='right'))
        OOF.Subproblem.Set_Solver(subproblem='bc_test:skeleton:mesh:default',
                                  solver_mode=AdvancedSolverMode(
                                      nonlinear_solver=NoNonlinearSolver(),
                                      time_stepper=StaticDriver(),
                                      symmetric_solver=ConjugateGradient(
                                          preconditioner=ILUPreconditioner(),
                                          tolerance=1e-13,
                                          max_iterations=1000)))
        OOF.Mesh.Solve(mesh='bc_test:skeleton:mesh', endtime=0.0)

        OOF.File.Load.Data(
            filename=reference_file("bc_data", "fixedfloatloop"))
        from ooflib.engine import mesh
        saved = mesh.meshes["fixedfloatloop:skeleton:mesh"]
        damned = mesh.meshes["bc_test:skeleton:mesh"]
        self.assertEqual(saved.compare(damned, 1.0e-13), 0)
コード例 #28
0
ファイル: pixel_test.py プロジェクト: anilkunwar/OOF2
 def setUp(self):
     global gfxmanager
     global pixelselection
     from ooflib.common.IO import gfxmanager
     from ooflib.common import pixelselection
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("image_data","image_test.ppm"),
         microstructure_name=automatic,
         height=automatic, width=automatic)
     OOF.Windows.Graphics.New()
コード例 #29
0
 def Delete(self):
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "rectangle.ppm"),
         microstructure_name="rectangle.ppm",
         height=automatic,
         width=automatic)
     OOF.Image.Delete(image="rectangle.ppm:rectangle.ppm")
     ms = getMicrostructure("rectangle.ppm")
     self.assertEqual(len(ms.imageNames()), 0)
     self.assertEqual(len(ms.getImageContexts()), 0)
コード例 #30
0
 def doModify(self, registration, startfile, compfile, kwargs):
     import os, random
     from ooflib.SWIG.common import crandom
     OOF.File.Load.Data(
         filename=reference_file("skeleton_data","periodic_mods", startfile))
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     mod = registration(**kwargs)
     random.seed(17)
     crandom.rndmseed(17)
     OOF.Skeleton.Modify(skeleton="skeltest:modtest", modifier=mod)
     sk0 = skeletoncontext.skeletonContexts["skeltest:modtest"].getObject()
     self.assert_(sk0.sanity_check())
     fname = reference_file("skeleton_data", "periodic_mods", compfile)
     if generate and not os.path.exists(fname):
         # Save the new Skeleton under a different name
         OOF.Microstructure.Rename(microstructure="skeltest",
                                   name="reference")
         OOF.File.Save.Skeleton(filename=fname, mode="w", format="ascii",
                                skeleton="reference:modtest")
         # Change the name back, so that tearDown won't complain.
         OOF.Microstructure.Rename(microstructure="reference",
                                   name="skeltest")
     else:
         # Saving and reloading the Skeleton guarantees that node
         # indices match up with the reference skeleton.  Nodes are
         # re-indexed when a skeleton is saved.
         OOF.File.Save.Skeleton(
             filename="skeleton_mod_test",
             mode="w", format="ascii",
             skeleton="skeltest:modtest")
         OOF.Microstructure.Delete(microstructure="skeltest")
         OOF.File.Load.Data(filename="skeleton_mod_test")
         # Load the reference Skeleton.
         OOF.File.Load.Data(filename=fname)
         # Compare the two Skeletons
         sk1 = skeletoncontext.skeletonContexts[
             "skeltest:modtest"].getObject()
         sk2 = skeletoncontext.skeletonContexts[
             "reference:modtest"].getObject()
         # Tolerance is 1.0e-13, 100x double-precision noise.
         self.assertEqual(sk1.compare(sk2, 1.0e-13), 0)
         os.remove("skeleton_mod_test")
         OOF.Microstructure.Delete(microstructure="reference")
コード例 #31
0
ファイル: activearea_test.py プロジェクト: anilkunwar/OOF2
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     from ooflib.common.IO import gfxmanager
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="active",
         height=20.0, width=20.0)
     OOF.Image.AutoGroup(image="active:small.ppm")
     OOF.Windows.Graphics.New()
コード例 #32
0
 def setUp(self):
     global gfxmanager
     global pixelselection
     from ooflib.common.IO import gfxmanager
     from ooflib.common import pixelselection
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("image_data","image_test.ppm"),
         microstructure_name=automatic,
         height=automatic, width=automatic)
     OOF.Windows.Graphics.New()
コード例 #33
0
ファイル: amr_test.py プロジェクト: anilkunwar/OOF2
    def RefineSubproblem(self):
        from ooflib.engine import mesh
        OOF.File.Load.Data(filename=reference_file("mesh_data",
                                                   "el_shape2.mesh"))
        meshctxt = mesh.meshes['el_shape.png:skeleton:mesh']
        skelctxt = meshctxt.getParent()
        OOF.Windows.Graphics.New()
        OOF.Graphics_1.Toolbox.Pixel_Select.Rectangle(
            source='el_shape.png:el_shape.png',
            points=[Point(0.222,9.736), Point(2.728,3.110)],
            shift=0, ctrl=0)
        OOF.PixelGroup.New(name='upperpixels', microstructure='el_shape.png')
        OOF.PixelGroup.AddSelection(microstructure='el_shape.png', 
                                    group='upperpixels')
        OOF.Subproblem.New(name='subproblem',
                           mesh='el_shape.png:skeleton:mesh',
                           subproblem=PixelGroupSubProblem(group='upperpixels'))
        OOF.Subproblem.Set_Solver(
            subproblem='el_shape.png:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                nonlinear_solver=NoNonlinearSolver(),
                time_stepper=StaticDriver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1.e-13, max_iterations=1000)))
        OOF.Mesh.Solve(
            mesh='el_shape.png:skeleton:mesh', endtime=0.0)
        OOF.Subproblem.Copy_Field_State(
            source='el_shape.png:skeleton:mesh:default',
            target='el_shape.png:skeleton:mesh:subproblem')
        OOF.Subproblem.Copy_Equation_State(
            source='el_shape.png:skeleton:mesh:default',
            target='el_shape.png:skeleton:mesh:subproblem')
        OOF.Skeleton.Modify(
            skeleton='el_shape.png:skeleton',
            modifier=Refine(targets=AdaptiveMeshRefine(
                    subproblem='el_shape.png:skeleton:mesh:subproblem',
                    estimator=ZZ_Estimator(
                        norm=L2ErrorNorm(),flux=Stress,threshold=10)
                    ),
                            criterion=Unconditionally(),
                            degree=Trisection(rule_set='conservative'),
                            alpha=0.29999999999999999))
        self.assertEqual(meshctxt.nelements(), 400)
        newNel = len(skelctxt.getObject().elements)
        self.assert_(newNel > 400)

        OOF.Mesh.Modify(mesh='el_shape.png:skeleton:mesh',
                        modifier=RebuildMesh())
        self.assertEqual(meshctxt.nelements(), newNel)
        
        OOF.Graphics_1.File.Close()
        OOF.Material.Delete(name="green-material")
        OOF.Property.Delete(
            property="Mechanical:Elasticity:Isotropic:green_elasticity")
コード例 #34
0
ファイル: image_test.py プロジェクト: shkeshavarz/OOF2
 def Delete(self):
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "rectangle.ppm"),
         microstructure_name="rectangle.ppm",
         height=automatic,
         width=automatic,
     )
     OOF.Image.Delete(image="rectangle.ppm:rectangle.ppm")
     ms = getMicrostructure("rectangle.ppm")
     self.assertEqual(len(ms.imageNames()), 0)
     self.assertEqual(len(ms.getImageContexts()), 0)
コード例 #35
0
 def Load(self):
     OOF.File.Load.Data(
         filename=reference_file("skeleton_data", "savetest"))
     self.assertEqual(skeletoncontext.skeletonContexts.nActual(), 1)
     self.assert_(["skeltest", "savetest"] in
                  skeletoncontext.skeletonContexts.keys())
     skelctxt = skeletoncontext.skeletonContexts["skeltest:savetest"]
     skel = skelctxt.getObject()
     self.assertEqual(skel.nnodes(), 81)
     self.assertEqual(skel.nelements(), 64)
     self.assert_(skel.sanity_check())
コード例 #36
0
ファイル: fundamental_test.py プロジェクト: pk-organics/OOF3D
 def ScriptSyntaxErr0(self):
     self.assertRaises(SyntaxError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "syntaxerror.py"))
     # syntaxerror.py tries to define 'bandersnatch' before the
     # line containing the syntax error, and 'borogoves' after it.
     # Neither should be defined, because none of the file should
     # have actually been evaluated.
     self.assertRaises(NameError, utils.OOFeval, "bandersnatch")
     self.assertRaises(NameError, utils.OOFeval, "borogoves")
コード例 #37
0
ファイル: fundamental_test.py プロジェクト: anilkunwar/OOF2
 def ScriptSyntaxErr0(self):
     self.assertRaises(SyntaxError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "syntaxerror.py"))
     # syntaxerror.py tries to define 'bandersnatch' before the
     # line containing the syntax error, and 'borogoves' after it.
     # Neither should be defined, because none of the file should
     # have actually been evaluated.
     self.assertRaises(NameError, utils.OOFeval, "bandersnatch")
     self.assertRaises(NameError, utils.OOFeval, "borogoves")
コード例 #38
0
 def PropSave(self):
     OOF.Property.Copy(property="Color", new_name="bloo")
     OOF.Property.Parametrize.Color.bloo(
         color=RGBColor(red=0.1,green=0.1,blue=0.9))
     OOF.File.Save.Property(filename="prop_save_test",
                            mode="w", format="ascii",
                            property="Color:bloo")
     self.assert_(filecmp.cmp(reference_file("matprop_data","propsave"),
                              "prop_save_test"))
     os.remove("prop_save_test")
     OOF.Property.Delete(property="Color:bloo")
コード例 #39
0
 def PropSave(self):
     OOF.Property.Copy(property="Color", new_name="bloo")
     OOF.Property.Parametrize.Color.bloo(
         color=RGBColor(red=0.1,green=0.1,blue=0.9))
     OOF.File.Save.Property(filename="prop_save_test",
                            mode="w", format="ascii",
                            property="Color:bloo")
     self.assert_(filecmp.cmp(reference_file("matprop_data","propsave"),
                              "prop_save_test"))
     os.remove("prop_save_test")
     OOF.Property.Delete(property="Color:bloo")
コード例 #40
0
ファイル: activearea_test.py プロジェクト: song2001/OOF2
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     from ooflib.common.IO import gfxmanager
     OOF.Microstructure.Create_From_ImageFile(filename=reference_file(
         "ms_data", "small.ppm"),
                                              microstructure_name="active",
                                              height=20.0,
                                              width=20.0)
     OOF.Image.AutoGroup(image="active:small.ppm")
     OOF.Windows.Graphics.New()
コード例 #41
0
 def Save(self):
     import filecmp, os
     OOF.Microstructure.New(name="save_test", width=2.5, height=3.5,
                            width_in_pixels=10, height_in_pixels=10)
     OOF.File.Save.Microstructure(filename="ms_save_test",
                                  mode="w",
                                  format="ascii",
                                  microstructure="save_test")
     self.assert_(filecmp.cmp("ms_save_test",
                              reference_file("ms_data","saved_ms")))
     os.remove("ms_save_test")
コード例 #42
0
 def ScriptException2(self):
     # This script is the same, but it calls the first script using
     # a nested menu command.  teststring and/or another test will
     # not be "ok" if lines following the error are being
     # processed.
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "nestederror.py"))
     self.assert_(utils.OOFeval('teststring')=="ok" and
                  utils.OOFeval('anothertest')=="ok")
コード例 #43
0
ファイル: fundamental_test.py プロジェクト: anilkunwar/OOF2
 def ScriptException0(self):
     # Check that an exception thrown by a script halts the
     # execution of the script.  The script sets teststring to
     # "ok", raises an exception by using an undefined variable,
     # and then sets teststring to "not ok".  If the exception is
     # not handled properly, lines following the error will be
     # read, and teststring will be set to "not ok".
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename = reference_file("fundamental_data",
                                                 "pyerror.py"))
     self.assertEqual(utils.OOFeval('teststring'), "ok")
コード例 #44
0
ファイル: fundamental_test.py プロジェクト: pk-organics/OOF3D
 def ScriptException0(self):
     # Check that an exception thrown by a script halts the
     # execution of the script.  The script sets teststring to
     # "ok", raises an exception by using an undefined variable,
     # and then sets teststring to "not ok".  If the exception is
     # not handled properly, lines following the error will be
     # read, and teststring will be set to "not ok".
     self.assertRaises(ooferror.ErrUserError,
                       OOF.File.Load.Script,
                       filename=reference_file("fundamental_data",
                                               "pyerror.py"))
     self.assertEqual(utils.OOFeval('teststring'), "ok")
コード例 #45
0
ファイル: image_test.py プロジェクト: shkeshavarz/OOF2
 def Load(self):
     OOF.Microstructure.New(name="load_test", width=150, height=121, width_in_pixels=150, height_in_pixels=121)
     OOF.File.Load.Image(
         filename=reference_file("ms_data", "rectangle.ppm"),
         microstructure="load_test",
         height=automatic,
         width=automatic,
     )
     ms = getMicrostructure("load_test")
     ms_images = ms.imageNames()
     self.assertEqual(len(ms_images), 1)
     self.assert_("rectangle.ppm" in ms_images)
コード例 #46
0
 def setUp(self):
     global skeletoncontext
     from ooflib.engine import skeletoncontext
     global cskeleton
     from ooflib.SWIG.engine import cskeleton
     global cmicrostructure
     from ooflib.SWIG.common import cmicrostructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="skeltest",
         height=20.0, width=20.0)
     OOF.Image.AutoGroup(image="skeltest:small.ppm")
コード例 #47
0
 def Rich_Save(self):
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "small.ppm"),
         microstructure_name="rich",
         height=automatic,
         width=automatic,
     )
     OOF.Image.AutoGroup(image="rich:small.ppm")
     OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
         source="rich:small.ppm", points=[Point(66.0, 55.0), Point(87.6, 41.8)], shift=0, ctrl=0
     )
     OOF.PixelGroup.New(name="test", microstructure="rich")
     OOF.PixelGroup.AddSelection(microstructure="rich", group="test")
     OOF.Graphics_1.Toolbox.Pixel_Select.Circle(
         source="rich:small.ppm", points=[Point(31.2, 40.4), Point(60.1, 41.2)], shift=0, ctrl=0
     )
     OOF.ActiveArea.Activate_Selection_Only(microstructure="rich")
     OOF.ActiveArea.Store(microstructure="rich", name="act1")
     OOF.Graphics_1.Toolbox.Pixel_Select.Clear(source="rich:small.ppm")
     OOF.File.Save.Microstructure(filename="rich_save_test", mode="w", format="ascii", microstructure="rich")
     self.assert_(filecmp.cmp("rich_save_test", reference_file("ms_data", "rich_ms")))
     os.remove("rich_save_test")
コード例 #48
0
ファイル: image_test.py プロジェクト: shkeshavarz/OOF2
    def Modify(self):
        import filecmp, os, random
        from ooflib.SWIG.common import crandom
        from ooflib.SWIG.image import oofimage

        global image_modify_args
        menuitem = OOF.Image.Modify
        for m in menuitem.items:
            try:
                test_list = image_modify_args[m.name]
            except KeyError:
                print >> sys.stderr, "No test data for image modifier ", m.name
            else:
                for (datafilename, argdict) in test_list:
                    argdict["image"] = "imagemod_test:image_test.ppm"
                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", "image_test.ppm"),
                        microstructure_name="imagemod_test",
                        height=automatic,
                        width=automatic,
                    )
                    random.seed(17)
                    crandom.rndmseed(17)
                    m.callWithArgdict(argdict)

                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", datafilename),
                        microstructure_name="comparison",
                        height=automatic,
                        width=automatic,
                    )
                    im1 = imagecontext.imageContexts["imagemod_test:image_test.ppm"].getObject()
                    im2 = imagecontext.imageContexts["comparison:" + datafilename].getObject()
                    # Tolerance is 1./65535., which is the level of
                    # "quantization noise" for 16-bit color channels.
                    self.assert_(im1.compare(im2, 1.0 / 65535.0))

                    OOF.Microstructure.Delete(microstructure="comparison")
                    OOF.Microstructure.Delete(microstructure="imagemod_test")
コード例 #49
0
 def setUp(self):
     global materialmanager
     from ooflib.engine import materialmanager
     self.mat_manager = materialmanager.materialmanager
     global material
     from ooflib.SWIG.engine import material
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="mat_test", height=20.0,
         width=20.0)
     OOF.Image.AutoGroup(image="mat_test:small.ppm")
コード例 #50
0
    def Modify(self):
        import filecmp, os, random
        from ooflib.SWIG.common import crandom
        from ooflib.SWIG.image import oofimage
        global image_modify_args
        menuitem = OOF.Image.Modify
        for m in menuitem.items:
            try:
                test_list = image_modify_args[m.name]
            except KeyError:
                print >> sys.stderr, "No test data for image modifier ", m.name
            else:
                for (datafilename, argdict) in test_list:
                    argdict['image'] = "imagemod_test:image_test.ppm"
                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data",
                                                "image_test.ppm"),
                        microstructure_name="imagemod_test",
                        height=automatic,
                        width=automatic)
                    random.seed(17)
                    crandom.rndmseed(17)
                    m.callWithArgdict(argdict)

                    OOF.Microstructure.Create_From_ImageFile(
                        filename=reference_file("image_data", datafilename),
                        microstructure_name="comparison",
                        height=automatic,
                        width=automatic)
                    im1 = imagecontext.imageContexts[
                        "imagemod_test:image_test.ppm"].getObject()
                    im2 = imagecontext.imageContexts["comparison:" +
                                                     datafilename].getObject()
                    # Tolerance is 1./65535., which is the level of
                    # "quantization noise" for 16-bit color channels.
                    self.assert_(im1.compare(im2, 1. / 65535.))

                    OOF.Microstructure.Delete(microstructure="comparison")
                    OOF.Microstructure.Delete(microstructure="imagemod_test")
コード例 #51
0
    def Save(self):
        import os, filecmp

        OOF.Skeleton.New(
            name="savetest",
            microstructure="skeltest",
            x_elements=8,
            y_elements=8,
            skeleton_geometry=QuadSkeleton(top_bottom_periodicity=False, left_right_periodicity=False),
        )
        OOF.File.Save.Skeleton(filename="skeleton_save", mode="w", format="ascii", skeleton="skeltest:savetest")
        self.assert_(filecmp.cmp(reference_file("skeleton_data", "savetest"), "skeleton_save"))
        os.remove("skeleton_save")
コード例 #52
0
 def setUp(self):
     global materialmanager
     from ooflib.engine import materialmanager
     self.mat_manager = materialmanager.materialmanager
     global material
     from ooflib.SWIG.engine import material
     global microstructure
     from ooflib.common import microstructure
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name="mat_test", height=20.0,
         width=20.0)
     OOF.Image.AutoGroup(image="mat_test:small.ppm")
コード例 #53
0
 def Save(self):
     import os, filecmp
     OOF.Skeleton.New(
         name="savetest", microstructure="skeltest",
         x_elements=8, y_elements=8,
         skeleton_geometry=QuadSkeleton(left_right_periodicity=True,
                                        top_bottom_periodicity=True))
     OOF.File.Save.Skeleton(filename="skeleton_save",
                            mode="w", format="ascii",
                            skeleton="skeltest:savetest")
     self.assert_(filecmp.cmp(reference_file("skeleton_data",
                                             "periodic_savetest"),
                              "skeleton_save"))
     os.remove("skeleton_save")
コード例 #54
0
 def setUp(self):
     global microstructure
     from ooflib.common import microstructure
     from ooflib.common.IO import gfxmanager
     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="active",
                                              height=20.0,
                                              width=20.0,
                                              depth=20.0)
     OOF.Image.AutoGroup(image="active:5color")
     OOF.Windows.Graphics.New()
コード例 #55
0
 def Redo(self):
     from ooflib.SWIG.image import oofimage
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("image_data", "image_test.ppm"),
         microstructure_name="redo_test",
         height=automatic,
         width=automatic)
     image_context = imagecontext.imageContexts["redo_test:image_test.ppm"]
     OOF.Image.Modify.Gray(image="redo_test:image_test.ppm")
     im_0 = image_context.getObject()
     OOF.Image.Undo(image="redo_test:image_test.ppm")
     OOF.Image.Redo(image="redo_test:image_test.ppm")
     im_1 = image_context.getObject()
     self.assertEqual(id(im_0), id(im_1))
コード例 #56
0
 def Rename(self):
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "rectangle.ppm"),
         microstructure_name="rectangle.ppm",
         height=automatic,
         width=automatic)
     ms_0 = getMicrostructure("rectangle.ppm")
     image_id = id(ms_0.getImageContexts()[0])
     OOF.Image.Rename(image="rectangle.ppm:rectangle.ppm", name="newname")
     ms_0 = getMicrostructure("rectangle.ppm")
     image_id = id(ms_0.getImageContexts()[0])
     self.assertEqual(len(ms_0.imageNames()), 1)
     self.assert_("newname" in ms_0.imageNames())
     self.assertEqual(image_id, id(ms_0.getImageContexts()[0]))
コード例 #57
0
 def Save(self):
     import filecmp, os
     OOF.Microstructure.New(name="save_test",
                            width=2.5,
                            height=3.5,
                            width_in_pixels=10,
                            height_in_pixels=10)
     OOF.File.Save.Microstructure(filename="ms_save_test",
                                  mode="w",
                                  format="ascii",
                                  microstructure="save_test")
     self.assert_(
         filecmp.cmp("ms_save_test", reference_file("ms_data", "saved_ms")))
     os.remove("ms_save_test")
コード例 #58
0
 def Create_From_ImageFile(self):
     from ooflib.SWIG.image import oofimage
     from ooflib.common import primitives
     from ooflib.SWIG.common.IO import stringimage
     self.assertRaises(oofimage.ImageMagickError,
                       OOF.Microstructure.Create_From_ImageFile,
                       filename="nosuchfile",
                       microstructure_name="nosuchfile",
                       height=automatic,
                       width=automatic)
     self.assertRaises(ooferror.ErrUserError,
                       OOF.Microstructure.Create_From_ImageFile,
                       filename=reference_file("ms_data", "small.ppm"),
                       microstructure_name="oops",
                       height=-1.0,
                       width=-1.0)
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data", "small.ppm"),
         microstructure_name="small.ms",
         height=20.0,
         width=20.0)
     ms = getMicrostructure("small.ms")
     self.assertEqual(ms.size(), primitives.Point(20.0, 20.0))
     self.assertEqual(ms.sizeInPixels(), primitives.iPoint(150, 150))
     self.assertEqual(ms.sizeOfPixels(), (20.0 / 150, 20.0 / 150))
     ms_images = ms.imageNames()
     self.assertEqual(len(ms_images), 1)
     self.assert_("small.ppm" in ms_images)
     img = oofimage.getImage("small.ms:small.ppm")
     strimg = stringimage.StringImage(ms.sizeInPixels(), ms.size())
     img.fillstringimage(strimg)
     outfile = file('hexstringimage.dat', 'w')
     print >> outfile, strimg.hexstringimage()
     outfile.close()
     assert filecmp.cmp('hexstringimage.dat',
                        reference_file('ms_data', 'smallppm.hex'))
     os.remove("hexstringimage.dat")