Пример #1
0
    def RK4(self):
        OOF.Subproblem.Set_Solver(
            subproblem="microstructure:skeleton:mesh:default",
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.0e-6,
                    minstep=1.0e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=RK4()),
                ),
                nonlinear_solver=Newton(relative_tolerance=1e-08, absolute_tolerance=1.0e-13, maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(), tolerance=1e-13, max_iterations=1000
                ),
            ),
        )
        OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=2.0)

        self.assert_(file_utils.fp_file_compare("test.dat", os.path.join("mesh_data", "nldiff.dat"), tolerance=1.0e-6))
        file_utils.remove("test.dat")
        self.assert_(
            file_utils.fp_file_compare("tempout.dat", os.path.join("mesh_data", "tempout.dat"), tolerance=1.0e-5)
        )
        file_utils.remove("tempout.dat")
Пример #2
0
 def Save(self):
     OOF.Named_Analysis.Create(
         name='output1', 
         operation=DirectOutput(),
         data=getOutput('Field:Value',field=Temperature),
         domain=EntireMesh(),
         sampling=GridSampleSet(
             x_points=3,y_points=3,z_points=3,
             show_x=True,show_y=True,show_z=True))
     OOF.Named_Analysis.Create(
         name='output2', 
         operation=AverageOutput(),
         data=getOutput('Field:Value',field=Temperature),
         domain=EntireMesh(),
         sampling=ContinuumSampleSet(order=automatic))
     OOF.Named_Analysis.SaveAnalysisDefs(
         filename='test.dat',
         mode='w',
         format='ascii', 
         names=['output1', 'output2'])
     self.assert_(
         fp_file_compare('test.dat',
                         os.path.join('output_data', 'analysisdefs.out'),
                         1.e-10))
     file_utils.remove('test.dat')
     # NamedAnalyses persist after the Microstructure is deleted,
     # so be sure to explicitly delete all NamedAnalyses at the end
     # of each test, to avoid interactions with subsequent tests.
     OOF.Named_Analysis.Delete(
         name="output2")
     OOF.Named_Analysis.Delete(
         name="output1")
Пример #3
0
 def Matrix_Multiply(self):
     ident = loadMatrix('identity')
     matrix1 = loadMatrix('matrix1')
     matrix2 = loadMatrix('matrix2')
     prod = ident*matrix1
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod1.out'),
                                  1.e-8))
     prod = matrix1*ident
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod1.out'),
                                  1.e-8))
     prod = matrix1*matrix2
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod2.out'),
                                  1.e-8))
     prod = matrix2*matrix1
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod3.out'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #4
0
 def perform(self, test):
     if self.skip:
         return
     print >> sys.stderr, "Running", self.referencefile
     if self.commands:
         from ooflib.common import utils
         for cmd in self.commands:
             utils.OOFexec(cmd)
     menuitem = getattr(OOF.Mesh.Analyze, self.operation)
     menuitem.callWithDefaults(
         mesh='microstructure:skeleton:' + self.mesh,
         data=getOutput(self.output, **self.oparams),
         time=self.time,
         domain=self.domain,
         sampling=self.sampling,
         destination=OutputStream(filename='test.dat', mode='w'))
     ## TODO 3.1: The default params for fp_file_compare include
     ## "comment='#'", so comments in files aren't compared.  This
     ## is useful for log files, since they contain a comment with
     ## the OOF version number, which changes.  However, output
     ## files include meaningful comments that *should* be
     ## compared.  Adding "comment=None" to the args here would
     ## achieve that.  Doing so makes the tests fail because the
     ## output files have "show_x=True" and the reference files
     ## have "show_x=1".  Do the reference files need to be
     ## updated, or do some versions of Python write bools as 1,0
     ## instead of True,False?
     test.assert_(
         fp_file_compare('test.dat',
                         os.path.join('output_data', self.referencefile),
                         self.tolerance))
     file_utils.remove('test.dat')
Пример #5
0
 def QuasiStatic(self):
     OOF.Mesh.Scheduled_Output.New(
         mesh='microstructure:skeleton:mesh',
         name='LRcorner',
         output=BulkAnalysis(
             output_type='Aggregate',
             data=getOutput('Field:Value',field=Displacement),
             operation=DirectOutput(),
             domain=SinglePoint(point=Point(1,0)),
             sampling=DiscretePointSampleSet(show_x=False,show_y=False)))
     OOF.Mesh.Scheduled_Output.Schedule.Set(
         mesh='microstructure:skeleton:mesh',
         output='LRcorner',
         scheduletype=AbsoluteOutputSchedule(),
         schedule=Periodic(delay=0.0,interval=0.1))
     OOF.Mesh.Scheduled_Output.Destination.Set(
         mesh='microstructure:skeleton:mesh',
         output='LRcorner',
         destination=OutputStream(filename='rotate.out',mode='w'))
     OOF.Mesh.Apply_Field_Initializers_at_Time(
         mesh='microstructure:skeleton:mesh', time=0)
     OOF.Mesh.Solve(
         mesh='microstructure:skeleton:mesh', endtime=1.0)
     self.assert_(file_utils.fp_file_compare(
         'rotate.out',
         os.path.join('mesh_data', 'rotatingsquare1.out'),
         tolerance=1.e-8))
     file_utils.remove('rotate.out')
Пример #6
0
 def QuasiStatic(self):
     OOF.Mesh.Scheduled_Output.New(
         mesh='microstructure:skeleton:mesh',
         name='LRcorner',
         output=BulkAnalysis(output_type='Aggregate',
                             data=getOutput('Field:Value',
                                            field=Displacement),
                             operation=DirectOutput(),
                             domain=SinglePoint(point=Point(1, 0)),
                             sampling=DiscretePointSampleSet(show_x=False,
                                                             show_y=False)))
     OOF.Mesh.Scheduled_Output.Schedule.Set(
         mesh='microstructure:skeleton:mesh',
         output='LRcorner',
         scheduletype=AbsoluteOutputSchedule(),
         schedule=Periodic(delay=0.0, interval=0.1))
     OOF.Mesh.Scheduled_Output.Destination.Set(
         mesh='microstructure:skeleton:mesh',
         output='LRcorner',
         destination=OutputStream(filename='rotate.out', mode='w'))
     OOF.Mesh.Apply_Field_Initializers_at_Time(
         mesh='microstructure:skeleton:mesh', time=0)
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)
     self.assert_(
         file_utils.fp_file_compare('rotate.out',
                                    os.path.join('mesh_data',
                                                 'rotatingsquare1.out'),
                                    tolerance=1.e-8))
     file_utils.remove('rotate.out')
