Rebuild the FEM model

About the development of the FEM module/workbench.

Moderator: bernd

S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Rebuild the FEM model

Post by S-Y.Chen »

If I have a FreeCAD FEM model, which contains the following actions

1. Import the STEP file.
2. Apply materials, BC and Loading
3. Meshing
4. solve and post-processing

If I change the geometry in the STEP file of STEP 1 with an external CAD, is there any way I can rebuild the whole model and solve (step 1 to 4) without redo all the steps above ?

Thanks for the help.

Regards
S-Y. Chen
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

S-Y.Chen wrote: Fri May 29, 2020 5:59 am If I have a FreeCAD FEM model, which contains the following actions

1. Import the STEP file.
2. Apply materials, BC and Loading
3. Meshing
4. solve and post-processing

If I change the geometry in the STEP file of STEP 1 with an external CAD, is there any way I can rebuild the whole model and solve (step 1 to 4) without redo all the steps above ?

Thanks for the help.

Regards
S-Y. Chen
With python for sure lot of things could be automated. How much afford is needed depends on the changes in your geometry. Do you change the length of edges only? Means the count of nodes, edges, faces is still the same? Or do you really change the geometry? Means you add or delete edges. Would be good if you post two examples of the changed geometry.
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

bernd wrote: Fri May 29, 2020 7:05 am
S-Y.Chen wrote: Fri May 29, 2020 5:59 am If I have a FreeCAD FEM model, which contains the following actions

1. Import the STEP file.
2. Apply materials, BC and Loading
3. Meshing
4. solve and post-processing

If I change the geometry in the STEP file of STEP 1 with an external CAD, is there any way I can rebuild the whole model and solve (step 1 to 4) without redo all the steps above ?

Thanks for the help.

Regards
S-Y. Chen
With python for sure lot of things could be automated. How much afford is needed depends on the changes in your geometry. Do you change the length of edges only? Means the count of nodes, edges, faces is still the same? Or do you really change the geometry? Means you add or delete edges. Would be good if you post two examples of the changed geometry.
The topology of the CAD won't be changed. That means, yes, the count of nodes, edges, faces is still the same. And the ID of each CAD entity should remains the same.
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

S-Y.Chen wrote: Fri May 29, 2020 7:08 am
bernd wrote: Fri May 29, 2020 7:05 am
S-Y.Chen wrote: Fri May 29, 2020 5:59 am If I have a FreeCAD FEM model, which contains the following actions

1. Import the STEP file.
2. Apply materials, BC and Loading
3. Meshing
4. solve and post-processing

If I change the geometry in the STEP file of STEP 1 with an external CAD, is there any way I can rebuild the whole model and solve (step 1 to 4) without redo all the steps above ?

Thanks for the help.

Regards
S-Y. Chen
With python for sure lot of things could be automated. How much afford is needed depends on the changes in your geometry. Do you change the length of edges only? Means the count of nodes, edges, faces is still the same? Or do you really change the geometry? Means you add or delete edges. Would be good if you post two examples of the changed geometry.
The topology of the CAD won't be changed. That means, yes, the count of nodes, edges, faces is still the same. And the ID of each CAD entity should remains the same.
Two STEP files attached here.
Attachments
examp112_02.STEP
(15.63 KiB) Downloaded 34 times
examp112_01.STEP
(15.62 KiB) Downloaded 33 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

- open document, run analysis, show results
- run Python code

Code: Select all

App.ActiveDocument.FEMGeom.Shape = App.ActiveDocument.getObjectsByLabel("examp112")[0].Shape
- recompute document
- remesh (if netgen mesh is used, the mesh will be chaned on document recompute)
- run analysis, show results


change_geometry_fem.FCStd
(32.18 KiB) Downloaded 40 times
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

bernd wrote: Fri May 29, 2020 9:24 am - open document, run analysis, show results
- run Python code

Code: Select all

App.ActiveDocument.FEMGeom.Shape = App.ActiveDocument.getObjectsByLabel("examp112")[0].Shape
- recompute document
- remesh (if netgen mesh is used, the mesh will be chaned on document recompute)
- run analysis, show results



change_geometry_fem.FCStd
Sorry, I don't quite understand the process and logics.

In the first action "- open document, run analysis, show results". Does this mean that model already imported the original STEP model ? (my step 1 tp 4?)

And, when does the change of the STEP file comes into effect ? And what does this line of code do ?
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

in the file is a FEM analysis which uses one ouf your geometries. The line of code does exchange the geometry of the geometrical document object from one of your geometries to the other. The attribute which holds the geometry is called Shape. Afte the geometry was exchanged the document needs recompute. The loads and fixed are adapted. Now the mesh needs do be remeshed and the analysis could be run with the exchaned geometry. Hope this helps.

At the moment the geoemtry exchange can not be done by the Gui AFAIK, but I am not sure. For reference: https://forum.freecadweb.org/viewtopic.php?f=8&t=46975
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

Script should work perfectly for me at this point. Thank you.

I did give it a try. And I am wondering how does FreeCAD decide the name of the newly imported "geometrical document object" ? Is there a way to obtain this name (through script), assuming that we need to know it in batch mode execution ?

Thank again for the help.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

be aware there is a Name and a Label for each document object. Which one of both are you talking about?
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

Actually I just figure out there are two names (label) to be used, so I am talking about both. How do I get both name and label through script ?

And I gave it a try on my own model. I imported a STEP file examp104_01, and setup the FEM and run. And then I imported a STEP file examp104_02 again, as shown in the figure below
20200603_01.jpg
20200603_01.jpg (49.57 KiB) Viewed 1101 times
Then i issued the command
App.ActiveDocument.examp104_01.Shape = App.ActiveDocument.getObjectsByLabel("examp104_02")[0].Shape

But I got the following error message :
AttributeError: 'App.Document' object has no attribute 'examp104_01'

What did I do wrong here ?

Thanks again for the help !

Regard
S-Y. Chen
Post Reply