def setup(doc=None, solvertype="ccxtools"): if solvertype == "z88": # constraint displacement is not supported for Z88 # pass a not valid solver name for z88, thus no solver is created solvertype = "z88_not_valid" # 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()))) # setup CalculiX cantilever # apply a prescribed displacement of 250 mm in -z on the front end face doc = setup_cantilever_base_solid(doc, solvertype) analysis = doc.Analysis geom_obj = doc.Box # constraint displacement con_disp = ObjectsFem.makeConstraintDisplacement( doc, name="ConstraintDisplacmentPrescribed") con_disp.References = [(geom_obj, "Face2")] con_disp.zFix = False con_disp.zFree = False con_disp.zDisplacement = -250.0 analysis.addObject(con_disp) doc.recompute() return doc
def test_femobjects_make(self): doc = self.active_doc analysis = ObjectsFem.makeAnalysis(doc) analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject( ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintPulley(doc)) analysis.addObject(ObjectsFem.makeConstraintSelfWeight(doc)) analysis.addObject(ObjectsFem.makeConstraintTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintTransform(doc)) analysis.addObject(ObjectsFem.makeElementFluid1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry2D(doc)) analysis.addObject(ObjectsFem.makeElementRotation1D(doc)) analysis.addObject(ObjectsFem.makeMaterialFluid(doc)) mat = analysis.addObject(ObjectsFem.makeMaterialSolid(doc))[0] analysis.addObject(ObjectsFem.makeMaterialMechanicalNonlinear( doc, mat)) msh = analysis.addObject(ObjectsFem.makeMeshGmsh(doc))[0] analysis.addObject(ObjectsFem.makeMeshBoundaryLayer(doc, msh)) analysis.addObject(ObjectsFem.makeMeshGroup(doc, msh)) analysis.addObject(ObjectsFem.makeMeshRegion(doc, msh)) analysis.addObject(ObjectsFem.makeMeshNetgen(doc)) analysis.addObject(ObjectsFem.makeMeshResult(doc)) analysis.addObject(ObjectsFem.makeResultMechanical(doc)) analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc)) analysis.addObject(ObjectsFem.makeSolverCalculix(doc)) sol = analysis.addObject(ObjectsFem.makeSolverElmer(doc))[0] analysis.addObject(ObjectsFem.makeSolverZ88(doc)) analysis.addObject(ObjectsFem.makeEquationElasticity(doc, sol)) analysis.addObject(ObjectsFem.makeEquationElectrostatic(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFlow(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFluxsolver(doc, sol)) analysis.addObject(ObjectsFem.makeEquationHeat(doc, sol)) # TODO the equations show up twice on Tree (on solver and on analysis), if they are added to the analysis group doc.recompute() self.assertEqual(len(analysis.Group), testtools.get_defmake_count() - 1) # because of the analysis itself count -1
def test_femobjects_make(self): doc = self.active_doc analysis = ObjectsFem.makeAnalysis(doc) analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject(ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintPulley(doc)) analysis.addObject(ObjectsFem.makeConstraintSelfWeight(doc)) analysis.addObject(ObjectsFem.makeConstraintTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintTransform(doc)) analysis.addObject(ObjectsFem.makeElementFluid1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry2D(doc)) analysis.addObject(ObjectsFem.makeElementRotation1D(doc)) analysis.addObject(ObjectsFem.makeMaterialFluid(doc)) mat = analysis.addObject(ObjectsFem.makeMaterialSolid(doc))[0] analysis.addObject(ObjectsFem.makeMaterialMechanicalNonlinear(doc, mat)) msh = analysis.addObject(ObjectsFem.makeMeshGmsh(doc))[0] analysis.addObject(ObjectsFem.makeMeshBoundaryLayer(doc, msh)) analysis.addObject(ObjectsFem.makeMeshGroup(doc, msh)) analysis.addObject(ObjectsFem.makeMeshRegion(doc, msh)) analysis.addObject(ObjectsFem.makeMeshNetgen(doc)) analysis.addObject(ObjectsFem.makeMeshResult(doc)) analysis.addObject(ObjectsFem.makeResultMechanical(doc)) analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc)) analysis.addObject(ObjectsFem.makeSolverCalculix(doc)) sol = analysis.addObject(ObjectsFem.makeSolverElmer(doc))[0] analysis.addObject(ObjectsFem.makeSolverZ88(doc)) analysis.addObject(ObjectsFem.makeEquationElasticity(doc, sol)) analysis.addObject(ObjectsFem.makeEquationElectrostatic(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFlow(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFluxsolver(doc, sol)) analysis.addObject(ObjectsFem.makeEquationHeat(doc, sol)) # is = 43 (just copy in empty file to test, or run unit test case, it is printed) # TODO if the equations and gmsh mesh childs are added to the analysis, # they show up twice on Tree (on solver resp. gemsh mesh obj and on analysis) # https://forum.freecadweb.org/viewtopic.php?t=25283 doc.recompute() self.assertEqual(len(analysis.Group), testtools.get_defmake_count() - 1) # because of the analysis itself count -1
def test_femobjects_make(self): doc = self.active_doc analysis = ObjectsFem.makeAnalysis(doc) analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject(ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintPulley(doc)) analysis.addObject(ObjectsFem.makeConstraintSelfWeight(doc)) analysis.addObject(ObjectsFem.makeConstraintTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintTransform(doc)) analysis.addObject(ObjectsFem.makeElementFluid1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry2D(doc)) analysis.addObject(ObjectsFem.makeElementRotation1D(doc)) analysis.addObject(ObjectsFem.makeMaterialFluid(doc)) mat = analysis.addObject(ObjectsFem.makeMaterialSolid(doc))[0] analysis.addObject(ObjectsFem.makeMaterialMechanicalNonlinear(doc, mat)) msh = analysis.addObject(ObjectsFem.makeMeshGmsh(doc))[0] analysis.addObject(ObjectsFem.makeMeshBoundaryLayer(doc, msh)) analysis.addObject(ObjectsFem.makeMeshGroup(doc, msh)) analysis.addObject(ObjectsFem.makeMeshRegion(doc, msh)) analysis.addObject(ObjectsFem.makeMeshNetgen(doc)) analysis.addObject(ObjectsFem.makeMeshResult(doc)) analysis.addObject(ObjectsFem.makeResultMechanical(doc)) analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc)) analysis.addObject(ObjectsFem.makeSolverCalculix(doc)) sol = analysis.addObject(ObjectsFem.makeSolverElmer(doc))[0] analysis.addObject(ObjectsFem.makeSolverZ88(doc)) analysis.addObject(ObjectsFem.makeEquationElasticity(doc, sol)) analysis.addObject(ObjectsFem.makeEquationElectrostatic(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFlow(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFluxsolver(doc, sol)) analysis.addObject(ObjectsFem.makeEquationHeat(doc, sol)) # TODO the equations show up twice on Tree (on solver and on analysis), if they are added to the analysis group doc.recompute() self.assertEqual(len(analysis.Group), testtools.get_defmake_count() - 1) # because of the analysis itself count -1
def test_femobjects_derivedfromstd(self): # only the last True type is used doc = self.active_doc self.assertTrue(ObjectsFem.makeAnalysis(doc).isDerivedFrom('Fem::FemAnalysis')) self.assertTrue(ObjectsFem.makeConstraintBearing(doc).isDerivedFrom('Fem::ConstraintBearing')) self.assertTrue(ObjectsFem.makeConstraintBodyHeatSource(doc).isDerivedFrom('Fem::ConstraintPython')) self.assertTrue(ObjectsFem.makeConstraintContact(doc).isDerivedFrom('Fem::ConstraintContact')) self.assertTrue(ObjectsFem.makeConstraintDisplacement(doc).isDerivedFrom('Fem::ConstraintDisplacement')) self.assertTrue(ObjectsFem.makeConstraintElectrostaticPotential(doc).isDerivedFrom('Fem::ConstraintPython')) self.assertTrue(ObjectsFem.makeConstraintFixed(doc).isDerivedFrom('Fem::ConstraintFixed')) self.assertTrue(ObjectsFem.makeConstraintFlowVelocity(doc).isDerivedFrom('Fem::ConstraintPython')) self.assertTrue(ObjectsFem.makeConstraintFluidBoundary(doc).isDerivedFrom('Fem::ConstraintFluidBoundary')) self.assertTrue(ObjectsFem.makeConstraintForce(doc).isDerivedFrom('Fem::ConstraintForce')) self.assertTrue(ObjectsFem.makeConstraintGear(doc).isDerivedFrom('Fem::ConstraintGear')) self.assertTrue(ObjectsFem.makeConstraintHeatflux(doc).isDerivedFrom('Fem::ConstraintHeatflux')) self.assertTrue(ObjectsFem.makeConstraintInitialFlowVelocity(doc).isDerivedFrom('Fem::ConstraintPython')) self.assertTrue(ObjectsFem.makeConstraintInitialTemperature(doc).isDerivedFrom('Fem::ConstraintInitialTemperature')) self.assertTrue(ObjectsFem.makeConstraintPlaneRotation(doc).isDerivedFrom('Fem::ConstraintPlaneRotation')) self.assertTrue(ObjectsFem.makeConstraintPressure(doc).isDerivedFrom('Fem::ConstraintPressure')) self.assertTrue(ObjectsFem.makeConstraintPulley(doc).isDerivedFrom('Fem::ConstraintPulley')) self.assertTrue(ObjectsFem.makeConstraintSelfWeight(doc).isDerivedFrom('Fem::ConstraintPython')) self.assertTrue(ObjectsFem.makeConstraintTemperature(doc).isDerivedFrom('Fem::ConstraintTemperature')) self.assertTrue(ObjectsFem.makeConstraintTransform(doc).isDerivedFrom('Fem::ConstraintTransform')) self.assertTrue(ObjectsFem.makeElementFluid1D(doc).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeElementGeometry1D(doc).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeElementGeometry2D(doc).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeElementRotation1D(doc).isDerivedFrom('Fem::FeaturePython')) materialsolid = ObjectsFem.makeMaterialSolid(doc) self.assertTrue(ObjectsFem.makeMaterialFluid(doc).isDerivedFrom('App::MaterialObjectPython')) self.assertTrue(materialsolid.isDerivedFrom('App::MaterialObjectPython')) self.assertTrue(ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid).isDerivedFrom('Fem::FeaturePython')) mesh = ObjectsFem.makeMeshGmsh(doc) self.assertTrue(mesh.isDerivedFrom('Fem::FemMeshObjectPython')) self.assertTrue(ObjectsFem.makeMeshBoundaryLayer(doc, mesh).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeMeshGroup(doc, mesh).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeMeshRegion(doc, mesh).isDerivedFrom('Fem::FeaturePython')) self.assertTrue(ObjectsFem.makeMeshNetgen(doc).isDerivedFrom('Fem::FemMeshShapeNetgenObject')) self.assertTrue(ObjectsFem.makeMeshResult(doc).isDerivedFrom('Fem::FemMeshObjectPython')) self.assertTrue(ObjectsFem.makeResultMechanical(doc).isDerivedFrom('Fem::FemResultObjectPython')) solverelmer = ObjectsFem.makeSolverElmer(doc) self.assertTrue(ObjectsFem.makeSolverCalculixCcxTools(doc).isDerivedFrom('Fem::FemSolverObjectPython')) self.assertTrue(ObjectsFem.makeSolverCalculix(doc).isDerivedFrom('Fem::FemSolverObjectPython')) self.assertTrue(solverelmer.isDerivedFrom('Fem::FemSolverObjectPython')) self.assertTrue(ObjectsFem.makeSolverZ88(doc).isDerivedFrom('Fem::FemSolverObjectPython')) self.assertTrue(ObjectsFem.makeEquationElasticity(doc, solverelmer).isDerivedFrom('App::FeaturePython')) self.assertTrue(ObjectsFem.makeEquationElectrostatic(doc, solverelmer).isDerivedFrom('App::FeaturePython')) self.assertTrue(ObjectsFem.makeEquationFlow(doc, solverelmer).isDerivedFrom('App::FeaturePython')) self.assertTrue(ObjectsFem.makeEquationFluxsolver(doc, solverelmer).isDerivedFrom('App::FeaturePython')) self.assertTrue(ObjectsFem.makeEquationHeat(doc, solverelmer).isDerivedFrom('App::FeaturePython'))
def test_femobjects_isoftype(self): doc = self.active_doc from femtools.femutils import is_of_type self.assertTrue(is_of_type(ObjectsFem.makeAnalysis(doc), 'Fem::FemAnalysis')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintBearing(doc), 'Fem::ConstraintBearing')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintBodyHeatSource(doc), 'Fem::ConstraintBodyHeatSource')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintContact(doc), 'Fem::ConstraintContact')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintDisplacement(doc), 'Fem::ConstraintDisplacement')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintElectrostaticPotential(doc), 'Fem::ConstraintElectrostaticPotential')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintFixed(doc), 'Fem::ConstraintFixed')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintFlowVelocity(doc), 'Fem::ConstraintFlowVelocity')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintFluidBoundary(doc), 'Fem::ConstraintFluidBoundary')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintForce(doc), 'Fem::ConstraintForce')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintGear(doc), 'Fem::ConstraintGear')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintHeatflux(doc), 'Fem::ConstraintHeatflux')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'Fem::ConstraintInitialFlowVelocity')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintInitialTemperature(doc), 'Fem::ConstraintInitialTemperature')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintPlaneRotation(doc), 'Fem::ConstraintPlaneRotation')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintPressure(doc), 'Fem::ConstraintPressure')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintPulley(doc), 'Fem::ConstraintPulley')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintSelfWeight(doc), 'Fem::ConstraintSelfWeight')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintTemperature(doc), 'Fem::ConstraintTemperature')) self.assertTrue(is_of_type(ObjectsFem.makeConstraintTransform(doc), 'Fem::ConstraintTransform')) self.assertTrue(is_of_type(ObjectsFem.makeElementFluid1D(doc), 'Fem::FemElementFluid1D')) self.assertTrue(is_of_type(ObjectsFem.makeElementGeometry1D(doc), 'Fem::FemElementGeometry1D')) self.assertTrue(is_of_type(ObjectsFem.makeElementGeometry2D(doc), 'Fem::FemElementGeometry2D')) self.assertTrue(is_of_type(ObjectsFem.makeElementRotation1D(doc), 'Fem::FemElementRotation1D')) materialsolid = ObjectsFem.makeMaterialSolid(doc) self.assertTrue(is_of_type(ObjectsFem.makeMaterialFluid(doc), 'Fem::Material')) self.assertTrue(is_of_type(materialsolid, 'Fem::Material')) self.assertTrue(is_of_type(ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'Fem::MaterialMechanicalNonlinear')) mesh = ObjectsFem.makeMeshGmsh(doc) self.assertTrue(is_of_type(mesh, 'Fem::FemMeshGmsh')) self.assertTrue(is_of_type(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'Fem::FemMeshBoundaryLayer')) self.assertTrue(is_of_type(ObjectsFem.makeMeshGroup(doc, mesh), 'Fem::FemMeshGroup')) self.assertTrue(is_of_type(ObjectsFem.makeMeshRegion(doc, mesh), 'Fem::FemMeshRegion')) self.assertTrue(is_of_type(ObjectsFem.makeMeshNetgen(doc), 'Fem::FemMeshShapeNetgenObject')) self.assertTrue(is_of_type(ObjectsFem.makeMeshResult(doc), 'Fem::FemMeshResult')) self.assertTrue(is_of_type(ObjectsFem.makeResultMechanical(doc), 'Fem::FemResultMechanical')) solverelmer = ObjectsFem.makeSolverElmer(doc) self.assertTrue(is_of_type(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverCalculixCcxTools')) self.assertTrue(is_of_type(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObjectCalculix')) self.assertTrue(is_of_type(solverelmer, 'Fem::FemSolverObjectElmer')) self.assertTrue(is_of_type(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObjectZ88')) self.assertTrue(is_of_type(ObjectsFem.makeEquationElasticity(doc, solverelmer), 'Fem::FemEquationElmerElasticity')) self.assertTrue(is_of_type(ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'Fem::FemEquationElmerElectrostatic')) self.assertTrue(is_of_type(ObjectsFem.makeEquationFlow(doc, solverelmer), 'Fem::FemEquationElmerFlow')) self.assertTrue(is_of_type(ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'Fem::FemEquationElmerFluxsolver')) self.assertTrue(is_of_type(ObjectsFem.makeEquationHeat(doc, solverelmer), 'Fem::FemEquationElmerHeat'))
def setup_cantileverprescribeddisplacement(doc=None, solver='ccxtools'): # setup CalculiX cantilever, apply a prescribed displacement of 250 mm in -z on the front end face doc = setup_cantileverbase(doc, solver) # displacement_constraint displacement_constraint = doc.Analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc, name="ConstraintDisplacmentPrescribed"))[0] displacement_constraint.References = [(doc.Box, "Face2")] displacement_constraint.zFix = False displacement_constraint.zFree = False displacement_constraint.zDisplacement = -250.0 doc.recompute() return doc
def setup_cantileverprescribeddisplacement(doc=None, solver='ccxtools'): # setup CalculiX cantilever, apply a prescribed displacement of 250 mm in -z on the front end face doc = setup_cantileverbase(doc, solver) # displacement_constraint displacement_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintDisplacement( doc, name="ConstraintDisplacmentPrescribed"))[0] displacement_constraint.References = [(doc.Box, "Face2")] displacement_constraint.zFix = False displacement_constraint.zFree = False displacement_constraint.zDisplacement = -250.0 doc.recompute() return doc
def setup(doc=None, solvertype="ccxtools"): # setup CalculiX cantilever # apply a prescribed displacement of 250 mm in -z on the front end face if solvertype == "z88": # constraint displacement is not supported for Z88 # pass a not valid solver name for z88, thus no solver is created solvertype = "z88_not_valid" doc = setup_cantileverbase(doc, solvertype) # displacement_constraint displacement_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintDisplacement(doc, name="ConstraintDisplacmentPrescribed") )[0] displacement_constraint.References = [(doc.Box, "Face2")] displacement_constraint.zFix = False displacement_constraint.zFree = False displacement_constraint.zDisplacement = -250.0 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 geom_obj = doc.addObject("Part::Plane", "Plate") geom_obj.Width = 6000 geom_obj.Length = 8000 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 = "buckling" solver_obj.BucklingFactors = 10 solver_obj.GeometricalNonlinearity = "linear" solver_obj.ThermoMechSteadyState = False solver_obj.MatrixSolverType = "default" solver_obj.IterationsControlParameterTimeUse = False solver_obj.BucklingFactors = 1 analysis.addObject(solver_obj) # shell thickness thickness_obj = ObjectsFem.makeElementGeometry2D(doc, 50, 'Thickness') analysis.addObject(thickness_obj) # material material_obj = ObjectsFem.makeMaterialSolid(doc, "Steel") mat = material_obj.Material mat["Name"] = "CalculiX-Steel" mat["YoungsModulus"] = "210000 MPa" mat["PoissonRatio"] = "0.30" material_obj.Material = mat analysis.addObject(material_obj) # constraints displacement con_disp_x = ObjectsFem.makeConstraintDisplacement( doc, "ConstraintDisplacement_X") con_disp_x.References = [(geom_obj, "Edge1")] con_disp_x.xFix = True con_disp_x.xFree = False analysis.addObject(con_disp_x) con_disp_y = ObjectsFem.makeConstraintDisplacement( doc, "ConstraintDisplacement_Y") con_disp_y.References = [(geom_obj, "Vertex1")] con_disp_y.yFix = True con_disp_y.yFree = False analysis.addObject(con_disp_y) con_disp_z = ObjectsFem.makeConstraintDisplacement( doc, "ConstraintDisplacement_Z") con_disp_z.References = [ (geom_obj, "Edge1"), (geom_obj, "Edge2"), (geom_obj, "Edge3"), (geom_obj, "Edge4"), ] con_disp_z.zFix = True con_disp_z.zFree = False analysis.addObject(con_disp_z) # constraint force con_force = ObjectsFem.makeConstraintForce(doc, "ConstraintForce") con_force.References = [(geom_obj, "Edge3")] con_force.Force = 17162160 # 17'162.16 N con_force.Reversed = True con_force.Direction = (geom_obj, ["Edge2"]) analysis.addObject(con_force) # mesh from .meshes.mesh_buckling_plate_tria6 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 femmesh_obj.CharacteristicLengthMax = "300.0 mm" femmesh_obj.ElementDimension = "2D" doc.recompute() return doc
def test_femobjects_make(self): doc = self.active_doc analysis = ObjectsFem.makeAnalysis(doc) analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject( ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintPulley(doc)) analysis.addObject(ObjectsFem.makeConstraintSelfWeight(doc)) analysis.addObject(ObjectsFem.makeConstraintTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintTransform(doc)) analysis.addObject(ObjectsFem.makeElementFluid1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry2D(doc)) analysis.addObject(ObjectsFem.makeElementRotation1D(doc)) analysis.addObject(ObjectsFem.makeMaterialFluid(doc)) mat = analysis.addObject(ObjectsFem.makeMaterialSolid(doc))[0] analysis.addObject(ObjectsFem.makeMaterialMechanicalNonlinear( doc, mat)) analysis.addObject(ObjectsFem.makeMaterialReinforced(doc)) msh = analysis.addObject(ObjectsFem.makeMeshGmsh(doc))[0] analysis.addObject(ObjectsFem.makeMeshBoundaryLayer(doc, msh)) analysis.addObject(ObjectsFem.makeMeshGroup(doc, msh)) analysis.addObject(ObjectsFem.makeMeshRegion(doc, msh)) analysis.addObject(ObjectsFem.makeMeshNetgen(doc)) analysis.addObject(ObjectsFem.makeMeshResult(doc)) res = analysis.addObject(ObjectsFem.makeResultMechanical(doc))[0] if "BUILD_FEM_VTK" in FreeCAD.__cmake__: vres = analysis.addObject(ObjectsFem.makePostVtkResult(doc, res))[0] analysis.addObject( ObjectsFem.makePostVtkFilterClipRegion(doc, vres)) analysis.addObject( ObjectsFem.makePostVtkFilterClipScalar(doc, vres)) analysis.addObject( ObjectsFem.makePostVtkFilterCutFunction(doc, vres)) analysis.addObject(ObjectsFem.makePostVtkFilterWarp(doc, vres)) analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc)) analysis.addObject(ObjectsFem.makeSolverCalculix(doc)) sol = analysis.addObject(ObjectsFem.makeSolverElmer(doc))[0] analysis.addObject(ObjectsFem.makeSolverZ88(doc)) analysis.addObject(ObjectsFem.makeEquationElasticity(doc, sol)) analysis.addObject(ObjectsFem.makeEquationElectrostatic(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFlow(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFluxsolver(doc, sol)) analysis.addObject(ObjectsFem.makeEquationHeat(doc, sol)) # is = 48 (just copy in empty file to test, or run unit test case, it is printed) # TODO if the equations and gmsh mesh childs are added to the analysis, # they show up twice on Tree (on solver resp. gemsh mesh obj and on analysis) # https://forum.freecadweb.org/viewtopic.php?t=25283 doc.recompute() # if FEM VTK post processing is disabled, we are not able to create VTK post objects if "BUILD_FEM_VTK" in FreeCAD.__cmake__: fem_vtk_post = True else: fem_vtk_post = False # because of the analysis itself count -1 self.assertEqual(len(analysis.Group), testtools.get_defmake_count(fem_vtk_post) - 1)
def test_femobjects_derivedfromfem(self): # try to add all possible True types from inheritance chain see # https://forum.freecadweb.org/viewtopic.php?f=10&t=32625 doc = self.active_doc from femtools.femutils import is_derived_from materialsolid = ObjectsFem.makeMaterialSolid(doc) mesh = ObjectsFem.makeMeshGmsh(doc) solverelmer = ObjectsFem.makeSolverElmer(doc) # FemAnalysis self.assertTrue( is_derived_from(ObjectsFem.makeAnalysis(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeAnalysis(doc), 'Fem::FemAnalysis')) # ConstraintBearing self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'Fem::ConstraintBearing')) # ConstraintBodyHeatSource self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'Fem::ConstraintPython')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'Fem::ConstraintBodyHeatSource')) # ConstraintContact self.assertTrue( is_derived_from(ObjectsFem.makeConstraintContact(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintContact(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintContact(doc), 'Fem::ConstraintContact')) # ConstraintDisplacement self.assertTrue( is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'Fem::ConstraintDisplacement')) # ConstraintElectrostaticPotential self.assertTrue( is_derived_from( ObjectsFem.makeConstraintElectrostaticPotential(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from( ObjectsFem.makeConstraintElectrostaticPotential(doc), 'Fem::ConstraintPython')) self.assertTrue( is_derived_from( ObjectsFem.makeConstraintElectrostaticPotential(doc), 'Fem::ConstraintElectrostaticPotential')) # ConstraintFixed self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'Fem::ConstraintFixed')) # ConstraintFlowVelocity self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'Fem::ConstraintPython')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'Fem::ConstraintFlowVelocity')) # ConstraintFluidBoundary self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'Fem::ConstraintFluidBoundary')) # ConstraintForce self.assertTrue( is_derived_from(ObjectsFem.makeConstraintForce(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintForce(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintForce(doc), 'Fem::ConstraintForce')) # ConstraintGear self.assertTrue( is_derived_from(ObjectsFem.makeConstraintGear(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintGear(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintGear(doc), 'Fem::ConstraintGear')) # ConstraintHeatflux self.assertTrue( is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'Fem::ConstraintHeatflux')) # ConstraintInitialFlowVelocity self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'Fem::ConstraintPython')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'Fem::ConstraintInitialFlowVelocity')) # ConstraintInitialTemperature self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'Fem::ConstraintInitialTemperature')) # ConstraintPlaneRotation self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'Fem::ConstraintPlaneRotation')) # ConstraintPressure self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'Fem::ConstraintPressure')) # ConstraintPulley self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'Fem::ConstraintPulley')) # ConstraintSelfWeight self.assertTrue( is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'Fem::ConstraintPython')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'Fem::ConstraintSelfWeight')) # ConstraintTemperature self.assertTrue( is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'Fem::Constraint')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'Fem::ConstraintTemperature')) # ConstraintTransform self.assertTrue( is_derived_from(ObjectsFem.makeConstraintTransform(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeConstraintTransform(doc), 'Fem::ConstraintTransform')) # FemElementFluid1D self.assertTrue( is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'Fem::FemElementFluid1D')) # FemElementGeometry1D self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'Fem::FemElementGeometry1D')) # FemElementGeometry2D self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'Fem::FemElementGeometry2D')) # FemElementRotation1D self.assertTrue( is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'Fem::FemElementRotation1D')) # Material self.assertTrue( is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'App::MaterialObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'Fem::Material')) # Material self.assertTrue(is_derived_from(materialsolid, 'App::DocumentObject')) self.assertTrue( is_derived_from(materialsolid, 'App::MaterialObjectPython')) self.assertTrue(is_derived_from(materialsolid, 'Fem::Material')) # MaterialMechanicalNonlinear self.assertTrue( is_derived_from( ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'App::DocumentObject')) self.assertTrue( is_derived_from( ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'Fem::FeaturePython')) self.assertTrue( is_derived_from( ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'Fem::MaterialMechanicalNonlinear')) # MaterialReinforced self.assertTrue( is_derived_from(ObjectsFem.makeMaterialReinforced(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMaterialReinforced(doc), 'App::MaterialObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeMaterialReinforced(doc), 'Fem::MaterialReinforced')) # FemMeshGmsh self.assertTrue(is_derived_from(mesh, 'App::DocumentObject')) self.assertTrue(is_derived_from(mesh, 'Fem::FemMeshObjectPython')) self.assertTrue(is_derived_from(mesh, 'Fem::FemMeshGmsh')) # FemMeshBoundaryLayer self.assertTrue( is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'Fem::FemMeshBoundaryLayer')) # FemMeshGroup self.assertTrue( is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'Fem::FemMeshGroup')) # FemMeshRegion self.assertTrue( is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'Fem::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'Fem::FemMeshRegion')) # FemMeshShapeNetgenObject self.assertTrue( is_derived_from(ObjectsFem.makeMeshNetgen(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshNetgen(doc), 'Fem::FemMeshShapeNetgenObject')) # FemMeshResult self.assertTrue( is_derived_from(ObjectsFem.makeMeshResult(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshResult(doc), 'Fem::FemMeshObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeMeshResult(doc), 'Fem::FemMeshResult')) # FemResultMechanical self.assertTrue( is_derived_from(ObjectsFem.makeResultMechanical(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeResultMechanical(doc), 'Fem::FemResultObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeResultMechanical(doc), 'Fem::FemResultMechanical')) # FemSolverCalculixCcxTools self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverCalculixCcxTools')) # FemSolverObjectCalculix self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObjectCalculix')) # FemSolverObjectElmer self.assertTrue(is_derived_from(solverelmer, 'App::DocumentObject')) self.assertTrue(is_derived_from(solverelmer, 'Fem::FemSolverObject')) self.assertTrue( is_derived_from(solverelmer, 'Fem::FemSolverObjectPython')) self.assertTrue( is_derived_from(solverelmer, 'Fem::FemSolverObjectElmer')) # FemSolverObjectZ88 self.assertTrue( is_derived_from(ObjectsFem.makeSolverZ88(doc), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObject')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObjectPython')) self.assertTrue( is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObjectZ88')) # FemEquationElmerElasticity self.assertTrue( is_derived_from( ObjectsFem.makeEquationElasticity(doc, solverelmer), 'App::DocumentObject')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationElasticity(doc, solverelmer), 'App::FeaturePython')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationElasticity(doc, solverelmer), 'Fem::FemEquationElmerElasticity')) # FemEquationElmerElectrostatic self.assertTrue( is_derived_from( ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'App::DocumentObject')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'App::FeaturePython')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'Fem::FemEquationElmerElectrostatic')) # FemEquationElmerFlow self.assertTrue( is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'App::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'Fem::FemEquationElmerFlow')) # FemEquationElmerFluxsolver self.assertTrue( is_derived_from( ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'App::DocumentObject')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'App::FeaturePython')) self.assertTrue( is_derived_from( ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'Fem::FemEquationElmerFluxsolver')) # FemEquationElmerHeat self.assertTrue( is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'App::DocumentObject')) self.assertTrue( is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'App::FeaturePython')) self.assertTrue( is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'Fem::FemEquationElmerHeat'))
def test_femobjects_make(self): doc = self.active_doc analysis = ObjectsFem.makeAnalysis(doc) analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject( ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc)) analysis.addObject(ObjectsFem.makeConstraintPressure(doc)) analysis.addObject(ObjectsFem.makeConstraintPulley(doc)) analysis.addObject(ObjectsFem.makeConstraintSelfWeight(doc)) analysis.addObject(ObjectsFem.makeConstraintTemperature(doc)) analysis.addObject(ObjectsFem.makeConstraintTransform(doc)) analysis.addObject(ObjectsFem.makeElementFluid1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry1D(doc)) analysis.addObject(ObjectsFem.makeElementGeometry2D(doc)) analysis.addObject(ObjectsFem.makeElementRotation1D(doc)) analysis.addObject(ObjectsFem.makeMaterialFluid(doc)) mat = analysis.addObject(ObjectsFem.makeMaterialSolid(doc))[0] analysis.addObject(ObjectsFem.makeMaterialMechanicalNonlinear( doc, mat)) analysis.addObject(ObjectsFem.makeMaterialReinforced(doc)) msh = analysis.addObject(ObjectsFem.makeMeshGmsh(doc))[0] analysis.addObject(ObjectsFem.makeMeshBoundaryLayer(doc, msh)) analysis.addObject(ObjectsFem.makeMeshGroup(doc, msh)) analysis.addObject(ObjectsFem.makeMeshRegion(doc, msh)) analysis.addObject(ObjectsFem.makeMeshNetgen(doc)) analysis.addObject(ObjectsFem.makeMeshResult(doc)) res = analysis.addObject(ObjectsFem.makeResultMechanical(doc))[0] if "BUILD_FEM_VTK" in FreeCAD.__cmake__: vres = analysis.addObject(ObjectsFem.makePostVtkResult(doc, res))[0] analysis.addObject( ObjectsFem.makePostVtkFilterClipRegion(doc, vres)) analysis.addObject( ObjectsFem.makePostVtkFilterClipScalar(doc, vres)) analysis.addObject( ObjectsFem.makePostVtkFilterCutFunction(doc, vres)) analysis.addObject(ObjectsFem.makePostVtkFilterWarp(doc, vres)) analysis.addObject(ObjectsFem.makeSolverCalculixCcxTools(doc)) analysis.addObject(ObjectsFem.makeSolverCalculix(doc)) sol = analysis.addObject(ObjectsFem.makeSolverElmer(doc))[0] analysis.addObject(ObjectsFem.makeSolverZ88(doc)) analysis.addObject(ObjectsFem.makeEquationElasticity(doc, sol)) analysis.addObject(ObjectsFem.makeEquationElectrostatic(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFlow(doc, sol)) analysis.addObject(ObjectsFem.makeEquationFluxsolver(doc, sol)) analysis.addObject(ObjectsFem.makeEquationHeat(doc, sol)) doc.recompute() # if FEM VTK post processing is disabled, we are not able to create VTK post objects if "BUILD_FEM_VTK" in FreeCAD.__cmake__: fem_vtk_post = True else: fem_vtk_post = False count_defmake = testtools.get_defmake_count(fem_vtk_post) # because of the analysis itself count -1 self.assertEqual(len(analysis.Group), count_defmake - 1) self.assertEqual(len(doc.Objects), count_defmake) fcc_print("doc objects count: {}, method: {}".format( len(doc.Objects), sys._getframe().f_code.co_name))
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 # name is important because the other method in this module use obj name cube = doc.addObject("Part::Box", "Cube") cube.Height = "20 mm" cube.Length = "100 mm" cylinder = doc.addObject("Part::Cylinder", "Cylinder") cylinder.Height = "20 mm" cylinder.Radius = "6 mm" cylinder.Placement = FreeCAD.Placement( Vector(10, 12, 10), Rotation(0, 0, 90), Vector(0, 0, 0), ) cut = doc.addObject("Part::Cut", "Cut") cut.Base = cube cut.Tool = cylinder # mirroring mirror = doc.addObject("Part::Mirroring", "Mirror") mirror.Source = cut mirror.Normal = (1, 0, 0) mirror.Base = (100, 100, 20) # fusing fusion = doc.addObject("Part::Fuse", "Fusion") fusion.Base = cut fusion.Tool = mirror fusion.Refine = True # compound filter geom_obj = CompoundFilter.makeCompoundFilter(name='CompoundFilter') geom_obj.Base = fusion geom_obj.FilterType = 'window-volume' doc.recompute() if FreeCAD.GuiUp: geom_obj.Base.ViewObject.hide() 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 analysis.addObject(solver_obj) # material material_obj = ObjectsFem.makeMaterialSolid(doc, "FemMaterial") mat = material_obj.Material mat["Name"] = "CalculiX-Steel" mat["YoungsModulus"] = "210000 MPa" mat["PoissonRatio"] = "0.30" material_obj.Material = mat analysis.addObject(material_obj) # constraint pressure con_pressure = ObjectsFem.makeConstraintPressure( doc, name="FemConstraintPressure") con_pressure.References = [(geom_obj, "Face8")] con_pressure.Pressure = 10.0 con_pressure.Reversed = False analysis.addObject(con_pressure) # constraint displacement con_disp = ObjectsFem.makeConstraintDisplacement( doc, name="FemConstraintDisplacment") con_disp.References = [(geom_obj, "Face4"), (geom_obj, "Face5")] con_disp.xFree = False con_disp.xFix = True analysis.addObject(con_disp) # constraints transform con_transform1 = ObjectsFem.makeConstraintTransform( doc, name="FemConstraintTransform1") con_transform1.References = [(geom_obj, "Face4")] con_transform1.TransformType = "Cylindrical" con_transform1.X_rot = 0.0 con_transform1.Y_rot = 0.0 con_transform1.Z_rot = 0.0 analysis.addObject(con_transform1) con_transform2 = ObjectsFem.makeConstraintTransform( doc, name="FemConstraintTransform2") con_transform2.References = [(geom_obj, "Face5")] con_transform2.TransformType = "Cylindrical" con_transform2.X_rot = 0.0 con_transform2.Y_rot = 0.0 con_transform2.Z_rot = 0.0 analysis.addObject(con_transform2) # mesh from .meshes.mesh_transform_beam_hinged_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 femmesh_obj.CharacteristicLengthMax = '7 mm' 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 geom_obj = doc.addObject("Part::Box", "Box") geom_obj.Length = 3000 geom_obj.Width = 100 geom_obj.Height = 50 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 = "frequency" solver_obj.GeometricalNonlinearity = "linear" solver_obj.ThermoMechSteadyState = False solver_obj.MatrixSolverType = "default" solver_obj.IterationsControlParameterTimeUse = False solver_obj.EigenmodesCount = 10 solver_obj.EigenmodeHighLimit = 1000000.0 solver_obj.EigenmodeLowLimit = 0.01 analysis.addObject(solver_obj) # material material_obj = analysis.addObject( ObjectsFem.makeMaterialSolid(doc, "MechanicalMaterial"))[0] mat = material_obj.Material mat["Name"] = "Steel-Generic" mat["YoungsModulus"] = "200000 MPa" mat["PoissonRatio"] = "0.30" mat["Density"] = "7900 kg/m^3" material_obj.Material = mat analysis.addObject(material_obj) # constraint displacement xyz con_disp_xyz = ObjectsFem.makeConstraintDisplacement(doc, "Fix_XYZ") con_disp_xyz.References = [(doc.Box, "Edge4")] con_disp_xyz.xFix = True con_disp_xyz.xFree = False con_disp_xyz.xDisplacement = 0.0 con_disp_xyz.yFix = True con_disp_xyz.yFree = False con_disp_xyz.yDisplacement = 0.0 con_disp_xyz.zFix = True con_disp_xyz.zFree = False con_disp_xyz.zDisplacement = 0.0 analysis.addObject(con_disp_xyz) # constraint displacement yz con_disp_yz = ObjectsFem.makeConstraintDisplacement(doc, "Fix_YZ") con_disp_yz.References = [(doc.Box, "Edge8")] con_disp_yz.xFix = False con_disp_yz.xFree = True con_disp_yz.xDisplacement = 0.0 con_disp_yz.yFix = True con_disp_yz.yFree = False con_disp_yz.yDisplacement = 0.0 con_disp_yz.zFix = True con_disp_yz.zFree = False con_disp_yz.zDisplacement = 0.0 analysis.addObject(con_disp_yz) # mesh from .meshes.mesh_beamsimple_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 femmesh_obj.CharacteristicLengthMax = "25.0 mm" doc.recompute() return doc
def test_femobjects_type(self): doc = self.active_doc from femtools.femutils import type_of_obj self.assertEqual("Fem::FemAnalysis", type_of_obj(ObjectsFem.makeAnalysis(doc))) self.assertEqual("Fem::ConstraintBearing", type_of_obj(ObjectsFem.makeConstraintBearing(doc))) self.assertEqual( "Fem::ConstraintBodyHeatSource", type_of_obj(ObjectsFem.makeConstraintBodyHeatSource(doc))) self.assertEqual("Fem::ConstraintContact", type_of_obj(ObjectsFem.makeConstraintContact(doc))) self.assertEqual( "Fem::ConstraintDisplacement", type_of_obj(ObjectsFem.makeConstraintDisplacement(doc))) self.assertEqual( "Fem::ConstraintElectrostaticPotential", type_of_obj(ObjectsFem.makeConstraintElectrostaticPotential(doc))) self.assertEqual("Fem::ConstraintFixed", type_of_obj(ObjectsFem.makeConstraintFixed(doc))) self.assertEqual( "Fem::ConstraintFlowVelocity", type_of_obj(ObjectsFem.makeConstraintFlowVelocity(doc))) self.assertEqual( "Fem::ConstraintFluidBoundary", type_of_obj(ObjectsFem.makeConstraintFluidBoundary(doc))) self.assertEqual("Fem::ConstraintForce", type_of_obj(ObjectsFem.makeConstraintForce(doc))) self.assertEqual("Fem::ConstraintGear", type_of_obj(ObjectsFem.makeConstraintGear(doc))) self.assertEqual("Fem::ConstraintHeatflux", type_of_obj(ObjectsFem.makeConstraintHeatflux(doc))) self.assertEqual( "Fem::ConstraintInitialFlowVelocity", type_of_obj(ObjectsFem.makeConstraintInitialFlowVelocity(doc))) self.assertEqual( "Fem::ConstraintInitialTemperature", type_of_obj(ObjectsFem.makeConstraintInitialTemperature(doc))) self.assertEqual( "Fem::ConstraintPlaneRotation", type_of_obj(ObjectsFem.makeConstraintPlaneRotation(doc))) self.assertEqual("Fem::ConstraintPressure", type_of_obj(ObjectsFem.makeConstraintPressure(doc))) self.assertEqual("Fem::ConstraintPulley", type_of_obj(ObjectsFem.makeConstraintPulley(doc))) self.assertEqual("Fem::ConstraintSelfWeight", type_of_obj(ObjectsFem.makeConstraintSelfWeight(doc))) self.assertEqual( "Fem::ConstraintTemperature", type_of_obj(ObjectsFem.makeConstraintTemperature(doc))) self.assertEqual("Fem::ConstraintTransform", type_of_obj(ObjectsFem.makeConstraintTransform(doc))) self.assertEqual("Fem::FemElementFluid1D", type_of_obj(ObjectsFem.makeElementFluid1D(doc))) self.assertEqual("Fem::FemElementGeometry1D", type_of_obj(ObjectsFem.makeElementGeometry1D(doc))) self.assertEqual("Fem::FemElementGeometry2D", type_of_obj(ObjectsFem.makeElementGeometry2D(doc))) self.assertEqual("Fem::FemElementRotation1D", type_of_obj(ObjectsFem.makeElementRotation1D(doc))) materialsolid = ObjectsFem.makeMaterialSolid(doc) self.assertEqual("Fem::Material", type_of_obj(ObjectsFem.makeMaterialFluid(doc))) self.assertEqual("Fem::Material", type_of_obj(materialsolid)) self.assertEqual( "Fem::MaterialMechanicalNonlinear", type_of_obj( ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid))) self.assertEqual("Fem::MaterialReinforced", type_of_obj(ObjectsFem.makeMaterialReinforced(doc))) mesh = ObjectsFem.makeMeshGmsh(doc) self.assertEqual("Fem::FemMeshGmsh", type_of_obj(mesh)) self.assertEqual( "Fem::FemMeshBoundaryLayer", type_of_obj(ObjectsFem.makeMeshBoundaryLayer(doc, mesh))) self.assertEqual("Fem::FemMeshGroup", type_of_obj(ObjectsFem.makeMeshGroup(doc, mesh))) self.assertEqual("Fem::FemMeshRegion", type_of_obj(ObjectsFem.makeMeshRegion(doc, mesh))) self.assertEqual("Fem::FemMeshShapeNetgenObject", type_of_obj(ObjectsFem.makeMeshNetgen(doc))) self.assertEqual("Fem::FemMeshResult", type_of_obj(ObjectsFem.makeMeshResult(doc))) self.assertEqual("Fem::FemResultMechanical", type_of_obj(ObjectsFem.makeResultMechanical(doc))) solverelmer = ObjectsFem.makeSolverElmer(doc) self.assertEqual( "Fem::FemSolverCalculixCcxTools", type_of_obj(ObjectsFem.makeSolverCalculixCcxTools(doc))) self.assertEqual("Fem::FemSolverObjectCalculix", type_of_obj(ObjectsFem.makeSolverCalculix(doc))) self.assertEqual("Fem::FemSolverObjectElmer", type_of_obj(solverelmer)) self.assertEqual("Fem::FemSolverObjectZ88", type_of_obj(ObjectsFem.makeSolverZ88(doc))) self.assertEqual( "Fem::FemEquationElmerElasticity", type_of_obj(ObjectsFem.makeEquationElasticity(doc, solverelmer))) self.assertEqual( "Fem::FemEquationElmerElectrostatic", type_of_obj(ObjectsFem.makeEquationElectrostatic(doc, solverelmer))) self.assertEqual( "Fem::FemEquationElmerFlow", type_of_obj(ObjectsFem.makeEquationFlow(doc, solverelmer))) self.assertEqual( "Fem::FemEquationElmerFluxsolver", type_of_obj(ObjectsFem.makeEquationFluxsolver(doc, solverelmer))) self.assertEqual( "Fem::FemEquationElmerHeat", type_of_obj(ObjectsFem.makeEquationHeat(doc, solverelmer)))
def test_femobjects_derivedfromstd(self): # only the last True type is used doc = self.active_doc self.assertTrue( ObjectsFem.makeAnalysis(doc).isDerivedFrom("Fem::FemAnalysis")) self.assertTrue( ObjectsFem.makeConstraintBearing(doc).isDerivedFrom( "Fem::ConstraintBearing")) self.assertTrue( ObjectsFem.makeConstraintBodyHeatSource(doc).isDerivedFrom( "Fem::ConstraintPython")) self.assertTrue( ObjectsFem.makeConstraintContact(doc).isDerivedFrom( "Fem::ConstraintContact")) self.assertTrue( ObjectsFem.makeConstraintDisplacement(doc).isDerivedFrom( "Fem::ConstraintDisplacement")) self.assertTrue( ObjectsFem.makeConstraintElectrostaticPotential(doc).isDerivedFrom( "Fem::ConstraintPython")) self.assertTrue( ObjectsFem.makeConstraintFixed(doc).isDerivedFrom( "Fem::ConstraintFixed")) self.assertTrue( ObjectsFem.makeConstraintFlowVelocity(doc).isDerivedFrom( "Fem::ConstraintPython")) self.assertTrue( ObjectsFem.makeConstraintFluidBoundary(doc).isDerivedFrom( "Fem::ConstraintFluidBoundary")) self.assertTrue( ObjectsFem.makeConstraintForce(doc).isDerivedFrom( "Fem::ConstraintForce")) self.assertTrue( ObjectsFem.makeConstraintGear(doc).isDerivedFrom( "Fem::ConstraintGear")) self.assertTrue( ObjectsFem.makeConstraintHeatflux(doc).isDerivedFrom( "Fem::ConstraintHeatflux")) self.assertTrue( ObjectsFem.makeConstraintInitialFlowVelocity(doc).isDerivedFrom( "Fem::ConstraintPython")) self.assertTrue( ObjectsFem.makeConstraintInitialTemperature(doc).isDerivedFrom( "Fem::ConstraintInitialTemperature")) self.assertTrue( ObjectsFem.makeConstraintPlaneRotation(doc).isDerivedFrom( "Fem::ConstraintPlaneRotation")) self.assertTrue( ObjectsFem.makeConstraintPressure(doc).isDerivedFrom( "Fem::ConstraintPressure")) self.assertTrue( ObjectsFem.makeConstraintPulley(doc).isDerivedFrom( "Fem::ConstraintPulley")) self.assertTrue( ObjectsFem.makeConstraintSelfWeight(doc).isDerivedFrom( "Fem::ConstraintPython")) self.assertTrue( ObjectsFem.makeConstraintTemperature(doc).isDerivedFrom( "Fem::ConstraintTemperature")) self.assertTrue( ObjectsFem.makeConstraintTransform(doc).isDerivedFrom( "Fem::ConstraintTransform")) self.assertTrue( ObjectsFem.makeElementFluid1D(doc).isDerivedFrom( "Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeElementGeometry1D(doc).isDerivedFrom( "Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeElementGeometry2D(doc).isDerivedFrom( "Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeElementRotation1D(doc).isDerivedFrom( "Fem::FeaturePython")) materialsolid = ObjectsFem.makeMaterialSolid(doc) self.assertTrue( ObjectsFem.makeMaterialFluid(doc).isDerivedFrom( "App::MaterialObjectPython")) self.assertTrue( materialsolid.isDerivedFrom("App::MaterialObjectPython")) self.assertTrue( ObjectsFem.makeMaterialMechanicalNonlinear( doc, materialsolid).isDerivedFrom("Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeMaterialReinforced(doc).isDerivedFrom( "App::MaterialObjectPython")) mesh = ObjectsFem.makeMeshGmsh(doc) self.assertTrue(mesh.isDerivedFrom("Fem::FemMeshObjectPython")) self.assertTrue( ObjectsFem.makeMeshBoundaryLayer( doc, mesh).isDerivedFrom("Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeMeshGroup(doc, mesh).isDerivedFrom("Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeMeshRegion( doc, mesh).isDerivedFrom("Fem::FeaturePython")) self.assertTrue( ObjectsFem.makeMeshNetgen(doc).isDerivedFrom( "Fem::FemMeshShapeNetgenObject")) self.assertTrue( ObjectsFem.makeMeshResult(doc).isDerivedFrom( "Fem::FemMeshObjectPython")) self.assertTrue( ObjectsFem.makeResultMechanical(doc).isDerivedFrom( "Fem::FemResultObjectPython")) solverelmer = ObjectsFem.makeSolverElmer(doc) self.assertTrue( ObjectsFem.makeSolverCalculixCcxTools(doc).isDerivedFrom( "Fem::FemSolverObjectPython")) self.assertTrue( ObjectsFem.makeSolverCalculix(doc).isDerivedFrom( "Fem::FemSolverObjectPython")) self.assertTrue( solverelmer.isDerivedFrom("Fem::FemSolverObjectPython")) self.assertTrue( ObjectsFem.makeSolverZ88(doc).isDerivedFrom( "Fem::FemSolverObjectPython")) self.assertTrue( ObjectsFem.makeEquationElasticity( doc, solverelmer).isDerivedFrom("App::FeaturePython")) self.assertTrue( ObjectsFem.makeEquationElectrostatic( doc, solverelmer).isDerivedFrom("App::FeaturePython")) self.assertTrue( ObjectsFem.makeEquationFlow( doc, solverelmer).isDerivedFrom("App::FeaturePython")) self.assertTrue( ObjectsFem.makeEquationFluxsolver( doc, solverelmer).isDerivedFrom("App::FeaturePython")) self.assertTrue( ObjectsFem.makeEquationHeat( doc, solverelmer).isDerivedFrom("App::FeaturePython")) fcc_print("doc objects count: {}, method: {}".format( len(doc.Objects), sys._getframe().f_code.co_name)) # TODO: vtk post objs, thus 5 obj less than test_femobjects_make self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
def test_femobjects_derivedfromfem(self): # try to add all possible True types from inheritance chain see # https://forum.freecadweb.org/viewtopic.php?f=10&t=32625 doc = self.active_doc from femtools.femutils import is_derived_from # FemAnalysis analysis = ObjectsFem.makeAnalysis(doc) self.assertTrue(is_derived_from(analysis, "App::DocumentObject")) self.assertTrue(is_derived_from(analysis, "Fem::FemAnalysis")) # ConstraintBearing constraint_bearing = ObjectsFem.makeConstraintBearing(doc) self.assertTrue( is_derived_from(constraint_bearing, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_bearing, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_bearing, "Fem::ConstraintBearing")) # ConstraintBodyHeatSource constraint_body_heat_source = ObjectsFem.makeConstraintBodyHeatSource( doc) self.assertTrue( is_derived_from(constraint_body_heat_source, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_body_heat_source, "Fem::ConstraintPython")) self.assertTrue( is_derived_from(constraint_body_heat_source, "Fem::ConstraintBodyHeatSource")) # ConstraintContact constraint_contact = ObjectsFem.makeConstraintContact(doc) self.assertTrue( is_derived_from(constraint_contact, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_contact, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_contact, "Fem::ConstraintContact")) # ConstraintDisplacement constraint_dicplacement = ObjectsFem.makeConstraintDisplacement(doc) self.assertTrue( is_derived_from(constraint_dicplacement, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_dicplacement, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_dicplacement, "Fem::ConstraintDisplacement")) # ConstraintElectrostaticPotential constraint_electorstatic_potential = ObjectsFem.makeConstraintElectrostaticPotential( doc) self.assertTrue( is_derived_from(constraint_electorstatic_potential, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_electorstatic_potential, "Fem::ConstraintPython")) self.assertTrue( is_derived_from(constraint_electorstatic_potential, "Fem::ConstraintElectrostaticPotential")) # ConstraintFixed constraint_fixed = ObjectsFem.makeConstraintFixed(doc) self.assertTrue( is_derived_from(constraint_fixed, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_fixed, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_fixed, "Fem::ConstraintFixed")) # ConstraintFlowVelocity constraint_flow_velocity = ObjectsFem.makeConstraintFlowVelocity(doc) self.assertTrue( is_derived_from(constraint_flow_velocity, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_flow_velocity, "Fem::ConstraintPython")) self.assertTrue( is_derived_from(constraint_flow_velocity, "Fem::ConstraintFlowVelocity")) # ConstraintFluidBoundary constraint_fluid_boundary = ObjectsFem.makeConstraintFluidBoundary(doc) self.assertTrue( is_derived_from(constraint_fluid_boundary, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_fluid_boundary, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_fluid_boundary, "Fem::ConstraintFluidBoundary")) # ConstraintForce constraint_force = ObjectsFem.makeConstraintForce(doc) self.assertTrue( is_derived_from(constraint_force, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_force, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_force, "Fem::ConstraintForce")) # ConstraintGear constraint_gear = ObjectsFem.makeConstraintGear(doc) self.assertTrue(is_derived_from(constraint_gear, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_gear, "Fem::Constraint")) self.assertTrue(is_derived_from(constraint_gear, "Fem::ConstraintGear")) # ConstraintHeatflux constraint_heat_flux = ObjectsFem.makeConstraintHeatflux(doc) self.assertTrue( is_derived_from(constraint_heat_flux, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_heat_flux, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_heat_flux, "Fem::ConstraintHeatflux")) # ConstraintInitialFlowVelocity constraint_initial_flow_velocity = ObjectsFem.makeConstraintInitialFlowVelocity( doc) self.assertTrue( is_derived_from(constraint_initial_flow_velocity, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_initial_flow_velocity, "Fem::ConstraintPython")) self.assertTrue( is_derived_from(constraint_initial_flow_velocity, "Fem::ConstraintInitialFlowVelocity")) # ConstraintInitialTemperature constraint_initial_temperature = ObjectsFem.makeConstraintInitialTemperature( doc) self.assertTrue( is_derived_from(constraint_initial_temperature, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_initial_temperature, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_initial_temperature, "Fem::ConstraintInitialTemperature")) # ConstraintPlaneRotation constraint_plane_rotation = ObjectsFem.makeConstraintPlaneRotation(doc) self.assertTrue( is_derived_from(constraint_plane_rotation, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_plane_rotation, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_plane_rotation, "Fem::ConstraintPlaneRotation")) # ConstraintPressure constraint_pressure = ObjectsFem.makeConstraintPressure(doc) self.assertTrue( is_derived_from(constraint_pressure, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_pressure, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_pressure, "Fem::ConstraintPressure")) # ConstraintPulley constraint_pulley = ObjectsFem.makeConstraintPulley(doc) self.assertTrue( is_derived_from(constraint_pulley, "App::DocumentObject")) self.assertTrue(is_derived_from(constraint_pulley, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_pulley, "Fem::ConstraintPulley")) # ConstraintSelfWeight constraint_self_weight = ObjectsFem.makeConstraintSelfWeight(doc) self.assertTrue( is_derived_from(constraint_self_weight, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_self_weight, "Fem::ConstraintPython")) self.assertTrue( is_derived_from(constraint_self_weight, "Fem::ConstraintSelfWeight")) # ConstraintTemperature constraint_temperature = ObjectsFem.makeConstraintTemperature(doc) self.assertTrue( is_derived_from(constraint_temperature, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_temperature, "Fem::Constraint")) self.assertTrue( is_derived_from(constraint_temperature, "Fem::ConstraintTemperature")) # ConstraintTransform constraint_transform = ObjectsFem.makeConstraintTransform(doc) self.assertTrue( is_derived_from(constraint_transform, "App::DocumentObject")) self.assertTrue( is_derived_from(constraint_transform, "Fem::ConstraintTransform")) # FemElementFluid1D fluid1d = ObjectsFem.makeElementFluid1D(doc) self.assertTrue(is_derived_from(fluid1d, "App::DocumentObject")) self.assertTrue(is_derived_from(fluid1d, "Fem::FeaturePython")) self.assertTrue(is_derived_from(fluid1d, "Fem::FemElementFluid1D")) # FemElementGeometry1D geometry1d = ObjectsFem.makeElementGeometry1D(doc) self.assertTrue(is_derived_from(geometry1d, "App::DocumentObject")) self.assertTrue(is_derived_from(geometry1d, "Fem::FeaturePython")) self.assertTrue( is_derived_from(geometry1d, "Fem::FemElementGeometry1D")) # FemElementGeometry2D geometry2d = ObjectsFem.makeElementGeometry2D(doc) self.assertTrue(is_derived_from(geometry2d, "App::DocumentObject")) self.assertTrue(is_derived_from(geometry2d, "Fem::FeaturePython")) self.assertTrue( is_derived_from(geometry2d, "Fem::FemElementGeometry2D")) # FemElementRotation1D rotation1d = ObjectsFem.makeElementRotation1D(doc) self.assertTrue(is_derived_from(rotation1d, "App::DocumentObject")) self.assertTrue(is_derived_from(rotation1d, "Fem::FeaturePython")) self.assertTrue( is_derived_from(rotation1d, "Fem::FemElementRotation1D")) # Material Fluid material_fluid = ObjectsFem.makeMaterialFluid(doc) self.assertTrue(is_derived_from(material_fluid, "App::DocumentObject")) self.assertTrue( is_derived_from(material_fluid, "App::MaterialObjectPython")) self.assertTrue(is_derived_from(material_fluid, "Fem::Material")) # Material Solid material_solid = ObjectsFem.makeMaterialSolid(doc) self.assertTrue(is_derived_from(material_solid, "App::DocumentObject")) self.assertTrue( is_derived_from(material_solid, "App::MaterialObjectPython")) self.assertTrue(is_derived_from(material_solid, "Fem::Material")) # MaterialMechanicalNonlinear material_nonlinear = ObjectsFem.makeMaterialMechanicalNonlinear( doc, material_solid) self.assertTrue( is_derived_from(material_nonlinear, "App::DocumentObject")) self.assertTrue( is_derived_from(material_nonlinear, "Fem::FeaturePython")) self.assertTrue( is_derived_from(material_nonlinear, "Fem::MaterialMechanicalNonlinear")) # MaterialReinforced material_reinforced = ObjectsFem.makeMaterialReinforced(doc) self.assertTrue( is_derived_from(material_reinforced, "App::DocumentObject")) self.assertTrue( is_derived_from(material_reinforced, "App::MaterialObjectPython")) self.assertTrue( is_derived_from(material_reinforced, "Fem::MaterialReinforced")) # FemMeshGmsh mesh_gmsh = ObjectsFem.makeMeshGmsh(doc) self.assertTrue(is_derived_from(mesh_gmsh, "App::DocumentObject")) self.assertTrue(is_derived_from(mesh_gmsh, "Fem::FemMeshObjectPython")) self.assertTrue(is_derived_from(mesh_gmsh, "Fem::FemMeshGmsh")) # FemMeshBoundaryLayer mesh_boundarylayer = ObjectsFem.makeMeshBoundaryLayer(doc, mesh_gmsh) self.assertTrue( is_derived_from(mesh_boundarylayer, "App::DocumentObject")) self.assertTrue( is_derived_from(mesh_boundarylayer, "Fem::FeaturePython")) self.assertTrue( is_derived_from(mesh_boundarylayer, "Fem::FemMeshBoundaryLayer")) # FemMeshGroup mesh_group = ObjectsFem.makeMeshGroup(doc, mesh_gmsh) self.assertTrue(is_derived_from(mesh_group, "App::DocumentObject")) self.assertTrue(is_derived_from(mesh_group, "Fem::FeaturePython")) self.assertTrue(is_derived_from(mesh_group, "Fem::FemMeshGroup")) # FemMeshRegion mesh_region = ObjectsFem.makeMeshRegion(doc, mesh_gmsh) self.assertTrue(is_derived_from(mesh_region, "App::DocumentObject")) self.assertTrue(is_derived_from(mesh_region, "Fem::FeaturePython")) self.assertTrue(is_derived_from(mesh_region, "Fem::FemMeshRegion")) # FemMeshShapeNetgenObject mesh_netgen = ObjectsFem.makeMeshNetgen(doc) self.assertTrue(is_derived_from(mesh_netgen, "App::DocumentObject")) self.assertTrue( is_derived_from(mesh_netgen, "Fem::FemMeshShapeNetgenObject")) # FemMeshResult mesh_result = ObjectsFem.makeMeshResult(doc) self.assertTrue(is_derived_from(mesh_result, "App::DocumentObject")) self.assertTrue( is_derived_from(mesh_result, "Fem::FemMeshObjectPython")) self.assertTrue(is_derived_from(mesh_result, "Fem::FemMeshResult")) # FemResultMechanical result_mechanical = ObjectsFem.makeResultMechanical(doc) self.assertTrue( is_derived_from(result_mechanical, "App::DocumentObject")) self.assertTrue( is_derived_from(result_mechanical, "Fem::FemResultObjectPython")) self.assertTrue( is_derived_from(result_mechanical, "Fem::FemResultMechanical")) # FemSolverCalculixCcxTools solver_ccxtools = ObjectsFem.makeSolverCalculixCcxTools(doc) self.assertTrue(is_derived_from(solver_ccxtools, "App::DocumentObject")) self.assertTrue( is_derived_from(solver_ccxtools, "Fem::FemSolverObject")) self.assertTrue( is_derived_from(solver_ccxtools, "Fem::FemSolverObjectPython")) self.assertTrue( is_derived_from(solver_ccxtools, "Fem::FemSolverCalculixCcxTools")) # FemSolverObjectCalculix solver_calculix = ObjectsFem.makeSolverCalculix(doc) self.assertTrue(is_derived_from(solver_calculix, "App::DocumentObject")) self.assertTrue( is_derived_from(solver_calculix, "Fem::FemSolverObject")) self.assertTrue( is_derived_from(solver_calculix, "Fem::FemSolverObjectPython")) self.assertTrue( is_derived_from(solver_calculix, "Fem::FemSolverObjectCalculix")) # FemSolverObjectElmer solver_elmer = ObjectsFem.makeSolverElmer(doc) self.assertTrue(is_derived_from(solver_elmer, "App::DocumentObject")) self.assertTrue(is_derived_from(solver_elmer, "Fem::FemSolverObject")) self.assertTrue( is_derived_from(solver_elmer, "Fem::FemSolverObjectPython")) self.assertTrue( is_derived_from(solver_elmer, "Fem::FemSolverObjectElmer")) # FemSolverObjectZ88 solver_z88 = ObjectsFem.makeSolverZ88(doc) self.assertTrue(is_derived_from(solver_z88, "App::DocumentObject")) self.assertTrue(is_derived_from(solver_z88, "Fem::FemSolverObject")) self.assertTrue( is_derived_from(solver_z88, "Fem::FemSolverObjectPython")) self.assertTrue(is_derived_from(solver_z88, "Fem::FemSolverObjectZ88")) # FemEquationElmerElasticity equation_elasticity = ObjectsFem.makeEquationElasticity( doc, solver_elmer) self.assertTrue( is_derived_from(equation_elasticity, "App::DocumentObject")) self.assertTrue( is_derived_from(equation_elasticity, "App::FeaturePython")) self.assertTrue( is_derived_from(equation_elasticity, "Fem::FemEquationElmerElasticity")) # FemEquationElmerElectrostatic equation_electrostatic = ObjectsFem.makeEquationElectrostatic( doc, solver_elmer) self.assertTrue( is_derived_from(equation_electrostatic, "App::DocumentObject")) self.assertTrue( is_derived_from(equation_electrostatic, "App::FeaturePython")) self.assertTrue( is_derived_from(equation_electrostatic, "Fem::FemEquationElmerElectrostatic")) # FemEquationElmerFlow equation_flow = ObjectsFem.makeEquationFlow(doc, solver_elmer) self.assertTrue(is_derived_from(equation_flow, "App::DocumentObject")) self.assertTrue(is_derived_from(equation_flow, "App::FeaturePython")) self.assertTrue( is_derived_from(equation_flow, "Fem::FemEquationElmerFlow")) # FemEquationElmerFluxsolver equation_flux = ObjectsFem.makeEquationFluxsolver(doc, solver_elmer) self.assertTrue(is_derived_from(equation_flux, "App::DocumentObject")) self.assertTrue(is_derived_from(equation_flux, "App::FeaturePython")) self.assertTrue( is_derived_from(equation_flux, "Fem::FemEquationElmerFluxsolver")) # FemEquationElmerHeat equation_heat = ObjectsFem.makeEquationHeat(doc, solver_elmer) self.assertTrue(is_derived_from(equation_heat, "App::DocumentObject")) self.assertTrue(is_derived_from(equation_heat, "App::FeaturePython")) self.assertTrue( is_derived_from(equation_heat, "Fem::FemEquationElmerHeat")) fcc_print("doc objects count: {}, method: {}".format( len(doc.Objects), sys._getframe().f_code.co_name)) # TODO: vtk post objs, thus 5 obj less than test_femobjects_make self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
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(0, -2000, 0) v2 = vec(500, -2000, 0) v3 = vec(500, 0, 0) v4 = vec(3500, 0, 0) v5 = vec(3500, -2000, 0) v6 = vec(4000, -2000, 0) v7 = vec(4000, 2000, 0) v8 = vec(0, 2000, 0) l1 = ln(v1, v2) l2 = ln(v2, v3) l3 = ln(v3, v4) l4 = ln(v4, v5) l5 = ln(v5, v6) l6 = ln(v6, v7) l7 = ln(v7, v8) l8 = ln(v8, v1) geom_obj = doc.addObject("Part::Feature", "FIB_Wall") geom_obj.Shape = Part.Face(Part.Wire([l1, l2, l3, l4, l5, l6, l7, l8])) 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 analysis.addObject(solver_obj) # shell thickness thickness_obj = ObjectsFem.makeElementGeometry2D(doc, 150.0, "ShellThickness") analysis.addObject(thickness_obj) # material matrixprop = {} matrixprop["Name"] = "Concrete-EN-C35/45" matrixprop["YoungsModulus"] = "32000 MPa" matrixprop["PoissonRatio"] = "0.17" matrixprop["CompressiveStrength"] = "15.75 MPa" # make some hint on the possible angle units in material system matrixprop["AngleOfFriction"] = "30 deg" reinfoprop = {} reinfoprop["Name"] = "Reinforcement-FIB-B500" reinfoprop["YieldStrength"] = "315 MPa" # not an official FreeCAD material property reinfoprop["ReinforcementRatio"] = "0.0" material_reinforced = ObjectsFem.makeMaterialReinforced(doc, "MaterialReinforced") material_reinforced.Material = matrixprop material_reinforced.Reinforcement = reinfoprop analysis.addObject(material_reinforced) # constraint fixed con_fixed = ObjectsFem.makeConstraintFixed(doc, "ConstraintFixed") con_fixed.References = [(geom_obj, "Edge1"), (geom_obj, "Edge5")] analysis.addObject(con_fixed) # constraint force con_force = ObjectsFem.makeConstraintForce(doc, "ConstraintForce") con_force.References = [(geom_obj, "Edge7")] con_force.Force = 1000000.0 con_force.Direction = (geom_obj, ["Edge8"]) con_force.Reversed = False analysis.addObject(con_force) # constraint displacement con_disp = ObjectsFem.makeConstraintDisplacement(doc, "ConstraintDisplacmentPrescribed") con_disp.References = [(geom_obj, "Face1")] con_disp.zFree = False con_disp.zFix = True analysis.addObject(con_disp) # mesh from .meshes.mesh_rc_wall_2d_tria6 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
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 objects bottom_flange = doc.addObject("Part::Plane", "Bottom_Flange") bottom_flange.Length = 10000 bottom_flange.Width = 150 top_flange = doc.addObject("Part::Plane", "Top_Flange") top_flange.Length = 10000 top_flange.Width = 150 top_flange.Placement.Base = (0, 0, 278.6) web = doc.addObject("Part::Plane", "Top_Flange") web.Length = 10000 web.Width = 278.6 web.Placement = FreeCAD.Placement( FreeCAD.Vector(0, 75, 0), FreeCAD.Rotation(0, 0, 90), FreeCAD.Vector(0, 0, 0), ) geom_obj = doc.addObject("Part::MultiFuse", "Fusion") geom_obj.Shapes = [bottom_flange, top_flange, web] 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 = "buckling" solver_obj.GeometricalNonlinearity = "linear" solver_obj.ThermoMechSteadyState = False solver_obj.MatrixSolverType = "default" solver_obj.IterationsControlParameterTimeUse = False solver_obj.BucklingFactors = 1 analysis.addObject(solver_obj) # shell thicknesses thickness_flanges = ObjectsFem.makeElementGeometry2D(doc, 10.7, 'Thickness_Flanges') thickness_flanges.References = [(geom_obj, ("Face1", "Face2", "Face3", "Face4"))] analysis.addObject(thickness_flanges) thickness_web = ObjectsFem.makeElementGeometry2D(doc, 7.1, 'Thickness_Web') thickness_web.References = [(geom_obj, "Face5")] analysis.addObject(thickness_web) # material material_obj = ObjectsFem.makeMaterialSolid(doc, "Steel") mat = material_obj.Material mat["Name"] = "CalculiX-Steel" mat["YoungsModulus"] = "210000 MPa" mat["PoissonRatio"] = "0.30" material_obj.Material = mat analysis.addObject(material_obj) # constraints displacement con_disp_x = ObjectsFem.makeConstraintDisplacement(doc, "ConstraintDisplacement_X") con_disp_x.References = [(geom_obj, "Vertex2")] con_disp_x.xFix = True con_disp_x.xFree = False analysis.addObject(con_disp_x) con_disp_yz = ObjectsFem.makeConstraintDisplacement(doc, "ConstraintDisplacement_YZ") con_disp_yz.References = [(geom_obj, ("Edge15", "Edge16"))] con_disp_yz.yFix = True con_disp_yz.yFree = False con_disp_yz.zFix = True con_disp_yz.zFree = False analysis.addObject(con_disp_yz) # constraints force con_force_in_x = ObjectsFem.makeConstraintForce(doc, "Force_in_X") con_force_in_x.References = [(geom_obj, ("Edge3", "Edge7", "Edge8", "Edge12"))] con_force_in_x.Force = 155350 con_force_in_x.Reversed = False con_force_in_x.Direction = (geom_obj, ["Edge4"]) analysis.addObject(con_force_in_x) con_force_rev_x = ObjectsFem.makeConstraintForce(doc, "Force_rev_X") con_force_rev_x.References = [(geom_obj, ("Edge1", "Edge5", "Edge10", "Edge14"))] con_force_rev_x.Force = 155350 con_force_rev_x.Reversed = True con_force_rev_x.Direction = (geom_obj, ["Edge4"]) analysis.addObject(con_force_rev_x) # mesh from .meshes.mesh_buckling_ibeam_tria6 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 femmesh_obj.CharacteristicLengthMax = "50.0 mm" femmesh_obj.ElementDimension = "2D" doc.recompute() return doc
def test_femobjects_derivedfromfem(self): # try to add all possible True types from inheritance chain see https://forum.freecadweb.org/viewtopic.php?f=10&t=32625 doc = self.active_doc from femtools.femutils import is_derived_from materialsolid = ObjectsFem.makeMaterialSolid(doc) mesh = ObjectsFem.makeMeshGmsh(doc) solverelmer = ObjectsFem.makeSolverElmer(doc) self.assertTrue(is_derived_from(ObjectsFem.makeAnalysis(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeAnalysis(doc), 'Fem::FemAnalysis')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBearing(doc), 'Fem::ConstraintBearing')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'Fem::ConstraintPython')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintBodyHeatSource(doc), 'Fem::ConstraintBodyHeatSource')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintContact(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintContact(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintContact(doc), 'Fem::ConstraintContact')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintDisplacement(doc), 'Fem::ConstraintDisplacement')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintElectrostaticPotential(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintElectrostaticPotential(doc), 'Fem::ConstraintPython')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintElectrostaticPotential(doc), 'Fem::ConstraintElectrostaticPotential')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFixed(doc), 'Fem::ConstraintFixed')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'Fem::ConstraintPython')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFlowVelocity(doc), 'Fem::ConstraintFlowVelocity')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintFluidBoundary(doc), 'Fem::ConstraintFluidBoundary')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintForce(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintForce(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintForce(doc), 'Fem::ConstraintForce')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintGear(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintGear(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintGear(doc), 'Fem::ConstraintGear')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintHeatflux(doc), 'Fem::ConstraintHeatflux')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'Fem::ConstraintPython')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialFlowVelocity(doc), 'Fem::ConstraintInitialFlowVelocity')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintInitialTemperature(doc), 'Fem::ConstraintInitialTemperature')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPlaneRotation(doc), 'Fem::ConstraintPlaneRotation')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPressure(doc), 'Fem::ConstraintPressure')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintPulley(doc), 'Fem::ConstraintPulley')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'Fem::ConstraintPython')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintSelfWeight(doc), 'Fem::ConstraintSelfWeight')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'Fem::Constraint')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintTemperature(doc), 'Fem::ConstraintTemperature')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintTransform(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeConstraintTransform(doc), 'Fem::ConstraintTransform')) self.assertTrue(is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeElementFluid1D(doc), 'Fem::FemElementFluid1D')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry1D(doc), 'Fem::FemElementGeometry1D')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeElementGeometry2D(doc), 'Fem::FemElementGeometry2D')) self.assertTrue(is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeElementRotation1D(doc), 'Fem::FemElementRotation1D')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'App::MaterialObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialFluid(doc), 'Fem::Material')) self.assertTrue(is_derived_from(materialsolid, 'App::DocumentObject')) self.assertTrue(is_derived_from(materialsolid, 'App::MaterialObjectPython')) self.assertTrue(is_derived_from(materialsolid, 'Fem::Material')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeMaterialMechanicalNonlinear(doc, materialsolid), 'Fem::MaterialMechanicalNonlinear')) self.assertTrue(is_derived_from(mesh, 'App::DocumentObject')) self.assertTrue(is_derived_from(mesh, 'Fem::FemMeshObjectPython')) self.assertTrue(is_derived_from(mesh, 'Fem::FemMeshGmsh')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshBoundaryLayer(doc, mesh), 'Fem::FemMeshBoundaryLayer')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshGroup(doc, mesh), 'Fem::FemMeshGroup')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'Fem::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshRegion(doc, mesh), 'Fem::FemMeshRegion')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshNetgen(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshNetgen(doc), 'Fem::FemMeshShapeNetgenObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshResult(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshResult(doc), 'Fem::FemMeshObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeMeshResult(doc), 'Fem::FemMeshResult')) self.assertTrue(is_derived_from(ObjectsFem.makeResultMechanical(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeResultMechanical(doc), 'Fem::FemResultObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeResultMechanical(doc), 'Fem::FemResultMechanical')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculixCcxTools(doc), 'Fem::FemSolverCalculixCcxTools')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverCalculix(doc), 'Fem::FemSolverObjectCalculix')) self.assertTrue(is_derived_from(solverelmer, 'App::DocumentObject')) self.assertTrue(is_derived_from(solverelmer, 'Fem::FemSolverObject')) self.assertTrue(is_derived_from(solverelmer, 'Fem::FemSolverObjectPython')) self.assertTrue(is_derived_from(solverelmer, 'Fem::FemSolverObjectElmer')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverZ88(doc), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObject')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObjectPython')) self.assertTrue(is_derived_from(ObjectsFem.makeSolverZ88(doc), 'Fem::FemSolverObjectZ88')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElasticity(doc, solverelmer), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElasticity(doc, solverelmer), 'App::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElasticity(doc, solverelmer), 'Fem::FemEquationElmerElasticity')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'App::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationElectrostatic(doc, solverelmer), 'Fem::FemEquationElmerElectrostatic')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'App::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFlow(doc, solverelmer), 'Fem::FemEquationElmerFlow')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'App::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationFluxsolver(doc, solverelmer), 'Fem::FemEquationElmerFluxsolver')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'App::DocumentObject')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'App::FeaturePython')) self.assertTrue(is_derived_from(ObjectsFem.makeEquationHeat(doc, solverelmer), 'Fem::FemEquationElmerHeat'))
def setup(doc=None, solvertype="ccxtools"): # setup reinfoced wall in 2D if doc is None: doc = init_doc() # part from FreeCAD import Vector as vec import Part from Part import makeLine as ln v1 = vec(0, -2000, 0) v2 = vec(500, -2000, 0) v3 = vec(500, 0, 0) v4 = vec(3500, 0, 0) v5 = vec(3500, -2000, 0) v6 = vec(4000, -2000, 0) v7 = vec(4000, 2000, 0) v8 = vec(0, 2000, 0) l1 = ln(v1, v2) l2 = ln(v2, v3) l3 = ln(v3, v4) l4 = ln(v4, v5) l5 = ln(v5, v6) l6 = ln(v6, v7) l7 = ln(v7, v8) l8 = ln(v8, v1) rcwall = doc.addObject("Part::Feature", "FIB_Wall") rcwall.Shape = Part.Face(Part.Wire([l1, l2, l3, l4, l5, l6, l7, l8])) 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.AnalysisType = "static" solver.GeometricalNonlinearity = "linear" solver.ThermoMechSteadyState = False solver.MatrixSolverType = "default" solver.IterationsControlParameterTimeUse = False # shell thickness thickness = analysis.addObject( ObjectsFem.makeElementGeometry2D(doc, 0, "ShellThickness"))[0] thickness.Thickness = 150.0 # material matrixprop = {} matrixprop["Name"] = "Concrete-EN-C35/45" matrixprop["YoungsModulus"] = "32000 MPa" matrixprop["PoissonRatio"] = "0.17" matrixprop["CompressiveStrength"] = "15.75 MPa" # make some hint on the possible angle units in material system matrixprop["AngleOfFriction"] = "30 deg" matrixprop["Density"] = "2500 kg/m^3" reinfoprop = {} reinfoprop["Name"] = "Reinforcement-FIB-B500" reinfoprop["YieldStrength"] = "315 MPa" # not an official FreeCAD material property reinfoprop["ReinforcementRatio"] = "0.0" material_reinforced = analysis.addObject( ObjectsFem.makeMaterialReinforced(doc, "MaterialReinforced"))[0] material_reinforced.Material = matrixprop material_reinforced.Reinforcement = reinfoprop # fixed_constraint fixed_constraint = analysis.addObject( ObjectsFem.makeConstraintFixed(doc, name="ConstraintFixed"))[0] fixed_constraint.References = [(rcwall, "Edge1"), (rcwall, "Edge5")] # force constraint force_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintForce(doc, name="ConstraintForce"))[0] force_constraint.References = [(rcwall, "Edge7")] force_constraint.Force = 1000000.0 force_constraint.Direction = (rcwall, ["Edge8"]) force_constraint.Reversed = False # displacement_constraint displacement_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintDisplacement( doc, name="ConstraintDisplacmentPrescribed"))[0] displacement_constraint.References = [(rcwall, "Face1")] displacement_constraint.zFix = True # mesh from .meshes.mesh_rc_wall_2d_tria6 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_rcwall2d(doc=None, solver='ccxtools'): # setup reinfoced wall in 2D if doc is None: doc = init_doc() # part from FreeCAD import Vector as vec import Part from Part import makeLine as ln v1 = vec(0, -2000, 0) v2 = vec(500, -2000, 0) v3 = vec(500, 0, 0) v4 = vec(3500, 0, 0) v5 = vec(3500, -2000, 0) v6 = vec(4000, -2000, 0) v7 = vec(4000, 2000, 0) v8 = vec(0, 2000, 0) l1 = ln(v1, v2) l2 = ln(v2, v3) l3 = ln(v3, v4) l4 = ln(v4, v5) l5 = ln(v5, v6) l6 = ln(v6, v7) l7 = ln(v7, v8) l8 = ln(v8, v1) rcwall = doc.addObject("Part::Feature", "FIB_Wall") rcwall.Shape = Part.Face(Part.Wire([l1, l2, l3, l4, l5, l6, l7, l8])) # 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 = analysis.addObject( ObjectsFem.makeSolverCalculix(doc, 'SolverCalculiX'))[0] solver.AnalysisType = 'static' solver.GeometricalNonlinearity = 'linear' solver.ThermoMechSteadyState = False solver.MatrixSolverType = 'default' solver.IterationsControlParameterTimeUse = False elif solver is 'ccxtools': solver = analysis.addObject( ObjectsFem.makeSolverCalculixCcxTools(doc, 'CalculiXccxTools'))[0] solver.AnalysisType = 'static' solver.GeometricalNonlinearity = 'linear' solver.ThermoMechSteadyState = False solver.MatrixSolverType = 'default' solver.IterationsControlParameterTimeUse = False solver.WorkingDir = u'' # shell thickness thickness = analysis.addObject( ObjectsFem.makeElementGeometry2D(doc, 0, 'ShellThickness'))[0] thickness.Thickness = 150.0 # material matrixprop = {} matrixprop['Name'] = "Concrete-EN-C35/45" matrixprop['YoungsModulus'] = "32000 MPa" matrixprop['PoissonRatio'] = "0.17" matrixprop['CompressiveStrength'] = "15.75 MPa" # make some hint on the possible angle units in material system matrixprop['AngleOfFriction'] = "30 deg" matrixprop['Density'] = '2500 kg/m^3' reinfoprop = {} reinfoprop['Name'] = "Reinforcement-FIB-B500" reinfoprop['YieldStrength'] = "315 MPa" # not an official FreeCAD material property reinfoprop['ReinforcementRatio'] = "0.0" material_reinforced = analysis.addObject( ObjectsFem.makeMaterialReinforced(doc, 'MaterialReinforced'))[0] material_reinforced.Material = matrixprop material_reinforced.Reinforcement = reinfoprop # fixed_constraint fixed_constraint = analysis.addObject( ObjectsFem.makeConstraintFixed(doc, name="ConstraintFixed"))[0] fixed_constraint.References = [(rcwall, "Edge1"), (rcwall, "Edge5")] # force constraint force_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintForce(doc, name="ConstraintForce"))[0] force_constraint.References = [(rcwall, "Edge7")] force_constraint.Force = 1000000.0 force_constraint.Direction = (rcwall, ["Edge8"]) force_constraint.Reversed = False # displacement_constraint displacement_constraint = doc.Analysis.addObject( ObjectsFem.makeConstraintDisplacement( doc, name="ConstraintDisplacmentPrescribed"))[0] displacement_constraint.References = [(rcwall, "Face1")] displacement_constraint.zFix = True # mesh from femexamples.meshes.mesh_rc_wall_2d_tria6 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