Пример #7
0
    def RKlinear(self):
        # This test uses a linear solver to generate the reference
        # data for the subsequent nonlinear solvers.
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.e-6,
                    minstep=1.e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=RK4())),
                nonlinear_solver=NoNonlinearSolver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=2.0)

        self.assert_(
            file_utils.fp_file_compare('test.dat',
                                       os.path.join('mesh_data', 'nldiff.dat'),
                                       tolerance=1.e-6))
        file_utils.remove('test.dat')
        self.assert_(
            file_utils.fp_file_compare('tempout.dat',
                                       os.path.join('mesh_data',
                                                    'tempout.dat'),
                                       tolerance=1.e-5))
        file_utils.remove('tempout.dat')
Пример #8
0
 def Matrix_Multiply(self):
     ident = loadMatrix('identity')
     matrix1 = loadMatrix('matrix1')
     matrix2 = loadMatrix('matrix2')
     prod = ident*matrix1
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod1.out'),
                                  1.e-8))
     prod = matrix1*ident
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod1.out'),
                                  1.e-8))
     prod = matrix1*matrix2
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod2.out'),
                                  1.e-8))
     prod = matrix2*matrix1
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod3.out'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #9
0
    def BEnewton(self):
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.e-5,
                    minstep=1.e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=BackwardEuler())),
                nonlinear_solver=Newton(
                    relative_tolerance=1e-08,
                    absolute_tolerance=1.e-13,
                    maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(
            mesh='microstructure:skeleton:mesh',
            endtime=1.0)

        self.assert_(file_utils.fp_file_compare(
                'test.dat',
                os.path.join('mesh_data', 'nldiff.dat'),
                tolerance=1.e-3,
                nlines=16))
        file_utils.remove('test.dat')
        self.assert_(file_utils.fp_file_compare(
                'tempout.dat',
                os.path.join('mesh_data', 'tempout.dat'),
                tolerance=1.e-3,
                nlines=910))
        file_utils.remove('tempout.dat')
Пример #10
0
 def VectorIO(self):
     vector = loadVector('vector0')
     vector.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vector0.out'),
                                  1.e-8))
     file_utils.remove('vector.out')
Пример #11
0
    def SS22(self):
        # Setting the AdaptiveDriver tolerance to 1.e-7 allows this
        # test to pass with the fp_file_compare tolerance set to
        # 1.e-6, but then the test runs really slowly.  Using
        # tolerances of 1.e-5 and 1.e-4, respectively, lets the test
        # run in a reasonable amount of time.
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.e-5,
                    minstep=1.e-6,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=SS22(theta1=0.5, theta2=0.5))),
                nonlinear_solver=Newton(relative_tolerance=1e-08,
                                        absolute_tolerance=1.e-13,
                                        maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=2.0)

        self.assert_(
            file_utils.fp_file_compare('test.dat',
                                       os.path.join('mesh_data', 'nldiff.dat'),
                                       tolerance=1.e-4))
        file_utils.remove('test.dat')
        self.assert_(
            file_utils.fp_file_compare('tempout.dat',
                                       os.path.join('mesh_data',
                                                    'tempout.dat'),
                                       tolerance=1.e-4))
        file_utils.remove('tempout.dat')
Пример #12
0
    def RKlinear(self):
        # This test uses a linear solver to generate the reference
        # data for the subsequent nonlinear solvers.
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.e-6,
                    minstep=1.e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=RK4())),
                nonlinear_solver=NoNonlinearSolver(),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(
            mesh='microstructure:skeleton:mesh',
            endtime=2.0)

        self.assert_(file_utils.fp_file_compare(
                'test.dat',
                os.path.join('mesh_data', 'nldiff.dat'),
                tolerance=1.e-6))
        file_utils.remove('test.dat')
        self.assert_(file_utils.fp_file_compare(
                'tempout.dat',
                os.path.join('mesh_data', 'tempout.dat'),
                tolerance=1.e-5))
        file_utils.remove('tempout.dat')
Пример #13
0
 def Save_Pinned(self):
     OOF.Graphics_1.Toolbox.Pin_Nodes.Pin(
         skeleton='bluegreen:skeleton',
         point=Point(-15.7509, 25.046, 0.586289),
         view=View(cameraPosition=Coord(-15.8018, 25.0947, 0.579851),
                   focalPoint=Coord(5, 5, 5),
                   up=Coord(0.143933, -0.0681609, -0.987237),
                   angle=30,
                   clipPlanes=[],
                   invertClip=0,
                   size_x=690,
                   size_y=618))
     OOF.Graphics_1.Toolbox.Pin_Nodes.Pin(
         skeleton='bluegreen:skeleton',
         point=Point(-15.7517, 25.0469, 0.593985),
         view=View(cameraPosition=Coord(-15.8018, 25.0947, 0.579851),
                   focalPoint=Coord(5, 5, 5),
                   up=Coord(0.143933, -0.0681609, -0.987237),
                   angle=30,
                   clipPlanes=[],
                   invertClip=0,
                   size_x=690,
                   size_y=618))
     OOF.File.Save.Skeleton(filename='pinnedskel.dat',
                            mode='w',
                            format='ascii',
                            skeleton='bluegreen:skeleton')
     self.assert_(
         file_utils.fp_file_compare(
             "pinnedskel.dat", os.path.join("skeleton_data", "pintest"),
             1.e-9))
     file_utils.remove("pinnedskel.dat")
Пример #14
0
 def readwrite(self, infile, compfile):
     matrix = loadMatrix(infile)
     saveMatrix(matrix, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, compfile),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #15
0
    def BEnewton(self):
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.e-5,
                    minstep=1.e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=BackwardEuler())),
                nonlinear_solver=Newton(relative_tolerance=1e-08,
                                        absolute_tolerance=1.e-13,
                                        maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)

        self.assert_(
            file_utils.fp_file_compare('test.dat',
                                       os.path.join('mesh_data', 'nldiff.dat'),
                                       tolerance=1.e-3,
                                       nlines=16))
        file_utils.remove('test.dat')
        self.assert_(
            file_utils.fp_file_compare('tempout.dat',
                                       os.path.join('mesh_data',
                                                    'tempout.dat'),
                                       tolerance=1.e-3,
                                       nlines=910))
        file_utils.remove('tempout.dat')
Пример #16
0
 def Multiply(self):
     vector0 = loadVector('vector0')
     vector1 = loadVector('vector1')
     vec = 2*vector0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0*2.0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0/0.5
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec *= 2.0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec /= 0.5
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     dot = vector0 * vector1
     self.assertEqual(dot, 20.0)
     dot = vector0.dot(vector1)
     self.assertEqual(dot, 20.0)
     file_utils.remove('vector.out')
Пример #17
0
 def VectorIO(self):
     vector = loadVector('vector0')
     vector.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vector0.out'),
                                  1.e-8))
     file_utils.remove('vector.out')
