Exemplo n.º 1
0
 def comboFluidChanged(self, index):
     if 'alphas' not in self.BoundarySettings:
         self.BoundarySettings['alphas'] = {}
     setInputFieldQuantity(
         self.form.inputVolumeFraction,
         str(self.BoundarySettings['alphas'].get(
             self.getMaterialName(index), 0.0)))
Exemplo n.º 2
0
 def runMeshProcess(self):
     self.console_message_cart = ''
     self.Start = time.time()
     self.Timer.start()
     self.console_log("Starting cut-cell Cartesian meshing ...")
     try:
         self.get_active_analysis()
         self.set_mesh_params()
         import CfdCartTools  # Fresh init before remeshing
         self.cart_mesh = CfdCartTools.CfdCartTools(self.obj)
         cart_mesh = self.cart_mesh
         setInputFieldQuantity(self.form.if_max, str(cart_mesh.get_clmax()))
         print("\nStarting cut-cell Cartesian meshing ...\n")
         print('  Part to mesh: Name --> '
               + cart_mesh.part_obj.Name + ',  Label --> '
               + cart_mesh.part_obj.Label + ', ShapeType --> '
               + cart_mesh.part_obj.Shape.ShapeType)
         print('  CharacteristicLengthMax: ' + str(cart_mesh.clmax))
         cart_mesh.get_dimension()
         # cart_mesh.get_tmp_file_paths(self.utility)
         cart_mesh.get_tmp_file_paths()
         cart_mesh.setup_mesh_case_dir()
         cart_mesh.get_group_data()
         cart_mesh.get_region_data()  # Writes region stls so need file structure
         cart_mesh.write_mesh_case()
         self.console_log("Writing the STL files of the part surfaces ...")
         cart_mesh.write_part_file()
         self.console_log("Running {} ...".format(self.utility))
         self.runCart(cart_mesh)
     except Exception as ex:
         self.console_log("Error: " + ex.message, '#FF0000')
         self.Timer.stop()
         raise
Exemplo n.º 3
0
 def update(self):
     """ Fills the widgets """
     setInputFieldQuantity(self.form.if_max, self.clmax)
     self.form.if_max.setToolTip("Select 0 to use default value")
     setInputFieldQuantity(self.form.if_min, self.clmin)
     self.form.if_min.setToolTip("Select 0 to use default value")
     index_dimension = self.form.cb_dimension.findText(self.dimension)
     self.form.cb_dimension.setCurrentIndex(index_dimension)
    def selectPredefine(self):
        index = self.form.PredefinedMaterialLibraryComboBox.currentIndex()

        mat_file_path = self.form.PredefinedMaterialLibraryComboBox.itemData(
            index)
        self.form.fluidDescriptor.setText(
            self.materials[mat_file_path]["Description"])
        for m in self.fields:
            setInputFieldQuantity(self.text_boxes[m],
                                  self.materials[mat_file_path].get(m, ''))
Exemplo n.º 5
0
    def initialiseUponReload(self):
        """ fills the widgets """
        if self.mesh_obj.Proxy.Type == 'FemMeshGmsh':
            self.form.if_gmsh_rellen.setValue(self.obj.RelativeLength)
        elif self.mesh_obj.Proxy.Type == 'CfdMeshCart':
            self.form.if_rellen.setValue(self.obj.RelativeLength)
            setInputFieldQuantity(self.form.if_refinethick,
                                  self.obj.RefinementThickness)
            if self.numlayer > 1:  # Only reload when there are more than one layer
                self.form.check_boundlayer.toggle()
                self.form.if_numlayer.setValue(self.obj.NumberLayers)
                self.form.if_expratio.setValue(self.obj.ExpansionRatio)
                setInputFieldQuantity(self.form.if_firstlayerheight,
                                      self.obj.FirstLayerHeight)

            self.form.if_refinelevel.setValue(self.obj.RefinementLevel)
            self.form.if_edgerefinement.setValue(self.obj.RegionEdgeRefinement)
            if self.obj.Baffle:
                self.form.baffle_check.toggle()
Exemplo n.º 6
0
    def update(self):
        """ Fills the widgets """
        setInputFieldQuantity(self.form.if_max, self.clmax)
        setInputFieldQuantity(self.form.if_pointInMeshX, str(self.PointInMesh.get('x')) + "mm")
        setInputFieldQuantity(self.form.if_pointInMeshY, str(self.PointInMesh.get('y')) + "mm")
        setInputFieldQuantity(self.form.if_pointInMeshZ, str(self.PointInMesh.get('z')) + "mm")
        self.form.if_cellsbetweenlevels.setValue(self.cellsbetweenlevels)
        self.form.if_edgerefine.setValue(self.edgerefine)

        index_dimension = self.form.cb_dimension.findText(self.dimension)
        self.form.cb_dimension.setCurrentIndex(index_dimension)
        index_utility = self.form.cb_utility.findText(self.utility)
        self.form.cb_utility.setCurrentIndex(index_utility)
 def createTextBoxesBasedOnPhysics(self):
     if self.physics_obj.Flow == 'Incompressible':
         self.fields = ['Density', 'DynamicViscosity']
     else:
         self.fields = [
             'MolarMass', 'Cp', 'SutherlandConstant',
             'SutherlandTemperature'
         ]
     self.text_boxes = {}
     for name in self.fields:
         widget = FreeCADGui.UiLoader().createWidget("Gui::InputField")
         widget.setObjectName(name)
         widget.setProperty("format", "g")
         val = getattr(self.obj, name)
         widget.setProperty("unit", val)
         widget.setProperty("minimum", 0)
         widget.setProperty("singleStep", 0.1)
         self.form.propertiesLayout.addRow(
             self.obj.getDocumentationOfProperty(name) + ":", widget)
         self.text_boxes[name] = widget
         setInputFieldQuantity(widget, val)
