Beispiel #1
0
    def test_add_group_elements(self):
        """
        Add a node group, add elements to it. Verify that elements added
        and elements in getGroupElements are the same.
        """
        from femexamples.meshes.mesh_canticcx_tetra10 import create_elements
        from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes

        fm = Fem.FemMesh()
        control = create_nodes(fm)
        if not control:
            fcc_print("failed to create nodes")
        control = create_elements(fm)
        if not control:
            fcc_print("failed to create elements")

        # information
        # fcc_print(fm)

        elements_to_be_added = [
            1, 2, 3, 4, 49, 64, 88, 100, 102, 188, 189, 190, 191
        ]
        myid = fm.addGroup("mynodegroup", "Node")

        # fcc_print(fm.getGroupElements(myid))

        fm.addGroupElements(myid, elements_to_be_added)
        elements_returned = list(fm.getGroupElements(myid))  # returns tuple
        # fcc_print(elements_returned)
        self.assertEqual(
            elements_to_be_added,
            elements_returned,
            msg=("elements to be added {0} and elements returned {1} differ".
                 format(elements_to_be_added, elements_returned)))
Beispiel #2
0
    def test_delete_groups(self):
        """
        Adds a number of groups to FemMesh and deletes them
        afterwards. Checks whether GroupCount is OK
        """
        from femexamples.meshes.mesh_canticcx_tetra10 import create_elements
        from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes

        fm = Fem.FemMesh()
        control = create_nodes(fm)
        if not control:
            fcc_print("failed to create nodes")
        control = create_elements(fm)
        if not control:
            fcc_print("failed to create elements")

        # information
        # fcc_print(fm)
        old_group_count = fm.GroupCount
        myids = []
        for i in range(1000):
            myids.append(fm.addGroup("group" + str(i), "Node"))
        for grpid in myids:
            fm.removeGroup(grpid)
        new_group_count = fm.GroupCount
        self.assertEqual(
            old_group_count,
            new_group_count,
            msg=
            ("GroupCount before and after adding and deleting groups differ: {0} != {1}"
             .format(old_group_count, new_group_count)))
Beispiel #3
0
    def test_add_groups(self):
        """
        Create different groups with different names. Check whether the
        ids are correct, the names are correct, and whether the GroupCount is
        correct.
        """

        from femexamples.meshes.mesh_canticcx_tetra10 import create_elements
        from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes

        fm = Fem.FemMesh()
        control = create_nodes(fm)
        if not control:
            fcc_print("failed to create nodes")
        control = create_elements(fm)
        if not control:
            fcc_print("failed to create elements")

        # information
        # fcc_print(fm)

        expected_dict = {}
        expected_dict["ids"] = []
        expected_dict["names"] = [
            "MyNodeGroup", "MyEdgeGroup", "MyVolumeGroup", "My0DElementGroup",
            "MyBallGroup"
        ]
        expected_dict["types"] = [
            "Node", "Edge", "Volume", "0DElement", "Ball"
        ]
        expected_dict["count"] = fm.GroupCount + 5
        result_dict = {}

        mygrpids = []
        for (name, typ) in zip(expected_dict["names"], expected_dict["types"]):
            mygrpids.append(fm.addGroup(name, typ))

        expected_dict["ids"] = sorted(tuple(mygrpids))

        # fcc_print("expected dict")
        # fcc_print(expected_dict)

        result_dict["count"] = fm.GroupCount
        result_dict["ids"] = sorted(fm.Groups)
        result_dict["types"] = list(
            [fm.getGroupElementType(g) for g in fm.Groups])
        result_dict["names"] = list([fm.getGroupName(g) for g in fm.Groups])

        # fcc_print("result dict")
        # fcc_print(result_dict)

        self.assertEqual(expected_dict,
                         result_dict,
                         msg="expected: {0}\n\nresult: {1}\n\n differ".format(
                             expected_dict, result_dict))
def setup_cantileverbase(doc=None, solver="ccxtools"):
    # setup CalculiX cantilever base model

    if doc is None:
        doc = init_doc()

    # part
    box_obj = doc.addObject("Part::Box", "Box")
    box_obj.Height = box_obj.Width = 1000
    box_obj.Length = 8000

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

    # solver
    # TODO How to pass multiple solver for one analysis in one doc
    if solver == "calculix":
        solver_object = analysis.addObject(
            ObjectsFem.makeSolverCalculix(doc, "SolverCalculiX")
        )[0]
        solver_object.AnalysisType = "static"
        solver_object.GeometricalNonlinearity = "linear"
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = "default"
        solver_object.IterationsControlParameterTimeUse = False
    elif solver == "ccxtools":
        solver_object = analysis.addObject(
            ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiXccxTools")
        )[0]
        solver_object.AnalysisType = "static"
        solver_object.GeometricalNonlinearity = "linear"
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = "default"
        solver_object.IterationsControlParameterTimeUse = False
        solver_object.WorkingDir = u""
    elif solver == "elmer":
        analysis.addObject(ObjectsFem.makeSolverElmer(doc, "SolverElmer"))
    elif solver == "z88":
        analysis.addObject(ObjectsFem.makeSolverZ88(doc, "SolverZ88"))

    # material
    material_object = analysis.addObject(
        ObjectsFem.makeMaterialSolid(doc, "FemMaterial")
    )[0]
    mat = material_object.Material
    mat["Name"] = "CalculiX-Steel"
    mat["YoungsModulus"] = "210000 MPa"
    mat["PoissonRatio"] = "0.30"
    mat["Density"] = "7900 kg/m^3"
    mat["ThermalExpansionCoefficient"] = "0.012 mm/m/K"
    material_object.Material = mat

    # fixed_constraint
    fixed_constraint = analysis.addObject(
        ObjectsFem.makeConstraintFixed(doc, name="ConstraintFixed")
    )[0]
    fixed_constraint.References = [(doc.Box, "Face1")]

    # mesh
    from femexamples.meshes.mesh_canticcx_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
