Skip to main content

Find the time-varying center of gravity location of a deforming model

| 09.16.2022

Today’s script tip comes from Vishnu Venkataraman, Application Engineer at Ansys.

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.

Methodology followed:

  • Get the time varying deformation vectors for all nodes using: dpf.operators.displacement
  • Create a mesh region based on existing mesh using dpf.MeshedRegion
  • Update the node locations of the created mesh based on the deformation vectors at each time point.
  • Find the COG using dpf.operators.geo.center_of_gravity by feeding in the mesh regions at every time point .

Function to find the time varying COG of your model:

Use the below function like:

body_named_selection = ‘MYBODY’
timepoint = 3
find_COG_at_time (body_named_selection, timepoint)

Please remember to create a body named selection called ‘MYBODY’

def find coG at time (bodynamedselection, timepoint):
    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 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 from existing 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 ( [2]]) 
    createdmesh_nodeids = created mesh.Node Ids 
    for elem in my_mesh.Elements: 
    created mesh.AddSolidElement (elem. Id,
    map(lambda x: creatednesh nodeids.IndexOf(x), elem. CornerNodeIds)) 
    #scoping operator to scope to named selection 
    ns op = dpf.operators.scoping.on named selection(
        requested location='Elemental', named selection_name=bodynamedselection,
        data sources=dataSource) 
    mymeshscoping = ns_op.outputs.mesh_scoping 
    # cog field 
    cogfield = of gravity (mesh=created mesh,mesh scoping mymeshscoping).outputs.field 
    # CoG data 
    return list (cogfield. GetData().Data)