I have created a 3D model in FreeCAD, and now I want to use Elmer to FEM. I have installed Elmer 9.0 and set up the paths to ElmerSolver and ElmerGrid in FreeCAD 0.20. I've done the material, mesh, fixed, and pressure settings via python script. Next I want to run Elmer through python script and get the result. Does anyone know the solution to this, and would it be best to show the code?
Here is my code and interface.
Code: Select all
import sys # path to your FreeCAD.so or FreeCAD.dll file
sys.path.append("C:/Users/86138/fc_env_py39/Library/bin")
import FreeCAD as App
import FreeCADGui as Gui
import ObjectsFem
# show FreeCAD interface
Gui.showMainWindow()
doc = App.openDocument('C:/senior year/Bachelor/220601_B_GUO/devel/src/pythonProject/hexagon.FCStd')
# let us create some objects
# import to create objects
# analysis
analysis_object = ObjectsFem.makeAnalysis(doc, "Analysis")
# solver (we gone use the well tested Elmer solver object)
solver_object = ObjectsFem.makeSolverElmer(doc, "SolverElmer")
ObjectsFem.makeEquationElasticity(App.ActiveDocument, App.ActiveDocument.SolverElmer)
solver_object.SteadyStateMaxIterations = 1
solver_object.SteadyStateMinIterations = 0
analysis_object.addObject(solver_object)
elasticity = App.getDocument('hexagon').getObject('Elasticity')
elasticity.CalculatePrincipal = True
elasticity.CalculateStrains = True
elasticity.CalculateStresses = True
# material
material_object = ObjectsFem.makeMaterialSolid(doc, "MaterialSolid")
mat = material_object.Material
mat['Name'] = "Steel-S235JR"
mat['YoungsModulus'] = "210000 MPa"
mat['PoissonRatio'] = "0.30"
mat['Density'] = "7800 kg/m^3"
material_object.Material = mat
analysis_object.addObject(material_object)
# fixed_constraint
fixed_constraint = ObjectsFem.makeConstraintFixed(doc, "FemConstraintFixed")
fixed_constraint.References = [(App.ActiveDocument.Pad, "Face2")]
analysis_object.addObject(fixed_constraint)
# pressure_constraint
pressure_constraint = ObjectsFem.makeConstraintPressure(doc, "FemConstraintPressure")
pressure_constraint.References = [(App.ActiveDocument.Pad, "Face1")]
pressure_constraint.Pressure = 1000.0
pressure_constraint.Reversed = True
analysis_object.addObject(pressure_constraint)
# mesh
femmesh_obj = ObjectsFem.makeMeshGmsh(doc, "HexagonRing_Mesh")
femmesh_obj.Part = doc.Pad
doc.recompute()
from femmesh.gmshtools import GmshTools as gt
gmsh_mesh = gt(femmesh_obj)
error = gmsh_mesh.create_mesh()
print(error)
doc.recompute()
analysis_object.addObject(femmesh_obj)
# recompute
doc.recompute()
# activating analysis
import FemGui
FemGui.setActiveAnalysis(doc.Analysis)
# save as
FreeCAD.ActiveDocument.saveAs('C:/senior year/Bachelor/220601_B_GUO/devel/src/pythonProject/FEM')
# Hide FreeCAD interface
FreeCADGui.getMainWindow().hide()