예제 #1
0
    def makeParameterTable(self, value, interactive):
        # 'value' is an Output prototype.  The parameter table is
        # rebuilt every time the Output changes.
        debug.mainthreadTest()
        self.destroyParameterTable()

        # 'value' is an Output of the requested type, but it may have
        # incorrect parameter values.  Cloning the output creates
        # clones of the parameters, each with auxData "Output" set to
        # its pipeline component.  The Parameters' widgets can use
        # this data if necessary (see invariantwidget.py).
        self.output = value.clone()

        # get the hierarchical list of the settable parameters
        paramhier = self.output.listAllParametersHierarchically(onlySettable=1)

        self.params = utils.flatten_all(paramhier)

        if self.params:
            for param in self.params:
                if param.value is None:
                    param.value = param.default
            self.paramtable = parameterwidgets.HierParameterTable(paramhier,
                                                                  scope=self)
            self.parambox.pack_start(self.paramtable.gtk, expand=0, fill=0)
            self.widgetChanged(self.paramtable.isValid(), interactive)
            self.paramtable.show()
            self.sbcallback = switchboard.requestCallbackMain(
                self.paramtable, self.tableChangedCB)
        else:
            self.paramtable = None
            self.widgetChanged(1, interactive)
예제 #2
0
 def __call__(self, time, output, domain, sampling, destination):
     olist = sampling.evaluate(domain, output)
     if len(olist) > 0:
         vmin = vmax = olist[0][1].initRange()
         for sample, value in olist:
             vmin, vmax = value.expandRange(vmin, vmax)
         self.printResults(time, utils.flatten_all([vmin, vmax]),
                           destination)
예제 #3
0
    def PositionOutputs(self):
        global position_output_args
        tolerance = 1.0e-08
        from ooflib.common import utils
        from ooflib.engine import mesh
        from ooflib.engine.IO import output
        from ooflib.SWIG.engine import mastercoord
        tree = output.positionOutputs
        outputpaths = tree.leafpaths()
        outputnames = [ string.join(x,':') for x in outputpaths ]
        OOF.File.Load.Data(filename=reference_file('output_data',
                                                 'position_mesh'))
        meshobj = mesh.meshes['microstructure:skeleton:mesh'].getObject()
        for name in outputnames:
            try:
                (param_args, results) = position_output_args[name]
            except KeyError:
                print >> sys.stderr,  "No test data for PositionOutput %s." % name
            else:
                outputobj = tree[name].object
                paramhier = outputobj.listAllParametersHierarchically(
                    onlySettable=1)
                params = utils.flatten_all(paramhier)
                # Actually set the settable parameters.
                pdict = {}
                for p in params:
                    pdict[p.name]=param_args[p.name]
                #
                outputclone = outputobj.clone(params=pdict)

                # The "Analyze" menu item doesn't do PositionOutputs,
                # so we do these directly.  Evaluate each element at
                # mastercoord (0,0).

                elset = meshobj.element_iterator()
                reslist = []
                while not elset.end():
                    lmnt = elset.element()
                    reslist += outputclone.evaluate(
                        meshobj, [lmnt],
                        [[mastercoord.MasterCoord(0.0,0.0)]])
                    elset.next()
                for (r1,r2) in zip(reslist, results):
                    self.assert_( (r1-r2)**2 < tolerance )
        del meshobj
        OOF.Material.Delete(name='material')
예제 #4
0
 def makeParameterTable(self, value, interactive):
     debug.mainthreadTest()
     self.destroyParameterTable()
     # get the hierarchical list of clones of the settable parameters
     self.paramhier = value.listAllParametersHierarchically(onlySettable=1)
     self.params = utils.flatten_all(self.paramhier)
     if self.params:
         self.paramtable = \
                         parameterwidgets.HierParameterTable(self.paramhier,
                                                             scope=self)
         self.parambox.pack_start(self.paramtable.gtk, expand=0, fill=0)
         self.widgetChanged(self.paramtable.isValid(), interactive)
         self.paramtable.show()
         self.sbcallback = switchboard.requestCallbackMain(
             self.paramtable, self.tableChangedCB)
     else:
         self.paramtable = None
         self.widgetChanged(1, interactive)
예제 #5
0
 def __init__(self, params, scope=None, verbose=False):
     self.paramhier = params
     ParameterTable.__init__(self,
                             utils.flatten_all(params),
                             scope,
                             verbose=verbose)
예제 #6
0
 def __init__(self, params, scope=None):
     self.paramhier = params
     ParameterTable.__init__(self, utils.flatten_all(params), scope)
예제 #7
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')