def Activated(self):
     FreeCAD.ActiveDocument.openTransaction(
         "Create cut-cell Cartesian mesh")
     FreeCADGui.addModule("FemGui")
     analysis_obj = FemGui.getActiveAnalysis()
     if analysis_obj:
         meshObj = CfdTools.getMesh(analysis_obj)
     else:
         meshObj = None
     if not meshObj:
         sel = FreeCADGui.Selection.getSelection()
         if len(sel) == 1:
             if sel[0].isDerivedFrom("Part::Feature"):
                 mesh_obj_name = sel[0].Name + "_CartesianMesh"
                 FreeCADGui.addModule("CfdMeshCart")
                 FreeCADGui.doCommand("CfdMeshCart.makeCfdMeshCart('" +
                                      mesh_obj_name + "')")
                 FreeCADGui.doCommand(
                     "App.ActiveDocument.ActiveObject.Part = App.ActiveDocument."
                     + sel[0].Name)
                 if FemGui.getActiveAnalysis():
                     FreeCADGui.addModule("FemGui")
                     FreeCADGui.doCommand(
                         "FemGui.getActiveAnalysis().addObject(App.ActiveDocument.ActiveObject)"
                     )
                 FreeCADGui.ActiveDocument.setEdit(
                     FreeCAD.ActiveDocument.ActiveObject.Name)
     else:
         print "ERROR: You cannot have more than one mesh object"
     FreeCADGui.Selection.clearSelection()
Beispiel #2
0
    def __init__(self, analysis_obj):
        super(CfdCaseWriterFoam, self).__init__()
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """

        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.physics_model, isPresent = CfdTools.getPhysicsModel(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_objs = CfdTools.getMaterials(analysis_obj)
        self.bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj)
        self.initial_conditions, isPresent = CfdTools.getInitialConditions(
            analysis_obj)
        self.porousZone_objs, self.porousZonePresent = CfdTools.getPorousObjects(
            analysis_obj)
        self.alphaZone_objs = CfdTools.getAlphaObjects(analysis_obj)
        self.zone_objs = CfdTools.getZoneObjects(analysis_obj)
        self.mesh_generated = False

        self.signals = CfdCaseWriterSignals()

        if len(self.alphaZone_objs) > 0:
            self.physics_model['Time'] = 'Transient'
            # TODO: remove this code and add GUI support for transient simulations
            self.solver_obj.TimeStep = 0.001
            self.solver_obj.WriteInterval = 0.05
            self.solver_obj.EndTime = 1
Beispiel #3
0
    def __init__(self, analysis_obj):
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """
        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.part_obj = self.mesh_obj.Part
        if not self.part_obj:
            print(
                "Error!, mesh has no Part property link to an geometry object")
        self.dimension = CfdTools.getPartDimension(self.part_obj)
        self.material_obj = CfdTools.getMaterial(analysis_obj)
        self.bc_group = CfdTools.getConstraintGroup(
            analysis_obj)  # not work for pure Python constraint yet
        self.mesh_generated = False
        # unit schema detection is usful for mesh scaling, boundary type area, pressure calculation
        self.unit_shema = FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Units/").GetInt("UserSchema")

        self.case_file_name = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName + u".json"
        if self.solver_obj.Parallel:
            # FIXME: XDMF is the preferred file io for parallel mesh in the future
            self.mesh_file_name = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName + u".hdf5"
        else:
            self.mesh_file_name = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName + u".xml"

        self.case_settings = OrderedDict(
        )  # OrderedDict does not support pprint
        self.case_settings['case_name'] = self.solver_obj.InputCaseName
        self.case_settings['case_folder'] = self.solver_obj.WorkingDir
        self.case_settings['case_file'] = self.case_file_name
Beispiel #4
0
 def __init__(self, analysis_obj):
     self.analysis_obj = analysis_obj
     self.solver_obj = CfdTools.getSolver(analysis_obj)
     self.physics_model = CfdTools.getPhysicsModel(analysis_obj)
     self.mesh_obj = CfdTools.getMesh(analysis_obj)
     self.material_objs = CfdTools.getMaterials(analysis_obj)
     self.bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj)
     self.initial_conditions = CfdTools.getInitialConditions(analysis_obj)
     self.porousZone_objs = CfdTools.getPorousZoneObjects(analysis_obj)
     self.initialisationZone_objs = CfdTools.getInitialisationZoneObjects(analysis_obj)
     self.zone_objs = CfdTools.getZoneObjects(analysis_obj)
     self.mesh_generated = False
     self.working_dir = CfdTools.getOutputPath(self.analysis_obj)