Пример #18
0
    def SS22(self):
        # Setting the AdaptiveDriver tolerance to 1.e-7 allows this
        # test to pass with the fp_file_compare tolerance set to
        # 1.e-6, but then the test runs really slowly.  Using
        # tolerances of 1.e-5 and 1.e-4, respectively, lets the test
        # run in a reasonable amount of time.
        OOF.Subproblem.Set_Solver(
            subproblem="microstructure:skeleton:mesh:default",
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.1,
                    tolerance=1.0e-5,
                    minstep=1.0e-6,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=SS22(theta1=0.5, theta2=0.5)),
                ),
                nonlinear_solver=Newton(relative_tolerance=1e-08, absolute_tolerance=1.0e-13, maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(), tolerance=1e-13, max_iterations=1000
                ),
            ),
        )
        OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=2.0)

        self.assert_(file_utils.fp_file_compare("test.dat", os.path.join("mesh_data", "nldiff.dat"), tolerance=1.0e-4))
        file_utils.remove("test.dat")
        self.assert_(
            file_utils.fp_file_compare("tempout.dat", os.path.join("mesh_data", "tempout.dat"), tolerance=1.0e-4)
        )
        file_utils.remove("tempout.dat")
Пример #19
0
 def Add(self):
     vector0 = loadVector('vector0')
     vector1 = loadVector('vector1')
     self.assertEqual(vector0.size(), 4)
     self.assertEqual(vector1.size(), 4)
     sum = vector0 + vector1
     sum.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec.axpy(2.0, vector1)
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum2.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec += vector1
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum.out'),
                                  1.e-8))
     diff = vector0 - vector1
     diff.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecdiff.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec -= vector1
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecdiff.out'),
                                  1e-08))
     file_utils.remove('vector.out')
Пример #20
0
    def StrainCheck(self):
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure: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='microstructure:skeleton:mesh',
                       endtime=0.0)
        OOF.Mesh.Analyze.Direct_Output(
            mesh='microstructure:skeleton:mesh',
            time=latest,
            data=getOutput('Strain:Value',
                           type=GeometricStrain()),
            domain=EntireMesh(),
            sampling=GridSampleSet(x_points=3,
                                   y_points=3,
                                   show_x=True,
                                   show_y=True),
            destination=OutputStream(filename='plane_stress_rhs.out', mode='w'))

        outputdestination.forgetTextOutputStreams()

        self.assert_(fp_file_compare(
            'plane_stress_rhs.out',
            os.path.join('output_data','plane_stress_ref.dat'),
            1.0e-08)
                     )
        file_utils.remove('plane_stress_rhs.out')
Пример #21
0
    def RK4(self):
        # I can't get this to work with any parameter values.
        OOF.Subproblem.Set_Solver(
            subproblem='microstructure:skeleton:mesh:default',
            solver_mode=AdvancedSolverMode(
                time_stepper=AdaptiveDriver(
                    initialstep=0.0001,
                    tolerance=1.e-3,
                    minstep=1.e-05,
                    errorscaling=AbsoluteErrorScaling(),
                    stepper=TwoStep(singlestep=RK4())),
                nonlinear_solver=Newton(relative_tolerance=1e-08,
                                        absolute_tolerance=1.e-13,
                                        maximum_iterations=200),
                symmetric_solver=ConjugateGradient(
                    preconditioner=ILUPreconditioner(),
                    tolerance=1e-13,
                    max_iterations=1000)))
        OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)

        self.assert_(
            file_utils.fp_file_compare('nlbulktemp.dat',
                                       os.path.join('mesh_data',
                                                    'nlbulktemp.dat'),
                                       tolerance=1.e-5))
        file_utils.remove('nlbulktemp.dat')
        self.assert_(
            file_utils.fp_file_compare('nlavgtoptemp.dat',
                                       os.path.join('mesh_data',
                                                    'nlavgtoptemp.dat'),
                                       tolerance=1.e-6))
        file_utils.remove('nlavgtoptemp.dat')
Пример #22
0
 def Multiply(self):
     vector0 = loadVector('vector0')
     vector1 = loadVector('vector1')
     vec = 2*vector0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0*2.0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0/0.5
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec *= 2.0
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec /= 0.5
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecprod.out'),
                                  1.e-8))
     dot = vector0 * vector1
     self.assertEqual(dot, 20.0)
     dot = vector0.dot(vector1)
     self.assertEqual(dot, 20.0)
     file_utils.remove('vector.out')
Пример #23
0
 def Add(self):
     vector0 = loadVector('vector0')
     vector1 = loadVector('vector1')
     self.assertEqual(vector0.size(), 4)
     self.assertEqual(vector1.size(), 4)
     sum = vector0 + vector1
     sum.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec.axpy(2.0, vector1)
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum2.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec += vector1
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecsum.out'),
                                  1.e-8))
     diff = vector0 - vector1
     diff.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecdiff.out'),
                                  1.e-8))
     vec = vector0.clone()
     vec -= vector1
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'vecdiff.out'),
                                  1e-08))
     file_utils.remove('vector.out')
Пример #24
0
 def readwrite(self, infile, compfile):
     matrix = loadMatrix(infile)
     saveMatrix(matrix, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, compfile),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #25
0
 def Static(self):
     OOF.Mesh.Apply_Field_Initializers_at_Time(
         mesh='microstructure:skeleton:mesh', time=1)
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)
     OOF.Mesh.Analyze.Direct_Output(
         mesh='microstructure:skeleton:mesh',
         time=latest,
         data=getOutput('Field:Value', field=Displacement),
         domain=SinglePoint(point=Point(1, 0)),
         sampling=DiscretePointSampleSet(show_x=True, show_y=True),
         destination=OutputStream(filename='rotate.out', mode='w'))
     self.assert_(
         file_utils.compare_last('rotate.out',
                                 [1, 0, 1 / sqrt(2.) - 1, 1 / sqrt(2.)]))
     OOF.Mesh.Analyze.Direct_Output(
         mesh='microstructure:skeleton:mesh',
         time=latest,
         data=getOutput('Field:Value', field=Displacement),
         domain=SinglePoint(point=Point(0, 1)),
         sampling=DiscretePointSampleSet(show_x=True, show_y=True),
         destination=OutputStream(filename='rotate.out', mode='w'))
     self.assert_(
         file_utils.compare_last('rotate.out',
                                 [0, 1, -1 / sqrt(2.), 1 / sqrt(2.) - 1]))
     file_utils.remove('rotate.out')
