def _unsetSolvable(menuitem, subproblem): subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem] subpctxt.begin_writing() try: subpctxt.solveFlag = False finally: subpctxt.end_writing() switchboard.notify("subproblem solvability changed", subproblem) subpctxt.getParent().setStatus(meshstatus.Unsolved("Solvability changed"))
def _removeSolver(menuitem, subproblem): subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem] subpctxt.begin_writing() try: subpctxt.solver_mode = None finally: subpctxt.end_writing() switchboard.notify("subproblem solver changed", subproblem) subpctxt.getParent().setStatus(meshstatus.Unsolved("Solver removed"))
def _setSolvable(menuitem, subproblem): subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem] subpctxt.begin_writing() try: subpctxt.solveFlag = True fieldsdefined = subpctxt.define_timederiv_fields() finally: subpctxt.end_writing() switchboard.notify("subproblem solvability changed", subproblem) for fld in fieldsdefined: switchboard.notify("field defined", subproblem, fld.name(), 1) subpctxt.getParent().setStatus(meshstatus.Unsolved("Solvability changed"))
def changed(self, message): # Called when fields, equations, or materials have changed. self.defnChanged.increment() # timestamp self.getObject().requirePrecompute() self.findTimeDependent() self.find_second_order_fields() switchboard.notify("subproblem changed", self) ## TODO: Get rid of "mesh changed", and just use ## Mesh.setStatus? There seem to be a lot of nearly redundant ## signals. switchboard.notify("mesh changed", self.parent) fieldsdefined = self.define_timederiv_fields() for fld in fieldsdefined: switchboard.notify("field defined", self.path(), fld.name(), 1) self.getParent().setStatus(meshstatus.Unsolved(message))
dfile.argument('name', csname) dfile.argument('cs', cs) dfile.endCmd() # Scheduled outputs meshcontext.outputSchedule.saveAll(dfile, meshcontext) # Status. This should be the last thing written. dfile.startCmd(meshmenu.Status) dfile.argument('mesh', meshcontext.path()) if isinstance(meshcontext.status, meshstatus.Unsolved): # Since the order in which mesh attributes were written to the # data file is somewhat arbitrary, the details of an # "Unsolved" status aren't terribly meaningful. Use generic # details. dfile.argument('status', meshstatus.Unsolved("Newly loaded.")) else: dfile.argument('status', meshcontext.status) dfile.endCmd() def getMyMasterElementDict(masterelems): edict = {} masterdict = masterelement.getMasterElementDict() for ename in masterelems: try: master = masterdict[ename] edict[master.ncorners()] = master except KeyError: raise ooferror.ErrUserError("Element type \"%s\" is unknown." % ename)
def setStatus(self, meshcontext): meshcontext.setStatus(meshstatus.Unsolved("Rebuilt"))
def writeMesh(dfile, meshcontext, includeFields=True): skelcontext = meshcontext.getParent() skelpath = skelcontext.path() femesh = meshcontext.femesh() # Create mesh. dfile.startCmd(meshmenu.New) dfile.argument('name', meshcontext.name()) masterelems = [el.name() for el in meshcontext.elementdict.values()] dfile.argument('masterelems', masterelems) dfile.argument('skeleton', skelpath) dfile.endCmd() # Create subproblems anyfields = False # used later to decide if field values must be saved for subpctxt in meshcontext.subproblems(): subp = subpctxt.subptype subpobj = subpctxt.getObject() if subpctxt.name() != ooflib.engine.mesh.defaultSubProblemName: dfile.startCmd(subpmenu.New) dfile.argument('name', subpctxt.name()) dfile.argument('subproblem', subp) dfile.argument('mesh', meshcontext.path()) dfile.endCmd() # Define and activate Fields on subproblems definedfields = [field.name() for field in subpctxt.all_compound_fields()] activefields = [field.name() for field in subpctxt.all_compound_fields() if subpobj.is_active_field(field)] if config.dimension == 2: inplanefields = [field.name() for field in subpctxt.all_compound_fields() if femesh.in_plane(field)] if definedfields: anyfields = True dfile.startCmd(subpmenu.Fields) dfile.argument('subproblem', subpctxt.path()) dfile.argument('defined', definedfields) dfile.argument('active', activefields) if config.dimension() == 2: dfile.argument('inplane', inplanefields) dfile.endCmd() # Time derivative fields have a separate menu item to preserve # backwards compatibiltiy from the pre-time-dependence days. timederivfields = [field.name() for field in subpctxt.all_compound_fields() if subpctxt.is_defined_field(field.time_derivative())] if timederivfields: dfile.startCmd(subpmenu.Time_Derivative_Fields) dfile.argument('subproblem', subpctxt.path()) dfile.argument('fields', timederivfields) dfile.endCmd() # Equations equations = [eqn.name() for eqn in subpctxt.all_equations()] if equations: dfile.startCmd(subpmenu.Equations) dfile.argument('subproblem', subpctxt.path()) dfile.argument('equations', equations) dfile.endCmd() # Solver if subpctxt.time_stepper is not None: dfile.startCmd(subpmenu.Solver) dfile.argument('subproblem', subpctxt.path()) dfile.argument('solver_mode', subpctxt.solver_mode) dfile.endCmd() # End loop over subproblems # Field initializers for field in meshcontext.all_subproblem_fields(): init = meshcontext.get_initializer(field) if init: dfile.startCmd(meshmenu.Initialize_Field) dfile.argument('mesh', meshcontext.path()) dfile.argument('field', field) dfile.argument('initializer', init) dfile.endCmd() # Boundary conditions bcnames = meshcontext.allBndyCondNames() bcnames.sort() for bcname in bcnames: bc = meshcontext.getBdyCondition(bcname) # bc's that are invisible in the gui are generally created by # internal processes. Explicity saving and loading them can # lead to conflicts. if bc.isVisible(): dfile.startCmd(meshmenu.Boundary_Condition) dfile.argument('mesh', meshcontext.path()) dfile.argument('bcname', bcname) dfile.argument('bc', bc) dfile.endCmd() # Boundary condition initializers bcnames = [bc.name() for bc in meshcontext.initialized_bcs()] bcnames.sort() for bcname in bcnames: dfile.startCmd(meshmenu.Set_BC_Initializer) dfile.argument('mesh', meshcontext.path()) dfile.argument('bc', bcname) dfile.argument('initializer', meshcontext.get_bc_initializer(bcname)) dfile.endCmd() if anyfields and includeFields: # Cached data. Cached data must be stored before the current # data, so that when it's reloaded, the current data isn't # overwritten. lastcachedtime = None for time in meshcontext.cachedTimes(): meshcontext.restoreCachedData(time) writeAndCacheFields(dfile, meshcontext, time) meshcontext.releaseCachedData() lastcachedtime = time meshcontext.restoreLatestData() if lastcachedtime != meshcontext.getCurrentTime(): writeFields(dfile, meshcontext) meshcontext.releaseLatestData() # allow overwrites later # Time dfile.startCmd(meshmenu.Time) dfile.argument('mesh', meshcontext.path()) dfile.argument('time', meshcontext.getCurrentTime()) dfile.endCmd() # Cross sections: for csname in meshcontext.cross_sections.all_names(): # already ordered cs = meshcontext.cross_sections[csname] dfile.startCmd(meshmenu.CrossSection) dfile.argument('mesh', meshcontext.path()) dfile.argument('name', csname) dfile.argument('cs', cs) dfile.endCmd() # Scheduled outputs meshcontext.outputSchedule.saveAll(dfile, meshcontext) # Status. This should be the last thing written. dfile.startCmd(meshmenu.Status) dfile.argument('mesh', meshcontext.path()) if isinstance(meshcontext.status, (meshstatus.Unsolved, meshstatus.Solving)): # Since the order in which mesh attributes were written to the # data file is somewhat arbitrary, the details of an # "Unsolved" status aren't terribly meaningful. Use generic # details. Also, there's no point in storing a "Solving" # status, because it won't be true when the mesh is loaded. dfile.argument('status', meshstatus.Unsolved("Newly loaded.")) else: dfile.argument('status', meshcontext.status) dfile.endCmd()