FEM unit test failure in Cmd mode

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

same build but copy the code --> on error

output:

Code: Select all

>>> 
>>> 
>>> # code to copy
active_doc=App.newDocument()

box = active_doc.addObject("Part::Box", "Box")
fixed_constraint = active_doc.addObject("Fem::ConstraintFixed", "FemConstraintFixed")
fixed_constraint.References = [(box, "Face1")]
active_doc.recompute()... 

import Fem
ref = fixed_constraint.References[0]
femmesh = Fem.FemMesh()

from femmesh.meshtools import get_femnodes_by_refshape as getnodes
getnodes(femmesh, ref)

>>> >>> >>> >>> >>> 2
>>> >>> >>> >>> >>> >>> >>> (<Part::PartFeature>, ('Face1',))
  ReferenceShape ... Type: Face, Object name: Box, Object label: Box, Element name: Face1
<Face object at 0x556db96a92b0>
<class 'Part.Face'>
Face
[]
>>> >>> 

User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

BTW: I must admit it is quite easy to add a new unit test module to FreeCAD FEM :D
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

next found:

- start FreeCADCmd
- run the unit test --> failure
- copy the code --> it runs
- run the unit test --> it runs
- run the unit test --> it runs
- close FreeCADCmd, restart
- run the unit test --> failure
- copy the code --> it runs
- run the unit test --> it runs
- and so on
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FEM unit test failure in Cmd mode

Post by wmayer »

What about this?

Code: Select all

import Part
box=Part.makeBox(1,1,1)
face=box.Face1
issubclass(type(face), Part.Face)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

the command to add a box

Code: Select all

box = self.active_doc.addObject("Part::Box","Box")
seams to return a PythonFeature with a NullShape inside the unit test method in CMD (only inside unit test in FreeCADCmd !) ... whereas the Part.makeBox() returns a solid box shape

see branch https://github.com/berndhahnebach/FreeC ... femunitcmd commit (ATM) https://github.com/berndhahnebach/FreeC ... it/d696a42

Code: Select all

import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass1"))
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))

Code: Select all

>>> 
>>> import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass1"))
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))
>>> 
 
<Solid object at 0x55c9fa644250> 
Solid 
True 
.
----------------------------------------------------------------------
Ran 1 test in 0.004s

OK
<unittest.runner.TextTestResult run=1 errors=0 failures=0>
>>> 
 
<Shape object at 0x55c9fa63d2d0> 
E
======================================================================
ERROR: test_face_subclass2 (femtest.testcmdproblem.TestCmdProblem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/testcmdproblem.py", line 85, in test_face_subclass2
    fcc_print(box.Shape.ShapeType)
Base.FreeCADError: cannot determine type of null shape

----------------------------------------------------------------------
Ran 1 test in 0.005s

FAILED (errors=1)
<unittest.runner.TextTestResult run=1 errors=1 failures=0>
>>> 
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FEM unit test failure in Cmd mode

Post by wmayer »

This is correct behaviour and it's also the same with the GUI version.

Code: Select all

box=App.ActiveDocument.addObject("Part::Box","Box")
box.Shape.isNull() # True
App.ActiveDocument.recompute() # 1
box.Shape.isNull() # False
Adding a Box feature just adds a new object and marks it as touched to be re-computed in the next update cycle.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

https://github.com/berndhahnebach/FreeC ... femunitcmd

ok with a recompute I am another step further, but I tested the recompute before ... it works in even more use cases, but I am still able to break it somehow. I will post later on.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

this works ...

Code: Select all

import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))

Code: Select all

>>> 
>>> 
>>> import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))

>>> import TestCmdProblem 

 
Shape: <Shape object at 0x562bd4eb9840> 
isNull: True 

 
Shape: <Solid object at 0x562bd4eb9840> 
isNull: False 
ShapeType: Solid 
Subclass: True 
(<Part::PartFeature>, ('Face1',))
  ReferenceShape ... Type: Face, Object name: Box, Object label: Box, Element name: Face1
<Face object at 0x562bd4ebf140>
<class 'Part.Face'>
Face
.
----------------------------------------------------------------------
Ran 1 test in 0.009s

OK
<unittest.runner.TextTestResult run=1 errors=0 failures=0>
>>> >>> 
>>> 


restart FreeCAD Cmd, but this does not, the second one should be ok at least it has just above been ok:

Code: Select all

import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testccxtools.TestCcxTools.test_1_static_analysis"))
# wait for output than
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))


Code: Select all


