Ejemplo n.º 1
0
def post_processing():
    py_mentat.py_send('*post_open_default')
    py_mentat.py_send('*post_value Equivalent Von Mises Stress')
    py_mentat.py_send('*post_contour_bands')
    n_id = py_mentat.py_get_int("scalar_max_node()")
    value = py_mentat.py_get_float('scalar_1({})'.format(n_id))
    if value:
        print('the result is ', value)
    else:
        print('no value')
Ejemplo n.º 2
0
    def _get_set_entry_list(self,
                            centroid,
                            nnodes,
                            extend,
                            axes=[0, 1, 2],
                            tol=1e-12):

        nodes = np.zeros(0, dtype=int)
        #coord = np.zeros((0,3))
        dist = np.zeros(0)

        n = pm.py_get_int('nsets()')
        k = pm.py_get_int('nset_entries(%d)' % n)

        #print('nsets, entries', n, k)

        for k in range(1, k + 1):
            node = pm.py_get_int('set_entry(%d,%d)' % (n, k))
            nodes = np.append(nodes, node)

            x = pm.py_get_float('node_x(%d)' % node)
            y = pm.py_get_float('node_y(%d)' % node)
            z = pm.py_get_float('node_z(%d)' % node)
            xi = np.array([x, y, z])

            dist = np.append(
                dist, np.linalg.norm(centroid.take(axes) - xi.take(axes)))
            #coord = np.vstack((coord,[x,y,z]))

        sorted_nodes = nodes[np.argsort(dist)]
        sorted_dist = np.sort(dist)

        j = 0
        if extend:
            while (sorted_dist[nnodes + j] - sorted_dist[nnodes - 1]
                   )**2 < tol and nnodes + j < len(dist):
                j = j + 1
        if j > 0:
            print(
                'WARNING: Extended number of NextNodes from %d to %d due to equal distances.'
                % (nnodes, nnodes + j))

        return sorted_nodes[:nnodes + j]
Ejemplo n.º 3
0
def find_n_coord(n: list) -> [list, list]:
    """Find the coordinates of a list of nodes

    Parameters
    ----------
    n : list
        The list of nodes

    Returns
    -------
    [list, list]
        The x and y coordinates
    """

    #   Initialisations
    x = []
    y = []

    for i in n:

        x.append(py_get_float("node_x({})".format(i)))
        y.append(py_get_float("node_y({})".format(i)))

    return x, y
Ejemplo n.º 4
0
def sweep_nodes(
    a: str,
    c: int,
) -> None:
    """Sweep a specific set of nodes

    Parameters
    ----------
    a : str
        The axis of the nodes
    c : int
        The coordinate of the nodes
    """

    #   Initialisations
    n_l = []

    #   Fetch the total number of nodes
    n_n = py_get_int("max_node_id()")

    #   Loop through the number of nodes
    for i in range(1, n_n + 1):

        #   Fetch the relevant coordinate of the current node
        c_n = py_get_float("node_{}({})".format(a, i))

        #   Check if the selected coordinate matches the desirec coordinate
        if c_n == c:

            #   Add the node to the list
            n_l.append(i)

    #   Sweep the nodes
    py_send("*sweep_nodes ")

    #   Loop through the selected nodes
    for i in n_l:
        py_send("{} ".format(i))

    py_send("#")

    return
Ejemplo n.º 5
0
def add_bc_fd_edge(
    label: str,
    a: str,
    d: str,
    e: int,
    m: float,
    tab_nam: str = None,
) -> None:
    """[summary]

    Parameters
    ----------
    label : str
        The label of the boundary condition
    a : str
        The axis of the applied boundary condition
        "x" or "y"
    d : str
        The direction of the applied boundary condition
        "x" or "y"
    e : int
        The edge coordinate of the boundary condition
    m : float
        The magnitude of the applied displacement
    tab_nam : str, optional
        The name of the table defining the displacement function, by default None
    """

    #   Initialisation
    n_l = []

    #   Fetch the total number of nodes
    n_n = py_get_int("max_node_id()")

    #   Apply the fixed boundary condition
    py_send("*new_apply")
    py_send("*apply_type fixed_displacement")
    py_send("*apply_name bc_fd_{}".format(label))
    py_send("*apply_dof {}".format(a))
    py_send("*apply_dof_value {} {}".format(a, m))

    #   Apply the displacement function if applicable
    if tab_nam is not None:
        py_send("*apply_dof_table {} {}".format(a, tab_nam))

    #   Loop through the number of nodes
    for i in range(1, n_n + 1):

        #   Fetch the relevant coordinate of the current node
        c_n = py_get_float("node_{}({})".format(d, i))

        #   Check if the selected coordinate matches the desired edge
        if c_n == e:

            #   Add the node to the list
            n_l.append(i)

    #   Apply the boundary condition to the selected nodes
    py_send("*add_apply_nodes ")

    #   Loop through the selected nodes
    for i in n_l:
        py_send("{} ".format(i))

    py_send("#")

    return
Ejemplo n.º 6
0
def all_val(
    template,
    l: str,
    fp_t16: str,
    ) -> None:
    """Obtain values for all nodes from results

    Parameters
    ----------
    template 
        The unit template parameters
    l : str
        The label for the results file
        Either a template or unit identifier
    fp_t16 : str
        The file path of the model t16 file
    """

    #   The labels of the desired results
    label = []
    label.append("Displacement X")
    label.append("Displacement Y")
    label.append("Reaction Force X")
    label.append("Reaction Force Y")
    label.append("Total Strain Energy Density")
    label.append("Comp 11 of Total Strain")
    label.append("Comp 22 of Total Strain")
    label.append("Displacement")
    label.append("Reaction Force")

    #   Open the results file
    py_send("@main(results) @popup(modelplot_pm) *post_open \"{}\"".format(fp_t16))
    py_send("*post_numerics")

    #   Loop through all given labels
    for i in range(0, len(label)):

        #   Initialise list for the current label
        v = []

        #   Rewind the post file to the initial step
        py_send("*post_rewind")

        #   Set the post file to the current label
        py_send("*post_value {}".format(label[i]))

        #   Loop through all steps of the post file
        for j in range(0, template.n_steps + 1):

            #   Append an empty list to create a new index for every step
            v.append([])

            #   Loop through all 
            for k in range(1, template.n_n + 1):

                #   Append the current node's value to the list at the current step
                v[j].append(py_get_float("scalar_1({})".format(k)))

            #   Increment the post file
            py_send("*post_next")

        #   Save the values to a .csv file
        save_2d_list_to_csv(template, label[i] + "_" + l, v)

    #   Rewind and close the post file
    py_send("*post_rewind")
    py_send("*post_close")

    return