Пример #26
0
 def Save(self):
     OOF.Microstructure.New(name="save_test",
                            width=2.5,
                            height=3.5,
                            depth=4.5,
                            width_in_pixels=10,
                            height_in_pixels=10,
                            depth_in_pixels=10)
     OOF.File.Save.Microstructure(filename="ms_save_test",
                                  mode="w",
                                  format="ascii",
                                  microstructure="save_test")
     self.assert_(
         file_utils.fp_file_compare("ms_save_test",
                                    os.path.join("ms_data", "saved_ms"),
                                    1.e-10))
     file_utils.remove("ms_save_test")
     OOF.File.Save.Microstructure(filename="ms_save_test",
                                  mode="w",
                                  format="binary",
                                  microstructure="save_test")
     self.assert_(
         file_utils.fp_file_compare(
             "ms_save_test", os.path.join("ms_data", "saved_ms_binary"),
             1.e-10))
     file_utils.remove("ms_save_test")
Пример #27
0
 def Static(self):
     OOF.Mesh.Apply_Field_Initializers_at_Time(
         mesh='microstructure:skeleton:mesh', time=1)
     OOF.Mesh.Solve(
         mesh='microstructure:skeleton:mesh', endtime=1.0)
     OOF.Mesh.Analyze.Direct_Output(
         mesh='microstructure:skeleton:mesh',
         time=latest,
         data=getOutput('Field:Value',field=Displacement),
         domain=SinglePoint(point=Point(1,0)),
         sampling=DiscretePointSampleSet(show_x=True,show_y=True),
         destination=OutputStream(filename='rotate.out',mode='w'))
     self.assert_(file_utils.compare_last(
             'rotate.out',
             [1, 0, 1/sqrt(2.)-1, 1/sqrt(2.)]))
     OOF.Mesh.Analyze.Direct_Output(
         mesh='microstructure:skeleton:mesh',
         time=latest,
         data=getOutput('Field:Value',field=Displacement),
         domain=SinglePoint(point=Point(0,1)),
         sampling=DiscretePointSampleSet(show_x=True,show_y=True),
         destination=OutputStream(filename='rotate.out',mode='w'))
     self.assert_(file_utils.compare_last(
             'rotate.out',
             [0, 1, -1/sqrt(2.), 1/sqrt(2.)-1]))
     file_utils.remove('rotate.out')
