コード例 #1
0
def plot_reaction_forces(structure, step, layer=None, scale=1.0):
    """
    Plots reaction forces for the Structure analysis results.

    Parameters
    ----------
    structure : obj
        Structure object.
    step : str
        Name of the Step.
    layer : str
        Layer name for plotting.
    scale : float
        Scale of the arrows.

    Returns
    -------
    None

    """

    if not layer:
        layer = '{0}-{1}'.format(step, 'reactions')

    try:
        clear_layer(layer)
    except:
        create_layer(layer)

    rfx = array(list(
        structure.results[step]['nodal']['rfx'].values()))[:, newaxis]
    rfy = array(list(
        structure.results[step]['nodal']['rfy'].values()))[:, newaxis]
    rfz = array(list(
        structure.results[step]['nodal']['rfz'].values()))[:, newaxis]
    rf = hstack([rfx, rfy, rfz])
    rfm = norm(rf, axis=1)
    rmax = max(rfm)
    nodes = array(structure.nodes_xyz())

    for i in where(rfm > 0)[0]:

        sp = nodes[i, :]
        ep = nodes[i, :] + rf[i, :] * -scale * 0.001
        col = colorbar(rfm[i] / rmax, input='float', type=1)
        line = draw_line(start=sp, end=ep, width=0.01, color=col, layer=layer)

        set_object_property(object=line, property='rfx', value=rf[i, 0])
        set_object_property(object=line, property='rfy', value=rf[i, 1])
        set_object_property(object=line, property='rfz', value=rf[i, 2])
        set_object_property(object=line, property='rfm', value=rfm[i])
コード例 #2
0
def weld_meshes_from_layer(layer_input, layer_output):
    """
    Grab meshes on an input layer and weld them onto an output layer.

    Parameters
    ----------
    layer_input : str
        Layer containing the Blender meshes to weld.
    layer_output : str
        Layer to plot single welded mesh.

    Returns
    -------
    None

    """

    print('Welding meshes on layer:{0}'.format(layer_input))

    S = Structure(path=' ')

    add_nodes_elements_from_layers(S,
                                   mesh_type='ShellElement',
                                   layers=layer_input)

    faces = []

    for element in S.elements.values():
        faces.append(element.nodes)

    try:
        clear_layer(layer_output)
    except:
        create_layer(layer_output)

    vertices = S.nodes_xyz()

    xdraw_mesh(name='welded_mesh',
               vertices=vertices,
               faces=faces,
               layer=layer_output)
コード例 #3
0
ファイル: drawing.py プロジェクト: tclim/compas

