Basically, I'm trying to run a step by step dynamic analysis of my model which I'm trying to decompose into the following steps:
-Running an initial static/(dynamic ideally) analysis of the model on CCX
-Save the resulting mesh with displacements, stresses and modified characteristics of the model
-Write a new inp file with new displacement values extracted from a different software/file and applied onto the displaced model
-Rinse and repeat for a user defined simulation time divided into a defined number of steps
-Extract and show animation of the whole simulation, or all the previous result files of each step
I've based some ideas on these threads but it didn't clear up much for me:
thread
thread
thread
thread
thread
thread
And the FEM tutorial, of course: https://wiki.freecadweb.org/FEM_Tutorial_Python
Here's what I've gathered, or hypothesized:
- Deep inside the write_inp_file() function, there's another function called write_step_equation(inpfile, self), which controls/write the type of analysis run by the calculix solver, so if I create/add a loop inside that function for *DYNAMIC or *MODAL_DYNAMIC analysis, could that work? That also means implementing something to read/write the displacement for the external input(software/user).
That loop could look something like this, correct me if I'm wrong:
In the inp file:
Code: Select all
[**List of model properties(mesh, nodes, node_geometry, material, node sets for constraints(displacement, fixed, planetary...)
*NSET, NEST=ActuatorNodes
Node_number_1
.
.
.
**Initial step
*STEP
*STATIC
**Parameters dependent on steps(self weight, constraints, fluid flow...)
**Outputs
*END STEP]
In Python:
[code]
[For step in step_time:
new_displacement=Calculate_and_return_new_diplacement(external_file/software)#function to create
new_step_inp_file=add_step_to_inp_file(new_displacement, previous_inp_file)#function to create, that does the following inp modification ]
In inp file:[code]
[**Copy/or open first file in the new inp, with fea.write_inp_file(),
*STEP
*MODAL DYNAMIC, PERTURBATION or *STATIC,PERTURBATION *******Which saves previous step results(mesh status, stresses, displacement and includes them in the new step( from [url][https://www.feacluster.com/CalculiX/ccx_2.18/doc/ccx/node332.html])
Initial_time_increment value, Time_period_of_the_step
**Parameters dependent on steps(self weight, new constraints deleting previous displacement, fluid flow...) with write_constraints_propdata()
**Outputs
*END STEP]
Once all steps are complete, I've yet to understand how to visualize the animation of the result, since I'm not sure it's possible on FreeCAD, i'll have to use ParaView, or another visualizer.
Here's my idea of the beginning of the python code to run for the dynamic step by step FEM analysis:
[code]
[#Hypothesis that Geometry, Analysis, SolverCCX, Material, Self Weight, Initial displacement and Mesh are set for the model in the GUI
def dynamic_loading_test(freeCAD_doc_path, test_time_length,time_increment, init_disp):
nb_steps=test_time_length//time_increment
step_nb=0
# opening the geometry and analysis FreeCAD file
FreeCAD.openDocument(freeCAD_doc_path)
file_name=os.path.splitext(os.path.basename(freeCAD_doc_path))[0]
App.setActiveDocument(file_name)
App.ActiveDocument=App.getDocument(file_name)
freeCAD_doc=App.ActiveDocument
# activating analysis
import FemGui
FemGui.setActiveAnalysis(freeCAD_doc.Analysis)
# run the analysis step by step for the first one
from femtools import ccxtools
fea = ccxtools.FemToolsCcx()
fea.update_objects()
fea.setup_working_dir()
fea.setup_ccx()
message = fea.check_prerequisites()
if not message:
fea.purge_results()
fea.write_inp_file() #initial displacement
fea.ccx_run()
fea.load_results()
else:
FreeCAD.Console.PrintError("Houston, we have a problem! {}\n".format(message)) # in report view
print("Houston, we have a problem! {}\n".format(message)) # in python console
# loop
while step_nb<=nb_steps :
new_displacement=Calculate_and_return_new_diplacement(external_file/software)#function to create
new_step_inp_file=add_step_to_inp_file(new_displacement, previous_inp_file)#function to create, that does the following inp modification
# run the analysis for each step or create a new analysis for each step?
fea_step = ccxtools.FemToolsCcx()
fea_step.update_objects()
fea_step.setup_working_dir()
fea_step.setup_ccx()
message = fea_step.check_prerequisites()
if not message:
fea_step.purge_results()
fea_step.ccx_run()
fea_step.load_results()
step_nb+=1
else:
FreeCAD.Console.PrintError("Houston, we have a problem! {}\n".format(message)) # in report view
print("Houston, we have a problem! {}\n".format(message)) # in python console
]
I've also attached my File for the geometry I'm working with, the force would be exerted on the small beam protruding from the frame.
Any help would be greatly appreciated, thank you for your time.
-