Пример #28
0
 def Scalar_Multiply(self):
     matrix = loadMatrix('matrix1')
     prod = matrix*2.0
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     prod = 2.0*matrix
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     prod = matrix/0.5
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     matrix2 = matrix.clone()
     matrix2 *= 2.0
     saveMatrix(matrix2, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     matrix2 = matrix.clone()
     matrix2 /= 0.5
     saveMatrix(matrix2, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod.out'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #29
0
 def Scalar_Multiply(self):
     matrix = loadMatrix('matrix1')
     prod = matrix*2.0
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     prod = 2.0*matrix
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     prod = matrix/0.5
     saveMatrix(prod, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     matrix2 = matrix.clone()
     matrix2 *= 2.0
     saveMatrix(matrix2, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                  os.path.join(datadir, 'prod.out'),
                  1.e-8))
     matrix2 = matrix.clone()
     matrix2 /= 0.5
     saveMatrix(matrix2, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'prod.out'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #30
0
 def Transpose(self):
     matrix1 = loadMatrix('matrix1')
     mat = matrix1.transpose()
     saveMatrix(mat, "matrix.out")
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'transpose.mtx'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #31
0
 def NamedVectorField(self):
     self.scheduleNamedVectorField('test.dat', 0.1)
     self.solve()
     self.assert_(file_utils.fp_file_compare(
             'test.dat',
             os.path.join('mesh_data', 'vectorfieldoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #32
0
 def check(self):
     self.assert_(
         file_utils.fp_file_compare("riiight.out", os.path.join("mesh_data", "riiight.out"), tolerance=1.0e-4)
     )
     file_utils.remove("riiight.out")
     self.assert_(
         file_utils.fp_file_compare("stress_nl2.out", os.path.join("mesh_data", "stress_nl2.out"), tolerance=1.0e-4)
     )
     file_utils.remove("stress_nl2.out")
Пример #33
0
 def NamedTensorFlux(self):
     self.scheduleNamedTensorFluxNormal('test.dat', 0.1)
     self.solve()
     self.assert_(file_utils.fp_file_compare(
             'test.dat',
             os.path.join('mesh_data', 'tensorfluxoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #34
0
    def checkPoleFigures(self, prefix, nBins=None, colorMap=None):
        nBins = nBins or 30
        colorMap = colorMap or colormap.GrayMap()

        OOF.OrientationMap.Pole_Figure(
            microstructure='microstructure', 
            pixels=every, 
            symmetry='Cubic',
            pole=AngleDirection(theta=0,phi=0),
            nBins=nBins,
            min=0, max=automatic,
            colormap=colorMap,
            filename='test.pdf')
        self.assert_(fp_file_compare(
                'test.pdf', os.path.join('polefigure_data', prefix+'_0.pdf'),
                1.e-8, comment='%', pdfmode=True))

        OOF.OrientationMap.Pole_Figure(
            microstructure='microstructure', 
            pixels=every, 
            symmetry='Cubic',
            pole=AngleDirection(theta=45,phi=0),
            nBins=nBins,
            min=0, max=automatic,
            colormap=colorMap,
            filename='test.pdf')
        self.assert_(fp_file_compare(
                'test.pdf', os.path.join('polefigure_data', prefix+'_1.pdf'),
                1.e-8, comment='%', pdfmode=True))

        OOF.OrientationMap.Pole_Figure(
            microstructure='microstructure', 
            pixels=every, 
            symmetry='Orthorhombic',
            pole=AngleDirection(theta=45,phi=0),
            nBins=nBins,
            min=0, max=automatic,
            colormap=colorMap,
            filename='test.pdf')
        self.assert_(fp_file_compare(
                'test.pdf', os.path.join('polefigure_data', prefix+'_2.pdf'),
                1.e-8, comment='%', pdfmode=True))
        file_utils.remove('test.pdf')

        OOF.OrientationMap.Pole_Figure(
            microstructure='microstructure', 
            pixels=every, 
            symmetry='Orthorhombic',
            pole=AngleDirection(theta=45,phi=30),
            nBins=nBins,
            min=0, max=automatic,
            colormap=colorMap,
            filename='test.pdf')
        self.assert_(fp_file_compare(
                'test.pdf', os.path.join('polefigure_data', prefix+'_3.pdf'),
                1.e-8, comment='%', pdfmode=True))
        file_utils.remove('test.pdf')
Пример #35
0
 def NamedVectorField(self):
     self.scheduleNamedVectorField('test.dat', 0.1)
     self.solve()
     self.assert_(
         file_utils.fp_file_compare(
             'test.dat', os.path.join('mesh_data', 'vectorfieldoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #36
0
 def NamedTensorFlux(self):
     self.scheduleNamedTensorFluxNormal('test.dat', 0.1)
     self.solve()
     self.assert_(
         file_utils.fp_file_compare(
             'test.dat', os.path.join('mesh_data', 'tensorfluxoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #37
0
 def compare(self, filename):
     OOF.File.Save.Mesh(filename=filename,
                        mode='w',
                        format='ascii',
                        mesh='microstructure:skeleton:mesh')
     self.assert_(
         file_utils.fp_file_compare(filename,
                                    os.path.join('mesh_data', filename),
                                    1.e-6))
     file_utils.remove(filename)
Пример #38
0
    def StressFreeStrain(self):
        OOF.Material.Add_property(name="middle", property="Mechanical:Elasticity:Isotropic")
        OOF.Material.Add_property(name="edges", property="Mechanical:Elasticity:Isotropic")
        OOF.Property.Copy(property="Mechanical:StressFreeStrain:Anisotropic:Orthorhombic", new_name="new")
        OOF.Material.Add_property(name="middle", property="Mechanical:StressFreeStrain:Anisotropic:Orthorhombic:new")
        OOF.Property.Parametrize.Mechanical.StressFreeStrain.Anisotropic.Orthorhombic.new(
            epsilon0=OrthorhombicRank2Tensor(xx=0.0, yy=0.0, zz=0.1)
        )
        OOF.Property.Copy(property="Orientation", new_name="new")
        OOF.Material.Add_property(name="middle", property="Orientation:new")
        OOF.Property.Parametrize.Orientation.new(angles=Axis(angle=90, x=0.0, y=1, z=1.0))
        OOF.Subproblem.Field.Define(subproblem="microstructure:skeleton:mesh:default", field=Displacement)
        OOF.Subproblem.Field.Activate(subproblem="microstructure:skeleton:mesh:default", field=Displacement)
        OOF.Mesh.Field.In_Plane(mesh="microstructure:skeleton:mesh", field=Displacement)
        OOF.Subproblem.Equation.Activate(subproblem="microstructure:skeleton:mesh:default", equation=Force_Balance)
        OOF.Mesh.Boundary_Conditions.New(
            name="bc",
            mesh="microstructure:skeleton:mesh",
            condition=DirichletBC(
                field=Displacement,
                field_component="x",
                equation=Force_Balance,
                eqn_component="x",
                profile=ContinuumProfileXTd(function="0", timeDerivative="0", timeDerivative2="0"),
                boundary="left",
            ),
        )
        OOF.Mesh.Boundary_Conditions.New(
            name="bc<2>",
            mesh="microstructure:skeleton:mesh",
            condition=DirichletBC(
                field=Displacement,
                field_component="y",
                equation=Force_Balance,
                eqn_component="y",
                profile=ContinuumProfileXTd(function="0", timeDerivative="0", timeDerivative2="0"),
                boundary="left",
            ),
        )
        OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=0.0)
        OOF.File.Save.Mesh(filename="mesh1.dat", mode="w", format="ascii", mesh="microstructure:skeleton:mesh")
        self.assert_(
            file_utils.fp_file_compare("mesh1.dat", os.path.join("aniso_data", "stressfreestrain1.dat"), tolerance)
        )
        OOF.Property.Parametrize.Orientation.new(angles=Axis(angle=0, x=0.0, y=1.0, z=1.0))
        OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=0.0)
        OOF.File.Save.Mesh(filename="mesh2.dat", mode="w", format="ascii", mesh="microstructure:skeleton:mesh")
        self.assert_(
            file_utils.fp_file_compare("mesh2.dat", os.path.join("aniso_data", "stressfreestrain2.dat"), tolerance)
        )
        file_utils.remove("mesh1.dat")
        file_utils.remove("mesh2.dat")

        OOF.Property.Delete(property="Orientation:new")
        OOF.Property.Delete(property="Mechanical:StressFreeStrain:Anisotropic:Orthorhombic:new")
Пример #39
0
 def TwoTogetherAsync(self):
     # Two outputs sent to one file.
     self.scheduleUnnamedVectorField('test.dat', 0.1)
     self.scheduleUnnamedTensorFluxNormal('test.dat', 0.2)
     self.solve()
     self.assert_(
         file_utils.fp_file_compare(
             'test.dat', os.path.join('mesh_data', 'asyncoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #40
0
 def TwoTogetherAsync(self):
     # Two outputs sent to one file.
     self.scheduleUnnamedVectorField('test.dat', 0.1)
     self.scheduleUnnamedTensorFluxNormal('test.dat', 0.2)
     self.solve()
     self.assert_(file_utils.fp_file_compare(
             'test.dat',
             os.path.join('mesh_data', 'asyncoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('test.dat')
Пример #41
0
 def check(self):
     self.assert_(file_utils.fp_file_compare(
             'riiight.out',
             os.path.join('mesh_data', 'riiight.out'),
             tolerance=1.e-4))
     file_utils.remove('riiight.out')
     self.assert_(file_utils.fp_file_compare(
             'stress_nl2.out',
             os.path.join('mesh_data', 'stress_nl2.out'),
             tolerance=1.e-4))
     file_utils.remove('stress_nl2.out')
Пример #42
0
    def All2x2x2(self):
        ms = microstructure.getMicrostructure('microstructure')
        skel = skeletoncontext.getSkeleton(ms, "skeleton").getObject()
        # The non-trivial combinations of voxels correspond to voxel
        # signatures between 1 and 255.  Signature 0 has no voxels in
        # it, and would be equivalent to the Trivial test, above.
        sigs = range(1, 256)
        for sig in sigs:
            nvox = self.selectSig(sig)
            sigstr = voxelsetboundary.printSig(sig)
            print "Selected voxels:", sigstr, "(sig=%d)" % sig
            self.assertEqual(nvox, self.selectionSize())

            OOF.PixelGroup.AddSelection(microstructure='microstructure',
                                        group='pixelgroup')
            self.assertEqual(ms.nCategories(), 2)  # triggers categorization

            unselectedCat = ms.category(Point(0, 0, 0))
            selectedCat = 1 - unselectedCat
            print "selectedCat=", selectedCat, "unselectedCat=",\
                unselectedCat

            skel.dumpVSB(selectedCat, "selected.dat")
            skel.dumpVSB(unselectedCat, "unselected.dat")
            # ms.dumpVSBLines(selectedCat, "selected_"+sigstr+".lines")
            # ms.dumpVSBLines(unselectedCat, "unselected_"+sigstr+".lines")

            selectedVol = ms.volumeOfCategory(selectedCat)
            unselectedVol = ms.volumeOfCategory(unselectedCat)
            print "selectedVol=", selectedVol, \
                "unselectedVol=", unselectedVol
            print "Checking connectivity for selected voxels, category",\
                selectedCat
            self.assert_(skel.checkVSB(selectedCat))
            print "Checking connectivity for unselected voxels, category",\
                unselectedCat
            self.assert_(skel.checkVSB(unselectedCat))
            self.assertAlmostEqual(selectedVol, nvox)
            self.assertAlmostEqual(unselectedVol, 64 - nvox)
            # Check that the saved VSB graphs are correct
            sigstr = sigstr.replace('|', '-')
            self.assert_(
                file_utils.fp_file_compare(
                    "selected.dat",
                    os.path.join("vsb_data", "selected_" + sigstr + ".dat"),
                    1.e-9))
            self.assert_(
                file_utils.fp_file_compare(
                    "unselected.dat",
                    os.path.join("vsb_data", "unselected_" + sigstr + ".dat"),
                    1.e-9))
            print "-------"
            file_utils.remove("selected.dat")
            file_utils.remove("unselected.dat")
Пример #43
0
 def check(self):
     self.assert_(file_utils.fp_file_compare(
             'riiight.out',
             os.path.join('mesh_data', 'riiight.out'),
             tolerance=1.e-4))
     file_utils.remove('riiight.out')
     self.assert_(file_utils.fp_file_compare(
             'stress_nl2.out',
             os.path.join('mesh_data', 'stress_nl2.out'),
             tolerance=1.e-4))
     file_utils.remove('stress_nl2.out')
Пример #44
0
 def solveAndCheck(self, filename):
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=0.0)
     OOF.File.Save.Mesh(filename='solved',
                        mode='w',
                        format='ascii',
                        mesh='microstructure:skeleton:mesh')
     self.assert_(
         file_utils.fp_file_compare('solved',
                                    os.path.join('bc_data', filename),
                                    1.e-10))
     file_utils.remove("solved")
Пример #45
0
 def Adaptive_Pts(self):
     self.adaptive()
     self.topleftOutput(interval=0.1, filename='test.dat')
     self.shearTopPoints()
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)
     self.assert_(
         file_utils.fp_file_compare(
             'test.dat', os.path.join('mesh_data', 'td_dirichlet.dat'),
             1.e-10))
     file_utils.remove('test.dat')
     outputdestination.forgetTextOutputStreams()
Пример #46
0
 def Adaptive_Pts(self):
     self.adaptive()
     self.topleftOutput(interval=0.1, filename='test.dat')
     self.shearTopPoints()
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=1.0)
     self.assert_(
         file_utils.fp_file_compare(
             'test.dat',
             os.path.join('mesh_data', 'td_dirichlet.dat'),
             1.e-10))
     file_utils.remove('test.dat')
     outputdestination.forgetTextOutputStreams()
Пример #47
0
    def IC(self):  # Incomplete Cholesky decomposition
        matrix = loadMatrix('identity')
        pcwrap = preconditioner.ICPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.unfactored(), 'matrix.out')
        self.assert_(
            fp_file_compare('matrix.out', os.path.join(datadir, 'identity'),
                            1.e-8))

        ## NOTE: The reference matrices were generated by this
        ## program, not SparseLib++, because the SparseLib++ IC
        ## preconditioner seems to be broken...

        matrix = loadMatrix('small_sym_sparse2.mat')
        pc = pcwrap.create_preconditioner(matrix)
        # Save the *upper* triangle, even though the lower one is more
        # natural for the ICPreconditioner class. The reference file
        # generated by SparseLib++ contains the upper triangle.
        saveMatrix(pc.upper(), 'matrix.out')
        self.assert_(
            fp_file_compare('matrix.out',
                            os.path.join(datadir, 'small_sym_upper2.out'),
                            1.e-8))

        matrix = loadMatrix('small_sym_sparse.mat')
        pc = pcwrap.create_preconditioner(matrix)
        # Save the *upper* triangle, even though the lower one is more
        # natural for the ICPreconditioner class. The reference file
        # generated by SparseLib++ contains the upper triangle.
        saveMatrix(pc.upper(), 'matrix.out')
        self.assert_(
            fp_file_compare('matrix.out',
                            os.path.join(datadir, 'small_sym_upper.out'),
                            1.e-8))

        # Big matrices from Matrix Market. 'bcsstk07' has been
        # removed. It can't be factored, apparently due to a pathology
        # of the matrix or the algorithm.  It passes the complete
        # Cholesky test.
        for mtxname in (
                's1rmq4m1',
                'bcsstk01',
        ):
            print >> sys.stderr, mtxname + '.mtx'
            matrix = loadMatrix(mtxname + '.mtx', fortran=True, symmetric=True)
            pc = pcwrap.create_preconditioner(matrix)
            self.assert_(pc.upper().unique_indices())
            saveMatrix(pc.upper(), 'matrix.out')
            self.assert_(
                fp_file_compare('matrix.out',
                                os.path.join(datadir, mtxname + '_upper.out'),
                                1.e-8))
        file_utils.remove('matrix.out')
Пример #48
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_(file_utils.fp_file_compare(
         "prop_save_test",
         os.path.join("matprop_data", "propsave"), 1.e-9))
     file_utils.remove("prop_save_test")
     OOF.Property.Delete(property="Color:bloo")
Пример #49
0
 def compareFiles(self, topfile, leftfile):
     self.assert_(
         file_utils.fp_file_compare('temptop.dat',
                                    os.path.join('mesh_data', topfile),
                                    1.e-10))
     self.assert_(
         file_utils.fp_file_compare('templeft.dat',
                                    os.path.join('mesh_data', leftfile),
                                    1.e-10))
     file_utils.remove('temptop.dat')
     file_utils.remove('templeft.dat')
     outputdestination.forgetTextOutputStreams()
Пример #50
0
    def LU(self):
        # Test the ILU code on dense matrices.
        # A full identity matrix
        matrix = loadMatrix('identity-full')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'identity-full'),
                                     1.e-8))

        # Non-trivial test: a dense asymmetric matrix.
        matrix = loadMatrix('dense-asym-mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'ilu_unfactored'),
                                     1.e-8))
        # Check the preconditioner solutions...
        for vecname in ('rhs2.1', 'rhs2.2', 'rhs2.3'):
            vec = loadVector(vecname)
            result = pc.solve(vec)
            result.save('vector.out')
            self.assert_(fp_file_compare('vector.out',
                                         os.path.join(datadir,
                                                      vecname+'_ilu.out'),
                                         1.e-8))

        # A big(ger) dense matrix
        matrix = loadMatrix('big.mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'big.mat'),
                                     1.e-8))
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        file_utils.remove('matrix.out')
        file_utils.remove('vector.out')
Пример #51
0
    def LU(self):
        # Test the ILU code on dense matrices.
        # A full identity matrix
        matrix = loadMatrix('identity-full')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'identity-full'),
                                     1.e-8))

        # Non-trivial test: a dense asymmetric matrix.
        matrix = loadMatrix('dense-asym-mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'ilu_unfactored'),
                                     1.e-8))
        # Check the preconditioner solutions...
        for vecname in ('rhs2.1', 'rhs2.2', 'rhs2.3'):
            vec = loadVector(vecname)
            result = pc.solve(vec)
            result.save('vector.out')
            self.assert_(fp_file_compare('vector.out',
                                         os.path.join(datadir,
                                                      vecname+'_ilu.out'),
                                         1.e-8))

        # A big(ger) dense matrix
        matrix = loadMatrix('big.mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'big.mat'),
                                     1.e-8))
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        file_utils.remove('matrix.out')
        file_utils.remove('vector.out')
Пример #52
0
    def PDFOutput(self):
        from ooflib.common.IO import gfxmanager
        # Load the output mesh, and draw a nice filled contour plot.
        OOF.File.Load.Data(filename=reference_file('output_data',
                                                 'position_mesh'))
        OOF.Windows.Graphics.New()
        OOF.LayerEditor.LayerSet.New(window='Graphics_1')
        OOF.LayerEditor.LayerSet.DisplayedObject(
            category='Mesh', object='microstructure:skeleton:mesh')
        OOF.LayerEditor.LayerSet.Add_Method(
            method=FilledContourDisplay(
            what=getOutput('Field:Component',
                           component='x',
                           field=Displacement),
            where=getOutput('original'),
            min=automatic, max=automatic, levels=11,
            nbins=5, colormap=ThermalMap()))
        OOF.LayerEditor.LayerSet.DisplayedObject(
            category='Microstructure', object='microstructure')
        OOF.LayerEditor.LayerSet.Add_Method(
            method=MicrostructureMaterialDisplay(
                no_material=Gray(value=0.0),
                no_color=RGBColor(red=0.0,green=0.0,blue=1.0)))
        OOF.LayerEditor.LayerSet.Send(window='Graphics_1')
        OOF.Graphics_1.File.Save_Image(filename="test.pdf",overwrite=True)

        # In Python 2.7 and above, the floating point numbers in the
        # comments in the pdf file have short reprs, (eg, 0.6 instead
        # of 0.59999999999999998).  That messes up the character
        # counts later in the file, so we have to use different
        # reference files for different floating point formats.  Check
        # float_repr_style instead of the Python version number
        # because not all platforms support the short reprs.
        try:
            shortform = sys.float_repr_style == 'short'
        except AttributeError:
            shortform = False
        if shortform:
            self.assert_(
                fp_file_compare(
                    'test.pdf', os.path.join('output_data','posmesh-short.pdf'),
                    1.0e-08, comment="%", pdfmode=True) )
        else:
            self.assert_(
                fp_file_compare(
                    'test.pdf', os.path.join('output_data','posmesh.pdf'),
                    1.0e-08, comment="%", pdfmode=True) )
        file_utils.remove('test.pdf')
            
        OOF.Graphics_1.File.Close()
        OOF.Material.Delete(name="material")
Пример #53
0
    def PDFOutput(self):
        from ooflib.common.IO import gfxmanager
        # Load the output mesh, and draw a nice filled contour plot.
        OOF.File.Load.Data(filename=reference_file('output_data',
                                                 'position_mesh'))
        OOF.Windows.Graphics.New()
        OOF.LayerEditor.LayerSet.New(window='Graphics_1')
        OOF.LayerEditor.LayerSet.DisplayedObject(
            category='Mesh', object='microstructure:skeleton:mesh')
        OOF.LayerEditor.LayerSet.Add_Method(
            method=FilledContourDisplay(
            what=getOutput('Field:Component',
                           component='x',
                           field=Displacement),
            where=getOutput('original'),
            min=automatic, max=automatic, levels=11,
            nbins=5, colormap=ThermalMap()))
        OOF.LayerEditor.LayerSet.DisplayedObject(
            category='Microstructure', object='microstructure')
        OOF.LayerEditor.LayerSet.Add_Method(
            method=MicrostructureMaterialDisplay(
                no_material=Gray(value=0.0),
                no_color=RGBColor(red=0.0,green=0.0,blue=1.0)))
        OOF.LayerEditor.LayerSet.Send(window='Graphics_1')
        OOF.Graphics_1.File.Save_Image(filename="test.pdf",overwrite=True)

        # In Python 2.7 and above, the floating point numbers in the
        # comments in the pdf file have short reprs, (eg, 0.6 instead
        # of 0.59999999999999998).  That messes up the character
        # counts later in the file, so we have to use different
        # reference files for different floating point formats.  Check
        # float_repr_style instead of the Python version number
        # because not all platforms support the short reprs.
        try:
            shortform = sys.float_repr_style == 'short'
        except AttributeError:
            shortform = False
        if shortform:
            self.assert_(
                fp_file_compare(
                    'test.pdf', os.path.join('output_data','posmesh-short.pdf'),
                    1.0e-08, comment="%", pdfmode=True) )
        else:
            self.assert_(
                fp_file_compare(
                    'test.pdf', os.path.join('output_data','posmesh.pdf'),
                    1.0e-08, comment="%", pdfmode=True) )
        file_utils.remove('test.pdf')
            
        OOF.Graphics_1.File.Close()
        OOF.Material.Delete(name="material")
Пример #54
0
 def Add(self):
     matrix1 = loadMatrix('matrix1')
     matrix2 = loadMatrix('matrix2')
     sum = matrix1 + matrix2
     saveMatrix(sum, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'sum.mat'),
                                  1.e-8))
     diff = matrix1 - matrix2
     saveMatrix(diff, 'matrix.out')
     self.assert_(fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'diff.mat'),
                                  1.e-8))
     file_utils.remove('matrix.out')
Пример #55
0
 def compareFiles(self, topfile, leftfile):
     self.assert_(
         file_utils.fp_file_compare(
             'temptop.dat',
             os.path.join('mesh_data', topfile),
             1.e-10))
     self.assert_(
         file_utils.fp_file_compare(
             'templeft.dat',
             os.path.join('mesh_data', leftfile),
             1.e-10))
     file_utils.remove('temptop.dat')
     file_utils.remove('templeft.dat')
     outputdestination.forgetTextOutputStreams()
Пример #56
0
    def IC(self):               # Incomplete Cholesky decomposition
        matrix = loadMatrix('identity')
        pcwrap = preconditioner.ICPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.unfactored(), 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'identity'),
                                     1.e-8))

        ## NOTE: The reference matrices were generated by this
        ## program, not SparseLib++, because the SparseLib++ IC
        ## preconditioner seems to be broken...

        matrix = loadMatrix('small_sym_sparse2.mat')
        pc = pcwrap.create_preconditioner(matrix)
        # Save the *upper* triangle, even though the lower one is more
        # natural for the ICPreconditioner class. The reference file
        # generated by SparseLib++ contains the upper triangle.
        saveMatrix(pc.upper(), 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir,
                                                  'small_sym_upper2.out'),
                                     1.e-8))

        matrix = loadMatrix('small_sym_sparse.mat')
        pc = pcwrap.create_preconditioner(matrix)
        # Save the *upper* triangle, even though the lower one is more
        # natural for the ICPreconditioner class. The reference file
        # generated by SparseLib++ contains the upper triangle.
        saveMatrix(pc.upper(), 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir,
                                                  'small_sym_upper.out'),
                                     1.e-8))

        # Big matrices from Matrix Market. 'bcsstk07' has been
        # removed. It can't be factored, apparently due to a pathology
        # of the matrix or the algorithm.  It passes the complete
        # Cholesky test.
        for mtxname in ('s1rmq4m1', 'bcsstk01',):
            print >> sys.stderr,  mtxname+'.mtx'
            matrix = loadMatrix(mtxname+'.mtx', fortran=True, symmetric=True)
            pc = pcwrap.create_preconditioner(matrix)
            self.assert_(pc.upper().unique_indices())
            saveMatrix(pc.upper(), 'matrix.out')
            self.assert_(fp_file_compare(
                    'matrix.out', os.path.join(datadir,
                                               mtxname+'_upper.out'),
                    1.e-8))
        file_utils.remove('matrix.out')