Exemplo n.º 8
0
 def searchPointInMesh(self):
     print("Searching for an internal vector point ...")
     pointCheck = self.cart_mesh.automatic_inside_point_detect()
     iMPx, iMPy, iMPz = pointCheck
     setInputFieldQuantity(self.form.if_pointInMeshX, str(iMPx) + "mm")
     setInputFieldQuantity(self.form.if_pointInMeshY, str(iMPy) + "mm")
     setInputFieldQuantity(self.form.if_pointInMeshZ, str(iMPz) + "mm")
Exemplo n.º 9
0
 def writeMesh(self):
     self.console_message_cart = ''
     self.Start = time.time()
     self.Timer.start()
     # Re-initialise CfdMeshTools with new parameters
     self.set_mesh_params()
     FreeCADGui.addModule("CfdMeshTools")
     FreeCADGui.addModule("CfdTools")
     FreeCADGui.doCommand("FreeCAD.ActiveDocument." + self.mesh_obj.Name + ".Proxy.cart_mesh = "
                          "CfdMeshTools.CfdMeshTools(FreeCAD.ActiveDocument." + self.mesh_obj.Name + ")")
     FreeCADGui.doCommand("cart_mesh = FreeCAD.ActiveDocument." + self.mesh_obj.Name + ".Proxy.cart_mesh")
     cart_mesh = self.mesh_obj.Proxy.cart_mesh
     self.consoleMessage("Preparing meshing ...")
     try:
         QApplication.setOverrideCursor(Qt.WaitCursor)
         self.get_active_analysis()
         self.set_mesh_params()
         setInputFieldQuantity(self.form.if_max, str(cart_mesh.get_clmax()))
         print("\nStarting meshing ...\n")
         print('  Part to mesh: Name --> '
               + cart_mesh.part_obj.Name + ',  Label --> '
               + cart_mesh.part_obj.Label + ', ShapeType --> '
               + cart_mesh.part_obj.Shape.ShapeType)
         print('  CharacteristicLengthMax: ' + str(cart_mesh.clmax))
         FreeCADGui.doCommand("cart_mesh.get_dimension()")
         FreeCADGui.doCommand("cart_mesh.get_file_paths(CfdTools.getOutputPath(FreeCAD.ActiveDocument." + self.analysis.Name + "))")
         FreeCADGui.doCommand("cart_mesh.setup_mesh_case_dir()")
         self.consoleMessage("Exporting mesh region data ...")
         FreeCADGui.doCommand("cart_mesh.get_region_data()")  # Writes region stls so need file structure
         FreeCADGui.doCommand("cart_mesh.write_mesh_case()")
         self.consoleMessage("Exporting the part surfaces ...")
         FreeCADGui.doCommand("cart_mesh.write_part_file()")
         self.consoleMessage("Mesh case written to {}".format(self.cart_mesh.meshCaseDir))
     except Exception as ex:
         self.consoleMessage("Error: " + str(ex), '#FF0000')
         raise
     finally:
         self.Timer.stop()
         QApplication.restoreOverrideCursor()
     self.updateUI()
Exemplo n.º 10
0
 def searchPointInMesh(self):
     print ("Searching for an internal vector point ...")
     import CfdCartTools  # Fresh init before remeshing
     self.cart_mesh = CfdCartTools.CfdCartTools(self.obj)
     pointCheck = self.cart_mesh.automatic_inside_point_detect()
     iMPx, iMPy, iMPz = pointCheck
     setInputFieldQuantity(self.form.if_pointInMeshX, str(iMPx) + "mm")
     setInputFieldQuantity(self.form.if_pointInMeshY, str(iMPy) + "mm")
     setInputFieldQuantity(self.form.if_pointInMeshZ, str(iMPz) + "mm")
Exemplo n.º 11
0
 def runMeshProcess(self):
     self.console_message_cart = ''
     self.Start = time.time()
     self.Timer.start()
     # Re-initialise CfdMeshTools with new parameters
     self.set_mesh_params()
     self.cart_mesh = CfdMeshTools.CfdMeshTools(self.mesh_obj)
     self.consoleMessage("Starting meshing ...")
     try:
         QApplication.setOverrideCursor(Qt.WaitCursor)
         self.get_active_analysis()
         self.set_mesh_params()
         cart_mesh = self.cart_mesh
         setInputFieldQuantity(self.form.if_max, str(cart_mesh.get_clmax()))
         print("\nStarting meshing ...\n")
         print('  Part to mesh: Name --> ' + cart_mesh.part_obj.Name +
               ',  Label --> ' + cart_mesh.part_obj.Label +
               ', ShapeType --> ' + cart_mesh.part_obj.Shape.ShapeType)
         print('  CharacteristicLengthMax: ' + str(cart_mesh.clmax))
         cart_mesh.get_dimension()
         cart_mesh.get_file_paths(CfdTools.getOutputPath(self.analysis))
         cart_mesh.setup_mesh_case_dir()
         self.consoleMessage("Exporting mesh region data ...")
         cart_mesh.get_region_data(
         )  # Writes region stls so need file structure
         cart_mesh.write_mesh_case()
         self.consoleMessage("Exporting the part surfaces ...")
         cart_mesh.write_part_file()
         self.consoleMessage("Running {} ...".format(self.utility))
         self.runCart(cart_mesh)
     except Exception as ex:
         self.consoleMessage("Error: " + str(ex), '#FF0000')
         self.Timer.stop()
         raise
     finally:
         QApplication.restoreOverrideCursor()