Beispiel #5
0
def setup_cantileverbase(doc=None, solver='ccxtools'):
    # setup CalculiX cantilever base model

    if doc is None:
        doc = init_doc()

    # part
    box_obj = doc.addObject('Part::Box', 'Box')
    box_obj.Height = box_obj.Width = 1000
    box_obj.Length = 8000

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

    solver
    # TODO How to pass multiple solver for one analysis in one doc
    if solver is None:
        pass  # no solver is added
    elif solver is 'calculix':
        solver_object = analysis.addObject(
            ObjectsFem.makeSolverCalculix(doc, 'SolverCalculiX'))[0]
        solver_object.AnalysisType = 'static'
        solver_object.GeometricalNonlinearity = 'linear'
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = 'default'
        solver_object.IterationsControlParameterTimeUse = False
    elif solver is 'ccxtools':
        solver_object = analysis.addObject(
            ObjectsFem.makeSolverCalculixCcxTools(doc, 'CalculiXccxTools'))[0]
        solver_object.AnalysisType = 'static'
        solver_object.GeometricalNonlinearity = 'linear'
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = 'default'
        solver_object.IterationsControlParameterTimeUse = False
        solver_object.WorkingDir = u''
    elif solver is 'elmer':
        analysis.addObject(ObjectsFem.makeSolverElmer(doc, 'SolverElmer'))
    elif solver is 'z88':
        analysis.addObject(ObjectsFem.makeSolverZ88(doc, 'SolverZ88'))

    # material
    material_object = analysis.addObject(
        ObjectsFem.makeMaterialSolid(doc, 'FemMaterial'))[0]
    mat = material_object.Material
    mat['Name'] = "CalculiX-Steel"
    mat['YoungsModulus'] = "210000 MPa"
    mat['PoissonRatio'] = "0.30"
    mat['Density'] = "7900 kg/m^3"
    mat['ThermalExpansionCoefficient'] = "0.012 mm/m/K"
    material_object.Material = mat

    # fixed_constraint
    fixed_constraint = analysis.addObject(
        ObjectsFem.makeConstraintFixed(doc, name="ConstraintFixed"))[0]
    fixed_constraint.References = [(doc.Box, "Face1")]

    # mesh
    from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes, create_elements
    fem_mesh = Fem.FemMesh()
    control = create_nodes(fem_mesh)
    if not control:
        print('ERROR on creating nodes')
    control = create_elements(fem_mesh)
    if not control:
        print('ERROR on creating elements')
    femmesh_obj = analysis.addObject(
        doc.addObject('Fem::FemMeshObject', mesh_name))[0]
    femmesh_obj.FemMesh = fem_mesh

    doc.recompute()
    return doc
Beispiel #6
0
def setup_cantileverbase(doc=None, solver='ccxtools'):
    # setup CalculiX cantilever base model

    if doc is None:
        doc = init_doc()

    # part
    box_obj = doc.addObject('Part::Box', 'Box')
    box_obj.Height = box_obj.Width = 1000
    box_obj.Length = 8000

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

    solver
    # TODO How to pass multiple solver for one analysis in one doc
    if solver is None:
        pass  # no solver is added
    elif solver is 'calculix':
        solver_object = analysis.addObject(ObjectsFem.makeSolverCalculix(doc, 'SolverCalculiX'))[0]
        solver_object.AnalysisType = 'static'
        solver_object.GeometricalNonlinearity = 'linear'
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = 'default'
        solver_object.IterationsControlParameterTimeUse = False
    elif solver is 'ccxtools':
        solver_object = analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc, 'CalculiXccxTools'))[0]
        solver_object.AnalysisType = 'static'
        solver_object.GeometricalNonlinearity = 'linear'
        solver_object.ThermoMechSteadyState = False
        solver_object.MatrixSolverType = 'default'
        solver_object.IterationsControlParameterTimeUse = False
        solver_object.WorkingDir = u''
    elif solver is 'elmer':
        analysis.addObject(ObjectsFem.makeSolverElmer(doc, 'SolverElmer'))
    elif solver is 'z88':
        analysis.addObject(ObjectsFem.makeSolverZ88(doc, 'SolverZ88'))

    # material
    material_object = analysis.addObject(ObjectsFem.makeMaterialSolid(doc, 'FemMaterial'))[0]
    mat = material_object.Material
    mat['Name'] = "CalculiX-Steel"
    mat['YoungsModulus'] = "210000 MPa"
    mat['PoissonRatio'] = "0.30"
    mat['Density'] = "7900 kg/m^3"
    mat['ThermalExpansionCoefficient'] = "0.012 mm/m/K"
    material_object.Material = mat

    # fixed_constraint
    fixed_constraint = analysis.addObject(ObjectsFem.makeConstraintFixed(doc, name="ConstraintFixed"))[0]
    fixed_constraint.References = [(doc.Box, "Face1")]

    # mesh
    from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes, create_elements
    fem_mesh = Fem.FemMesh()
    control = create_nodes(fem_mesh)
    if not control:
        print('ERROR on creating nodes')
    control = create_elements(fem_mesh)
    if not control:
        print('ERROR on creating elements')
    femmesh_obj = analysis.addObject(doc.addObject('Fem::FemMeshObject', mesh_name))[0]
    femmesh_obj.FemMesh = fem_mesh

    doc.recompute()
    return doc