Пример #57
0
 def Multiply(self):
     matrix = loadMatrix('matrix1')
     vector = loadVector('vector0')
     vec = matrix*vector
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'matvec.out'),
                                  1.e-8))
     vec = vector*matrix
     vec.save('vector.out')
     self.assert_(fp_file_compare('vector.out',
                                  os.path.join(datadir, 'matvec2.out'),
                                  1.e-8))
     file_utils.remove('vector.out')
Пример #58
0
 def ThermalConductivity(self):
     OOF.Material.Add_property(name="edges", property="Thermal:Conductivity:Isotropic")
     OOF.Property.Copy(property="Thermal:Conductivity:Anisotropic:Orthorhombic", new_name="new")
     OOF.Property.Parametrize.Thermal.Conductivity.Anisotropic.Orthorhombic.new(
         kappa=OrthorhombicRank2Tensor(xx=1.0, yy=1.0, zz=10.0)
     )
     OOF.Material.Add_property(name="middle", property="Thermal:Conductivity:Anisotropic:Orthorhombic:new")
     OOF.Property.Copy(property="Orientation", new_name="new")
     OOF.Property.Parametrize.Orientation.new(angles=Axis(angle=90, x=0.0, y=1.0, z=1.0))
     OOF.Material.Add_property(name="middle", property="Orientation:new")
     OOF.Subproblem.Field.Define(subproblem="microstructure:skeleton:mesh:default", field=Temperature)
     OOF.Subproblem.Field.Activate(subproblem="microstructure:skeleton:mesh:default", field=Temperature)
     OOF.Mesh.Field.In_Plane(mesh="microstructure:skeleton:mesh", field=Temperature)
     OOF.Subproblem.Equation.Activate(subproblem="microstructure:skeleton:mesh:default", equation=Heat_Eqn)
     OOF.Mesh.Boundary_Conditions.New(
         name="bc",
         mesh="microstructure:skeleton:mesh",
         condition=DirichletBC(
             field=Temperature,
             field_component="",
             equation=Heat_Eqn,
             eqn_component="",
             profile=ContinuumProfileXTd(function="1.0", timeDerivative="0", timeDerivative2="0"),
             boundary="bottomleft",
         ),
     )
     OOF.Mesh.Boundary_Conditions.New(
         name="bc",
         mesh="microstructure:skeleton:mesh",
         condition=DirichletBC(
             field=Temperature,
             field_component="",
             equation=Heat_Eqn,
             eqn_component="",
             profile=ContinuumProfileXTd(function="0.0", timeDerivative="0", timeDerivative2="0"),
             boundary="topright",
         ),
     )
     OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=0.0)
     OOF.File.Save.Mesh(filename="mesh.dat", mode="w", format="ascii", mesh="microstructure:skeleton:mesh")
     self.assert_(file_utils.fp_file_compare("mesh.dat", os.path.join("aniso_data", "heatcond1.dat"), tolerance))
     file_utils.remove("mesh.dat")
     OOF.Property.Parametrize.Orientation.new(angles=Axis(angle=0, x=0.0, y=1.0, z=1.0))
     OOF.Mesh.Solve(mesh="microstructure:skeleton:mesh", endtime=0.0)
     OOF.File.Save.Mesh(filename="mesh.dat", mode="w", format="ascii", mesh="microstructure:skeleton:mesh")
     self.assert_(file_utils.fp_file_compare("mesh.dat", os.path.join("aniso_data", "heatcond2.dat"), tolerance))
     file_utils.remove("mesh.dat")
     OOF.Property.Delete(property="Thermal:Conductivity:Anisotropic:Orthorhombic:new")
     OOF.Property.Delete(property="Orientation:new")