Exemplo n.º 12
0
    def initialiseUponReload(self):
        if self.physicsModel['Time'] == 'Steady':
            self.form.radioButtonSteady.toggle()
        elif self.physicsModel['Time'] == 'Transient':
            self.form.radioButtonTransient.toggle()

        if self.physicsModel['Flow'] == 'Incompressible':
            self.form.radioButtonIncompressible.toggle()
        elif self.physicsModel['Flow'] == 'Compressible':
            self.form.radioButtonCompressible.toggle()

        if self.physicsModel['Turbulence'] == 'Laminar':
            self.form.turbulenceCheckBox.toggle()
            self.form.radioButtonLaminar.toggle()
        elif self.physicsModel['Turbulence'] == 'RANS':
            self.form.turbulenceCheckBox.toggle()
            self.form.radioButtonRANS.toggle()
        ti = CfdTools.indexOrDefault(RANS_MODELS,
                                     self.physicsModel.get('TurbulenceType'),
                                     0)
        self.form.turbulenceComboBox.setCurrentIndex(ti)

        if self.physicsModel['Thermal'] == "Energy":
            self.form.thermalCheckBox.toggle()
            self.form.radioButtonEnergy.toggle()
        elif self.physicsModel['Thermal'] == "Buoyancy":
            self.form.thermalCheckBox.toggle()
            self.form.radioButtonBuoyancy.toggle()

        material_objs = CfdTools.getMaterials(
            CfdTools.getParentAnalysisObject(self.obj))
        if len(material_objs) > 1:
            self.form.gravityFrame.setVisible(True)
            # Add if absent for backward file compatibility
            if not self.physicsModel.get('Gravity'):
                self.physicsModel['Gravity'] = {
                    'gx': 0.0,
                    'gy': -9.81,
                    'gz': 0.0
                }
            gx = self.physicsModel['Gravity']['gx']
            gy = self.physicsModel['Gravity']['gy']
            gz = self.physicsModel['Gravity']['gz']
            setInputFieldQuantity(self.form.gx, "{} m/s^2".format(gx))
            setInputFieldQuantity(self.form.gy, "{} m/s^2".format(gy))
            setInputFieldQuantity(self.form.gz, "{} m/s^2".format(gz))
Exemplo n.º 13
0
    def load(self):
        if self.obj.Time == 'Steady':
            self.form.radioButtonSteady.toggle()
        elif self.obj.Time == 'Transient':
            self.form.radioButtonTransient.toggle()

        if self.obj.Phase == 'Single':
            self.form.radioButtonSinglePhase.toggle()
        elif self.obj.Phase == 'FreeSurface':
            self.form.radioButtonFreeSurface.toggle()
        if self.obj.Flow == 'Incompressible':
            self.form.radioButtonIncompressible.toggle()
        elif self.obj.Flow == 'Compressible':
            self.form.radioButtonCompressible.toggle()
            self.form.checkBoxHighMach.setChecked(False)
        elif self.obj.Flow == 'HighMachCompressible':
            self.form.radioButtonCompressible.toggle()
            self.form.checkBoxHighMach.setChecked(True)

        if self.obj.Turbulence == 'Inviscid':
            self.form.viscousCheckBox.setChecked(False)
            self.form.radioButtonLaminar.toggle()
        if self.obj.Turbulence == 'Laminar':
            self.form.viscousCheckBox.setChecked(True)
            self.form.radioButtonLaminar.toggle()
        elif self.obj.Turbulence == 'RANS':
            self.form.viscousCheckBox.setChecked(True)
            self.form.radioButtonRANS.toggle()
        ti = CfdTools.indexOrDefault(RANS_MODELS, self.obj.TurbulenceModel, 0)
        self.form.turbulenceComboBox.setCurrentIndex(ti)

        #if self.obj.Thermal == "Energy":
        #    self.form.thermalCheckBox.toggle()
        #    self.form.radioButtonEnergy.toggle()
        #elif self.obj.Thermal == "Buoyancy":
        #    self.form.thermalCheckBox.toggle()
        #    self.form.radioButtonBuoyancy.toggle()

        setInputFieldQuantity(self.form.gx, self.obj.gx)
        setInputFieldQuantity(self.form.gy, self.obj.gy)
        setInputFieldQuantity(self.form.gz, self.obj.gz)

        self.updateUI()