Beispiel #5
0
 def __init__(self, analysis_obj):
     self.analysis_obj = analysis_obj
     self.solver_obj = CfdTools.getSolver(analysis_obj)
     self.physics_model, isPresent = CfdTools.getPhysicsModel(analysis_obj)
     self.mesh_obj = CfdTools.getMesh(analysis_obj)
     self.material_objs = CfdTools.getMaterials(analysis_obj)
     self.bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj)
     self.initial_conditions, isPresent = CfdTools.getInitialConditions(analysis_obj)
     self.porousZone_objs = CfdTools.getPorousZoneObjects(analysis_obj)
     self.initialisationZone_objs = CfdTools.getInitialisationZoneObjects(analysis_obj)
     self.zone_objs = CfdTools.getZoneObjects(analysis_obj)
     self.conversion2D_obj,self.conversionObjPresent = CfdTools.get2DConversionObject(analysis_obj)
     self.mesh_generated = False
Beispiel #6
0
    def __init__(self, analysis_obj):
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """
        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_obj = CfdTools.getMaterial(analysis_obj)
        self.bc_group = CfdTools.getConstraintGroup(analysis_obj)
        self.mesh_generated = False

        self.case_folder = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName
        self.mesh_file_name = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv"
        if self.solver_obj.HeatTransfering:
            self.builder = fcb.BasicBuilder(self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
        else:
            self.builder = fcb.BasicBuilder(self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
        self.builder.createCase()
Beispiel #7
0
    def __init__(self, analysis_obj):
        super(CfdCaseWriterFoam, self).__init__()

        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.physics_model, isPresent = CfdTools.getPhysicsModel(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_objs = CfdTools.getMaterials(analysis_obj)
        self.bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj)
        self.initial_conditions, isPresent = CfdTools.getInitialConditions(
            analysis_obj)
        self.porousZone_objs = CfdTools.getPorousZoneObjects(analysis_obj)
        self.initialisationZone_objs = CfdTools.getInitialisationZoneObjects(
            analysis_obj)
        self.zone_objs = CfdTools.getZoneObjects(analysis_obj)
        self.mesh_generated = False

        self.signals = CfdCaseWriterSignals()
Beispiel #8
0
    def __init__(self, analysis_obj):
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """
        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_obj = CfdTools.getMaterial(analysis_obj)
        self.bc_group = CfdTools.getConstraintGroup(analysis_obj)
        self.mesh_generated = False
        # unit schema detection is usful for mesh scaling, boundary type area, pressure calculation
        self.unit_shema = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units/").GetInt("UserSchema")

        self.case_file_name = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName + u".json"
        self.mesh_file_name = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName + u".xml"
        # Collections.OrderedDict  s also can not dump json
        self.case_settings = {'case_name': self.solver_obj.InputCaseName,
                                        'case_folder': self.solver_obj.WorkingDir,  'case_file': self.case_file_name}
Beispiel #9
0
    def __init__(self, analysis_obj):
        """ analysis_obj should contains all the information needed,
        boundaryConditionList is a list of all boundary Conditions objects(FemConstraint)
        """
        self.analysis_obj = analysis_obj
        self.solver_obj = CfdTools.getSolver(analysis_obj)
        self.mesh_obj = CfdTools.getMesh(analysis_obj)
        self.material_obj = CfdTools.getMaterial(analysis_obj)
        self.bc_group = CfdTools.getConstraintGroup(analysis_obj)
        self.mesh_generated = False
        # unit schema detection is usful for mesh scaling, boundary type area, pressure calculation
        self.unit_shema = FreeCAD.ParamGet(
            "User parameter:BaseApp/Preferences/Units/").GetInt("UserSchema")

        self.case_folder = self.solver_obj.WorkingDir + os.path.sep + self.solver_obj.InputCaseName
        self.mesh_file_name = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv"
        if self.solver_obj.HeatTransfering:
            self.builder = fcb.BasicBuilder(
                self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
        else:
            self.builder = fcb.BasicBuilder(
                self.case_folder, CfdTools.getSolverSettings(self.solver_obj))
Beispiel #10
0
    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")