How to plot directional deformation with vectors?

Javier Vique
Javier Vique Member, Employee Posts: 90
Second Anniversary 5 Answers 25 Likes 10 Comments
✭✭✭✭

In Mechanical, we can plot the total deformation as vector. However, there is no way to plot a directional deformation. This is reasonable, since a directional deformation is just a scalar value. However, an user might be interested to have a plot of that directional deformation with vectors which are proportionals to their values. How to do it?

Tagged:

Answers

  • Javier Vique
    Javier Vique Member, Employee Posts: 90
    Second Anniversary 5 Answers 25 Likes 10 Comments
    ✭✭✭✭

    This can be easily done using Python Result object. The directional deformation is read using dpf and then a custom field is created, applying zero value to the deformation on the other two directions. Please see below script done for deformation on z direction.
    If the deformation must be plot on a specific CS, please see this post.

    def define_dpf_workflow(analysis):
        import mech_dpf
        import Ans.DataProcessing as dpf
        mech_dpf.setExtAPI(ExtAPI)
        dataSource = dpf.DataSources(analysis.ResultFileName)
    
        scoping_refs = this.GetCustomPropertyByPath("Surface UZ/Scoping Property/Geometry Selection").Value
        nodes_loc = mech_dpf.GetNodeScopingByRefId(scoping_refs)
    
        uz = dpf.operators.result.displacement_Z()
        uz.inputs.data_sources.Connect(dataSource)
        uz.inputs.mesh_scoping.Connect(nodes_loc)
    
        num_nodes = nodes_loc.Count
    
        disp_vector = dpf.FieldsFactory.Create3DVectorField(numEntities = num_nodes)
        k = 0 
        for i in uz.outputs.fields_container.GetData()[0].ScopingIds:
            datak = uz.outputs.fields_container.GetData()[0].Data[k]
            k = k + 1
            disp_vector.Add(id=i,data=[0.0,0.0,datak])
    
        output = dpf.operators.utility.forward()
        output.inputs.any.Connect(disp_vector)
    
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(output)
        dpf_workflow.SetOutputContour(output)
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()
    

    The result would be like this:

  • Javier Vique
    Javier Vique Member, Employee Posts: 90
    Second Anniversary 5 Answers 25 Likes 10 Comments
    ✭✭✭✭

    Here an explanation of how to plot the directional deformation in a local coordinate system:
    -First, displacement must be rotated to the local coordinate system.
    -Then, a field is created with the desired component (z in the example below) and the rest 0.0
    -Last, that field must be rotated from local to global. Created field does not have any associated coordinate system, so if we plot it, Mechanical will understand that it is in global CS. So it is needed to grab the rotation matrix for the first rotation done and transpose it. Now that transposed rotation matrix is applied to the created field, so it is converted to global CS.
    Here the script used, being id_cs the id of the local coordinate system on which we want to plot our result:

    op_cs = dpf.operators.result.coordinate_system()
    op_cs.inputs.cs_id.Connect(id_cs)
    op_cs.inputs.data_sources.Connect(dataSource)
    cs = op_cs.outputs.field.GetData()
    
    op_d = dpf.operators.result.displacement()
    op_d.inputs.data_sources.Connect(dataSource)
    op_d.inputs.mesh_scoping.Connect(nodes_loc)
    u = op_d.outputs.fields_container.GetData()
    
    op_rot = dpf.operators.geo.rotate_fc()
    op_rot.inputs.fields_container.Connect(u)
    op_rot.inputs.coordinate_system.Connect(cs)
    u_rot = op_rot.outputs.fields_container.GetData()
    
    op_z = dpf.operators.logic.component_selector_fc()
    op_z.inputs.fields_container.Connect(u_rot)
    op_z.inputs.component_number.Connect(2)
    uz_rot = op_z.outputs.fields_container.GetData()
    
    num_nodes = nodes_loc.Count
    disp_vector = dpf.FieldsFactory.Create3DVectorField(numEntities = num_nodes)
    k = 0 
    for i in uz_rot[0].ScopingIds:
        datak = uz_rot[0].Data[k]
        k = k + 1
        disp_vector.Add(id=i,data=[0.0,0.0,datak])
    
    matrix = cs.Data
    transposed = [
        matrix[0], matrix[3], matrix[6],
        matrix[1], matrix[4], matrix[7],
        matrix[2], matrix[5], matrix[8],
        matrix[9], matrix[10], matrix[11]
    ]
    
    cs.UpdateEntityDataByEntityIndex(0,transposed)
    
    op_rot = dpf.operators.geo.rotate()
    op_rot.inputs.field.Connect(disp_vector)
    op_rot.inputs.field_rotation_matrix.Connect(cs)
    disp_vector_globalcs = op_rot.outputs.field.GetData()
    
    output = dpf.operators.utility.forward()
    output.inputs.any.Connect(disp_vector_globalcs)