no, just the code
it is exactly the same way I have done all my contributions to FreeCAD.
Moderator: bernd
no, just the code
it is exactly the same way I have done all my contributions to FreeCAD.
Code: Select all
import Fem
from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes, create_elements
fm = Fem.FemMesh()
control = create_nodes(fm)
print(control)
control = create_elements(fm)
print(control)
# informations
fm
fm.GroupCount
fm.addGroup("MyNodeGroup", "Node")
# should return or print the group ID, similar if a node is added to a mesh
# there should be the possibility to set a group ID
fm.GroupCount
fm.Groups
fm.getGroupElementType(0)
fm.getGroupElements(0)
fm.addGroupElements(0, [1,2,3,4,49,64,88,100,102,188,189,190,191])
fm.getGroupElements(0)
import ObjectsFem
doc = App.ActiveDocument
femmesh_obj = doc.addObject("Fem::FemMeshObject", "mymesh")
femmesh_obj.FemMesh = fm
doc.recompute()
doc.mymesh.ViewObject.HighlightedNodes = []
doc.mymesh.ViewObject.DisplayMode = "Faces & Wireframe"
doc.mymesh.ViewObject.HighlightedNodes = list(fm.getGroupElements(0))
Hey @bernd!bernd wrote: ↑Fri Sep 20, 2019 4:17 am py3 fix ... https://github.com/berndhahnebach/FreeC ... /femgroups
python only example ...Code: Select all
import Fem from femexamples.meshes.mesh_canticcx_tetra10 import create_nodes, create_elements fm = Fem.FemMesh() control = create_nodes(fm) print(control) control = create_elements(fm) print(control) # informations fm fm.GroupCount fm.addGroup("MyNodeGroup", "Node") # should return or print the group ID, similar if a node is added to a mesh # there should be the possibility to set a group ID fm.GroupCount fm.Groups fm.getGroupElementType(0) fm.getGroupElements(0) fm.addGroupElements(0, [1,2,3,4,49,64,88,100,102,188,189,190,191]) fm.getGroupElements(0) import ObjectsFem doc = App.ActiveDocument femmesh_obj = doc.addObject("Fem::FemMeshObject", "mymesh") femmesh_obj.FemMesh = fm doc.recompute() doc.mymesh.ViewObject.HighlightedNodes = [] doc.mymesh.ViewObject.DisplayMode = "Faces & Wireframe" doc.mymesh.ViewObject.HighlightedNodes = list(fm.getGroupElements(0))
Code: Select all
void addGroupElements(int id, size_t *elementids)
{
// Smesh C++ code goes here
}
Code: Select all
PyObject* FemMeshPy::addGroupElements(PyObject *args)
{
// parsing the Python object goes here
FemMesh::addGroupElements(id, elementids);
}
actually it was not late but early instead. post time is not local time but greenwich time AFAIK For me it was a quater past 5.
exactly. With this one could use the methods from C++ too.joha2 wrote: ↑Fri Sep 20, 2019 8:10 am How do you suggest to proceed with putting these functions into FemMesh.cpp? There it makes obviously no sense to use Python data types to access the arguments. So I would do the following:
In FemMesh.cpp:In FemMeshPy.cpp:Code: Select all
void addGroupElements(int id, size_t *elementids) { // Smesh C++ code goes here }
Is this the separation, you intended?Code: Select all
PyObject* FemMeshPy::addGroupElements(PyObject *args) { // parsing the Python object goes here FemMesh::addGroupElements(id, elementids); }
great
I do not know yet. I am the step by step guy. We have a tool to select nodes from a mesh. This could get some love. Furthermore a toggle button in Mesh group obj is thinkabel. Use mesher or use internal search for groups. Than activate netgen for the group tool too.
that was not a unit test. Just some code to have a test at all, to play with the new methods. It could be extended to a unit test the way you proposed it.
Hey bernd,
Ah OK. I already thought like this, but I wanted to be sure. I've provided the splitting of C++ and Python, that makes the code more usable - as you mentioned -, just a few minutes ago. Please have a look at it. Now the addGroup function returns the group ids. The customized group ID functionality is implemented, but it is ignored by Salome (although you are able to provide an ID to AddGroup).
Code: Select all
>>> fm.addGroup("mynodes", "Node")
0
>>> fm.addGroup("mynodes2", "Node", 4)
1
Code: Select all
>>> fm.removeGroup(0)
False
>>> fm.removeGroup(1)
False
>>> fm.addGroup("mynodegroup", "Node")
0
>>> fm.addGroupElements(0, [200, 201, 202])
>>> fm.GroupCount
1L
>>> fm.Groups
(0,)
>>> fm.addGroup("myallgroup", "All")
1
>>> fm.removeGroup(0)
True
>>> fm.removeGroup(1)
True
>>> fm.GroupCount
0L
>>> fm.Groups
()
May be it would be even better to add a new class called FemMeshGroup here https://github.com/FreeCAD/FreeCAD/blob ... sh.py#L221 There we would add some methods. There is not a reading test ATM. This would needed first, because to proof the writing we would need to read the groups. All tests threre are Pythontests, means it should be somehow test_mesh_groups_reading and test_mesh_groups_writing or even more methods. For every python group method we have one unit test method. with this we can later exactly find which was wrong. Means just one assert per method.joha2 wrote: ↑Sun Oct 06, 2019 9:35 am @bernd I know I asked that already, but I cannot find where we discussed this, whether on github or here in the forum: How to implement a useful unit test for the functions?
I already found Mod/Fem/femtest/App/test_mesh.py
There I would implement a new method into the TestMeshCommon class, namely test_mesh_groups_python().
Is there anything else to do?