Пример #1
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')
Пример #2
0
    def tearDown(self):
        # outputdestination is imported explicitly so that it's still
        # found even if earlier tests are commented out.
        from ooflib.engine.IO import outputdestination

        outputdestination.forgetTextOutputStreams()
        OOF.Material.Delete(name="material")
Пример #3
0
 def Conflict(self):
     from ooflib.SWIG.engine import ooferror2
     OOF.Help.No_Warnings(True)
     self.adaptive()
     self.floatTopEdge()
     self.floatLeftEdge()
     self.initializeMin('top', 0.0)
     self.initializeMin('left', 0.0)
     self.assertRaises(ooferror2.ErrWarning, self.initialize)
     OOF.Help.No_Warnings(False)
     outputdestination.forgetTextOutputStreams()
Пример #4
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()
Пример #5
0
 def Conflict(self):
     from ooflib.SWIG.engine import ooferror2
     OOF.Help.No_Warnings(True)
     self.adaptive()
     self.floatTopEdge()
     self.floatLeftEdge()
     self.initializeMin('top', 0.0)
     self.initializeMin('left', 0.0)
     self.assertRaises(ooferror2.ErrWarning, self.initialize)
     OOF.Help.No_Warnings(False)
     outputdestination.forgetTextOutputStreams()
Пример #6
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()
Пример #7
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()
Пример #8
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()
Пример #9
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')
Пример #10
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')
Пример #11
0
 def Range(self):
     OOF.Microstructure.New(
         name='microstructure', 
         width=1.0, height=1.0,
         width_in_pixels=10, height_in_pixels=10)
     OOF.Skeleton.New(
         name='skeleton',
         microstructure='microstructure', 
         x_elements=4, y_elements=4, 
         skeleton_geometry=QuadSkeleton(
             left_right_periodicity=False,top_bottom_periodicity=False))
     OOF.Mesh.New(
         name='mesh',
         skeleton='microstructure:skeleton',
         element_types=['D2_2', 'T3_3', 'Q4_4'])
     OOF.Subproblem.Field.Define(
         subproblem='microstructure:skeleton:mesh:default',
         field=Temperature)
     OOF.Mesh.Set_Field_Initializer(
         mesh='microstructure:skeleton:mesh',
         field=Temperature, 
         initializer=FuncScalarFieldInit(function='x'))
     OOF.Mesh.Apply_Field_Initializers(
         mesh='microstructure:skeleton:mesh')
     OOF.Mesh.Analyze.Range(
         mesh='microstructure:skeleton:mesh',
         time=latest,
         data=getOutput(
             'Field:Component',component='',field=Temperature),
         domain=EntireMesh(),
         sampling=GridSampleSet(
             x_points=10,y_points=10,
             show_x=True,show_y=True),
         destination=OutputStream(filename='test.dat', mode='w'))
     self.assert_(
         fp_file_compare(
             'test.dat',
             os.path.join('output_data', 'range.dat'),
             1.e-8))
     file_utils.remove('test.dat')
     outputdestination.forgetTextOutputStreams()
Пример #12
0
 def tearDown(self):
     from ooflib.engine.IO import outputdestination
     outputdestination.forgetTextOutputStreams()
     OOF.Material.Delete(name='material')
Пример #13
0
 def tearDown(self):
     # outputdestination is imported explicitly so that it's still
     # found even if earlier tests are commented out.
     from ooflib.engine.IO import outputdestination
     outputdestination.forgetTextOutputStreams()
     OOF.Material.Delete(name='material')
Пример #14
0
    def tearDown(self):
        from ooflib.engine.IO import outputdestination

        outputdestination.forgetTextOutputStreams()
        OOF.Material.Delete(name="material")
Пример #15
0
 def clearCB(self, button):
     outputdestination.forgetTextOutputStreams()
Пример #16
0
 def clearCB(self, button):
     outputdestination.forgetTextOutputStreams()
