def checkMeshType(self): mesh = FemUtils.getSingleMember(self.analysis, "Fem::FemMeshObject") if not FemUtils.isOfType(mesh, "FemMeshGmsh"): self.report.error( "Unsupported type of mesh. " "Mesh must be created with gmsh.") self.fail() return False return True
def checkSupported(self, allSupported): for m in self.analysis.Group: if FemUtils.isOfType(m, "Fem::Constraint"): supported = False for sc in allSupported: if FemUtils.isOfType(m, *sc): supported = True if not supported: self.report.warning( "Ignored unsupported constraint: %s" % m.Label) return True
def __init__(self, obj): self._obj = obj self._paramWidget = Gui.PySideUic.loadUi( App.getHomePath() + "Mod/Fem/Resources/ui/InitialFlowVelocity.ui") self._initParamWidget() self.form = [self._paramWidget] analysis = FemUtils.findAnalysisOfMember(obj) self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject") self._part = self._mesh.Part if self._mesh is not None else None self._partVisible = None self._meshVisible = None
def __init__(self, obj): self._obj = obj self._refWidget = FemSelectionWidgets.BoundarySelector() self._refWidget.setReferences(obj.References) self._paramWidget = Gui.PySideUic.loadUi( App.getHomePath() + "Mod/Fem/Resources/ui/ElectrostaticPotential.ui") self._initParamWidget() self.form = [self._refWidget, self._paramWidget] analysis = FemUtils.findAnalysisOfMember(obj) self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject") self._part = self._mesh.Part if self._mesh is not None else None self._partVisible = None self._meshVisible = None
def __init__(self, obj): self._obj = obj self._refWidget = FemSelectionWidgets.SolidSelector() self._refWidget.setReferences(obj.References) propWidget = obj.ViewObject.Proxy.getTaskWidget(obj.ViewObject) if propWidget is None: self.form = self._refWidget else: self.form = [self.refWidget, propWidget] analysis = FemUtils.findAnalysisOfMember(obj) self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject") self._part = self._mesh.Part if self._mesh is not None else None self._partVisible = None self._meshVisible = None
def __init__(self, solver, directory, testmode=False): self.analysis = FemUtils.findAnalysisOfMember(solver) self.solver = solver self.directory = directory self.testmode = testmode self._usedVarNames = set() self._builder = sifio.Builder() self._handledObjects = set()
def __init__(self, obj): self._obj = obj self._refWidget = FemSelectionWidgets.BoundarySelector() self._refWidget.setReferences(obj.References) self._paramWidget = Gui.PySideUic.loadUi( App.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui") self._initParamWidget() self.form = [self._refWidget, self._paramWidget] analysis = FemUtils.findAnalysisOfMember(obj) self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject") self._part = None if hasattr(self._mesh, "Part"): # Geometry of Gmesh mesh obj self._part = self._mesh.Part elif hasattr(self._mesh, "Shape"): # Geometry of Netgen mesh obj self._part = self._mesh.Shape self._partVisible = None self._meshVisible = None
def _getMeshDimension(self): obj = FemUtils.getSingleMember(self.analysis, "Fem::FemMeshObject") if obj.Part.Shape.Solids: return 3 elif obj.Part.Shape.Faces: return 2 elif obj.Part.Shape.Edges: return 1 return None
def checkMaterial(self): matObjs = FemUtils.getMember(self.analysis, "App::MaterialObjectPython") if len(matObjs) == 0: self.report.error("No material object found. " "At least one material is required.") self.fail() return False return True
def _checkAnalysis(self, obj): if FemUtils.isDerivedFrom(obj, "Fem::FemAnalysis"): deltaObjs = self._getAdded(obj) if deltaObjs: reset = False for o in deltaObjs: if self._partOfModel(o): reset = True if reset: self._resetAll(obj)
def _handleFluxsolver(self): activeIn = [] for equation in self.solver.Group: if FemUtils.isOfType(equation, "Fem::FemEquationElmerFluxsolver"): if equation.References: activeIn = equation.References[0][1] else: activeIn = self._getAllBodies() solverSection = self._getFluxsolverSolver(equation) for body in activeIn: self._addSolver(body, solverSection)
def Activated(self): s = Gui.Selection.getSelection() if len(s) == 1 and FemUtils.isDerivedFrom(s[0], "Fem::FemSolverObject"): App.ActiveDocument.openTransaction( "Add %s equation to %s" % (self.getSpecifier(), s[0].Label)) Gui.doCommand( "App.ActiveDocument.%(obj)s.Proxy.addEquation(" "App.ActiveDocument.%(obj)s, '%(name)s')" % {"obj": s[0].Name, "name": self.getSpecifier()}) App.ActiveDocument.commitTransaction() App.ActiveDocument.recompute()
def checkMesh(self): meshes = FemUtils.getMember(self.analysis, "Fem::FemMeshObject") if len(meshes) == 0: self.report.error("Missing a mesh object.") self.fail() return False elif len(meshes) > 1: self.report.error("Too many meshes. " "More than one mesh is not supported.") self.fail() return False return True
def _getAllBodies(self): obj = FemUtils.getSingleMember(self.analysis, "Fem::FemMeshObject") bodyCount = 0 prefix = "" if obj.Part.Shape.Solids: prefix = "Solid" bodyCount = len(obj.Part.Shape.Solids) elif obj.Part.Shape.Faces: prefix = "Face" bodyCount = len(obj.Part.Shape.Faces) elif obj.Part.Shape.Edges: prefix = "Edge" bodyCount = len(obj.Part.Shape.Edges) return [prefix + str(i + 1) for i in range(bodyCount)]
def load_results_ccxdat(self): dat_result_file = os.path.join(self.directory, _inputFileName + '.dat') if os.path.isfile(dat_result_file): mode_frequencies = importCcxDatResults.import_dat( dat_result_file, self.analysis) else: raise Exception( 'FEM: No .dat results found at {}!'.format(dat_result_file)) if mode_frequencies: for m in FemUtils.getMember(self.analysis, "Fem::FemResultObject"): if m.Eigenmode > 0: for mf in mode_frequencies: if m.Eigenmode == mf['eigenmode']: m.EigenmodeFrequency = mf['frequency']
def _handleElasticity(self): activeIn = [] for equation in self.solver.Group: if FemUtils.isOfType(equation, "Fem::FemEquationElmerElasticity"): if equation.References: activeIn = equation.References[0][1] else: activeIn = self._getAllBodies() solverSection = self._getElasticitySolver(equation) for body in activeIn: self._addSolver(body, solverSection) if activeIn: self._handleElasticityConstants() self._handleElasticityBndConditions() self._handleElasticityInitial(activeIn) self._handleElasticityBodyForces(activeIn) self._handleElasticityMaterial(activeIn)
def _writeMesh(self): mesh = FemUtils.getSingleMember(self.analysis, "Fem::FemMeshObject") unvPath = os.path.join(self.directory, "mesh.unv") groups = [] groups.extend(self._builder.getBodyNames()) groups.extend(self._builder.getBoundaryNames()) self._exportToUnv(groups, mesh, unvPath) if self.testmode: print("We are in testmode ElmerGrid may not be installed!") else: binary = settings.getBinary("ElmerGrid") if binary is None: raise WriteError("Couldn't find ElmerGrid binary.") args = [ binary, _ELMERGRID_IFORMAT, _ELMERGRID_OFORMAT, unvPath, "-out", self.directory ] subprocess.call(args)
def _handleFlow(self): activeIn = [] for equation in self.solver.Group: if FemUtils.isOfType(equation, "Fem::FemEquationElmerFlow"): if equation.References: activeIn = equation.References[0][1] else: activeIn = self._getAllBodies() solverSection = self._getFlowSolver(equation) for body in activeIn: self._addSolver(body, solverSection) if activeIn: self._handleFlowConstants() self._handleFlowBndConditions() self._handleFlowInitialVelocity(activeIn) #self._handleFlowInitial(activeIn) #self._handleFlowBodyForces(activeIn) self._handleFlowMaterial(activeIn) self._handleFlowEquation(activeIn)
def create(doc, name="ElmerSolver"): return FemUtils.createObject(doc, name, Proxy, ViewProxy)
def IsActive(self): s = Gui.Selection.getSelection() if len(s) == 1 and FemUtils.isDerivedFrom(s[0], "Fem::FemSolverObject"): return s[0].Proxy.isSupported(self.getSpecifier()) return False
def _checkEquation(self, obj): for o in obj.Document.Objects: if (FemUtils.isDerivedFrom(o, "Fem::FemSolverObject") and hasattr(o, "Group") and obj in o.Group): if o in _machines: _machines[o].reset()
def create(doc, name="Flow"): return FemUtils.createObject(doc, name, Proxy, ViewProxy)
def purge_results(self): for m in FemUtils.getMember(self.analysis, "Fem::FemResultObject"): if FemUtils.isOfType(m.Mesh, "FemMeshResult"): self.analysis.Document.removeObject(m.Mesh.Name) self.analysis.Document.removeObject(m.Name) App.ActiveDocument.recompute()
def _checkSolver(self, obj): analysis = FemUtils.findAnalysisOfMember(obj) for m in _machines.itervalues(): if analysis == m.analysis and obj == m.solver: m.reset()
def _checkModel(self, obj): if self._partOfModel(obj): analysis = FemUtils.findAnalysisOfMember(obj) if analysis is not None: self._resetAll(analysis)
def _partOfModel(self, obj): for t in self._WHITELIST: if FemUtils.isDerivedFrom(obj, t): return True return False
def create(doc, name="Electrostatic"): return FemUtils.createObject(doc, name, Proxy, ViewProxy)
def _getSingleMember(self, t): return FemUtils.getSingleMember(self.analysis, t)
def checkHandled(self, w): handled = w.getHandledConstraints() allConstraints = FemUtils.getMember(self.analysis, "Fem::Constraint") for obj in set(allConstraints) - handled: self.report.warning("Ignored constraint %s." % obj.Label)
def create(doc, name="SolverZ88"): return FemUtils.createObject( doc, name, Proxy, ViewProxy)