def xdraw_geodesics():
    NotImplementedError


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    from compas_blender.utilities import clear_layer
    from numpy.random import rand

    clear_layer(layer=1)

    vertices = [[-1, 0, 0], [-2, 0, 0], [-2, 1, 0], [-1, 1, 0]]
    faces = [[0, 1, 2], [2, 3, 0]]
    bmesh = xdraw_mesh(name='bmesh',
                       vertices=vertices,
                       faces=faces,
                       color=[1, 1, 1],
                       alpha=0.5,
                       layer=1)

    draw_cubes(pos=[[0, 3, 0]], radius=0.5, color=[1, 1, 0], layer=1)
    xdraw_cubes([{
        'radius': 0.5,
        'pos': [0, 2, 0],
        'color': [1, 0, 0],
コード例 #4
0
ファイル: drx_bending-control.py プロジェクト: tclim/compas
        ind = argmin(cdist(X, Xt), axis=1)
        vertices = vstack([X, Xt[ind, :]])
        n = X.shape[0]
        edges = [[i, i + n] for i in range(n)] + list(network.edges())
        xdraw_mesh(name='norms', vertices=vertices, edges=edges)
    return X


def fn(dofs, *args):
    network, Xt, tol, ds = args
    X = update(dofs=dofs, network=network, tol=tol, plot=False, Xt=Xt, ds=ds)
    ind = argmin(cdist(X, Xt), axis=1)
    return 1000 * mean(normrow(X - Xt[ind, :]))


clear_layer(layer=0)

# Beam input

L = 0.88
m = 20
ds = L / m
div = 10
E = 5 * 10**9
I = 2 * 10**(-11)
A = 0.005**2

# Solver input

mi = div * m
tol = 0.01
コード例 #5
0
ファイル: networkartist.py プロジェクト: tclim/compas
 def clear_layer(self):
     clear_layer(layer=self.layer)
コード例 #6
0
def plot_data(structure,
              step,
              field='um',
              layer=None,
              scale=1.0,
              radius=0.05,
              cbar=[None, None],
              iptype='mean',
              nodal='mean',
              mode='',
              cbar_size=1):
    """
    Plots analysis results on the deformed shape of the Structure.

    Parameters
    ----------
    structure : obj
        Structure object.
    step : str
        Name of the Step.
    field : str
        Field to plot, e.g. 'um', 'sxx', 'sm1'.
    layer : str
        Layer name for plotting.
    scale : float
        Scale on displacements for the deformed plot.
    radius : float
        Radius of the pipe visualisation meshes.
    cbar : list
        Minimum and maximum limits on the colorbar.
    iptype : str
        'mean', 'max' or 'min' of an element's integration point data.
    nodal : str
        'mean', 'max' or 'min' for nodal values.
    mode : int
        Mode or frequency number to plot, for modal, harmonic or buckling analysis.
    cbar_size : float
        Scale on the size of the colorbar.

    Returns
    -------
    None

    Notes
    -----
    - Pipe visualisation of line elements is not based on the element section.

    """

    if field in ['smaxp', 'smises']:
        nodal = 'max'
        iptype = 'max'

    elif field in ['sminp']:
        nodal = 'min'
        iptype = 'min'

    # Create and clear Blender layer

    if not layer:
        layer = '{0}-{1}{2}'.format(step, field, mode)

    try:
        clear_layer(layer)
    except:
        create_layer(layer)

    # Node and element data

    nodes = structure.nodes_xyz()
    elements = [
        structure.elements[i].nodes
        for i in sorted(structure.elements, key=int)
    ]
    nodal_data = structure.results[step]['nodal']
    nkeys = sorted(structure.nodes, key=int)

    ux = [nodal_data['ux{0}'.format(mode)][i] for i in nkeys]
    uy = [nodal_data['uy{0}'.format(mode)][i] for i in nkeys]
    uz = [nodal_data['uz{0}'.format(mode)][i] for i in nkeys]

    try:
        data = [nodal_data['{0}{1}'.format(field, mode)][i] for i in nkeys]
        dtype = 'nodal'

    except (Exception):
        data = structure.results[step]['element'][field]
        dtype = 'element'

    # Postprocess

    result = postprocess(nodes, elements, ux, uy, uz, data, dtype, scale, cbar,
                         1, iptype, nodal)

    try:
        toc, U, cnodes, fabs, fscaled, celements, eabs = result
        U = array(U)
        print('\n***** Data processed : {0} s *****'.format(toc))

    except:
        print(
            '\n***** Error encountered during data processing or plotting *****'
        )

    # Plot meshes

    npts = 8
    mesh_faces = []
    block_faces = [[0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5],
                   [2, 3, 7, 6], [3, 0, 4, 7]]
    tet_faces = [[0, 2, 1], [1, 2, 3], [1, 3, 0], [0, 3, 2]]
    pipes = []
    mesh_add = []

    for element, nodes in enumerate(elements):

        n = len(nodes)

        if n == 2:

            u, v = nodes
            pipe = draw_cylinder(start=U[u],
                                 end=U[v],
                                 radius=radius,
                                 div=npts,
                                 layer=layer)
            pipes.append(pipe)

            if dtype == 'element':
                col1 = col2 = celements[element]

            elif dtype == 'nodal':
                col1 = cnodes[u]
                col2 = cnodes[v]

            try:
                blendermesh = BlenderMesh(object=pipe)
                blendermesh.set_vertices_colors(
                    {i: col1
                     for i in range(0, 2 * npts, 2)})
                blendermesh.set_vertices_colors(
                    {i: col2
                     for i in range(1, 2 * npts, 2)})
            except:
                pass

        elif n in [3, 4]:

            if structure.elements[element].__name__ in [
                    'ShellElement', 'MembraneElement'
            ]:
                mesh_faces.append(nodes)
            else:
                for face in tet_faces:
                    mesh_faces.append([nodes[i] for i in face])

        elif n == 8:

            for block in block_faces:
                mesh_faces.append([nodes[i] for i in block])

    if mesh_faces:

        bmesh = xdraw_mesh(name='bmesh',
                           vertices=U,
                           faces=mesh_faces,
                           layer=layer)
        blendermesh = BlenderMesh(bmesh)
        blendermesh.set_vertices_colors(
            {i: col
             for i, col in enumerate(cnodes)})
        mesh_add = [bmesh]

    # Plot colourbar

    xr, yr, _ = structure.node_bounds()
    yran = yr[1] - yr[0] if yr[1] - yr[0] else 1
    s = yran * 0.1 * cbar_size
    xmin = xr[1] + 3 * s
    ymin = yr[0]

    cmesh = draw_plane(name='colorbar',
                       Lx=s,
                       dx=s,
                       Ly=10 * s,
                       dy=s,
                       layer=layer)
    set_objects_coordinates(objects=[cmesh], coords=[[xmin, ymin, 0]])
    blendermesh = BlenderMesh(object=cmesh)
    vertices = blendermesh.get_vertices_coordinates().values()

    y = array(list(vertices))[:, 1]
    yn = yran * cbar_size
    colors = colorbar(((y - ymin - 0.5 * yn) * 2 / yn)[:, newaxis],
                      input='array',
                      type=1)
    blendermesh.set_vertices_colors(
        {i: j
         for i, j in zip(range(len(vertices)), colors)})

    set_deselect()
    set_select(objects=pipes + mesh_add + [cmesh])
    bpy.context.view_layer.objects.active = cmesh
    bpy.ops.object.join()

    h = 0.6 * s

    for i in range(5):

        x0 = xmin + 1.2 * s
        yu = ymin + (5.8 + i) * s
        yl = ymin + (3.8 - i) * s
        vu = +max([eabs, fabs]) * (i + 1) / 5.
        vl = -max([eabs, fabs]) * (i + 1) / 5.

        draw_text(radius=h,
                  pos=[x0, yu, 0],
                  text='{0:.3g}'.format(vu),
                  layer=layer)
        draw_text(radius=h,
                  pos=[x0, yl, 0],
                  text='{0:.3g}'.format(vl),
                  layer=layer)

    draw_text(radius=h, pos=[x0, ymin + 4.8 * s, 0], text='0', layer=layer)
    draw_text(radius=h,
              pos=[xmin, ymin + 12 * s, 0],
              text='Step:{0}   Field:{1}'.format(step, field),
              layer=layer)
コード例 #7
0
def plot_data(structure,
              step,
              field,
              layer,
              scale=1.0,
              radius=0.05,
              cbar=[None, None],
              iptype='mean',
              nodal='mean',
              mode='',
              colorbar_size=1):
    """ Plots analysis results on the deformed shape of the Structure.

    Parameters
    ----------
    structure : obj
        Structure object.
    step : str
        Name of the Step.
    field : str
        Field to plot, e.g. 'um', 'sxx', 'sm1'.
    layer : int
        Layer number for plotting.
    scale : float
        Scale on displacements for the deformed plot.
    radius : float
        Radius of the pipe visualisation meshes.
    cbar : list
        Minimum and maximum limits on the colorbar.
    iptype : str
        'mean', 'max' or 'min' of an element's integration point data.
    nodal : str
        'mean', 'max' or 'min' for nodal values.
    mode : int
        Mode or frequency number to plot, for modal, harmonic or buckling analysis.
    colorbar_size : float
        Scale on the size of the colorbar.

    Returns
    -------
    None

    Notes
    -----
    - Pipe visualisation of line elements is not based on the element section.

    """

    clear_layer(layer=layer)

    # Node and element data

    nodes = structure.nodes_xyz()
    elements = [
        structure.elements[i].nodes
        for i in sorted(structure.elements, key=int)
    ]
    nodal_data = structure.results[step]['nodal']
    nkeys = sorted(structure.nodes, key=int)
    ux = [nodal_data['ux{0}'.format(mode)][i] for i in nkeys]
    uy = [nodal_data['uy{0}'.format(mode)][i] for i in nkeys]
    uz = [nodal_data['uz{0}'.format(mode)][i] for i in nkeys]

    try:
        data = [nodal_data['{0}{1}'.format(field, mode)][i] for i in nkeys]
        dtype = 'nodal'
    except (Exception):
        data = structure.results[step]['element'][field]
        dtype = 'element'

    # Postprocess

    result = postprocess(nodes, elements, ux, uy, uz, data, dtype, scale, cbar,
                         1, iptype, nodal)

    try:
        toc, U, cnodes, fabs, fscaled, celements, eabs = result
        U = array(U)
        print('\n***** Data processed : {0:.3f} s *****'.format(toc))

    except:
        print(
            '\n***** Error encountered during data processing or plotting *****'
        )

    # Plot meshes

    npts = 8
    mesh_faces = []

    for element, nodes in enumerate(elements):
        n = len(nodes)

        if n == 2:
            u, v = nodes
            pipe = draw_pipes(start=[U[u]],
                              end=[U[v]],
                              radius=radius,
                              layer=layer)[0]
            if dtype == 'element':
                col1 = col2 = [celements[element]] * npts
            elif dtype == 'nodal':
                col1 = [cnodes[u]] * npts
                col2 = [cnodes[v]] * npts
            blendermesh = BlenderMesh(pipe)
            blendermesh.set_vertex_colors(vertices=range(0, 2 * npts, 2),
                                          colors=col1)
            blendermesh.set_vertex_colors(vertices=range(1, 2 * npts, 2),
                                          colors=col2)

        elif n in [3, 4]:
            mesh_faces.append(nodes)

    if mesh_faces:
        bmesh = xdraw_mesh(name='bmesh',
                           vertices=U,
                           faces=mesh_faces,
                           layer=layer)
        blendermesh = BlenderMesh(bmesh)
        blendermesh.set_vertex_colors(vertices=range(U.shape[0]),
                                      colors=cnodes)

    # Plot colourbar

    xr, yr, _ = structure.node_bounds()
    yran = yr[1] - yr[0] if yr[1] - yr[0] else 1
    s = yran * 0.1 * colorbar_size
    xmin = xr[1] + 3 * s
    ymin = yr[0]

    cmesh = draw_plane(name='colorbar',
                       Lx=s,
                       dx=s,
                       Ly=10 * s,
                       dy=s,
                       layer=layer)
    set_object_location(object=cmesh, location=[xmin, ymin, 0])
    blendermesh = BlenderMesh(cmesh)
    verts = blendermesh.get_vertex_coordinates()

    y = array(verts)[:, 1]
    yn = yran * colorbar_size
    colors = colorbar(((y - ymin - 0.5 * yn) * 2 / yn)[:, newaxis],
                      input='array',
                      type=1)
    blendermesh.set_vertex_colors(vertices=range(len(verts)), colors=colors)

    h = 0.6 * s
    texts = []
    for i in range(5):
        x0 = xmin + 1.2 * s
        yu = ymin + (5.8 + i) * s
        yl = ymin + (3.8 - i) * s
        vu = float(+max(eabs, fabs) * (i + 1) / 5.)
        vl = float(-max(eabs, fabs) * (i + 1) / 5.)
        texts.extend([{
            'radius': h,
            'pos': [x0, yu, 0],
            'text': '{0:.3g}'.format(vu),
            'layer': layer
        }, {
            'radius': h,
            'pos': [x0, yl, 0],
            'text': '{0:.3g}'.format(vl),
            'layer': layer
        }])
    texts.extend([{
        'radius': h,
        'pos': [x0, ymin + 4.8 * s, 0],
        'text': '0',
        'layer': layer
    }, {
        'radius': h,
        'pos': [xmin, ymin + 12 * s, 0],
        'text': 'Step:{0}   Field:{1}'.format(step, field),
        'layer': layer
    }])

    xdraw_texts(texts)