Exemplo n.º 14
0
    def initialiseUponReload(self):
        """ fills the widgets """
        if self.mesh_obj.Proxy.Type == 'Fem::FemMeshGmsh':
            self.form.if_gmsh_rellen.setValue(self.obj.RelativeLength)
        elif self.mesh_obj.Proxy.Type == 'CfdMeshCart':
            self.form.if_rellen.setValue(self.obj.RelativeLength)
            setInputFieldQuantity(self.form.if_refinethick,
                                  self.obj.RefinementThickness)
            if self.numlayer > 1:  # Only reload when there are more than one layer
                self.form.check_boundlayer.toggle()
                self.form.if_numlayer.setValue(self.obj.NumberLayers)
                self.form.if_expratio.setValue(self.obj.ExpansionRatio)
                setInputFieldQuantity(self.form.if_firstlayerheight,
                                      self.obj.FirstLayerHeight)

            self.form.if_refinelevel.setValue(self.obj.RefinementLevel)
            self.form.if_edgerefinement.setValue(self.obj.RegionEdgeRefinement)
            if self.obj.Baffle:
                self.form.baffle_check.toggle()
            if self.obj.Internal:
                self.form.volumeRefinementToggle.toggle()
            index = self.validTypesOfInternalPrimitives.index(
                self.obj.InternalRegion["Type"])
            self.form.internalVolumePrimitiveSelection.setCurrentIndex(index)
            setInputFieldQuantity(
                self.form.xCenter,
                str(self.obj.InternalRegion["Center"]["x"]) + "m")
            setInputFieldQuantity(
                self.form.yCenter,
                str(self.obj.InternalRegion["Center"]["y"]) + "m")
            setInputFieldQuantity(
                self.form.zCenter,
                str(self.obj.InternalRegion["Center"]["z"]) + "m")
            setInputFieldQuantity(
                self.form.xLength,
                str(self.obj.InternalRegion["BoxLengths"]["x"]) + "m")
            setInputFieldQuantity(
                self.form.yLength,
                str(self.obj.InternalRegion["BoxLengths"]["y"]) + "m")
            setInputFieldQuantity(
                self.form.zLength,
                str(self.obj.InternalRegion["BoxLengths"]["z"]) + "m")
            setInputFieldQuantity(
                self.form.radius,
                str(self.obj.InternalRegion["SphereRadius"]) + "m")