Пример #59
0
 def TwoSeparateNamed(self):
     # Two outputs sent to separate files.
     self.scheduleNamedVectorField('vtest.dat', 0.1)
     self.scheduleNamedTensorFluxNormal('ttest.dat', 0.1)
     self.solve()
     self.assert_(file_utils.fp_file_compare(
             'vtest.dat',
             os.path.join('mesh_data', 'vectorfieldoutput.dat'),
             1.e-8))
     self.assert_(file_utils.fp_file_compare(
             'ttest.dat',
             os.path.join('mesh_data', 'tensorfluxoutput.dat'),
             1.e-8))
     self.rewind()
     file_utils.remove('vtest.dat')
     file_utils.remove('ttest.dat')
Пример #60
0
 def stressFreeStrainTest(self):
     OOF.Mesh.Apply_Field_Initializers(
         mesh='microstructure:skeleton:mesh')
     OOF.Mesh.Solve(mesh='microstructure:skeleton:mesh', endtime=0.0)
     OOF.Mesh.Analyze.Direct_Output(
         mesh='microstructure:skeleton:mesh',
         time=latest, 
         data=getOutput('Field:Value',field=Displacement),
         domain=EntireMesh(),
         sampling=GridSampleSet(
             x_points=10,y_points=10,show_x=True,show_y=True),
         destination=OutputStream(filename='pyprop.out',mode='w'))
     outputdestination.forgetTextOutputStreams()
     self.assert_(file_utils.fp_file_compare(
             'pyprop.out',
             os.path.join('mesh_data', 'pystressfreestrain.out'),
             1.e-6))
     file_utils.remove('pyprop.out')