Example #1
0
    def automaticInsidePointDetect(self):
        # Snappy requires that the chosen internal point must remain internal during the meshing process and therefore
        # the meshing algorithm might fail if the point accidentally in a sliver fall between the mesh and the geometry.
        # As a safety measure, the check distance is chosen to be approximately the size of the background mesh.
        shape = self.part_obj.Shape
        step_size = self.clmax * 2.5

        bound_box = self.part_obj.Shape.BoundBox
        error_safety_factor = 2.0
        if (step_size * error_safety_factor >= bound_box.XLength
                or step_size * error_safety_factor >= bound_box.YLength
                or step_size * error_safety_factor >= bound_box.ZLength):
            CfdTools.cfdError(
                "Current choice in characteristic length of {} might be too large for automatic "
                "internal point detection.".format(self.clmax))
        x1 = bound_box.XMin
        x2 = bound_box.XMax
        y1 = bound_box.YMin
        y2 = bound_box.YMax
        z1 = bound_box.ZMin
        z2 = bound_box.ZMax
        import random
        while 1:
            x = random.uniform(x1, x2)
            y = random.uniform(y1, y2)
            z = random.uniform(z1, z2)
            pointCheck = FreeCAD.Vector(x, y, z)
            result = shape.isInside(pointCheck, step_size, False)
            if result:
                return pointCheck
Example #2
0
    def automaticInsidePointDetect(self):
        #consider updating to something more elegant

        # NOTE: The problem with snappy appears to be that the chosen internal point must remain internal
        # after the refinement regions as well. To be safe, the distance to check is chosen
        # to be approximately the size of the background mesh.

        shape = self.part_obj.Shape
        # vertices = self.part_obj.Shape.Vertexes
        stepSize = self.clmax * 3.0

        # stepSize = self.clmax/self.scale*1.1
        # change = [FreeCAD.Vector(stepSize,stepSize,stepSize),
        #           FreeCAD.Vector(stepSize,-stepSize,stepSize),
        #           FreeCAD.Vector(-stepSize,stepSize,stepSize),
        #           FreeCAD.Vector(-stepSize,-stepSize,stepSize),
        #           FreeCAD.Vector(stepSize,stepSize,-stepSize),
        #           FreeCAD.Vector(stepSize,-stepSize,-stepSize),
        #           FreeCAD.Vector(-stepSize,stepSize,-stepSize),
        #           FreeCAD.Vector(-stepSize,-stepSize,-stepSize)]
        # for ii in range(len(vertices)):
        #     #print "vertex",ii,vertices[ii], vertices[ii].Point
        #     point = vertices[ii].Point
        #     for jj in range(8):
        #         pointCheck = point + change[jj]
        #         result = shape.isInside(pointCheck,stepSize/1.1,False)
        #         print pointCheck,result
        #         if result:
        #             return pointCheck

        boundBox = self.part_obj.Shape.BoundBox
        errorSafetyFactor = 2.0
        if (stepSize * errorSafetyFactor >= boundBox.XLength
                or stepSize * errorSafetyFactor >= boundBox.YLength
                or stepSize * errorSafetyFactor >= boundBox.ZLength):
            CfdTools.cfdError(
                "Current choice in characteristic length of {} is too large.".
                format(stepSize))
        x1 = boundBox.XMin
        x2 = boundBox.XMax
        y1 = boundBox.YMin
        y2 = boundBox.YMax
        z1 = boundBox.ZMin
        z2 = boundBox.ZMax
        import random
        while 1:
            x = random.uniform(x1, x2)
            y = random.uniform(y1, y2)
            z = random.uniform(z1, z2)
            pointCheck = FreeCAD.Vector(x, y, z)
            result = shape.isInside(pointCheck, stepSize, False)
            print pointCheck, result
            if result:
                #broek
                return pointCheck