Exemplo n.º 15
0
    def setInitialValues(self):
        """ Populate UI, update view from settings"""
        self.form.comboBoundaryType.addItems(BOUNDARY_NAMES)
        bi = indexOrDefault(BOUNDARY_TYPES,
                            self.BoundarySettingsOrig.get('BoundaryType'), 0)
        self.form.comboBoundaryType.setCurrentIndex(bi)
        si = indexOrDefault(SUBTYPES[bi],
                            self.BoundarySettingsOrig.get('BoundarySubtype'),
                            0)
        self.form.comboSubtype.setCurrentIndex(si)

        cart = self.BoundarySettings.get('VelocityIsCartesian', False)
        self.form.radioButtonCart.setChecked(cart)
        self.form.radioButtonMagNormal.setChecked(not cart)
        setInputFieldQuantity(self.form.inputCartX,
                              str(self.BoundarySettings.get('Ux')) + "m/s")
        setInputFieldQuantity(self.form.inputCartY,
                              str(self.BoundarySettings.get('Uy')) + "m/s")
        setInputFieldQuantity(self.form.inputCartZ,
                              str(self.BoundarySettings.get('Uz')) + "m/s")
        setInputFieldQuantity(
            self.form.inputVelocityMag,
            str(self.BoundarySettings.get('VelocityMag')) + "m/s")
        self.form.lineDirection.setText(
            self.BoundarySettings.get('DirectionFace'))
        self.form.checkReverse.setChecked(
            bool(self.BoundarySettings.get('ReverseNormal')))
        setInputFieldQuantity(
            self.form.inputPressure,
            str(self.BoundarySettings.get('Pressure')) + "kg/m/s^2")
        setInputFieldQuantity(self.form.inputSlipRatio,
                              str(self.BoundarySettings.get('SlipRatio')))
        setInputFieldQuantity(
            self.form.inputVolFlowRate,
            str(self.BoundarySettings.get('VolFlowRate')) + "m^3/s")
        setInputFieldQuantity(
            self.form.inputMassFlowRate,
            str(self.BoundarySettings.get('MassFlowRate')) + "kg/s")

        buttonId = self.BoundarySettings.get('PorousBaffleMethod', 0)
        selButton = self.form.buttonGroupPorous.button(buttonId)
        if selButton is not None:
            selButton.setChecked(True)
            self.buttonGroupPorousClicked(
                selButton)  # Signal is not generated on setChecked above
        setInputFieldQuantity(
            self.form.inputPressureDropCoeff,
            str(self.BoundarySettings.get('PressureDropCoeff')))
        setInputFieldQuantity(
            self.form.inputWireDiameter,
            str(self.BoundarySettings.get('ScreenWireDiameter')) + "m")
        setInputFieldQuantity(
            self.form.inputSpacing,
            str(self.BoundarySettings.get('ScreenSpacing')) + "m")

        self.form.comboThermalBoundaryType.addItems(THERMAL_BOUNDARY_NAMES)
        thi = indexOrDefault(
            THERMAL_BOUNDARY_TYPES,
            self.BoundarySettingsOrig.get('ThermalBoundaryType'), 0)
        self.form.comboThermalBoundaryType.setCurrentIndex(thi)
        setInputFieldQuantity(
            self.form.inputTemperature,
            str(self.BoundarySettings.get('Temperature', 273.0)) + "K")
        setInputFieldQuantity(
            self.form.inputHeatFlux,
            str(self.BoundarySettings.get('HeatFlux', 0.0)) + "W/m^2")
        setInputFieldQuantity(
            self.form.inputHeatTransferCoeff,
            str(self.BoundarySettings.get('HeatTransferCoeff', 0.0)) +
            "W/m^2/K")

        if self.turbModel is not None:
            self.form.comboTurbulenceSpecification.addItems(
                TURBULENT_INLET_SPEC[self.turbModel][0])
            ti = indexOrDefault(
                TURBULENT_INLET_SPEC[self.turbModel][1],
                self.BoundarySettingsOrig.get('TurbulenceInletSpecification'),
                0)
            self.form.comboTurbulenceSpecification.setCurrentIndex(ti)

        # Add volume fraction fields
        if len(self.material_objs) > 1:
            mat_names = []
            for m in self.material_objs:
                mat_names.append(m.Label)
            self.form.comboFluid.clear()
            self.form.comboFluid.addItems(mat_names[:-1])
        else:
            self.form.comboFluid.clear()

        setInputFieldQuantity(
            self.form.inputKineticEnergy,
            str(self.BoundarySettings.get('TurbulentKineticEnergy')) +
            "m^2/s^2")
        setInputFieldQuantity(
            self.form.inputSpecificDissipationRate,
            str(self.BoundarySettings.get('SpecificDissipationRate')) +
            "rad/s")
        setInputFieldQuantity(
            self.form.inputIntensity,
            str(self.BoundarySettings.get('TurbulenceIntensity')))
        setInputFieldQuantity(
            self.form.inputLengthScale,
            str(self.BoundarySettings.get('TurbulenceLengthScale')) + "m")
    def populateUiBasedOnPhysics(self):
        self.form.potentialFoamCheckBox.setToolTip(
            "Initialise the velocity field using an incompressible, potential "
            "or irrotational flow assumption.")
        checked = self.InitialVariables.get('PotentialFoam', False)
        self.form.potentialFoamCheckBox.setChecked(checked)
        self.form.basicPropertiesFrame.setVisible(not checked)

        setInputFieldQuantity(self.form.Ux,
                              str(self.InitialVariables.get('Ux')) + "m/s")
        setInputFieldQuantity(self.form.Uy,
                              str(self.InitialVariables.get('Uy')) + "m/s")
        setInputFieldQuantity(self.form.Uz,
                              str(self.InitialVariables.get('Uz')) + "m/s")
        setInputFieldQuantity(
            self.form.pressure,
            str(self.InitialVariables.get('Pressure')) + "kg/m/s^2")

        # Add volume fraction fields
        if len(self.material_objs) > 1:
            self.form.volumeFractionsFrame.setVisible(True)
            mat_names = []
            for m in self.material_objs:
                mat_names.append(m.Label)
            self.form.comboFluid.clear()
            self.form.comboFluid.addItems(mat_names[:-1])
        else:
            self.form.volumeFractionsFrame.setVisible(False)
            self.form.comboFluid.clear()

        if self.physicsModel['Turbulence'] in ['RANS', 'LES']:
            self.form.turbulencePropertiesFrame.setVisible(True)
        else:
            self.form.turbulencePropertiesFrame.setVisible(False)

        self.form.checkUseInletValues.setChecked(
            self.InitialVariables.get('UseInletTurbulenceValues', True))
        # Add any inlets to the list
        for b in self.boundaries:
            if b.BoundarySettings['BoundaryType'] == 'inlet':
                self.form.comboInlets.addItems([b.Label])
        self.form.comboInlets.setCurrentIndex(
            self.form.comboInlets.findText(self.InitialVariables.get('Inlet')))
        setInputFieldQuantity(self.form.inputk,
                              str(self.InitialVariables.get('k')) + "m^2/s^2")
        setInputFieldQuantity(
            self.form.inputOmega,
            str(self.InitialVariables.get('omega')) + "rad/s")
        self.updateTurbulenceModelsUi()

        if self.physicsModel['Thermal'] == 'Energy':
            self.form.energyFrame.setVisible(True)
            self.form.bouyancyFrame.setVisible(False)
        elif self.physicsModel['Thermal'] == 'Buoyancy':
            self.form.energyFrame.setVisible(False)
            self.form.bouyancyFrame.setVisible(True)
        else:
            self.form.thermalPropertiesFrame.setVisible(False)
Exemplo n.º 17
0
 def comboFluidChanged(self):
     alphaName = self.form.comboFluid.currentText()
     if 'alphas' in self.p:
         if alphaName in self.p['alphas']:
             setInputFieldQuantity(self.form.inputVolumeFraction, str(self.p['alphas'].get(alphaName, 0.0)))
