def processBoundaryConditions(self):
        """ Compute any quantities required before case build """
        settings = self.settings
        for bc_name in settings['boundaries']:
            bc = settings['boundaries'][bc_name]
            if not bc['VelocityIsCartesian']:
                veloMag = bc['VelocityMag']
                face = bc['DirectionFace'].split(':')
                # See if entered face actually exists and is planar
                try:
                    selected_object = self.analysis_obj.Document.getObject(
                        face[0])
                    if hasattr(selected_object, "Shape"):
                        elt = selected_object.Shape.getElement(face[1])
                        if elt.ShapeType == 'Face' and CfdTools.is_planar(elt):
                            n = elt.normalAt(0.5, 0.5)
                            if bc['ReverseNormal']:
                                n = [-ni for ni in n]
                            velocity = [ni * veloMag for ni in n]
                            bc['Ux'] = velocity[0]
                            bc['Uy'] = velocity[1]
                            bc['Uz'] = velocity[2]
                        else:
                            raise RuntimeError
                    else:
                        raise RuntimeError
                except (SystemError, RuntimeError):
                    raise RuntimeError(bc['DirectionFace'] +
                                       " is not a valid, planar face.")
            if settings['solver']['solverName'] in [
                    'simpleFoam', 'porousSimpleFoam', 'pimpleFoam'
            ]:
                bc['KinematicPressure'] = bc['Pressure'] / settings[
                    'fluidProperties'][0]['Density']

            if bc['PorousBaffleMethod'] == 1:
                wireDiam = bc['ScreenWireDiameter']
                spacing = bc['ScreenSpacing']
                CD = 1.0  # Drag coeff of wire (Simmons - valid for Re > ~300)
                beta = (1 - wireDiam / spacing)**2
                bc['PressureDropCoeff'] = CD * (1 - beta)

            if settings['solver']['solverName'] in [
                    'interFoam', 'multiphaseInterFoam'
            ]:
                # Make sure the first n-1 alpha values exist, and write the n-th one
                # consistently for multiphaseInterFoam
                sum_alpha = 0.0
                alphas_new = {}
                for i, m in enumerate(settings['fluidProperties']):
                    alpha_name = m['Name']
                    if i == len(settings['fluidProperties']) - 1:
                        if settings['solver'][
                                'solverName'] == 'multiphaseInterFoam':
                            alphas_new[alpha_name] = 1.0 - sum_alpha
                    else:
                        alpha = bc.get('alphas', {}).get(alpha_name, 0.0)
                        alphas_new[alpha_name] = alpha
                        sum_alpha += alpha
                bc['alphas'] = alphas_new
 def lineDirectionChanged(self, value):
     selection = value.split(':')
     # See if entered face actually exists and is planar
     try:
         selected_object = self.obj.Document.getObject(selection[0])
         if hasattr(selected_object, "Shape"):
             elt = selected_object.Shape.getElement(selection[1])
             if elt.ShapeType == 'Face' and CfdTools.is_planar(elt):
                 return
     except SystemError:
         pass
     FreeCAD.Console.PrintMessage(value + " is not a valid, planar face\n")
 def addSelection(self, doc_name, obj_name, sub, selectedPoint=None):
     """ Add the selected sub-element (face) of the part to the Reference list. Prevent selection in other
     document.
     """
     if FreeCADGui.activeDocument().Document.Name != self.obj.Document.Name:
         return
     selected_object = FreeCAD.getDocument(doc_name).getObject(obj_name)
     # On double click on a vertex of a solid sub is None and obj is the solid
     tempList = list(self.obj.References)
     print('Selection: ' + selected_object.Shape.ShapeType + '  ' +
           selected_object.Name + ':' + sub + " @ " + str(selectedPoint))
     if hasattr(selected_object, "Shape") and sub:
         elt = selected_object.Shape.getElement(sub)
         if elt.ShapeType == 'Face':
             selection = (selected_object.Name, sub)
             if self.selecting_references:
                 if selection not in self.obj.References:
                     tempList.append(selection)
                     # If the user hasn't picked anything for direction the selected face is used as default.
                     if self.form.lineDirection.text(
                     ) == "" and CfdTools.is_planar(elt):
                         self.form.lineDirection.setText(selection[0] +
                                                         ':' + selection[1])
                 else:
                     FreeCAD.Console.PrintMessage(
                         selection[0] + ':' + selection[1] +
                         ' already in reference list\n')
             if self.selecting_direction:
                 if CfdTools.is_planar(elt):
                     self.form.lineDirection.setText(selection[0] + ':' +
                                                     selection[1])
                     self.selecting_direction = False
                 else:
                     FreeCAD.Console.PrintMessage('Face must be planar\n')
     self.obj.References = list(tempList)
     self.rebuild_list_references()
     self.update_selectionbuttons_ui()
Exemple #4
0
 def directionSelection(self, doc_name, obj_name, sub, selectedPoint=None):
     if FreeCADGui.activeDocument().Document.Name != self.obj.Document.Name:
         return
     selected_object = FreeCAD.getDocument(doc_name).getObject(obj_name)
     # On double click on a vertex of a solid sub is None and obj is the solid
     print('Selection: ' + selected_object.Shape.ShapeType + '  ' +
           selected_object.Name + ':' + sub + " @ " + str(selectedPoint))
     if hasattr(selected_object, "Shape") and sub:
         elt = selected_object.Shape.getElement(sub)
         if elt.ShapeType == 'Face':
             selection = (selected_object.Name, sub)
             if self.selecting_direction:
                 if CfdTools.is_planar(elt):
                     self.selecting_direction = False
                     self.form.lineDirection.setText(
                         selection[0] + ':' +
                         selection[1])  # TODO: Display label, not name
                 else:
                     FreeCAD.Console.PrintMessage('Face must be planar\n')
    def processBoundaryConditions(self):
        """ Compute any quantities required before case build """
        settings = self.settings
        for bc_name in settings['boundaries']:
            bc = settings['boundaries'][bc_name]
            if not bc['VelocityIsCartesian']:
                veloMag = bc['VelocityMag']
                face = bc['DirectionFace'].split(':')
                # See if entered face actually exists and is planar
                try:
                    selected_object = self.analysis_obj.Document.getObject(
                        face[0])
                    if hasattr(selected_object, "Shape"):
                        elt = selected_object.Shape.getElement(face[1])
                        if elt.ShapeType == 'Face' and CfdTools.is_planar(elt):
                            n = elt.normalAt(0.5, 0.5)
                            if bc['ReverseNormal']:
                                n = [-ni for ni in n]
                            velocity = [ni * veloMag for ni in n]
                            bc['Ux'] = velocity[0]
                            bc['Uy'] = velocity[1]
                            bc['Uz'] = velocity[2]
                        else:
                            raise RuntimeError
                    else:
                        raise RuntimeError
                except (SystemError, RuntimeError):
                    raise RuntimeError(bc['DirectionFace'] +
                                       " is not a valid, planar face.")
            if not settings['alphaZonesPresent']:
                bc['KinematicPressure'] = bc['Pressure'] / next(
                    iter(settings['fluidProperties'].values()))['Density']

            if bc['PorousBaffleMethod'] == 1:
                wireDiam = bc['ScreenWireDiameter']
                spacing = bc['ScreenSpacing']
                CD = 1.0  # Drag coeff of wire (Simmons - valid for Re > ~300)
                beta = (1 - wireDiam / spacing)**2
                bc['PressureDropCoeff'] = CD * (1 - beta)