DLOAD - working code, but review and C++ help needed

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

@wmayer, can you check it that's OK for you? I added you name to the commits.

FEM: getNodesByFace should return int not long
FEM: Add getVolumesByFace and write_face_load functions
FEM: getNodesByEdge should return int not long
FEM: getNodesByVertex should return int not long

I did a test with a rather big mesh (7500000 points, over 500000 tetrahedra, DLOAD lines over 3000) and it works.
The branch:
https://github.com/PrzemoF/FreeCAD_sf_m ... m_dload_v1
The getVolumesByFace/DLOAD commit:
https://github.com/PrzemoF/FreeCAD_sf_m ... f044a55856
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

That -1 [1] is probably wrong or there is something funny happening in FreeCAD with direction when no direction is selected, but "Reverse direction" option is checked

[1] https://github.com/PrzemoF/FreeCAD_sf_m ... er.py#L191

Edit: Fix pushed. If the rest is fine I'll merge that fix into the main DLOAD commit
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: DLOAD - working code, but review and C++ help needed

Post by sgrogan »

I get a strange result pulling a cube
disp.PNG
disp.PNG (69.01 KiB) Viewed 2107 times
I hope I'm testing the right code
The Fix constraint was on the bottom of the cube.

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.4952 (Git)
Build type: Release
Branch: fem_dload_v1
Hash: 7d2b0ff3a7624a3cc6d62cd0bd5af6d3ca0e0cc1
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
"fight the good fight"
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

There is something wrong with direction and that's why I added "-1" when I though it's just a matter od reversing the direction. You're pushing the cube and I have the same problem here.
Attachments
FreeCAD_dload_invalid_direction.png
FreeCAD_dload_invalid_direction.png (179.58 KiB) Viewed 2088 times
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by wmayer »

@wmayer, can you check it that's OK for you? I added you name to the commits.
This looks good now. But the actual idea of the fix is to simplify getVolumesByFace a bit further.
Instead of

Code: Select all

    std::set<int> nbf = FemMesh::getNodesByFace(face);
    std::set<int> nodes_on_face;
    nodes_on_face.insert(nbf.begin(), nbf.end());
    nbf.clear();
you can write now

Code: Select all

    std::set<int> nodes_on_face = FemMesh::getNodesByFace(face);
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

I was looking at that piece of code, but I coudn't figure out what the purpose of that conversion. So it was just for the long->int change?
I'll make the changes, but I think we should not include it in the master unless that direction problem is solved.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by wmayer »

So it was just for the long->int change?
It was for this and the fact that GetID() returns an int and not a long. So, this change was also needed to keep everything consistent. The second point is that a long occupies 8 bytes on 64-bit UNIX-like systems while an int only occupies 4 bytes.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

OK, thanks for the explanation!
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by PrzemoF »

sgrogan wrote:I get a strange result pulling a cube
FreeCAD_FEM_mesh_inside_out.png
FreeCAD_FEM_mesh_inside_out.png (190.11 KiB) Viewed 2067 times
I hope I'm testing the right code
The Fix constraint was on the bottom of the cube.
[..]
I did some more tests and the mesh seems to be turned inside-out! :shock: It looks OK for factor 1 to 4 (4 - flat like a pancake), but for 5 and more it goes inside-out. It could be related to the way we're deforming mesh with factor.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: DLOAD - working code, but review and C++ help needed

Post by wmayer »

Here is an algorithm that handles all type of volumes but as (key, value) it gives the mesh face id and not the local number of a volume face. And the question from the current implementation also is if the face numbers 'face_ccx' works for all export formats and solvers or only for Abaqus/Calaculix.

IMO, we should split the current implementation into two functions. getVolumesByFace should be the implementation below and then a second function should be implemented which finds a volume's local face number from a mesh face.

Code: Select all

std::map<int, int> FemMesh::getVolumesByFace(const TopoDS_Face &face) const
{
    std::map<int, int> result;
    std::set<int> nodes_on_face = FemMesh::getNodesByFace(face);

    SMDS_VolumeIteratorPtr vol_iter = myMesh->GetMeshDS()->volumesIterator();
    while (vol_iter->more()) {
        const SMDS_MeshVolume* vol = vol_iter->next();
        int numFaces = vol->NbFaces();
        SMDS_ElemIteratorPtr face_iter = vol->facesIterator();

        while (face_iter->more()) {
            const SMDS_MeshFace* face = static_cast<const SMDS_MeshFace*>(face_iter->next());
            int numNodes = face->NbNodes();

            std::set<int> face_nodes;
            for (int i=0; i<numNodes; i++) {
                face_nodes.insert(face->GetNode(i)->GetID());
            }

            std::vector<int> element_face_nodes;
            std::set_intersection(nodes_on_face.begin(), nodes_on_face.end(), face_nodes.begin(), face_nodes.end(),
            std::back_insert_iterator<std::vector<int> >(element_face_nodes));

            if (element_face_nodes.size() == numNodes) {
                result[vol->GetID()] = face->GetID();
                break;
            }
        }
    }
    
    return result;
}
map
Post Reply