Exemplo n.º 18
0
    def initialiseUponReload(self):
        """ fills the widgets """
        if self.mesh_obj.MeshUtility == "gmsh":
            self.form.if_gmsh_rellen.setValue(self.obj.RelativeLength)
        else:
            self.form.if_rellen.setValue(self.obj.RelativeLength)
            setInputFieldQuantity(self.form.if_refinethick,
                                  self.obj.RefinementThickness)
            if self.numlayer > 1:  # Only reload when there are more than one layer
                self.form.check_boundlayer.toggle()
                self.form.if_numlayer.setValue(self.obj.NumberLayers)
                self.form.if_expratio.setValue(self.obj.ExpansionRatio)
                setInputFieldQuantity(self.form.if_firstlayerheight,
                                      self.obj.FirstLayerHeight)

            self.form.if_refinelevel.setValue(self.obj.RefinementLevel)
            self.form.if_edgerefinement.setValue(self.obj.RegionEdgeRefinement)
            if self.obj.Baffle:
                self.form.baffle_check.toggle()
            if self.obj.Internal:
                self.form.volumeRefinementToggle.toggle()
            index = self.validTypesOfInternalPrimitives.index(
                self.obj.InternalRegion["Type"])
            self.form.internalVolumePrimitiveSelection.setCurrentIndex(index)
            setInputFieldQuantity(
                self.form.xCenter,
                str(self.obj.InternalRegion["Center"]["x"]) + "m")
            setInputFieldQuantity(
                self.form.yCenter,
                str(self.obj.InternalRegion["Center"]["y"]) + "m")
            setInputFieldQuantity(
                self.form.zCenter,
                str(self.obj.InternalRegion["Center"]["z"]) + "m")
            setInputFieldQuantity(
                self.form.xLength,
                str(self.obj.InternalRegion["BoxLengths"]["x"]) + "m")
            setInputFieldQuantity(
                self.form.yLength,
                str(self.obj.InternalRegion["BoxLengths"]["y"]) + "m")
            setInputFieldQuantity(
                self.form.zLength,
                str(self.obj.InternalRegion["BoxLengths"]["z"]) + "m")
            setInputFieldQuantity(
                self.form.radius,
                str(self.obj.InternalRegion["SphereRadius"]) + "m")
            p1 = self.obj.InternalRegion.get("Point1", {
                "x": 0,
                "y": 0,
                "z": 0
            })
            self.obj.InternalRegion["Point1"] = p1
            setInputFieldQuantity(self.form.xPoint1, str(p1["x"]) + "m")
            setInputFieldQuantity(self.form.yPoint1, str(p1["y"]) + "m")
            setInputFieldQuantity(self.form.zPoint1, str(p1["z"]) + "m")
            p2 = self.obj.InternalRegion.get("Point2", {
                "x": 0,
                "y": 0,
                "z": 0
            })
            self.obj.InternalRegion["Point2"] = p2
            setInputFieldQuantity(self.form.xPoint2, str(p2["x"]) + "m")
            setInputFieldQuantity(self.form.yPoint2, str(p2["y"]) + "m")
            setInputFieldQuantity(self.form.zPoint2, str(p2["z"]) + "m")
            self.obj.InternalRegion["Radius1"] = self.obj.InternalRegion.get(
                "Radius1", 0)
            setInputFieldQuantity(
                self.form.radius1,
                str(self.obj.InternalRegion["Radius1"]) + "m")
            self.obj.InternalRegion["Radius2"] = self.obj.InternalRegion.get(
                "Radius2", 0)
            setInputFieldQuantity(
                self.form.radius2,
                str(self.obj.InternalRegion["Radius2"]) + "m")
Exemplo n.º 19
0
 def comboAspectRatioChanged(self):
     i = self.form.comboAspectRatio.currentIndex()
     setInputFieldQuantity(self.form.inputAspectRatio, ASPECT_RATIOS[i])
     self.form.comboAspectRatio.setToolTip(ASPECT_RATIO_TIPS[i])
Exemplo n.º 20
0
    def eDone(self, index):
        e = [[self.form.e1x.property('quantity').getValueAs('1').Value,
              self.form.e1y.property('quantity').getValueAs('1').Value,
              self.form.e1z.property('quantity').getValueAs('1').Value],
             [self.form.e2x.property('quantity').getValueAs('1').Value,
              self.form.e2y.property('quantity').getValueAs('1').Value,
              self.form.e2z.property('quantity').getValueAs('1').Value],
             [self.form.e3x.property('quantity').getValueAs('1').Value,
              self.form.e3y.property('quantity').getValueAs('1').Value,
              self.form.e3z.property('quantity').getValueAs('1').Value]]
        import CfdTools
        for i in range(3):
            e[i] = CfdTools.normalise(e[i])

        # Keep this one fixed. Make the other two orthogonal. The previous one edited gets to stay in its plane; the
        # one edited longest ago just gets recomputed
        if self.lastEVectorChanged == index:
            prevIndex = self.lastLastEVectorChanged
        else:
            prevIndex = self.lastEVectorChanged
        indexplus = (index + 1) % 3
        indexminus = (index - 1) % 3
        import numpy
        if indexplus == prevIndex:  # indexminus must be the one changed longest ago
            e[indexminus] = numpy.cross(e[index], e[indexplus])
            e[indexplus] = numpy.cross(e[indexminus], e[index])
        else:
            e[indexplus] = numpy.cross(e[indexminus], e[index])
            e[indexminus] = numpy.cross(e[index], e[indexplus])
        e[indexplus] = CfdTools.normalise(e[indexplus])
        e[indexminus] = CfdTools.normalise(e[indexminus])

        setInputFieldQuantity(self.form.e1x, str(e[0][0]))
        setInputFieldQuantity(self.form.e1y, str(e[0][1]))
        setInputFieldQuantity(self.form.e1z, str(e[0][2]))
        setInputFieldQuantity(self.form.e2x, str(e[1][0]))
        setInputFieldQuantity(self.form.e2y, str(e[1][1]))
        setInputFieldQuantity(self.form.e2z, str(e[1][2]))
        setInputFieldQuantity(self.form.e3x, str(e[2][0]))
        setInputFieldQuantity(self.form.e3y, str(e[2][1]))
        setInputFieldQuantity(self.form.e3z, str(e[2][2]))
