How do I find the time varying center of gravity location of my deforming body using DPF?


The COG of a body might vary with time as the body deforms and you might be interested in knowing how to compute the time varying COG.
This example also highlights on how you can create your own mesh with DPF.
Comments
-
Use the below function like :
find_COG_at_time('MYBODY',3) #Please remember to create a body named selection on the one you are interested in knowing the COG
def find_COG_at_time(bodynamedselection,timepoint): import mech_dpf import Ans.DataProcessing as dpf #Result Data analysis1 = ExtAPI.DataModel.Project.Model.Analyses[0] dataSource = dpf.DataSources(analysis1.Solution.ResultFilePath) #Get mesh my_model = dpf.Model(analysis1.Solution.ResultFilePath) my_mesh = my_model.Mesh #mytime my_time_scoping = timepoint #Get Deformation u = dpf.operators.result.displacement(time_scoping=my_time_scoping,data_sources=dataSource) disp_field = u.outputs.fields_container.GetData()[0] #Create my own mesh created_mesh=dpf.MeshedRegion(my_mesh.Nodes.Count,0) for node in my_mesh.Nodes: created_mesh.AddNode(node.Id,[node.X+disp_field.GetEntityDataById(node.Id)[0],node.Y+disp_field.GetEntityDataById(node.Id)[1],node.Z+disp_field.GetEntityDataById(node.Id)[2]]) createdmesh_nodeids = created_mesh.NodeIds for elem in my_mesh.Elements: created_mesh.AddSolidElement(elem.Id,map(lambda x: createdmesh_nodeids.IndexOf(x), elem.CornerNodeIds)) #scoping operator ns_op=dpf.operators.scoping.on_named_selection(requested_location='Elemental',named_selection_name=bodynamedselection,data_sources=dataSource) mymeshscoping = ns_op.outputs.mesh_scoping #Volume field cogfield = dpf.operators.geo.center_of_gravity(mesh = created_mesh,mesh_scoping=mymeshscoping).outputs.field #COG return list(cogfield.GetData().Data)
0 -
Hi @Vishnu, thank you for this example!
One remark though:
This is tagged as "PyDPF", yet as it is using the API for use within Mechanical, I am afraid this will create confusion for people trying to use this with PyDPF-Core/Post. Is there a better suited tag available? Or maybe we should create one specific for use of DPF from within Mechanical, be it in Python.
2 -
I think so too we may need to create one for DPF from within Mechanical
0 -
Hey! I added the DPF tag to your post! Also can you confirm that COG = "Centre of Gravity"? I don't think you state it anywhere.
0