>>> 
>>> 
>>> import unittest
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testccxtools.TestCcxTools.test_1_static_analysis"))
>>> import TestCcxTools 
--------------- Start of FEM tests --------------- 
Checking FEM new analysis... 
Checking FEM new solver... 
Checking FEM new material... 
Checking FEM new fixed constraint... 
Checking FEM new force constraint... 
Checking FEM new pressure constraint... 
Checking FEM new mesh... 
MechanicalMaterial has empty References.
FemConstraintFixed has Face reference shapes.
FemConstraintForce has Face reference shapes.
FemConstraintPressure has Face reference shapes.
Setting up working directory /tmp/FEM_unittests/FEM_ccx_static 
Checking FEM inp file prerequisites for static analysis... 
MechanicalMaterial has empty References.
Checking FEM inp file write... 
Writing /tmp/FEM_unittests/FEM_ccx_static/Mesh.inp for static analysis 
writerbaseCcx --> self.file_name  -->  /tmp/FEM_unittests/FEM_ccx_static/Mesh.inp
Constraint fixed: FemConstraintFixed
  Finite element mesh nodes will be retrieved by searching the appropriate nodes in the finite element mesh.
(<Part::PartFeature>, ('Face1',))
  ReferenceShape ... Type: Face, Object name: Box, Object label: Box, Element name: Face1
<Face object at 0x563252070d60>
<class 'Part.Face'>
Face
Unexpected error when writing CalculiX input file: <class 'TypeError'>
E
======================================================================
ERROR: test_1_static_analysis (femtest.testccxtools.TestCcxTools)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/testccxtools.py", line 143, in test_1_static_analysis
    error = fea.write_inp_file()
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtools/ccxtools.py", line 650, in write_inp_file
    self.inp_file_name = inp_writer.write_calculix_input_file()
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femsolver/calculix/writer.py", line 113, in write_calculix_input_file
    self.write_calculix_one_input_file()
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femsolver/calculix/writer.py", line 143, in write_calculix_one_input_file
    self.write_node_sets_constraints_fixed(inpfile)
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femsolver/calculix/writer.py", line 501, in write_node_sets_constraints_fixed
    self.get_constraints_fixed_nodes()
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femsolver/writerbase.py", line 133, in get_constraints_fixed_nodes
    femobj
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femmesh/meshtools.py", line 48, in get_femnodes_by_femobj_with_references
    node_set = get_femnodes_by_references(femmesh, femobj['Object'].References)
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femmesh/meshtools.py", line 84, in get_femnodes_by_references
    references_femnodes += get_femnodes_by_refshape(femmesh, ref)
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femmesh/meshtools.py", line 114, in get_femnodes_by_refshape
    nodes += femmesh.getNodesByFace(r)
TypeError: argument 1 must be Part.TopoShape, not Part.Face

----------------------------------------------------------------------
Ran 1 test in 0.029s

FAILED (errors=1)
<unittest.runner.TextTestResult run=1 errors=1 failures=0>
>>> 
>>> 
>>> 
>>> 
>>> unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromName("femtest.testcmdproblem.TestCmdProblem.test_face_subclass2"))
import TestCmdProblem 

 
Shape: <Shape object at 0x563251ff24e0> 
isNull: True 

 
Shape: <Solid object at 0x563251ff24e0> 
isNull: False 
ShapeType: Solid 
Subclass: True 
(<Part::PartFeature>, ('Face1',))
  ReferenceShape ... Type: Face, Object name: Box, Object label: Box, Element name: Face1
<Face object at 0x563251ff4da0>
<class 'Part.Face'>
Face
E
======================================================================
ERROR: test_face_subclass2 (femtest.testcmdproblem.TestCmdProblem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/testcmdproblem.py", line 106, in test_face_subclass2
    getnodes(femmesh, ref)
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femmesh/meshtools.py", line 114, in get_femnodes_by_refshape
    nodes += femmesh.getNodesByFace(r)
TypeError: argument 1 must be Part.TopoShape, not Part.Face

----------------------------------------------------------------------
Ran 1 test in 0.015s

FAILED (errors=1)
<unittest.runner.TextTestResult run=1 errors=1 failures=0>
>>> 
>>> 


very strange ...
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

I still have the problem on my Debian Buster even on a clean rebuild, but I do not have it on a Virtual Machine of a clean fresh Debian Buster.

Tried once again to narrow it, but it does not happen all the time, or in all circumstances ...
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: FEM unit test failure in Cmd mode

Post by bernd »

had to reinstall my Debian Buster after four years. As espected the problem is gone.
Post Reply