示例#1
0
def setup(doc=None, solvertype="ccxtools"):
    # setup model

    if doc is None:
        doc = init_doc()

    # geometry objects
    v1 = vec(-200, -100, 0)
    v2 = vec(200, -100, 0)
    v3 = vec(200, 100, 0)
    v4 = vec(-200, 100, 0)
    l1 = ln(v1, v2)
    l2 = ln(v2, v3)
    l3 = ln(v3, v4)
    l4 = ln(v4, v1)
    v5 = vec(0, 0, 0)
    c1 = ci(50, v5)
    face = Part.makeFace([Part.Wire([l1, l2, l3, l4]), c1],
                         "Part::FaceMakerBullseye")
    geom_obj = doc.addObject("Part::Feature", "Hole_Plate")
    geom_obj.Shape = face.extrude(vec(0, 0, 10))
    doc.recompute()

    if FreeCAD.GuiUp:
        geom_obj.ViewObject.Document.activeView().viewAxonometric()
        geom_obj.ViewObject.Document.activeView().fitAll()

    # analysis
    analysis = ObjectsFem.makeAnalysis(doc, "Analysis")

    # solver
    if solvertype == "calculix":
        solver = analysis.addObject(
            ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX"))[0]
    elif solvertype == "ccxtools":
        solver = analysis.addObject(
            ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools"))[0]
        solver.WorkingDir = u""
    if solvertype == "calculix" or solvertype == "ccxtools":
        solver.SplitInputWriter = False
        solver.AnalysisType = "static"
        solver.GeometricalNonlinearity = "linear"
        solver.ThermoMechSteadyState = False
        solver.MatrixSolverType = "default"
        solver.IterationsControlParameterTimeUse = False
        solver.GeometricalNonlinearity = 'nonlinear'
        solver.MaterialNonlinearity = 'nonlinear'

    # linear material
    matprop = {}
    matprop["Name"] = "CalculiX-Steel"
    matprop["YoungsModulus"] = "210000 MPa"
    matprop["PoissonRatio"] = "0.30"
    matprop["Density"] = "7900 kg/m^3"
    material = analysis.addObject(
        ObjectsFem.makeMaterialSolid(doc, "Material_lin"))[0]
    material.Material = matprop

    # nonlinear material
    nonlinear_material = analysis.addObject(
        ObjectsFem.makeMaterialMechanicalNonlinear(doc, material,
                                                   "Material_nonlin"))[0]
    nonlinear_material.YieldPoint1 = '240.0, 0.0'
    nonlinear_material.YieldPoint2 = '270.0, 0.025'
    # check solver attributes, Nonlinearity needs to be set to nonlinear

    # fixed_constraint
    fixed_constraint = analysis.addObject(
        ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed"))[0]
    fixed_constraint.References = [(geom_obj, "Face4")]

    # force constraint
    pressure_constraint = doc.Analysis.addObject(
        ObjectsFem.makeConstraintPressure(doc, "ConstraintPressure"))[0]
    pressure_constraint.References = [(geom_obj, "Face2")]
    pressure_constraint.Pressure = 130.0
    pressure_constraint.Reversed = True

    # mesh
    from .meshes.mesh_platewithhole_tetra10 import create_nodes, create_elements
    fem_mesh = Fem.FemMesh()
    control = create_nodes(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating nodes.\n")
    control = create_elements(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating elements.\n")
    femmesh_obj = analysis.addObject(ObjectsFem.makeMeshGmsh(doc,
                                                             mesh_name))[0]
    femmesh_obj.FemMesh = fem_mesh
    femmesh_obj.Part = geom_obj
    femmesh_obj.SecondOrderLinear = False

    doc.recompute()
    return doc
示例#2
0
def setup(doc=None, solvertype="ccxtools"):
    """ Nonlinear material example, plate with hole.

    https://forum.freecadweb.org/viewtopic.php?f=24&t=31997&start=30
    https://forum.freecadweb.org/viewtopic.php?t=33974&start=90
    https://forum.freecadweb.org/viewtopic.php?t=35893

    plate: 400x200x10 mm
    hole: diameter 100 mm (half cross section)
    load: 130 MPa tension
    linear material: Steel, E = 210000 MPa, my = 0.3
    nonlinear material: '240.0, 0.0' to '270.0, 0.025'
    TODO nonlinear material: give more information, use values from harry
    TODO compare results with example from HarryvL

    """

    if doc is None:
        doc = init_doc()

    # part
    import Part
    from FreeCAD import Vector as vec
    from Part import makeLine as ln
    from Part import makeCircle as ci

    v1 = vec(-200, -100, 0)
    v2 = vec(200, -100, 0)
    v3 = vec(200, 100, 0)
    v4 = vec(-200, 100, 0)
    l1 = ln(v1, v2)
    l2 = ln(v2, v3)
    l3 = ln(v3, v4)
    l4 = ln(v4, v1)
    v5 = vec(0, 0, 0)
    c1 = ci(50, v5)
    face = Part.makeFace([Part.Wire([l1, l2, l3, l4]), c1],
                         "Part::FaceMakerBullseye")
    partfem = doc.addObject("Part::Feature", "Hole_Plate")
    partfem.Shape = face.extrude(vec(0, 0, 10))
    doc.recompute()

    if FreeCAD.GuiUp:
        import FreeCADGui
        FreeCADGui.ActiveDocument.activeView().viewAxonometric()
        FreeCADGui.SendMsgToActiveView("ViewFit")

    # analysis
    analysis = ObjectsFem.makeAnalysis(doc, "Analysis")

    # solver
    if solvertype == "calculix":
        solver = analysis.addObject(
            ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX"))[0]
    elif solvertype == "ccxtools":
        solver = analysis.addObject(
            ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools"))[0]
        solver.WorkingDir = u""
    if solvertype == "calculix" or solvertype == "ccxtools":
        solver.SplitInputWriter = False
        solver.AnalysisType = "static"
        solver.GeometricalNonlinearity = "linear"
        solver.ThermoMechSteadyState = False
        solver.MatrixSolverType = "default"
        solver.IterationsControlParameterTimeUse = False
        solver.GeometricalNonlinearity = 'nonlinear'
        solver.MaterialNonlinearity = 'nonlinear'

    # linear material
    matprop = {}
    matprop["Name"] = "CalculiX-Steel"
    matprop["YoungsModulus"] = "210000 MPa"
    matprop["PoissonRatio"] = "0.30"
    matprop["Density"] = "7900 kg/m^3"
    material = analysis.addObject(
        ObjectsFem.makeMaterialSolid(doc, "Material_lin"))[0]
    material.Material = matprop

    # nonlinear material
    nonlinear_material = analysis.addObject(
        ObjectsFem.makeMaterialMechanicalNonlinear(doc, material,
                                                   "Material_nonlin"))[0]
    nonlinear_material.YieldPoint1 = '240.0, 0.0'
    nonlinear_material.YieldPoint2 = '270.0, 0.025'
    # check solver attributes, Nonlinearity needs to be set to nonlinear

    # fixed_constraint
    fixed_constraint = analysis.addObject(
        ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed"))[0]
    fixed_constraint.References = [(partfem, "Face4")]

    # force constraint
    pressure_constraint = doc.Analysis.addObject(
        ObjectsFem.makeConstraintPressure(doc, "ConstraintPressure"))[0]
    pressure_constraint.References = [(partfem, "Face2")]
    pressure_constraint.Pressure = 130.0
    pressure_constraint.Reversed = True

    # mesh
    from .meshes.mesh_platewithhole_tetra10 import create_nodes, create_elements
    fem_mesh = Fem.FemMesh()
    control = create_nodes(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating nodes.\n")
    control = create_elements(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating elements.\n")
    femmesh_obj = analysis.addObject(
        doc.addObject("Fem::FemMeshObject", mesh_name))[0]
    femmesh_obj.FemMesh = fem_mesh

    doc.recompute()
    return doc
def setup(doc=None, solvertype="ccxtools"):

    # init FreeCAD document
    if doc is None:
        doc = init_doc()

    # explanation object
    # just keep the following line and change text string in get_explanation method
    manager.add_explanation_obj(
        doc, get_explanation(manager.get_header(get_information())))

    # geometric object
    v1 = vec(-200, -100, 0)
    v2 = vec(200, -100, 0)
    v3 = vec(200, 100, 0)
    v4 = vec(-200, 100, 0)
    l1 = ln(v1, v2)
    l2 = ln(v2, v3)
    l3 = ln(v3, v4)
    l4 = ln(v4, v1)
    v5 = vec(0, 0, 0)
    c1 = ci(50, v5)
    face = Part.makeFace([Part.Wire([l1, l2, l3, l4]), c1],
                         "Part::FaceMakerBullseye")
    geom_obj = doc.addObject("Part::Feature", "Hole_Plate")
    geom_obj.Shape = face.extrude(vec(0, 0, 10))
    doc.recompute()

    if FreeCAD.GuiUp:
        geom_obj.ViewObject.Document.activeView().viewAxonometric()
        geom_obj.ViewObject.Document.activeView().fitAll()

    # analysis
    analysis = ObjectsFem.makeAnalysis(doc, "Analysis")

    # solver
    if solvertype == "calculix":
        solver_obj = ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX")
    elif solvertype == "ccxtools":
        solver_obj = ObjectsFem.makeSolverCalculixCcxTools(
            doc, "CalculiXccxTools")
        solver_obj.WorkingDir = u""
    else:
        FreeCAD.Console.PrintWarning(
            "Not known or not supported solver type: {}. "
            "No solver object was created.\n".format(solvertype))
    if solvertype == "calculix" or solvertype == "ccxtools":
        solver_obj.SplitInputWriter = False
        solver_obj.AnalysisType = "static"
        solver_obj.GeometricalNonlinearity = "linear"
        solver_obj.ThermoMechSteadyState = False
        solver_obj.MatrixSolverType = "default"
        solver_obj.IterationsControlParameterTimeUse = False
        solver_obj.GeometricalNonlinearity = 'nonlinear'
        solver_obj.MaterialNonlinearity = 'nonlinear'
    analysis.addObject(solver_obj)

    # linear material
    material_obj = ObjectsFem.makeMaterialSolid(doc, "Material_lin")
    matprop = material_obj.Material
    matprop["Name"] = "CalculiX-Steel"
    matprop["YoungsModulus"] = "210000 MPa"
    matprop["PoissonRatio"] = "0.30"
    material_obj.Material = matprop
    analysis.addObject(material_obj)

    # nonlinear material
    name_nlm = "Material_nonlin"
    nonlinear_mat = ObjectsFem.makeMaterialMechanicalNonlinear(
        doc, material_obj, name_nlm)
    nonlinear_mat.YieldPoint1 = '240.0, 0.0'
    nonlinear_mat.YieldPoint2 = '270.0, 0.025'
    analysis.addObject(nonlinear_mat)
    # check solver attributes, Nonlinearity needs to be set to nonlinear

    # constraint fixed
    con_fixed = ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed")
    con_fixed.References = [(geom_obj, "Face4")]
    analysis.addObject(con_fixed)

    # pressure constraint
    con_pressure = ObjectsFem.makeConstraintPressure(doc, "ConstraintPressure")
    con_pressure.References = [(geom_obj, "Face2")]
    con_pressure.Pressure = 130.0
    con_pressure.Reversed = True
    analysis.addObject(con_pressure)

    # mesh
    from .meshes.mesh_platewithhole_tetra10 import create_nodes, create_elements
    fem_mesh = Fem.FemMesh()
    control = create_nodes(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating nodes.\n")
    control = create_elements(fem_mesh)
    if not control:
        FreeCAD.Console.PrintError("Error on creating elements.\n")
    femmesh_obj = analysis.addObject(
        ObjectsFem.makeMeshGmsh(doc, get_meshname()))[0]
    femmesh_obj.FemMesh = fem_mesh
    femmesh_obj.Part = geom_obj
    femmesh_obj.SecondOrderLinear = False

    doc.recompute()
    return doc