Exemplo n.º 21
0
    def setInitialValues(self):
        for i in range(len(self.obj.partNameList)):
            self.form.listWidget.addItem(str(self.obj.partNameList[i]))

        if self.obj.Name.startswith('PorousZone'):
            ci = indexOrDefault(POROUS_CORRELATIONS, self.p.get('PorousCorrelation'), 0)
            self.form.comboBoxCorrelation.setCurrentIndex(ci)
            d = self.p.get('D')
            setInputFieldQuantity(self.form.dx, "{} m^-2".format(d[0]))
            setInputFieldQuantity(self.form.dy, "{} m^-2".format(d[1]))
            setInputFieldQuantity(self.form.dz, "{} m^-2".format(d[2]))
            f = self.p.get('F')
            setInputFieldQuantity(self.form.fx, "{} m^-1".format(f[0]))
            setInputFieldQuantity(self.form.fy, "{} m^-1".format(f[1]))
            setInputFieldQuantity(self.form.fz, "{} m^-1".format(f[2]))
            e1 = self.p.get('e1')
            setInputFieldQuantity(self.form.e1x, str(e1[0]))
            setInputFieldQuantity(self.form.e1y, str(e1[1]))
            setInputFieldQuantity(self.form.e1z, str(e1[2]))
            e2 = self.p.get('e2')
            setInputFieldQuantity(self.form.e2x, str(e2[0]))
            setInputFieldQuantity(self.form.e2y, str(e2[1]))
            setInputFieldQuantity(self.form.e2z, str(e2[2]))
            e3 = self.p.get('e3')
            setInputFieldQuantity(self.form.e3x, str(e3[0]))
            setInputFieldQuantity(self.form.e3y, str(e3[1]))
            setInputFieldQuantity(self.form.e3z, str(e3[2]))
            setInputFieldQuantity(self.form.inputOuterDiameter, "{} m".format(self.p.get('OuterDiameter')))
            tubeAxis = self.p.get('TubeAxis')
            setInputFieldQuantity(self.form.inputTubeAxisX, str(tubeAxis[0]))
            setInputFieldQuantity(self.form.inputTubeAxisY, str(tubeAxis[1]))
            setInputFieldQuantity(self.form.inputTubeAxisZ, str(tubeAxis[2]))
            setInputFieldQuantity(self.form.inputTubeSpacing, "{} m".format(self.p.get('TubeSpacing')))
            normalAxis = self.p.get('SpacingDirection')
            setInputFieldQuantity(self.form.inputBundleLayerNormalX, str(normalAxis[0]))
            setInputFieldQuantity(self.form.inputBundleLayerNormalY, str(normalAxis[1]))
            setInputFieldQuantity(self.form.inputBundleLayerNormalZ, str(normalAxis[2]))
            setInputFieldQuantity(self.form.inputAspectRatio, str(self.p.get('AspectRatio')))
            setInputFieldQuantity(self.form.inputVelocityEstimate, "{} m/s".format(self.p.get('VelocityEstimate')))

        elif self.obj.Name.startswith('InitialisationZone'):
            if 'Ux' in self.p:
                setInputFieldQuantity(self.form.inputUx, "{} m/s".format(self.p.get('Ux')))
                setInputFieldQuantity(self.form.inputUy, "{} m/s".format(self.p.get('Uy')))
                setInputFieldQuantity(self.form.inputUz, "{} m/s".format(self.p.get('Uz')))
                self.form.checkVelocity.setChecked(True)
            if 'Pressure' in self.p:
                setInputFieldQuantity(self.form.inputPressure, "{} kg/m/s^2".format(self.p.get('Pressure')))
                self.form.checkPressure.setChecked(True)
            if 'alphas' in self.p:
                self.form.checkAlpha.setChecked(True)
            # Simulate initial signals to get into correct state
            self.checkVelocityChanged(self.form.checkVelocity.isChecked())
            self.checkPressureChanged(self.form.checkPressure.isChecked())
            self.checkAlphaChanged(self.form.checkAlpha.isChecked())
Exemplo n.º 22
0
    def populateUiBasedOnPhysics(self):
        self.form.radioButtonPotentialFlow.setToolTip(
            "Initialise the velocity field using an incompressible, potential "
            "or irrotational flow assumption.")
        potential_foam = self.InitialVariables['PotentialFoam']
        use_inlet_UP = self.InitialVariables['UseInletUPValues']
        if potential_foam:
            self.form.radioButtonPotentialFlow.toggle()
        elif use_inlet_UP:
            self.form.radioButtonUseInletValuesUP.toggle()
        else:
            self.form.radioButtonSpecifyValues.toggle()

        setInputFieldQuantity(self.form.Ux,
                              str(self.InitialVariables['Ux']) + "m/s")
        setInputFieldQuantity(self.form.Uy,
                              str(self.InitialVariables['Uy']) + "m/s")
        setInputFieldQuantity(self.form.Uz,
                              str(self.InitialVariables['Uz']) + "m/s")
        setInputFieldQuantity(
            self.form.pressure,
            str(self.InitialVariables['Pressure']) + "kg/m/s^2")

        # Add volume fraction fields
        if self.physicsModel.Phase != 'Single':
            self.form.volumeFractionsFrame.setVisible(True)
            mat_names = []
            for m in self.material_objs:
                mat_names.append(m.Label)
            self.form.comboFluid.clear()
            self.form.comboFluid.addItems(mat_names[:-1])
        else:
            self.form.volumeFractionsFrame.setVisible(False)
            self.form.comboFluid.clear()

        if self.physicsModel.Turbulence in ['RANS', 'LES']:
            self.form.turbulencePropertiesFrame.setVisible(True)
        else:
            self.form.turbulencePropertiesFrame.setVisible(False)

        use_inlet_turb = self.InitialVariables['UseInletTurbulenceValues']
        self.form.checkUseInletValues.setChecked(use_inlet_turb)
        setInputFieldQuantity(self.form.inputk,
                              str(self.InitialVariables.get('k')) + "m^2/s^2")
        setInputFieldQuantity(
            self.form.inputOmega,
            str(self.InitialVariables.get('omega')) + "rad/s")

        use_inlet_temp = self.InitialVariables['UseInletTemperatureValues']
        self.form.checkUseInletValuesThermal.setChecked(use_inlet_temp)
        setInputFieldQuantity(self.form.inputTemperature,
                              str(self.InitialVariables['Temperature']) + "K")

        # Add any inlets to the list
        for b in self.boundaries:
            if b.BoundarySettings['BoundaryType'] in ['inlet', 'farField']:
                self.form.comboInlets.addItems([b.Label])
        self.form.comboInlets.setCurrentIndex(
            self.form.comboInlets.findText(self.InitialVariables['Inlet']))

        self.updateUi()
