Script Tip Friday- Compute the time varying COG

Script Tip Friday- Compute the time varying COG

No alt text provided for this image

Vishnu Venkataraman, Senior Application Engineers at Ansys, is back this week to help answer the question... "How do I find the time varying centre of gravity location of my deforming model using DPF in Ansys Mechanical?" Enjoy!

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'?        

Here's the full script:

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(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 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 = dpf.operators.geo.center_of_gravity(mesh=created_mesh,

?????????????????????????????????????????????????? mesh_scoping=mymeshscoping).outputs.field

??? # COG data

??? return list(cogfield.GetData().Data):
        
No alt text provided for this image

Do YOU have a Script Tip you'd like to share? Comment below and someone from Ansys will reach out and gather information so we can feature you on our next Script Tip Friday.??

要查看或添加评论,请登录

Ansys Structures的更多文章

社区洞察

其他会员也浏览了