Parameter study
Moderator: bernd
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Parameter study
Dear FEM-developers,
I want to post a thought/idea for further enhancing the usability of FEM-WB for optimization of parts; its about running parameter studies.
You can think of this as having the basic cantilever-calculix-3D-FEM-example and change the applied force or a dimension according a spreadsheet. For each of this parameters is a calculation done and the results (e.g. max. displacement) is put into a new column in the same spreadsheet.
This could help for instance finding a height of the cantilever where a specific displacement/stress is not exceeded.
I found the following related topics in the forum (see below) concerning the creation of 'part-families' using the spreadsheet but here is no simulation included and no results are read back into the spreadsheet.
What do you think Is this of interest for somebody else or already on the Todo of someone?
BR,
HoWil
Macro of hatari:
viewtopic.php?f=22&t=18437
Python script of ulrich1a:
viewtopic.php?f=10&t=18520
I want to post a thought/idea for further enhancing the usability of FEM-WB for optimization of parts; its about running parameter studies.
You can think of this as having the basic cantilever-calculix-3D-FEM-example and change the applied force or a dimension according a spreadsheet. For each of this parameters is a calculation done and the results (e.g. max. displacement) is put into a new column in the same spreadsheet.
This could help for instance finding a height of the cantilever where a specific displacement/stress is not exceeded.
I found the following related topics in the forum (see below) concerning the creation of 'part-families' using the spreadsheet but here is no simulation included and no results are read back into the spreadsheet.
What do you think Is this of interest for somebody else or already on the Todo of someone?
BR,
HoWil
Macro of hatari:
viewtopic.php?f=22&t=18437
Python script of ulrich1a:
viewtopic.php?f=10&t=18520
Re: Parameter study
Dear FEM-user,
its time to start learning python coding, further reading:
http://www.freecadweb.org/wiki/index.ph ... _to_Python
http://www.freecadweb.org/wiki/index.ph ... g_tutorial
What I would do, if you consider the mentioned scripts, is to set up a separate macro, that uses one of those scripts and run the FEM-analysis throughout the listed part variants.
This is not as difficult for a quick and dirty written macro, but may be involved, if it has to be made universal usable with a point and click interface.
What I do, when I want to do some coding in an area of FreeCAD, that I never used before, is the following:
- search for examples (forum, macros, source code, templates, wiki)
- explore the involved objects in the python console, see here: http://www.freecadweb.org/wiki/index.ph ... nterpreter
- write a short python script (I am using Geany as editor. It has a template for a python script, so it will give you a start.)
- call the script in the python console with
- explore the results of your variables in the python console and make further tests with it: applying new values to it, look which formulation gives no error message, so you can use it in your script.
This may take a little time, but should be faster, than waiting for somebody else.
I myself did not start a FEM-analysis from python so far. The question I have regarding this, does the call for the external analysis terminates, if the results are written, or do one need to write separate code to check this?
Ulrich
its time to start learning python coding, further reading:
http://www.freecadweb.org/wiki/index.ph ... _to_Python
http://www.freecadweb.org/wiki/index.ph ... g_tutorial
What I would do, if you consider the mentioned scripts, is to set up a separate macro, that uses one of those scripts and run the FEM-analysis throughout the listed part variants.
This is not as difficult for a quick and dirty written macro, but may be involved, if it has to be made universal usable with a point and click interface.
What I do, when I want to do some coding in an area of FreeCAD, that I never used before, is the following:
- search for examples (forum, macros, source code, templates, wiki)
- explore the involved objects in the python console, see here: http://www.freecadweb.org/wiki/index.ph ... nterpreter
- write a short python script (I am using Geany as editor. It has a template for a python script, so it will give you a start.)
- call the script in the python console with
Code: Select all
execfile("your_path_to your_python_script")
This may take a little time, but should be faster, than waiting for somebody else.
I myself did not start a FEM-analysis from python so far. The question I have regarding this, does the call for the external analysis terminates, if the results are written, or do one need to write separate code to check this?
Ulrich
Re: Parameter study
I know, and I already do, but the leaning curve is still flat, means I do ask for advice as I have done.ulrich1a wrote:Dear FEM-user,
its time to start learning python coding, further reading:
Many thanks for the rest.... I will go trough this and hopefully report back some example.ulrich1a wrote: What I would do, if you consider the mentioned scripts, is to set up a separate macro, that uses one of those scripts and run the FEM-analysis throughout the listed part variants.
This is not as difficult for a quick and dirty written macro, but may be involved, if it has to be made universal usable with a point and click interface.
What I do, when I want to do some coding in an area of FreeCAD, that I never used before, is the following:
- search for examples (forum, macros, source code, templates, wiki)
- explore the involved objects in the python console, see here: http://www.freecadweb.org/wiki/index.ph ... nterpreter
- write a short python script (I am using Geany as editor. It has a template for a python script, so it will give you a start.)
- call the script in the python console with- explore the results of your variables in the python console and make further tests with it: applying new values to it, look which formulation gives no error message, so you can use it in your script.Code: Select all
execfile("your_path_to your_python_script")
This may take a little time, but should be faster, than waiting for somebody else.
I myself did not start a FEM-analysis from python so far. The question I have regarding this, does the call for the external analysis terminates, if the results are written, or do one need to write separate code to check this?
Ulrich
BR,
HoWil
Re: Parameter study
start FreeCAD --> load FEM 3D example from Start WB --> activate the analysis --> run the following code:
Each CalculiX result is one point. Since it is a linear analysis and the load is just applied in steps the diagram is a boring linear line ...
Code: Select all
# create the forces to make a multiple analysis with
force = 1000000 # start force = 1.0 MN
fstep = 500000 # step force = 0.5 MN
forces = []
for f in range(20):
forces.append(force)
force+=fstep
# initialize analysis
import FemGui
FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis)
import FemToolsCcx
fea = FemToolsCcx.FemToolsCcx()
fea.update_objects()
fea.check_prerequisites()
fea.reset_all()
fea.update_objects()
# run analysis multiple times
for force in forces:
App.ActiveDocument.FemConstraintForce.Force = force
App.ActiveDocument.recompute()
print App.ActiveDocument.FemConstraintForce.Force
fea.run()
fea.load_results()
absdis = []
for o in App.ActiveDocument.Objects:
if o.isDerivedFrom('Fem::FemResultObject'):
# print o.Name, ' --> ', o.Stats[11]
absdis.append(o.Stats[11])
data = []
i = 0
for f in forces:
d = (f, absdis[i])
i += 1
data.append(d)
for d in data:
print d[0], ' --> ', d[1]
# draw a diagramm with Draft
# make a new document
App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
import Draft
for d in data:
Draft.makePoint(d[1], d[0] * 0.00001,0)
Gui.SendMsgToActiveView("ViewFit")
Re: Parameter study
This may help too: FEM_Tutorial_Python
Re: Parameter study
Looks like I have to write it because the thing I used until now does not check it:ulrich1a wrote:The question I have regarding this, does the call for the external analysis terminates, if the results are written, or do one need to write separate code to check this?
Ulrich
Code: Select all
process = QtCore.QProcess()
process.startDetached(paraview_command)
Re: Parameter study
Thank you very much!bernd wrote:start FreeCAD --> load FEM 3D example from Start WB --> activate the analysis --> run the following code:
...
Each CalculiX result is one point. Since it is a linear analysis and the load is just applied in steps the diagram is a boring linear line ...
Will look into it in detail. Looks pretty much what I want to achieve. Maybe, I will try to combine it with Spreadsheet.
Re: Parameter study
Added a matplotlib plot instead of the points in draw-wb. The results look like:
Code: Select all
##########################################################################
# Setting up the sweep parameter
##########################################################################
# create the forces to make a multiple analysis with
force = 1000000 # start force = 1.0 MN
fstep = 500000 # step force = 0.5 MN
forces = []
nr_steps = 10
for f in range(nr_steps):
forces.append(force)
force+=fstep
##########################################################################
# Initialize analysis
##########################################################################
import FemGui
FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.Analysis)
import FemToolsCcx
fea = FemToolsCcx.FemToolsCcx()
fea.update_objects()
fea.check_prerequisites()
fea.reset_all()
fea.update_objects()
# run analysis multiple times
for force in forces:
App.ActiveDocument.FemConstraintForce.Force = force
App.ActiveDocument.recompute()
print App.ActiveDocument.FemConstraintForce.Force
fea.run()
fea.load_results()
# evaluating the results ... absolute displacement
absdis = []
for o in App.ActiveDocument.Objects:
if o.isDerivedFrom('Fem::FemResultObject'):
# print o.Name, ' --> ', o.Stats[11]
absdis.append(o.Stats[11])
data = []
data_abs = []
i = 0
for f in forces:
displ_abs = absdis[i]
d = (f, displ_abs)
i += 1
data.append(d)
data_abs.append(displ_abs)
for d in data:
print d[0], ' --> ', d[1]
##########################################################################
# Plotting the results
##########################################################################
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(forces, absdis, linestyle='-', color='gray', alpha=0.5)
ax.plot(forces, absdis, linestyle='', marker='o')
ax.set_xlabel('Applied force in kN')
xticklabels = []
xticks = ax.get_xticks()
for xt in xticks:
xticklabels.append(str(xt/1000))
ax.set_xticklabels(xticklabels)
ax.set_ylabel('Absolute displacement in mm')
ax.grid()
plt.show()
fig.savefig('results.png')
Re: Parameter study
Hello,
I did some scripting on running ElmerSolver and Paraview on a mesh created in FreeCAD while sweeping some parameters. The parameters are specified and changed using Alias_manager. The created "part-family"- files are than reopenen again, mesh, exported as .unv, imported with ElmerGrid, solved with ElmerSolver, evaluated using Paraview and read back into the spreadsheet. For all interested see my demo files and the two screencasts below. I used the 3D-Calculix example and varied the height of the beam.
Preparation: Running the sweep and evaluation: Sample files: Requirements for running this example (installed Elmer, Gmsh, ...) are described in the included "explaination.txt".
I did some scripting on running ElmerSolver and Paraview on a mesh created in FreeCAD while sweeping some parameters. The parameters are specified and changed using Alias_manager. The created "part-family"- files are than reopenen again, mesh, exported as .unv, imported with ElmerGrid, solved with ElmerSolver, evaluated using Paraview and read back into the spreadsheet. For all interested see my demo files and the two screencasts below. I used the 3D-Calculix example and varied the height of the beam.
Preparation: Running the sweep and evaluation: Sample files: Requirements for running this example (installed Elmer, Gmsh, ...) are described in the included "explaination.txt".
Re: Parameter study
i can't view your webm files... the container is probably filled with a wmv file...