How do I apply pressure calculated as a function of polar coordinates of the element centroid in WB

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 467
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭
edited June 2023 in Structures

The pressure load object in WB LS-Dyna applies a constant pressure value on all the selected elements. How can I vary the pressure value as a function of polar coordinates (theta, phi) of the element the pressure is applied on?

enter image description here

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 467
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓

    This is not natively supported in WB LS-Dyna. However, one can use the following script to retrieve the element centroid and the geometry origin to convert cartesian to polar coordinates and apply a calculated pressure on individual elements using command snippets *DEFINE_CURVE and *LOAD_SEGMENT_ID

    NOTE:

    1. Please adjust the script to retrieve the origin from the geometry object in the DataModelTree. This script uses (0.0, 0.0, 0.0) as the origin.
    2. Define a Named selection of all the elements pressure is to be applied on and name it "elements_ns"
    import math
    
    # Get elements
    ns = ExtAPI.DataModel.GetObjectsByName("elements_ns")[0]
    
    mesh_data = ExtAPI.DataModel.MeshDataByName("Global")
    
    # Add Snippets
    analysis = Model.Analyses[0]
    # Add Load Curve
    load_curve = analysis.AddCommandSnippet()
    load_curve.Name = "DEFINE_CURVE"
    
    # Add Load Segment
    load_segment = analysis.AddCommandSnippet()
    load_segment.Name = "LOAD_SEGMENT"
    
    # Loop over all the elements
    
    origin = (0.0, 0.0, 0.0)  # Retrieve from Geometry Properties
    elements = ns.Ids
    for index, element in enumerate(elements, start=100):
        element = mesh_data.ElementById(element)
    
        element_centroid = element.Centroid
    
        u"""
        Convert cartesian coordinates to polar coordinates.
        """
        # R
        r = ((element_centroid[0] - origin[0]) ** 2 + (element_centroid[1] - origin[1]) ** 2 + (
                element_centroid[2] - origin[2]) ** 2) ** 0.5
        # THETA - Please check and convert the units if needed
        theta = math.acos((element_centroid[2] - origin[2]) / r) * (180.0 / math.pi)
        # PHI
        phi = math.atan((element_centroid[1] - origin[1]) / (element_centroid[0] - origin[0])) * (180.0 / math.pi)
    
        # Corner Nodes
        corner_node_ids = element.CornerNodeIds
    
        # Calculate Pressure on basis of a function -> f(theta, phi)
        p = 0.3 * math.sin(phi)
    
        load_curve.AppendText(u"""*DEFINE_CURVE
    $#lcid, sidr, sfa, sfo, offa, offo, dattyp, lcint
    {0}, 0, 1.0, 1.0, 0.0, 0.0, 0, 0
    $#a1, o1
    0.0, {1}
    1.0, {1}
    10.0, {1}
    """.format(index, p))
    
        load_segment.AppendText(u"""*LOAD_SEGMENT_ID
    $#id
    {0}
    $#lcid, sf, at, n1, n2, n3, n4, n5
    {1}, 1.0, 0.0, {2}, {3}, {4}, {5}, 0
    """.format(index * 2, index, corner_node_ids[0], corner_node_ids[1], corner_node_ids[2], corner_node_ids[3]))