Пример #1
0
    def _handleElasticityBodyForces(self, bodies):
        obj = self._getSingleMember("Fem::ConstraintSelfWeight")
        if obj is not None:
            for name in bodies:
                gravity = self._getConstant("Gravity", "L/T^2")
                m = self._getBodyMaterial(name).Material

                densityQuantity = Units.Quantity(m["Density"])
                dimension = "M/L^3"
                if name.startswith("Edge"):
                    # not tested, but it seems needed
                    # because density does not exist (IMHO, bernd)
                    density = None
                    if density:
                        density.Unit = Units.Unit(-2, 1)
                    dimension = "M/L^2"
                density = self._convert(densityQuantity, dimension)

                force1 = gravity * obj.Gravity_x * density
                force2 = gravity * obj.Gravity_y * density
                force3 = gravity * obj.Gravity_z * density
                self._bodyForce(name, "Stress Bodyforce 1", force1)
                self._bodyForce(name, "Stress Bodyforce 2", force2)
                self._bodyForce(name, "Stress Bodyforce 3", force3)
            self._handled(obj)
Пример #2
0
 def check_material_keys(self):
     if 'Density' in self.material:
         if 'Density' not in str(Units.Unit(self.material['Density'])):
             print('Density in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
             self.material['Density'] = '0 kg/m^3'
     else:
         print('Density not found in material data of: ' + self.material['Name'])
         self.material['Density'] = '0 kg/m^3'
     if self.obj.Category == 'Solid':
         # mechanical properties
         if 'YoungsModulus' in self.material:
             if 'Pressure' not in str(Units.Unit(self.material['YoungsModulus'])):  # unit type of YoungsModulus is Pressure
                 print('YoungsModulus in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
                 self.material['YoungsModulus'] = '0 MPa'
         else:
             print('YoungsModulus not found in material data of: ' + self.material['Name'])
             self.material['YoungsModulus'] = '0 MPa'
         if 'PoissonRatio' not in self.material:  # PoissonRatio does not have a unit, we do not gone check for a unit
             print('PoissonRatio not found in material data of: ' + self.material['Name'])
             self.material['PoissonRatio'] = '0'
     if self.obj.Category == 'Fluid':
         # Fluidic properties
         if 'KinematicViscosity' in self.material:
             if 'KinematicViscosity' not in str(Units.Unit(self.material['KinematicViscosity'])):
                 print('KinematicViscosity in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
                 self.material['KinematicViscosity'] = '0 m^2/s'
         else:
             print('KinematicViscosity not found in material data of: ' + self.material['Name'])
             self.material['KinematicViscosity'] = '0 m^2/s'
         if 'VolumetricThermalExpansionCoefficient' in self.material:
             if 'ThermalExpansionCoefficient' not in str(Units.Unit(self.material['VolumetricThermalExpansionCoefficient'])):  # unit type of VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient
                 print('VolumetricThermalExpansionCoefficient in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
                 self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K'
         else:
             print('VolumetricThermalExpansionCoefficient not found in material data of: ' + self.material['Name'])
             self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K'
     # Thermal properties
     if 'ThermalConductivity' in self.material:
         if 'ThermalConductivity' not in str(Units.Unit(self.material['ThermalConductivity'])):
             print('ThermalConductivity in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
             self.material['ThermalConductivity'] = '0 W/m/K'
     else:
         print('ThermalConductivity not found in material data of: ' + self.material['Name'])
         self.material['ThermalConductivity'] = '0 W/m/K'
     if 'ThermalExpansionCoefficient' in self.material:
         if 'ThermalExpansionCoefficient' not in str(Units.Unit(self.material['ThermalExpansionCoefficient'])):
             print('ThermalExpansionCoefficient in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
             self.material['ThermalExpansionCoefficient'] = '0 um/m/K'
     else:
         print('ThermalExpansionCoefficient not found in material data of: ' + self.material['Name'])
         self.material['ThermalExpansionCoefficient'] = '0 um/m/K'
     if 'SpecificHeat' in self.material:
         if 'SpecificHeat' not in str(Units.Unit(self.material['SpecificHeat'])):
             print('SpecificHeat in material data seams to have no unit or a wrong unit (reset the value): ' + self.material['Name'])
             self.material['SpecificHeat'] = '0 J/kg/K'
     else:
         print('SpecificHeat not found in material data of: ' + self.material['Name'])
         self.material['SpecificHeat'] = '0 J/kg/K'
Пример #3
0
def addObjectProperty(obj, prop, init_val, type, *args):
    """ Call addProperty on the object if it does not yet exist """
    added = False
    if prop not in obj.PropertiesList:
        added = obj.addProperty(type, prop, *args)
    if type == "App::PropertyQuantity":
        # Set the unit so that the quantity will be accepted
        # Has to be repeated on load as unit gets lost
        setattr(obj, prop, Units.Unit(init_val))
    if added:
        setattr(obj, prop, init_val)
        return True
    else:
        return False
Пример #4
0
 def check_material_keys(self):
     # FreeCAD units definition is at file end of src/Base/Unit.cpp
     if not self.material:
         FreeCAD.Console.PrintMessage('For some reason all material data is empty!\n')
         self.material['Name'] = 'Empty'
     if 'Density' in self.material:
         if 'Density' not in str(Units.Unit(self.material['Density'])):
             FreeCAD.Console.PrintMessage(
                 'Density in material data seems to have no unit '
                 'or a wrong unit (reset the value): {}\n'
                 .format(self.material['Name'])
             )
             self.material['Density'] = '0 kg/m^3'
     else:
         FreeCAD.Console.PrintMessage(
             'Density not found in material data of: {}\n'
             .format(self.material['Name'])
         )
         self.material['Density'] = '0 kg/m^3'
     if self.obj.Category == 'Solid':
         # mechanical properties
         if 'YoungsModulus' in self.material:
             # unit type of YoungsModulus is Pressure
             if 'Pressure' not in str(Units.Unit(self.material['YoungsModulus'])):
                 FreeCAD.Console.PrintMessage(
                     'YoungsModulus in material data seems to have no unit '
                     'or a wrong unit (reset the value): {}\n'
                     .format(self.material['Name'])
                 )
                 self.material['YoungsModulus'] = '0 MPa'
         else:
             FreeCAD.Console.PrintMessage(
                 'YoungsModulus not found in material data of: {}\n'
                 .format(self.material['Name'])
             )
             self.material['YoungsModulus'] = '0 MPa'
         if 'PoissonRatio' in self.material:
             # PoissonRatio does not have a unit, but it is checked it there is no value at all
             try:
                 float(self.material['PoissonRatio'])
             except:
                 FreeCAD.Console.PrintMessage(
                     'PoissonRatio has wrong or no data (reset the value): {}\n'
                     .format(self.material['PoissonRatio'])
                 )
                 self.material['PoissonRatio'] = '0'
         else:
             FreeCAD.Console.PrintMessage(
                 'PoissonRatio not found in material data of: {}\n'
                 .format(self.material['Name'])
             )
             self.material['PoissonRatio'] = '0'
     if self.obj.Category == 'Fluid':
         # Fluidic properties
         if 'KinematicViscosity' in self.material:
             ki_vis = self.material['KinematicViscosity']
             if 'KinematicViscosity' not in str(Units.Unit(ki_vis)):
                 FreeCAD.Console.PrintMessage(
                     'KinematicViscosity in material data seems to have no unit '
                     'or a wrong unit (reset the value): {}\n'
                     .format(self.material['Name'])
                 )
                 self.material['KinematicViscosity'] = '0 m^2/s'
         else:
             FreeCAD.Console.PrintMessage(
                 'KinematicViscosity not found in material data of: {}\n'
                 .format(self.material['Name'])
             )
             self.material['KinematicViscosity'] = '0 m^2/s'
         if 'VolumetricThermalExpansionCoefficient' in self.material:
             # unit type VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient
             vol_ther_ex_co = self.material['VolumetricThermalExpansionCoefficient']
             if 'VolumetricThermalExpansionCoefficient' not in str(Units.Unit(vol_ther_ex_co)):
                 FreeCAD.Console.PrintMessage(
                     'VolumetricThermalExpansionCoefficient in material data '
                     'seems to have no unit or a wrong unit (reset the value): {}\n'
                     .format(self.material['Name'])
                 )
                 self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K'
         else:
             FreeCAD.Console.PrintMessage(
                 'VolumetricThermalExpansionCoefficient not found in material data of: {}\n'
                 .format(self.material['Name'])
             )
             self.material['VolumetricThermalExpansionCoefficient'] = '0 m/m/K'
     # Thermal properties
     if 'ThermalConductivity' in self.material:
         if 'ThermalConductivity' not in str(Units.Unit(self.material['ThermalConductivity'])):
             FreeCAD.Console.PrintMessage(
                 'ThermalConductivity in material data seems to have no unit '
                 'or a wrong unit (reset the value): {}\n'
                 .format(self.material['Name'])
             )
             self.material['ThermalConductivity'] = '0 W/m/K'
     else:
         FreeCAD.Console.PrintMessage(
             'ThermalConductivity not found in material data of: {}\n'
             .format(self.material['Name'])
         )
         self.material['ThermalConductivity'] = '0 W/m/K'
     if 'ThermalExpansionCoefficient' in self.material:
         the_ex_co = self.material['ThermalExpansionCoefficient']
         if 'ThermalExpansionCoefficient' not in str(Units.Unit(the_ex_co)):
             FreeCAD.Console.PrintMessage(
                 'ThermalExpansionCoefficient in material data seems to have no unit '
                 'or a wrong unit (reset the value): {}\n'
                 .format(self.material['Name'])
             )
             self.material['ThermalExpansionCoefficient'] = '0 um/m/K'
     else:
         FreeCAD.Console.PrintMessage(
             'ThermalExpansionCoefficient not found in material data of: {}\n'
             .format(self.material['Name'])
         )
         self.material['ThermalExpansionCoefficient'] = '0 um/m/K'
     if 'SpecificHeat' in self.material:
         if 'SpecificHeat' not in str(Units.Unit(self.material['SpecificHeat'])):
             FreeCAD.Console.PrintMessage(
                 'SpecificHeat in material data seems to have no unit '
                 'or a wrong unit (reset the value): {}\n'
                 .format(self.material['Name'])
             )
             self.material['SpecificHeat'] = '0 J/kg/K'
     else:
         FreeCAD.Console.PrintMessage(
             'SpecificHeat not found in material data of: {}\n'
             .format(self.material['Name'])
         )
         self.material['SpecificHeat'] = '0 J/kg/K'
     FreeCAD.Console.PrintMessage('\n')
def make_arc_aperture(
    arc_inner_radius, arc_outer_radius, arc_length, blend_radius=Units.Quantity("0 mm")
):
    """Creates a wire outline of an arc.

    Args:
        arc_inner_radius (float): Radius of the inside edge of the arc.
        arc_outer_radius (float): Radius of the outside edge of the arc.
        arc_length (float): The length of the arc (measured in angle in radians)
        blend_radius (float): The amount to smooth the edges.

    Returns:
        wire1 (FreeCAD wire definition): An outline description of the shape.
        face1 (FreeCAD face definition): A surface description of the shape.
    """

    half_angle = arc_length / 2.0  # angles are in radian here
    ho = arc_outer_radius * sin(radians(half_angle))
    hi = arc_inner_radius * sin(radians(half_angle))
    vo = arc_outer_radius * cos(radians(half_angle))
    vi = arc_inner_radius * cos(radians(half_angle))

    # Create vector points for the ends and midpoint of the arcs
    p1 = Base.Vector(0, -ho, vo)
    p2 = Base.Vector(0, ho, vo)
    p3 = Base.Vector(0, -hi, vi)
    p4 = Base.Vector(0, hi, vi)
    cp1 = Base.Vector(0, 0, arc_outer_radius)
    cp2 = Base.Vector(0, 0, arc_inner_radius)

    if blend_radius != 0:
        # bh = blend_radius * cos(pi / 4)
        # bv = blend_radius * sin(pi / 4)
        hdiff = abs(ho - hi)
        vdiff = abs(vo - vi)
        line_angle = atan(vdiff / hdiff)
        # line_length = sqrt(hdiff ** 2 + vdiff ** 2)
        hp = blend_radius * cos(line_angle)
        vp = blend_radius * sin(line_angle)
        hap = blend_radius * cos(pi / 2 - line_angle)
        vap = blend_radius * sin(pi / 2 - line_angle)
        # hcp = blend_radius * cos(-pi / 4 - line_angle)
        # vcp = blend_radius * sin(-pi / 4 - line_angle)
        R = Units.Quantity(
            sqrt(blend_radius ** 2 + blend_radius ** 2), Units.Unit(1)
        )  # Setting units to mm
        hm1 = (R - blend_radius) * sin(-pi / 4 - line_angle + pi)
        vm1 = (R - blend_radius) * cos(-pi / 4 - line_angle + pi)
        hm2 = (R - blend_radius) * sin(-pi / 4 - line_angle)
        vm2 = (R - blend_radius) * cos(-pi / 4 - line_angle)
        hm3 = (R - blend_radius) * sin(-pi / 2 - line_angle)
        vm3 = (R - blend_radius) * cos(-pi / 2 - line_angle)
        # chdiff = abs(hp + hap)
        # cvdiff = abs(vp - vap)
        # cline_angle = atan(cvdiff / chdiff)
        # cline_length = sqrt(chdiff ** 2 + cvdiff ** 2)
        # hmp2 = cline_length / 2 * cos(cline_angle)
        # hcp2 = blend_radius * cos(cline_angle + pi / 4.0)
        # hcp3 = blend_radius * cos(cline_angle - pi / 4.0)
        # vmp2 = cline_length / 2 * sin(cline_angle)
        # vcp2 = blend_radius * sin(cline_angle + pi / 4.0)
        # vcp3 = blend_radius * sin(cline_angle - pi / 4.0)
        hp11 = -ho + hp
        hp12 = -ho + hap
        hp21 = ho - hap
        hp22 = ho - hp
        hp31 = -hi + hap
        hp32 = -hi - hp
        hp41 = hi + hp
        hp42 = hi - hap
        vp11 = vo - vp
        vp12 = vo + vap
        vp21 = vo + vap
        vp22 = vo - vp
        vp31 = vi + vap
        vp32 = vi + vp
        vp41 = vi + vp
        vp42 = vi + vap
        p1_1 = Base.Vector(0, hp11, vp11)
        p1_2 = Base.Vector(0, hp12, vp12)
        p2_1 = Base.Vector(0, hp21, vp21)
        p2_2 = Base.Vector(0, hp22, vp22)
        p3_1 = Base.Vector(0, hp31, vp31)
        p3_2 = Base.Vector(0, hp32, vp32)
        p4_1 = Base.Vector(0, hp41, vp41)
        p4_2 = Base.Vector(0, hp42, vp42)
        # cp1_1 = Base.Vector(0, hp11 + hmp2 - hcp2, vp11 + vmp2 + vcp2)
        # cp2_1 = Base.Vector(0, hp22 - hmp2 + hcp2, vp22 + vmp2 + vcp2)
        cp1_1 = Base.Vector(0, -ho + hm1, vo - vm1)
        cp2_1 = Base.Vector(0, ho + hm2, vo + vm2)
        cp3_1 = Base.Vector(0, -hi - hm3, vi - vm3)
        cp4_1 = Base.Vector(0, hi + hm3, vi - vm3)
        # temp extra lines
        # line3 = Part.LineSegment(p1_1, cp1_1)
        # line4 = Part.LineSegment(cp1_1, p1_2)
        # line5 = Part.LineSegment(p2_1, cp2_1)
        # line6 = Part.LineSegment(cp2_1, p2_2)
        # line7 = Part.LineSegment(p3_1, cp3_1)
        # line8 = Part.LineSegment(cp3_1, p3_2)
        # line9 = Part.LineSegment(p4_1, cp4_1)
        # line10 = Part.LineSegment(cp4_1, p4_2)
        # Create curves
        arc1 = Part.Arc(p1_2, cp1, p2_1)
        arc2 = Part.Arc(p4_2, cp2, p3_1)
        arcp1 = Part.Arc(p1_1, cp1_1, p1_2)
        arcp2 = Part.Arc(p2_1, cp2_1, p2_2)
        arcp3 = Part.Arc(p3_1, cp3_1, p3_2)
        arcp4 = Part.Arc(p4_1, cp4_1, p4_2)

        # Create lines
        line1 = Part.LineSegment(p2_2, p4_1)
        line2 = Part.LineSegment(p3_2, p1_1)

        # Make a shape
        shape1 = Part.Shape([arc1, arcp2, line1, arcp4, arc2, arcp3, line2, arcp1])
        # shape1 = Part.Shape([arc1, line5, line6, line1, line9, line10, arc2, line7,
        # line8, line2, line3, line4])

    else:
        # Create curves
        arc1 = Part.Arc(p1, cp1, p2)
        arc2 = Part.Arc(p4, cp2, p3)

        # Create lines
        line1 = Part.LineSegment(p2, p4)
        line2 = Part.LineSegment(p3, p1)

        # Make a shape
        shape1 = Part.Shape([arc1, line1, arc2, line2])

    # Make a wire outline.
    wire1 = Part.Wire(shape1.Edges)
    # Make a face.
    face1 = Part.Face(wire1)
    return wire1, face1
Пример #6
0
 def check_material_keys(self):
     # FreeCAD units definition is at file end of src/Base/Unit.cpp
     if not self.material:
         FreeCAD.Console.PrintMessage(
             "For some reason all material data is empty!\n")
         self.material["Name"] = "Empty"
     if "Density" in self.material:
         if "Density" not in str(Units.Unit(self.material["Density"])):
             FreeCAD.Console.PrintMessage(
                 "Density in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n".format(
                     self.material["Name"]))
             self.material["Density"] = "0 kg/m^3"
     else:
         FreeCAD.Console.PrintMessage(
             "Density not found in material data of: {}\n".format(
                 self.material["Name"]))
         self.material["Density"] = "0 kg/m^3"
     if self.obj.Category == "Solid":
         # mechanical properties
         if "YoungsModulus" in self.material:
             # unit type of YoungsModulus is Pressure
             if "Pressure" not in str(
                     Units.Unit(self.material["YoungsModulus"])):
                 FreeCAD.Console.PrintMessage(
                     "YoungsModulus in material data seems to have no unit "
                     "or a wrong unit (reset the value): {}\n".format(
                         self.material["Name"]))
                 self.material["YoungsModulus"] = "0 MPa"
         else:
             FreeCAD.Console.PrintMessage(
                 "YoungsModulus not found in material data of: {}\n".format(
                     self.material["Name"]))
             self.material["YoungsModulus"] = "0 MPa"
         if "PoissonRatio" in self.material:
             # PoissonRatio does not have a unit, but it is checked it there is no value at all
             try:
                 float(self.material["PoissonRatio"])
             except ValueError:
                 FreeCAD.Console.PrintMessage(
                     "PoissonRatio has wrong or no data (reset the value): {}\n"
                     .format(self.material["PoissonRatio"]))
                 self.material["PoissonRatio"] = "0"
         else:
             FreeCAD.Console.PrintMessage(
                 "PoissonRatio not found in material data of: {}\n".format(
                     self.material["Name"]))
             self.material["PoissonRatio"] = "0"
     if self.obj.Category == "Fluid":
         # Fluidic properties
         if "KinematicViscosity" in self.material:
             ki_vis = self.material["KinematicViscosity"]
             if "KinematicViscosity" not in str(Units.Unit(ki_vis)):
                 FreeCAD.Console.PrintMessage(
                     "KinematicViscosity in material data seems to have no unit "
                     "or a wrong unit (reset the value): {}\n".format(
                         self.material["Name"]))
                 self.material["KinematicViscosity"] = "0 m^2/s"
         else:
             FreeCAD.Console.PrintMessage(
                 "KinematicViscosity not found in material data of: {}\n".
                 format(self.material["Name"]))
             self.material["KinematicViscosity"] = "0 m^2/s"
         if "VolumetricThermalExpansionCoefficient" in self.material:
             # unit type VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient
             vol_ther_ex_co = self.material[
                 "VolumetricThermalExpansionCoefficient"]
             if "VolumetricThermalExpansionCoefficient" not in str(
                     Units.Unit(vol_ther_ex_co)):
                 FreeCAD.Console.PrintMessage(
                     "VolumetricThermalExpansionCoefficient in material data "
                     "seems to have no unit or a wrong unit (reset the value): {}\n"
                     .format(self.material["Name"]))
                 self.material[
                     "VolumetricThermalExpansionCoefficient"] = "0 m^3/m^3/K"
         else:
             FreeCAD.Console.PrintMessage(
                 "VolumetricThermalExpansionCoefficient not found in material data of: {}\n"
                 .format(self.material["Name"]))
             self.material[
                 "VolumetricThermalExpansionCoefficient"] = "0 m^3/m^3/K"
     # Thermal properties
     if "ThermalConductivity" in self.material:
         if "ThermalConductivity" not in str(
                 Units.Unit(self.material["ThermalConductivity"])):
             FreeCAD.Console.PrintMessage(
                 "ThermalConductivity in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n".format(
                     self.material["Name"]))
             self.material["ThermalConductivity"] = "0 W/m/K"
     else:
         FreeCAD.Console.PrintMessage(
             "ThermalConductivity not found in material data of: {}\n".
             format(self.material["Name"]))
         self.material["ThermalConductivity"] = "0 W/m/K"
     if "ThermalExpansionCoefficient" in self.material:
         the_ex_co = self.material["ThermalExpansionCoefficient"]
         if "ThermalExpansionCoefficient" not in str(Units.Unit(the_ex_co)):
             FreeCAD.Console.PrintMessage(
                 "ThermalExpansionCoefficient in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n".format(
                     self.material["Name"]))
             self.material["ThermalExpansionCoefficient"] = "0 um/m/K"
     else:
         FreeCAD.Console.PrintMessage(
             "ThermalExpansionCoefficient not found in material data of: {}\n"
             .format(self.material["Name"]))
         self.material["ThermalExpansionCoefficient"] = "0 um/m/K"
     if "SpecificHeat" in self.material:
         if "SpecificHeat" not in str(
                 Units.Unit(self.material["SpecificHeat"])):
             FreeCAD.Console.PrintMessage(
                 "SpecificHeat in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n".format(
                     self.material["Name"]))
             self.material["SpecificHeat"] = "0 J/kg/K"
     else:
         FreeCAD.Console.PrintMessage(
             "SpecificHeat not found in material data of: {}\n".format(
                 self.material["Name"]))
         self.material["SpecificHeat"] = "0 J/kg/K"
     FreeCAD.Console.PrintMessage("\n")
Пример #7
0
 def check_material_keys(self):
     # FreeCAD units definition is at file end of src/Base/Unit.cpp
     if not self.material:
         FreeCAD.Console.PrintMessage("For some reason all material data is empty!\n")
         self.material["Name"] = "NoName"
     if "Density" in self.material:
         if "Density" not in str(Units.Unit(self.material["Density"])):
             FreeCAD.Console.PrintMessage(
                 "Density in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n"
                 .format(self.material["Name"])
             )
             self.material["Density"] = "0 kg/m^3"
     else:
         FreeCAD.Console.PrintMessage(
             "Density not found in {}\n"
             .format(self.material["Name"])
         )
         self.material["Density"] = "0 kg/m^3"
     if self.obj.Category == "Solid":
         # mechanical properties
         if "YoungsModulus" in self.material:
             # unit type of YoungsModulus is Pressure
             if "Pressure" not in str(Units.Unit(self.material["YoungsModulus"])):
                 FreeCAD.Console.PrintMessage(
                     "YoungsModulus in material data seems to have no unit "
                     "or a wrong unit (reset the value): {}\n"
                     .format(self.material["Name"])
                 )
                 self.material["YoungsModulus"] = "0 MPa"
         else:
             FreeCAD.Console.PrintMessage(
                 "YoungsModulus not found in {}\n"
                 .format(self.material["Name"])
             )
             self.material["YoungsModulus"] = "0 MPa"
         if "PoissonRatio" in self.material:
             # PoissonRatio does not have a unit, but it is checked if there is no value at all
             try:
                 # next line with float() is ok
                 # a quantity of a empty string returns very small value, would be wrong here
                 float(self.material["PoissonRatio"])
             except ValueError:
                 FreeCAD.Console.PrintMessage(
                     "PoissonRatio has wrong or no data (reset the value): {}\n"
                     .format(self.material["PoissonRatio"])
                 )
                 self.material["PoissonRatio"] = "0"
         else:
             FreeCAD.Console.PrintMessage(
                 "PoissonRatio not found in {}\n"
                 .format(self.material["Name"])
             )
             self.material["PoissonRatio"] = "0"
     if self.obj.Category == "Fluid":
         # Fluidic properties
         if "KinematicViscosity" in self.material:
             ki_vis = self.material["KinematicViscosity"]
             if "KinematicViscosity" not in str(Units.Unit(ki_vis)):
                 FreeCAD.Console.PrintMessage(
                     "KinematicViscosity in material data seems to have no unit "
                     "or a wrong unit (reset the value): {}\n"
                     .format(self.material["Name"])
                 )
                 self.material["KinematicViscosity"] = "0 m^2/s"
         else:
             FreeCAD.Console.PrintMessage(
                 "KinematicViscosity not found in {}\n"
                 .format(self.material["Name"])
             )
             self.material["KinematicViscosity"] = "0 m^2/s"
         if "VolumetricThermalExpansionCoefficient" in self.material:
             # unit type VolumetricThermalExpansionCoefficient is ThermalExpansionCoefficient
             vol_ther_ex_co = self.material["VolumetricThermalExpansionCoefficient"]
             if "VolumetricThermalExpansionCoefficient" not in str(Units.Unit(vol_ther_ex_co)):
                 FreeCAD.Console.PrintMessage(
                     "VolumetricThermalExpansionCoefficient in material data "
                     "seems to have no unit or a wrong unit (reset the value): {}\n"
                     .format(self.material["Name"])
                 )
                 self.material["VolumetricThermalExpansionCoefficient"] = "0 m^3/m^3/K"
         else:
             FreeCAD.Console.PrintMessage(
                 "VolumetricThermalExpansionCoefficient not found in {}\n"
                 .format(self.material["Name"])
             )
             self.material["VolumetricThermalExpansionCoefficient"] = "0 m^3/m^3/K"
     # Thermal properties
     if "ThermalConductivity" in self.material:
         # TODO implement for all task panel values
         # https://forum.freecadweb.org/viewtopic.php?f=18&t=56912&p=516826#p516800
         try:
             Units.Quantity(self.material["ThermalConductivity"])
         except Exception:
             FreeCAD.Console.PrintError(
                 "Problem with the quantity for ThermalConductivity: '{}' Reset value.\n"
                 "May try the following in Python console:\n"
                 "from FreeCAD import Units\n"
                 "Units.Quantity('{}')\n"
                 .format(
                     self.material["ThermalConductivity"],
                     self.material["ThermalConductivity"]
                 )
             )
             self.material["ThermalConductivity"] = "0 W/m/K"
         if "ThermalConductivity" not in str(Units.Unit(self.material["ThermalConductivity"])):
             FreeCAD.Console.PrintMessage(
                 "ThermalConductivity in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n"
                 .format(self.material["Name"])
             )
             self.material["ThermalConductivity"] = "0 W/m/K"
     else:
         FreeCAD.Console.PrintMessage(
             "ThermalConductivity not found in {}\n"
             .format(self.material["Name"])
         )
         self.material["ThermalConductivity"] = "0 W/m/K"
     if "ThermalExpansionCoefficient" in self.material:
         the_ex_co = self.material["ThermalExpansionCoefficient"]
         if "ThermalExpansionCoefficient" not in str(Units.Unit(the_ex_co)):
             FreeCAD.Console.PrintMessage(
                 "ThermalExpansionCoefficient in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n"
                 .format(self.material["Name"])
             )
             self.material["ThermalExpansionCoefficient"] = "0 um/m/K"
     else:
         FreeCAD.Console.PrintMessage(
             "ThermalExpansionCoefficient not found in {}\n"
             .format(self.material["Name"])
         )
         self.material["ThermalExpansionCoefficient"] = "0 um/m/K"
     if "SpecificHeat" in self.material:
         if "SpecificHeat" not in str(Units.Unit(self.material["SpecificHeat"])):
             FreeCAD.Console.PrintMessage(
                 "SpecificHeat in material data seems to have no unit "
                 "or a wrong unit (reset the value): {}\n"
                 .format(self.material["Name"])
             )
             self.material["SpecificHeat"] = "0 J/kg/K"
     else:
         FreeCAD.Console.PrintMessage(
             "SpecificHeat not found in {}\n"
             .format(self.material["Name"])
         )
         self.material["SpecificHeat"] = "0 J/kg/K"
     FreeCAD.Console.PrintMessage("\n")
Пример #8
0
# https://wiki.freecadweb.org/Scripting_examples
# https://wiki.freecadweb.org/Quantity

from FreeCAD import Units

# creating a unit with certain signature
Units.Unit(0,1)      # Mass     (kg)
Units.Unit(1)        # Length   (mm)
Units.Unit(-1,1,-2)  # Pressure (kg/mm*s^2)

# using predefined constants
Units.Unit(Units.Length)
Units.Unit(Units.Mass)
Units.Unit(Units.Pressure)

# parsing unit out of a string
Units.Unit('kg/(m*s^2)')    # Pressure
Units.Unit('Pa')            # the same as combined unit Pascale
Units.Unit('J')             # Joule (work,energy) mm^2*kg/(s^2)

# you can use units from all supported systems of units
Units.Unit('psi')           # imperial pressure
Units.Unit('lb')            # imperial  mass
Units.Unit('ft^2')          # imperial area

# comparing units
Units.Unit(0,1) == Unit(Units.Mass)

# getting type of unit
Units.Unit('kg/(m*s^2)').Type == 'Pressure'