How to create custom field on custom mesh using DPF in mechanical

Vishnu
Vishnu Member, Employee Posts: 222
100 Comments 100 Likes Second Anniversary Name Dropper
✭✭✭✭
edited May 16 in Structures

Below is an example using mechdpf for creation of custom field on a custom mesh

Tagged:

Comments

  • Vishnu
    Vishnu Member, Employee Posts: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    edited May 16

    Methodology

    • Mesh Creation

      • A MeshedRegion object is created with 4 nodes and 1 element.
      • Nodes are added with specific coordinates.
      • A shell element is created using the node IDs.
    • Field Creation

      • Three 3D vector fields (time1_field, time2_field, time3_field) are created using dpf.FieldsFactory.Create3DVectorField.
      • The scoping IDs for each field are set to the node IDs of the mesh
      • Data for each field is defined
    • Fields Container Creation

      • field container is created from fields

    Sample Python Result Code Below:

    def define_dpf_workflow(analysis):
        import mech_dpf
        import Ans.DataProcessing as dpf
    
        #Create mesh
        mesh = dpf.MeshedRegion(4, 1)
        mesh.AddNode(1, [ 0.0, 0.0, 0.0 ])
        mesh.AddNode(2, [ 10.0, 0.0, 0.0 ])
        mesh.AddNode(3, [ 10.0, 10.0, 0.0 ])
        mesh.AddNode(4, [ 0.0, 10.0, 0.0 ])
        mesh.AddShellElement(1, [ 0, 1, 2, 3 ])
    
        # Set the mesh unit
        mesh.Unit = "mm"
    
        time1_field = dpf.FieldsFactory.Create3DVectorField(4)
        time2_field = dpf.FieldsFactory.Create3DVectorField(4)
        time3_field = dpf.FieldsFactory.Create3DVectorField(4)
    
        time1_field.Unit = "mm"
        time2_field.Unit = "mm"
        time3_field.Unit = "mm"
    
        time1_field.ScopingIds = mesh.NodeIds
        time2_field.ScopingIds = mesh.NodeIds
        time3_field.ScopingIds = mesh.NodeIds
    
        time1_field_data = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0]
        time2_field_data = [x*2 for x in [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0]]
        time3_field_data = [x*3 for x in [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0]]
    
        time1_field.Data = time1_field_data
        time2_field.Data = time2_field_data
        time3_field.Data = time3_field_data
    
    
        fc = dpf.FieldsContainerFactory.OverTimeFreqFieldsContainer(
            {0.1: time1_field, 0.2: time2_field, 0.3: time3_field}, "s"
        )
    
        nrm = dpf.operators.math.norm_fc(fields_container = fc)
    
        dpf_workflow = dpf.Workflow()
        #dpf_workflow.Add(fc)
        dpf_workflow.Add(nrm)
        # dpf_workflow.SetInputName(u, 0, 'time')
        # dpf_workflow.Connect('time', timeScop)
        dpf_workflow.SetOutputMesh(mesh)
        dpf_workflow.SetOutputContour(nrm)
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()
    
    

  • Vishnu
    Vishnu Member, Employee Posts: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    edited May 16