def validValue(self, val): # # Any string is a potentially valid value # return 1 try: if type(val) is StringType: return type(1.0 * utils.OOFeval(val)) is FloatType else: return isinstance(val, (FloatType, IntType)) except: return False
def get_value(self): debug.mainthreadTest() text = self.gtk.get_text().lstrip() # Derived classes should redefine get_value() to do something # sensible, if possible, when there is no input. They should # return None only if the input is invalid (which may or may # not be the same as having no input). if text: return utils.OOFeval(self.gtk.get_text()) return None
def endTime(self, meshctxt): txt = mainthread.runBlock(self.getEndTimeText) if not txt: # If the problem isn't time dependent and endtime isn't # set explicitly, just set it to the current time. if meshctxt and not meshctxt.timeDependent(): return meshctxt.getObject().getCurrentTime() try: return float(utils.OOFeval(txt)) except: pass
def quit(*args, **kwargs): # Called in text mode only, and on the main thread. In GUI mode, # use common.IO.GUI.quit.quit instead. *args allows this to be # used as a menu callback. exitstatus = kwargs.get('exitstatus', 0) if mainmenu.OOF.logChanged() and not quiet(): answer = utils.OOFeval('raw_input("*Save log file? [Yn]: ")') if answer in ('', 'Y', 'y', 'yes', 'Yes', 'YES'): # Oh, yes! mainmenu.OOF.File.Save.Python_Log() mainmenu.cleanlog() cleanup(shutdown, exitstatus) # doesn't return!
def ScriptException0(self): # Check that an exception thrown by a script halts the # execution of the script. The script sets teststring to # "ok", raises an exception by using an undefined variable, # and then sets teststring to "not ok". If the exception is # not handled properly, lines following the error will be # read, and teststring will be set to "not ok". self.assertRaises(ooferror.ErrUserError, OOF.File.Load.Script, filename=reference_file("fundamental_data", "pyerror.py")) self.assertEqual(utils.OOFeval('teststring'), "ok")
def __init__(self, name, registeredclass, subclass, ordering, params=[], secret=0, tip=None, discussion=None, **kwargs): self._name = name self.subclass = subclass if type(registeredclass) in (ListType, TupleType): self.registeredclasses = tuple(registeredclass[:]) else: self.registeredclasses = (registeredclass, ) self.ordering = ordering self.params = params self.secret = secret self.tip = tip self.discussion = discussion # Registered subclasses must have unique names in the main OOF # namespace: try: scls = utils.OOFeval(subclass.__name__) except NameError: # ok, name isn't already defined. self.exportToOOF() else: raise NameError( "RegisteredClass subclass '%s' is already defined." % subclass.__name__) self.__dict__.update(kwargs) # Store the registration. Extract it first, so that it also # works for the RegisteredCClasses. for registeredclass in self.registeredclasses: registeredclass.registry.append(self) # Sorting each time is inefficient, but doesn't happen often. registeredclass.registry.sort() switchboard.notify(registeredclass)
def tEditCB(self, button): if not self.tEditMode: # Switch to time editing mode self.tEditMode = True self.tEditButton.set_label("Done") self.tText.set_editable(True) else: # Switch out of time editing mode self.tEditMode = False self.tText.set_editable(False) self.tEditButton.set_label("Edit") try: t = utils.OOFeval(self.tText.get_text().lstrip()) except: pass else: self.time = t subthread.execute(self.updateData) # Since the user has entered a new time, don't # overwrite it when the graphics window's display time # changes. self.freezeTimeFlag = True self.freezeTimeButton.set_active(True) self.sensitize()
def repeatable(self): # Check that the mouse coord entry widgets contain appropriate # data. debug.mainthreadTest() selmeth = self.selectionMethodFactory.getRegistration() try: if 'down' in selmeth.events: # OOFeval raises exceptions if the text is not a valid # Python expression utils.OOFeval(self.xdownentry.get_text()) utils.OOFeval(self.ydownentry.get_text()) if config.dimension() == 3: utils.OOFeval(self.zdownentry.get_text()) if 'up' in selmeth.events: utils.OOFeval(self.xupentry.get_text()) utils.OOFeval(self.yupentry.get_text()) if config.dimension() == 3: utils.OOFeval(self.zupentry.get_text()) except: return 0 return 1
def get_value(self): v = AutoWidget.get_value(self) if v == automatic.automatic: return v return utils.OOFeval(v)
def get_value(self): debug.mainthreadTest() return self.clip(int(utils.OOFeval(self.entry.get_text())))
# This software was produced by NIST, an agency of the U.S. government, # and by statute is not subject to copyright in the United States. # Recipients of this software assume all responsibilities associated # with its operation, modification and maintenance. However, to # facilitate maintenance we ask that before distributing modified # versions of this software, you first contact the authors at # [email protected]. from ooflib.common import utils import generics checkpoint OOF.File.LoadStartUp.Script checkpoint toplevel widget mapped Error findWidget('Error').resize(592, 160) assert generics.errorMsg("NameError: global name 'y' is not defined\n\nErrUserError: Script 'TEST_DATA/pyerror.py' raised a NameError exception") findWidget('Error:gtk-ok').clicked() assert utils.OOFeval('teststring') == 'ok' findMenu(findWidget('OOF2:MenuBar'), 'File:Load:Script').activate() checkpoint toplevel widget mapped Dialog-Script findWidget('Dialog-Script').resize(191, 71) findWidget('Dialog-Script:filename').set_text('TEST_DATA/pyerror.py') findWidget('Dialog-Script:gtk-ok').clicked() checkpoint OOF.File.Load.Script checkpoint toplevel widget mapped Error findWidget('Error').resize(592, 160) assert generics.errorMsg("NameError: global name 'y' is not defined\n\nErrUserError: Script 'TEST_DATA/pyerror.py' raised a NameError exception") findWidget('Error:gtk-ok').clicked() assert utils.OOFeval('teststring') == 'ok' findMenu(findWidget('OOF2:MenuBar'), 'File:Quit').activate()
def make_linear_system(self, time, linsys): # Construct a LinearizedSystem object containing the # globally-indexed K, C, and M matrices, and the rhs vectors, # and the maps that extract submatrices and subvectors. # The linsys argument is either a LinearizedSystem object # previously created by this SubProblemContext, or None. If # it's not None, it will be updated and reused. mesh = self.getParent() femesh = mesh.getObject() subpobj = self.getObject() # Ask every *other* subproblem to interpolate its DoFs to the # given time. Our boundary conditions and/or material # properties may depend on them. for subproblem in mesh.subproblems(): if (subproblem is not self and subproblem.installedTime != time): vals = subproblem.interpolateValues(time) # This requires that the LinearizedSystem for the # other subproblem has already been computed. # However, it's never needed on the first call to # make_linear_system, so that's ok. subproblem.set_mesh_dofs(vals, time) ## TODO OPT: Be more sophisticated here. Instead of ## recomputing everything, only recompute the matrices and ## vectors that may have changed. ## TODO OPT: Recompute if nonlinear *and* relevant fields ## have changed, not just if nonlinear. Need field-specific ## timestamps in the Mesh? femesh.setCurrentSubProblem(self.getObject()) # Figure out which parts of the calculation have to be redone. # If always is set, all steps of the calculation will be # peformed, even if they're otherwise unnecessary. This can # be useful when debugging. # 'always' can be set with the command line option ## --command "always=True". always = False try: always = utils.OOFeval('always') except NameError: pass # If Properties depend nonlinearly on Fields, and if those # Fields have changed, the matrices need to be recomputed. # The relevant Fields are *all* the Fields defined in the # SubProblem's Elements, whether or not those Fields are # active in *this* SubProblem. flds = self.getParent().all_active_subproblem_fields() if linsys is not None: linsysComputed = linsys.computed else: linsysComputed = timestamp.timeZero newDefinition = self.defnChanged > linsysComputed or always newFieldValues = (max(self.fieldsInstalled, mesh.fieldsInitialized) > linsysComputed) or always newTime = linsys is None or linsys.time() != time or always newBdys = (mesh.boundariesChanged > linsysComputed or (newTime and self.timeDependentBCs()) ## TODO: Check for field dependent boundary conditions # or (newFieldValues and self.fieldDependentBCs(flds)) or always) newLinSys = (linsys is None) or newDefinition newMaterials = mesh.materialsChanged > linsysComputed or always rebuildMatrices = ( newLinSys or newMaterials or (self.nonlinear(flds) and (newBdys or newFieldValues)) or (newFieldValues and self.nonlinear_solver.needsResidual()) or (self.nonlinear_solver.needsJacobian() and self.nonlinear_solver.jacobianRequirementChanged() > linsysComputed) or (self.nonlinear_solver.needsResidual() and (newFieldValues or (self.nonlinear_solver.residualRequirementChanged() > linsysComputed))) or (newTime and self.timeDependentProperties(flds)) or always) if newDefinition: self.getObject().mapFields() # Create a new linearized system object if necessary if newLinSys: linsys = self.getObject().new_linear_system(time) linsys.computed = timestamp.TimeStamp() if newTime: linsys.set_time(time) # Apply boundary conditions to the linearized system object. # This has to be done before the matrix and rhs values are # computed. The matrix and rhs may be nonlinear and therefore # depend on field values, which may be determined by boundary # conditions. bcsReset = newLinSys or newBdys if bcsReset: # reset_bcs() calls Boundary.reset for all Boundaries in # the mesh, which resets all FloatBCs on the boundaries. femesh.reset_bcs() femesh.createAuxiliaryBCs() # convert PeriodicBCs --> FloatBCs femesh.createInterfaceFloatBCs(self) # jump conds --> FloatBCs # Find intersecting floating boundary conditions, and # arrange them into a tree structure. This must be done # *before* fixed boundary conditions are applied so that # intersecting fixed and floating bcs are treated # correctly. femesh.floatBCResolve(subpobj, time) # LinearizedSystem::force_bndy_rhs is used by # invoke_flux_bcs and invoke_force_bcs, and must be # cleared before either of them is called. linsys.clearForceBndyRhs() femesh.invoke_flux_bcs(subpobj, linsys, time) # Apply Dirichlet BCs. If new values have been assigned to # the Fields, the old Dirichlet BCs may have been overwritten, # so they have to be reapplied. if bcsReset or newFieldValues: linsys.resetFieldFlags() femesh.invoke_fixed_bcs(subpobj, linsys, time) if bcsReset: femesh.invoke_force_bcs(subpobj, linsys, time) # Set initial values of DoFs used in FloatBCs that # intersect fixedBCs. femesh.fix_float_bcs(subpobj, linsys, time) if rebuildMatrices: # Assemble vectors and matrices of the linearized system. linsys.clearMatrices() linsys.clearBodyRhs() if self.nonlinear_solver.needsResidual(): linsys.clearResidual() if self.nonlinear_solver.needsJacobian(): linsys.clearJacobian() # **** This is the cpu intensive step: **** self.getObject().make_linear_system(linsys, self.nonlinear_solver) self.newMatrixCount += 1 if bcsReset or rebuildMatrices or newFieldValues: linsys.build_submatrix_maps() # Apply floating boundary conditions by modifying maps in # the LinearizedSystem. This must follow # build_submatrix_maps() and precede build_MCK_maps(). femesh.invoke_float_bcs(subpobj, linsys, time) linsys.build_MCK_maps() # Construct vectors of first and second time derivatives # of the time-dependent Dirichlet boundary conditions. linsys.initDirichletDerivatives() femesh.setDirichletDerivatives(subpobj, linsys, time) if bcsReset: # Compute the part of the rhs due to fixed fields or fixed # time derivatives in boundary conditions. linsys.find_fix_bndy_rhs(self.getObject().get_meshdofs()) # Add the floating boundary condition profiles' # contributions to the rhs. This must come after # find_fix_bndy_rhs(), and must always be called if # find_fix_bndy_rhs() is called. ## TODO OPT: Only call float_contrib_rhs if solver needs ## to know the rhs explicitly. femesh.float_contrib_rhs(self.getObject(), linsys) femesh.clearCurrentSubProblem() linsys.computed.increment() # ## Don't remove this block. Comment it out instead. It's # ## likely to be needed later. # global debugcount # debugcount += 1 # if debugcount==3: # if always: # dumpfile = "dump-always" # else: # dumpfile = "dump" # linsys.dumpAll(dumpfile, time, "") # sys.exit() return linsys
def _getval(widget): text = widget.get_text().lstrip() if text: return utils.OOFeval(text) return 0.0
# bug. from ooflib.common import utils import generics findMenu(findWidget('OOF2:MenuBar'), 'File:Load:Script').activate() checkpoint toplevel widget mapped Dialog-Script findWidget('Dialog-Script').resize(191, 71) findWidget('Dialog-Script:filename').set_text('TEST_DATA/pyerror.py') findWidget('Dialog-Script:gtk-ok').clicked() checkpoint OOF.File.Load.Script checkpoint toplevel widget mapped Error findWidget('Error').resize(592, 160) assert generics.errorMsg("NameError: global name 'y' is not defined\n\nErrUserError: Script 'TEST_DATA/pyerror.py' raised a NameError exception") findWidget('Error:gtk-ok').clicked() assert utils.OOFeval('teststring') == 'ok' findMenu(findWidget('OOF2:MenuBar'), 'File:Load:Script').activate() checkpoint toplevel widget mapped Dialog-Script findWidget('Dialog-Script').resize(191, 71) findWidget('Dialog-Script:filename').set_text('TEST_DATA/errorcmd.py') findWidget('Dialog-Script:gtk-ok').clicked() checkpoint OOF.Help.Debug.Error.CError checkpoint OOF.File.Load.Script checkpoint toplevel widget mapped Error findWidget('Error').resize(592, 160) assert generics.errorMsg("ErrProgrammingError: Somebody made a mistake!\n(./SRC/common/cdebug.C:124)\n\nErrUserError: Script 'TEST_DATA/errorcmd.py' raised an ErrProgrammingError exception") findWidget('Error:gtk-ok').clicked() assert utils.OOFeval('teststring') == 'ok' # "Accidentally" open the Load Data dialog.
def get_value(self): return utils.OOFeval(self.chooser.get_value()).subclass
def moveCB(self, button): debug.mainthreadTest() xyz = [utils.OOFeval(text.get_text()) for text in self.texts] point = primitives.Point(*xyz) skelctxt = self.getSkeletonContext() subthread.execute(self.kbmove_subthread, (skelctxt, point))