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.
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
import Ans.DataProcessing as dpf
analysis1 = ExtAPI.DataModel.Project.Model.Analyses
dataSource = dpf.DataSources(analysis1.Solution.ResultFilePath)
my_model = dpf.Model(analysis1.Solution.ResultFilePath)
my_mesh = my_model.Mesh
my_time_scoping = timepoint
u = dpf.operators.result.displacement(time_scoping=my_time_scoping,data_sources=dataSource)
disp_field = u.outputs.fields_container.GetData()
#Create my own mesh
for node in my_mesh.Nodes:
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
cogfield = dpf.operators.geo.center_of_gravity(mesh = created_mesh,mesh_scoping=mymeshscoping).outputs.field
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.
I think so too we may need to create one for DPF from within Mechanical
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.