Test, FEM: Refactor existing tests as preparation for full analysis test

Signed-off-by: Przemo Firszt <przemo@firszt.eu>
This commit is contained in:
Przemo Firszt 2015-07-27 22:44:34 +01:00 committed by Yorik van Havre
parent 8d4510fd29
commit 1de29d0ffa

View File

@ -39,6 +39,7 @@ class FemTest(unittest.TestCase):
finally: finally:
FreeCAD.setActiveDocument("FemTest") FreeCAD.setActiveDocument("FemTest")
self.active_doc = FreeCAD.ActiveDocument self.active_doc = FreeCAD.ActiveDocument
self.create_box()
def test_new_analysis(self): def test_new_analysis(self):
FreeCAD.Console.PrintMessage('\nChecking FEM new analysis...\n') FreeCAD.Console.PrintMessage('\nChecking FEM new analysis...\n')
@ -64,31 +65,40 @@ class FemTest(unittest.TestCase):
mesh.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) mesh.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
self.failUnless(mesh, "FemTest of new mesh failed") self.failUnless(mesh, "FemTest of new mesh failed")
def create_box(self):
self.box = self.active_doc.addObject("Part::Box", "Box")
def create_fixed_constraint(self):
self.fixed_constraint = self.active_doc.addObject("Fem::ConstraintFixed", "FemConstraintFixed")
self.fixed_constraint.References = [(self.box, "Face1")]
def test_new_fixed_constraint(self): def test_new_fixed_constraint(self):
FreeCAD.Console.PrintMessage('\nChecking FEM new fixed constraint...\n') FreeCAD.Console.PrintMessage('\nChecking FEM new fixed constraint...\n')
box = self.active_doc.addObject("Part::Box", "Box") self.create_fixed_constraint()
fixed_constraint = self.active_doc.addObject("Fem::ConstraintFixed", "FemConstraintFixed") self.failUnless(self.fixed_constraint, "FemTest of new fixed constraint failed")
fixed_constraint.References = [(box, "Face1")]
self.failUnless(fixed_constraint, "FemTest of new fixed constraint failed") def create_force_constraint(self):
self.force_constraint = self.active_doc.addObject("Fem::ConstraintForce", "FemConstraintForce")
self.force_constraint.References = [(self.box, "Face1")]
self.force_constraint.Force = 10.000000
self.force_constraint.Direction = (self.box, ["Edge12"])
self.force_constraint.Reversed = True
def test_new_force_constraint(self): def test_new_force_constraint(self):
FreeCAD.Console.PrintMessage('\nChecking FEM new force constraint...\n') FreeCAD.Console.PrintMessage('\nChecking FEM new force constraint...\n')
box = self.active_doc.addObject("Part::Box", "Box") self.create_force_constraint()
force_constraint = self.active_doc.addObject("Fem::ConstraintForce", "FemConstraintForce") self.failUnless(self.force_constraint, "FemTest of new force constraint failed")
force_constraint.References = [(box, "Face1")]
force_constraint.Force = 10.000000 def create_pressure_constraint(self):
force_constraint.Direction = (box, ["Edge12"]) self.pressure_constraint = self.active_doc.addObject("Fem::ConstraintPressure", "FemConstraintPressure")
force_constraint.Reversed = True self.pressure_constraint.References = [(self.box, "Face1")]
self.failUnless(force_constraint, "FemTest of new force constraint failed") self.pressure_constraint.Pressure = 10.000000
self.pressure_constraint.Reversed = True
def test_new_pressure_constraint(self): def test_new_pressure_constraint(self):
FreeCAD.Console.PrintMessage('\nChecking FEM new pressure constraint...\n') FreeCAD.Console.PrintMessage('\nChecking FEM new pressure constraint...\n')
box = self.active_doc.addObject("Part::Box", "Box") self.create_pressure_constraint()
pressure_constraint = self.active_doc.addObject("Fem::ConstraintPressure", "FemConstraintPressure") self.failUnless(self.pressure_constraint, "FemTest of new pressure constraint failed")
pressure_constraint.References = [(box, "Face1")]
pressure_constraint.Pressure = 10.000000
pressure_constraint.Reversed = True
self.failUnless(pressure_constraint, "FemTest of new pressure constraint failed")
def tearDown(self): def tearDown(self):
FreeCAD.closeDocument("FemTest") FreeCAD.closeDocument("FemTest")