Example #3
0
 def doubleClicked(self, vobj):
     doc = FreeCADGui.getDocument(vobj.Object.Document)
     if not CfdTools.getActiveAnalysis():
         analysis_obj = CfdTools.getParentAnalysisObject(self.Object)
         if analysis_obj:
             CfdTools.setActiveAnalysis(analysis_obj)
         else:
             CfdTools.cfdError('No parent analysis object detected')
     if not doc.getInEdit():
         doc.setEdit(vobj.Object.Name)
     else:
         FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n')
     return True
 def setEdit(self, vobj, mode):
     analysis_object = CfdTools.getParentAnalysisObject(self.Object)
     if analysis_object is None:
         CfdTools.cfdError("No parent analysis object found")
         return False
     physics_model = CfdTools.getPhysicsModel(analysis_object)
     if not physics_model:
         CfdTools.cfdError("Analysis object must have a physics object")
         return False
     import _TaskPanelCfdFluidProperties
     taskd = _TaskPanelCfdFluidProperties.TaskPanelCfdFluidProperties(self.Object, physics_model)
     taskd.obj = vobj.Object
     FreeCADGui.Control.showDialog(taskd)
     return True
Example #5
0
 def convertClicked(self):
     fFObjName = self.listOfBoundaryNames[
         self.form.comboBoxFront.currentIndex()]
     bFObjName = self.listOfBoundaryNames[
         self.form.comboBoxBack.currentIndex()]
     if fFObjName == bFObjName:
         CfdTools.cfdError("Front and back faces cannot be the same.")
     else:
         doc_name = str(self.obj.Document.Name)
         frontObj = FreeCAD.getDocument(doc_name).getObject(fFObjName)
         backObj = FreeCAD.getDocument(doc_name).getObject(bFObjName)
         fShape = frontObj.Shape
         bShape = backObj.Shape
         if len(fShape.Faces) == 0 or len(bShape.Faces) == 0:
             CfdTools.cfdError("Either the front or back face is empty.")
         else:
             allFFacesPlaner = True
             allBFacesPlaner = True
             for faces in fShape.Faces:
                 if not (isinstance(faces.Surface, Part.Plane)):
                     allFFacesPlaner = False
                     break
             for faces in bShape.Faces:
                 if not (isinstance(faces.Surface, Part.Plane)):
                     allBFacesPlaner = False
                     break
             if allFFacesPlaner and allBFacesPlaner:
                 A1 = fShape.Faces[0].Surface.Axis
                 A2 = bShape.Faces[0].Surface.Axis
                 if self.norm(A1 - A2) <= 1e-6 or self.norm(A1 + A2):
                     if (len(frontObj.Shape.Vertexes) == len(
                             backObj.Shape.Vertexes)
                             and len(frontObj.Shape.Vertexes) > 0 and
                         (abs(frontObj.Shape.Area - backObj.Shape.Area) <
                          1e-6)):
                         self.distance = fShape.distToShape(bShape)[0]
                         self.convertMesh()
                     else:
                         CfdTools.cfdError(
                             "Front and back faces do not match up.")
                 else:
                     CfdTools.cfdError(
                         "Front and back faces are not aligned.")
             else:
                 CfdTools.cfdError(
                     "Front and back faces need to be flat surfaces.")