Exemplo n.º 23
0
    def runMeshProcess(self):
        FreeCADGui.doCommand(
            "\nFreeCAD.ActiveDocument.{}.CharacteristicLengthMax "
            "= '{}'".format(self.mesh_obj.Name, self.clmax))
        FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.MeshUtility "
                             "= '{}'".format(self.mesh_obj.Name, self.utility))
        FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.CellsBetweenLevels "
                             "= {}".format(self.mesh_obj.Name,
                                           self.cellsbetweenlevels))
        FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.EdgeRefinement "
                             "= {}".format(self.mesh_obj.Name,
                                           self.edgerefine))
        FreeCADGui.doCommand("FreeCAD.ActiveDocument.{}.PointInMesh "
                             "= {}".format(self.mesh_obj.Name,
                                           self.PointInMesh))

        self.console_message_cart = ''
        self.Start = time.time()
        self.Timer.start()
        self.console_log("Starting cut-cell Cartesian meshing ...")
        # try:
        #     self.get_active_analysis()
        #     self.set_mesh_params()
        #     import CfdCartTools  # Fresh init before remeshing
        #     self.cart_mesh = CfdCartTools.CfdCartTools(self.obj)
        #     cart_mesh = self.cart_mesh
        #     self.form.if_max.setText(str(cart_mesh.get_clmax()))
        #     print("\nStarting cut-cell Cartesian meshing ...\n")
        #     print('  Part to mesh: Name --> '
        #           + cart_mesh.part_obj.Name + ',  Label --> '
        #           + cart_mesh.part_obj.Label + ', ShapeType --> '
        #           + cart_mesh.part_obj.Shape.ShapeType)
        #     print('  CharacteristicLengthMax: ' + str(cart_mesh.clmax))
        #     # print('  CharacteristicLengthMin: ' + str(cart_mesh.clmin))
        #     # print('  ElementOrder: ' + cart_mesh.order)
        #     cart_mesh.get_dimension()
        #     cart_mesh.get_tmp_file_paths(self.utility)
        #     cart_mesh.setupMeshCaseDir()
        #     cart_mesh.get_group_data()
        #     cart_mesh.get_region_data()
        #     cart_mesh.write_part_file()
        #     cart_mesh.setupMeshDict(self.utility)
        #     cart_mesh.createMeshScript(run_parallel='false',
        #                                mesher_name='cartesianMesh',
        #                                num_proc=1,
        #                                cartMethod=self.utility)  # Extend in time
        #     self.paraviewScriptName = self.cart_mesh.createParaviewScript()
        #     self.runCart(cart_mesh)
        # except Exception as ex:
        #     self.console_log("Error: " + ex.message, '#FF0000')
        #     self.Timer.stop()
        try:
            self.get_active_analysis()
            self.set_mesh_params()
            import CfdCartTools  # Fresh init before remeshing
            self.cart_mesh = CfdCartTools.CfdCartTools(self.obj)
            cart_mesh = self.cart_mesh
            setInputFieldQuantity(self.form.if_max, str(cart_mesh.get_clmax()))
            print("\nStarting cut-cell Cartesian meshing ...\n")
            print('  Part to mesh: Name --> ' + cart_mesh.part_obj.Name +
                  ',  Label --> ' + cart_mesh.part_obj.Label +
                  ', ShapeType --> ' + cart_mesh.part_obj.Shape.ShapeType)
            print('  CharacteristicLengthMax: ' + str(cart_mesh.clmax))
            cart_mesh.get_dimension()
            # cart_mesh.get_tmp_file_paths(self.utility)
            cart_mesh.get_tmp_file_paths()
            cart_mesh.setup_mesh_case_dir()
            cart_mesh.get_group_data()
            cart_mesh.get_region_data(
            )  # Writes region stls so need file structure
            cart_mesh.write_mesh_case()
            self.console_log("Writing the STL files of the part surfaces ...")
            cart_mesh.write_part_file()
            self.console_log("Running {} ...".format(self.utility))
            self.runCart(cart_mesh)
        except Exception as ex:
            self.console_log("Error: " + ex.message, '#FF0000')
            self.Timer.stop()
            raise