Пример #17
0
 def Avg(self):
     OOF.Microstructure.New(
         name='microstructure',
         width=1.0, height=1.0, width_in_pixels=10, height_in_pixels=10)
     OOF.Material.New(
         name='material', material_type='bulk')
     OOF.Material.Assign(
         material='material', microstructure='microstructure', pixels=all)
     OOF.Property.Copy(
         property='Mechanical:Elasticity:Anisotropic:Tetragonal',
         new_name='instance')
     OOF.Property.Parametrize.Mechanical.Elasticity.Anisotropic.Tetragonal.instance(
         cijkl=TetragonalRank4TensorCij(
             c11=1, c12=0.1, c13=0.2, c33=0.3, c44=0.4, c66=0.6, c16=0.2))
     OOF.Material.Add_property(
         name='material', 
         property='Mechanical:Elasticity:Anisotropic:Tetragonal:instance')
     OOF.Property.Copy(
         property="Orientation", new_name='instance')
     OOF.Material.Add_property(
         name='material', property='Orientation:instance')
     OOF.Property.Parametrize.Orientation.instance(
         angles=Abg(alpha=45,beta=12,gamma=-37))
     OOF.Skeleton.New(
         name='skeleton',
         microstructure='microstructure',
         x_elements=20, y_elements=20,
         skeleton_geometry=TriSkeleton(
             left_right_periodicity=False,
             top_bottom_periodicity=False,
             arrangement='liberal'))
     OOF.Mesh.New(
         name='mesh',
         skeleton='microstructure:skeleton',
         element_types=['D2_2', 'T3_3', 'Q4_4'])
     OOF.Subproblem.Field.Define(
         subproblem='microstructure:skeleton:mesh:default',
         field=Displacement)
     OOF.Subproblem.Field.Activate(
         subproblem='microstructure:skeleton:mesh:default', 
         field=Displacement)
     OOF.Subproblem.Equation.Activate(
         subproblem='microstructure:skeleton:mesh:default',
         equation=Force_Balance)
     OOF.Subproblem.Equation.Activate(
         subproblem='microstructure:skeleton:mesh:default',
         equation=Plane_Stress)
     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='x',
             equation=Force_Balance,eqn_component='x',
             profile=ContinuumProfileXTd(
                 function='0.1',timeDerivative='0',timeDerivative2='0'),
             boundary='right'))
     OOF.Mesh.Boundary_Conditions.New(
         name='bc<3>', 
         mesh='microstructure:skeleton:mesh',
         condition=DirichletBC(
             field=Displacement,field_component='y',
             equation=Force_Balance,eqn_component='y',
             profile=ContinuumProfileXTd(
                 function='0.0',timeDerivative='0',timeDerivative2='0'),
             boundary='top'))
     OOF.Mesh.Boundary_Conditions.New(
         name='bc<4>', 
         mesh='microstructure:skeleton:mesh', 
         condition=DirichletBC(
             field=Displacement,field_component='y',
             equation=Force_Balance,eqn_component='y',
             profile=ContinuumProfileXTd(
                 function='0.0',timeDerivative='0',timeDerivative2='0'),
             boundary='bottom'))
     OOF.Subproblem.Set_Solver(
         subproblem='microstructure: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='microstructure:skeleton:mesh',
         endtime=0.0)
     OOF.Mesh.Analyze.Average(
         mesh='microstructure:skeleton:mesh', 
         data=getOutput('Flux:Value',flux=Stress),
         time=latest,
         domain=EntireMesh(),
         sampling=ElementSampleSet(order=automatic),
         destination=OutputStream(filename='test.dat',mode='w'))
     self.assert_(
         fp_file_compare(
             'test.dat',
             os.path.join('output_data', 'aniso_planestress.dat'),
             1.e-8))
     file_utils.remove('test.dat')
     outputdestination.forgetTextOutputStreams()
Пример #18
0
    def outputs(self, treename, tree, args, tolerance):
        from ooflib.common import utils
        from ooflib.engine.IO import analyze

        outputpaths = tree.leafpaths()
        outputnames = [ string.join(x,':') for x in outputpaths ]

        OOF.File.Load.Data(filename=reference_file('output_data',
                                                 'thermoelastic.mesh'))
        OOF.File.Load.Data(filename=reference_file('output_data',
                                                 'electroelastic.mesh'))
        for name in outputnames:
            try:
                testlist = args[name]
            except KeyError:
                print >> sys.stderr, "No test data for %s %s." % (treename,
                                                                  name)
            else:
                outputobj = tree[name].object
                paramhier = outputobj.listAllParametersHierarchically(
                    onlySettable=1)
                output_params = utils.flatten_all(paramhier)

                print >> sys.stderr, \
                      "Running test for %s %s." % (treename, name)
                
                for test in testlist:
                    meshname = test[0]
                    test_argdict = test[1]
                    comp_file = test[2]

                    output_param_dict = {}
                    for p in output_params:
                        output_param_dict[p.name]=test_argdict[p.name]

                    outputclone = outputobj.clone(params=output_param_dict)
                    
                    OOF.Mesh.Analyze.Direct_Output(
                        data=outputclone,
                        mesh=meshname,
                        time=latest,
                        domain=EntireMesh(),
                        sampling=GridSampleSet(x_points=10, y_points=10,
                                               show_x=True, show_y=True),
                        destination=OutputStream(filename='test.dat', mode='w')
                        )

                    outputdestination.forgetTextOutputStreams()

                    # Compare test.dat with the right comparison file.
                    print >> sys.stderr,  "Comparing test.dat to", \
                          reference_file('output_data', comp_file)
                    self.assert_(
                        fp_file_compare('test.dat',
                                        os.path.join('output_data', comp_file),
                                        tolerance ) )

                    file_utils.remove('test.dat')

                    # Check the average value of the output. As well
                    # as testing the averaging operation, it tests
                    # that constraints that are only applied weakly
                    # (such as plane stress) are satisfied weakly.
                    OOF.Mesh.Analyze.Average(
                        mesh=meshname,
                        data=outputclone,
                        time=latest,
                        domain=EntireMesh(),
                        sampling=ElementSampleSet(order=automatic),
                        destination=OutputStream(filename='test.dat',mode='w'))
                    outputdestination.forgetTextOutputStreams()

                    self.assert_(
                        fp_file_compare(
                            'test.dat',
                            os.path.join('output_data', 'avg_'+comp_file),
                                        tolerance))
                    file_utils.remove('test.dat')

        OOF.Material.Delete(name='therm_left')
        OOF.Material.Delete(name='therm_centre')
        OOF.Material.Delete(name='therm_right')
        OOF.Material.Delete(name='electro_left')
        OOF.Material.Delete(name='electro_centre')
        OOF.Material.Delete(name='electro_right')
        OOF.Property.Delete(property=
                            'Mechanical:StressFreeStrain:Isotropic:therm')
        OOF.Property.Delete(property=
                            'Couplings:ThermalExpansion:Isotropic:therm')