Example #6
0
    def setEdit(self, vobj, mode):
        analysis_object = CfdTools.getParentAnalysisObject(self.Object)
        if analysis_object is None:
            CfdTools.cfdError("No parent analysis object found")
            return False
        physics_model, is_present = CfdTools.getPhysicsModel(analysis_object)
        if not is_present:
            CfdTools.cfdError("Analysis object must have a physics object")
            return False
        boundaries = CfdTools.getCfdBoundaryGroup(analysis_object)

        import _TaskPanelCfdInitialiseInternalFlowField
        taskd = _TaskPanelCfdInitialiseInternalFlowField._TaskPanelCfdInitialiseInternalFlowField(
            self.Object, physics_model, boundaries)
        taskd.obj = vobj.Object
        FreeCADGui.Control.showDialog(taskd)
        return True
    def setEdit(self, vobj, mode):
        analysis_object = CfdTools.getParentAnalysisObject(self.Object)
        if analysis_object is None:
            CfdTools.cfdError("Boundary must have a parent analysis object")
            return False
        physics_model, is_present = CfdTools.getPhysicsModel(analysis_object)
        if not is_present:
            CfdTools.cfdError("Analysis object must have a physics object")
            return False

        import _TaskPanelCfdFluidBoundary
        taskd = _TaskPanelCfdFluidBoundary.TaskPanelCfdFluidBoundary(self.Object, physics_model)
        for obj in FreeCAD.ActiveDocument.Objects:
            if obj.isDerivedFrom("Fem::FemMeshObject"):
                obj.ViewObject.hide()
                obj.Part.ViewObject.show()
        self.Object.ViewObject.show()
        taskd.obj = vobj.Object
        FreeCADGui.Control.showDialog(taskd)
        return True
 def Activated(self):
     FreeCAD.Console.PrintMessage("Set fluid properties \n")
     FreeCAD.ActiveDocument.openTransaction("Set CfdFluidMaterialProperty")
     FreeCADGui.doCommand("")
     FreeCADGui.addModule("CfdTools")
     FreeCADGui.addModule("CfdFluidMaterial")
     editing_existing = False
     analysis_object = CfdTools.getActiveAnalysis()
     if analysis_object is None:
         CfdTools.cfdError("No active analysis object found")
         return False
     physics_model = CfdTools.getPhysicsModel(analysis_object)
     if not physics_model or physics_model.Phase == 'Single':
         members = analysis_object.Group
         for i in members:
             if isinstance(i.Proxy, _CfdMaterial):
                 FreeCADGui.activeDocument().setEdit(i.Name)
                 editing_existing = True
     if not editing_existing:
         FreeCADGui.doCommand(
             "CfdTools.getActiveAnalysis().addObject(CfdFluidMaterial.makeCfdFluidMaterial('FluidProperties'))")
         FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)
Example #9
0
 def initialiseUponReload(self):
     self.meshConverted = self.obj.Converter2D["TwoDMeshCreated"]
     self.frontFaceName = self.obj.Converter2D["FrontFace"]
     self.backFaceName = self.obj.Converter2D["BackFace"]
     if self.frontFaceName:
         try:
             indexFront = self.listOfBoundaryLabels.index(
                 self.frontFaceName)
             indexBack = self.listOfBoundaryLabels.index(self.backFaceName)
             self.form.comboBoxFront.setCurrentIndex(indexFront)
             self.form.comboBoxBack.setCurrentIndex(indexBack)
         except ValueError:
             CfdTools.cfdError("NOTE: Either the bounary with the name " +
                               str(self.frontFaceName) + " or " +
                               str(self.backFaceName) +
                               " no longer exists.")
     if self.meshConverted:
         self.form.conversionStatusText.setText(
             "Mesh has already been converted.")
         self.form.conversionStatusText.setStyleSheet('color: green')
         self.form.paraviewButton.setEnabled(True)
     else:
         self.form.conversionStatusText.setText("Not yet converted.")
         self.form.conversionStatusText.setStyleSheet('color: red')
Example #10
0
            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")
        else:
            CfdTools.cfdError("Mesh has already been converted!")

    def console_log(self, message="", color="#000000"):
        self.console_message_cart = self.console_message_cart \
                                    + '<font color="#0000FF">{0:4.1f}:</font> <font color="{1}">{2}</font><br>'.\
                                    format(time.time()
                                    - self.Start, color, message.encode('utf-8', 'replace'))
        self.form.console_output.setText(self.console_message_cart)
        self.form.console_output.moveCursor(QtGui.QTextCursor.End)

    def read_output(self):
        #while self.conversion_process.canReadLine():
        #print(str(self.conversion_process.readLine()), end="")#Avoid displaying on FreeCAD status bar
        #pass

        # Print any error output to console