def runCart(self, cart_mesh): cart_mesh.error = False QApplication.setOverrideCursor(Qt.WaitCursor) try: tmpdir = tempfile.gettempdir() meshCaseDir = os.path.join(tmpdir, 'meshCase') cmd = CfdTools.makeRunCommand('./Allmesh', meshCaseDir, source_env=False) FreeCAD.Console.PrintMessage("Executing: " + ' '.join(cmd) + "\n") env = QtCore.QProcessEnvironment.systemEnvironment() env_vars = CfdTools.getRunEnvironment() for key in env_vars: env.insert(key, env_vars[key]) self.mesh_process.setProcessEnvironment(env) self.mesh_process.start(cmd[0], cmd[1:]) if self.mesh_process.waitForStarted(): self.form.pb_run_mesh.setEnabled( False) # Prevent user running a second instance self.form.pb_stop_mesh.setEnabled(True) self.form.pb_paraview.setEnabled(False) else: self.console_log("Error starting meshing process", "#FF0000") cart_mesh.error = True finally: QApplication.restoreOverrideCursor()
def runMesh(self): self.Start = time.time() self.Timer.start() cart_mesh = self.cart_mesh try: QApplication.setOverrideCursor(Qt.WaitCursor) self.consoleMessage("Running {} ...".format( self.mesh_obj.MeshUtility)) cart_mesh.error = False cmd = CfdTools.makeRunCommand('./Allmesh', cart_mesh.meshCaseDir, source_env=False) FreeCAD.Console.PrintMessage("Executing: " + ' '.join(cmd) + "\n") env_vars = CfdTools.getRunEnvironment() self.mesh_process.start(cmd, env_vars=env_vars) if self.mesh_process.waitForStarted(): self.form.pb_run_mesh.setEnabled( False) # Prevent user running a second instance self.form.pb_stop_mesh.setEnabled(True) self.form.pb_paraview.setEnabled(False) self.form.pb_load_mesh.setEnabled(False) self.consoleMessage("Mesher started") else: self.consoleMessage("Error starting meshing process", "#FF0000") cart_mesh.error = True except Exception as ex: self.consoleMessage("Error: " + str(ex), '#FF0000') raise finally: QApplication.restoreOverrideCursor()
def get_solver_cmd(self, case_dir): self.initResiduals() self.residualPlot = ResidualPlot() # Environment is sourced in run script, so no need to include in run command cmd = CfdTools.makeRunCommand('./Allrun', case_dir, source_env=False) FreeCAD.Console.PrintMessage("Solver run command: " + ' '.join(cmd) + "\n") return cmd
def get_solver_cmd(self, case_dir): self.UxResiduals = [1] self.UyResiduals = [1] self.UzResiduals = [1] self.pResiduals = [1] self.niter = 0 self.print_next_error_lines = 0 self.print_next_error_file = False self.residualPlot = ResidualPlot() # Environment is sourced in run script, so no need to include in run command cmd = CfdTools.makeRunCommand('./Allrun', case_dir, source_env=False) FreeCAD.Console.PrintMessage("Solver run command: " + ' '.join(cmd) + "\n") return cmd
def runCart(self, cart_mesh): cart_mesh.error = False cmd = CfdTools.makeRunCommand('./Allmesh', cart_mesh.meshCaseDir, source_env=False) FreeCAD.Console.PrintMessage("Executing: " + ' '.join(cmd) + "\n") env_vars = CfdTools.getRunEnvironment() QApplication.setOverrideCursor(Qt.WaitCursor) self.mesh_process.start(cmd, env_vars=env_vars) if self.mesh_process.waitForStarted(): self.form.pb_run_mesh.setEnabled( False) # Prevent user running a second instance self.form.pb_stop_mesh.setEnabled(True) self.form.pb_paraview.setEnabled(False) self.form.pb_load_mesh.setEnabled(False) self.consoleMessage("Mesher started") else: self.consoleMessage("Error starting meshing process", "#FF0000") cart_mesh.error = True QApplication.restoreOverrideCursor()
def runCart(self, cart_mesh): cart_mesh.error = False cmd = CfdTools.makeRunCommand('./Allmesh', cart_mesh.meshCaseDir, source_env=False) FreeCAD.Console.PrintMessage("Executing: " + ' '.join(cmd) + "\n") env = QtCore.QProcessEnvironment.systemEnvironment() env_vars = CfdTools.getRunEnvironment() for key in env_vars: env.insert(key, env_vars[key]) self.mesh_process.setProcessEnvironment(env) self.mesh_process.start(cmd[0], cmd[1:]) if self.mesh_process.waitForStarted(): self.form.pb_run_mesh.setEnabled( False) # Prevent user running a second instance self.form.pb_stop_mesh.setEnabled(True) self.form.pb_paraview.setEnabled(False) self.form.pb_load_mesh.setEnabled(False) else: self.console_log("Error starting meshing process", "#FF0000") cart_mesh.error = True
def get_solver_cmd(self, case_dir): self.UxResiduals = [1] self.UyResiduals = [1] self.UzResiduals = [1] self.pResiduals = [1] self.niter = 0 self.print_next_error_lines = 0 self.print_next_error_file = False self.g('set style data lines') self.g.title("Simulation residuals") self.g.xlabel("Iteration") self.g.ylabel("Residual") self.g("set grid") self.g("set logscale y") self.g("set yrange [0.95:1.05]") self.g("set xrange [0:1]") # Environment is sourced in run script, so no need to include in run command cmd = CfdTools.makeRunCommand('./Allrun', case_dir, source_env=False) FreeCAD.Console.PrintMessage("Solver run command: " + ' '.join(cmd) + "\n") return cmd
def convertMesh(self): import tempfile import CfdCaseWriterFoam import CfdCartTools import TemplateBuilder import os if not (self.meshConverted): self.Start = time.time() self.Timer.start() self.console_log("Starting 3D to 2D mesh conversion ...") self.frontFaceName = self.form.comboBoxFront.currentText() self.backFaceName = self.form.comboBoxBack.currentText() tmpdir = tempfile.gettempdir() analysis_obj = FemGui.getActiveAnalysis() tmpdir = tempfile.gettempdir() self.meshCaseDir = os.path.join(tmpdir, "meshCase") self.meshObj = CfdTools.getMesh(analysis_obj) solver_obj = CfdTools.getSolver(analysis_obj) gmshMesh = False if self.meshObj.Proxy.Type == "Fem::FemMeshGmsh": # GMSH # Convert GMSH created UNV file to OpenFoam print("Writing GMSH UNV mesh to be converted to 2D mesh") unvMeshFile = self.meshCaseDir + os.path.sep + solver_obj.InputCaseName + u".unv" #try: if not os.path.exists(self.meshCaseDir): os.makedirs(self.meshCaseDir) bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj) self.mesh_generated = CfdTools.write_unv_mesh( self.meshObj, bc_group, unvMeshFile) gmshMesh = True frontFaceList = self.frontFaceName backFaceList = [self.backFaceName] else: case = CfdCaseWriterFoam.CfdCaseWriterFoam(analysis_obj) case.settings = {} case.settings['createPatchesFromSnappyBaffles'] = False case.setupPatchNames() keys = case.settings['createPatches'].keys() frontPatchIndex = keys.index(self.frontFaceName) frontFaceList = case.settings['createPatches'][ keys[frontPatchIndex]]['PatchNamesList'] backPatchIndex = keys.index(self.backFaceName) backFaceList = case.settings['createPatches'][ keys[backPatchIndex]]['PatchNamesList'] template_path = os.path.join(CfdTools.get_module_path(), "data", "defaultsMesh") settings = { 'ConvertTo2D': True, 'gmshMesh': gmshMesh, 'unvFileName': solver_obj.InputCaseName + u".unv", 'FrontFaceList': frontFaceList, 'BackFaceList': backFaceList[0], 'Distance': self.distance / 1000.0, 'TranslatedFoamPath': CfdTools.translatePath(CfdTools.getFoamDir(), ), 'MeshPath': self.meshCaseDir } TemplateBuilder.TemplateBuilder(self.meshCaseDir, template_path, settings) cmd = CfdTools.makeRunCommand('./ConvertMeshTo2D', self.meshCaseDir, source_env=False) #will fail silently in Windows fname = os.path.join(self.meshCaseDir, "ConvertMeshTo2D") import stat s = os.stat(fname) os.chmod(fname, s.st_mode | stat.S_IEXEC) FreeCAD.Console.PrintMessage("Executing: " + ' '.join(cmd) + "\n") env = QtCore.QProcessEnvironment.systemEnvironment() env_vars = CfdTools.getRunEnvironment() for key in env_vars: env.insert(key, env_vars[key]) self.conversion_process.setProcessEnvironment(env) self.conversion_process.start(cmd[0], cmd[1:]) if self.conversion_process.waitForStarted(): self.form.convertButton.setEnabled( False) # Prevent user running a second instance self.form.paraviewButton.setEnabled(False) else: self.console_log("Error starting meshing process", "#FF0000")