Exemplo n.º 1
0
def _setup_bar_grid_point_forces(log):
    op2_filename = os.path.join(MODEL_PATH, 'grid_point_forces', 'bar_grid_point_forces.op2')
    #from pyNastran.bdf.bdf import read_bdf
    #bdf_model = read_bdf()
    model = read_op2(op2_filename, load_geometry=True, combine=True,
                     exclude_results=None, log=log)
    log = model.log
    gpforce = model.grid_point_forces[1]  # type: RealGridPointForcesArray
    force = model.cbar_force[1]
    #['station', 'bending_moment1', 'bending_moment2', 'shear1', 'shear2', 'axial', 'torque']
    headers = force.get_headers()
    #istation = headers.index('station')
    itime = 0
    #ibending_moment1 = headers.index('bending_moment1')
    ibending_moment2 = headers.index('bending_moment2')
    #station = force.data[itime, :, istation]
    #bending_moment1 = force.data[itime, :, ibending_moment1]
    bending_moment2 = force.data[itime, :, ibending_moment2]

    coord_out = model.coords[0]
    nid_cp_cd, xyz_cid0, xyz_cp, icd_transform, icp_transform = model.get_xyz_in_coord_array(
        cid=0, fdtype='float64', idtype='int32')
    all_nids = nid_cp_cd[:, 0]

    all_eids, element_centroids_cid0 = get_element_centroids(model, idtype='int32', fdtype='float64')
    #stations = element_centroids_cid0[:-1, 0]
    stations = np.linspace(0., 10., num=51)
    #model.log.level = 'warning'
    #print(stations)

    nids_bar = []
    nids_beam = []
    for eid, elem in sorted(model.elements.items()):
        if elem.type == 'CBAR':
            nids_bar.append(elem.nodes)
        elif elem.type == 'BEAM':
            nids_beam.append(elem.nodes)
    nids_bar = np.array(nids_bar, dtype='int32')
    nids_beam = np.array(nids_beam, dtype='int32')
    inid_bar = np.searchsorted(all_nids, nids_bar)
    x1 = xyz_cid0[inid_bar[:, 0], 0]
    x2 = xyz_cid0[inid_bar[:, 1], 0]
    out = (
        model, coord_out, nid_cp_cd, icd_transform,
        all_nids, xyz_cid0,
        all_eids, element_centroids_cid0,
        gpforce, x1, x2, bending_moment2,
        stations)
    return out
Exemplo n.º 2
0
    def test_gpforce_02(self):
        IS_MATPLOTLIB = False
        op2_filename = os.path.join(MODEL_PATH, 'grid_point_forces', 'bar_grid_point_forces.op2')
        #from pyNastran.bdf.bdf import read_bdf
        #bdf_model = read_bdf()
        log = SimpleLogger(level='warning')
        model = read_op2(op2_filename, load_geometry=True, combine=True,
                         exclude_results=None, log=log)
        log = model.log
        gpforce = model.grid_point_forces[1]  # type: RealGridPointForcesArray
        force = model.cbar_force[1]
        #['station', 'bending_moment1', 'bending_moment2', 'shear1', 'shear2', 'axial', 'torque']
        headers = force.get_headers()
        #istation = headers.index('station')
        itime = 0
        #ibending_moment1 = headers.index('bending_moment1')
        ibending_moment2 = headers.index('bending_moment2')
        #station = force.data[itime, :, istation]
        #bending_moment1 = force.data[itime, :, ibending_moment1]
        bending_moment2 = force.data[itime, :, ibending_moment2]

        coord_out = model.coords[0]
        nid_cp_cd, xyz_cid0, xyz_cp, icd_transform, icp_transform = model.get_xyz_in_coord_array(
            cid=0, fdtype='float64', idtype='int32')
        all_nids = nid_cp_cd[:, 0]

        all_eids, element_centroids_cid0 = get_element_centroids(model, idtype='int32', fdtype='float64')
        #stations = element_centroids_cid0[:-1, 0]
        stations = np.linspace(0., 10., num=51)
        #model.log.level = 'warning'
        #print(stations)

        nids_bar = []
        nids_beam = []
        for eid, elem in sorted(model.elements.items()):
            if elem.type == 'CBAR':
                nids_bar.append(elem.nodes)
            elif elem.type == 'BEAM':
                nids_beam.append(elem.nodes)
        nids_bar = np.array(nids_bar, dtype='int32')
        nids_beam = np.array(nids_beam, dtype='int32')
        inid_bar = np.searchsorted(all_nids, nids_bar)
        x1 = xyz_cid0[inid_bar[:, 0], 0]
        x2 = xyz_cid0[inid_bar[:, 1], 0]

        with self.assertRaises(AssertionError):
            log.error('problem with extract_freebody_loads...')
            fb_force, fb_moment = gpforce.extract_freebody_loads(
                all_eids,
                coord_out, model.coords,
                nid_cp_cd,
                icd_transform,
                itime=0, debug=True,
                log=log)

        if IS_MATPLOTLIB:  # pragma: no cover
            fig = plt.figure()
            ax = fig.gca()
            L = 10.0
            x = xyz_cid0[:, 0].copy()
            x.sort()
            M = x ** 2 / 2
            # F = wx
            # M = wx^2/2
            ax.plot(x1, bending_moment2[::2], 'o-', label='BM2', linewidth=3)
            ax.plot(x2, bending_moment2[1::2], 'o--', )
            ax.plot(L-x, M, 'o-', label='exact', linewidth=1)
            ax.grid(True)

        #nids = [1]
        #eids = [1]
        force_out_sum, moment_out_sum = gpforce.extract_interface_loads(
            all_nids, all_eids,
            coord_out, model.coords,
            nid_cp_cd, icd_transform,
            xyz_cid0,
            #summation_point: Optional[NDArray3float]=None,
            consider_rxf=True, itime=0,
            debug=True, log=log)
        assert np.allclose(force_out_sum, [0., 0., 0.]), force_out_sum
        assert np.allclose(moment_out_sum, [0., 0., 0.]), moment_out_sum

        # this one is empty...
        nids = [1]
        eids = [2]
        force_out_sum, moment_out_sum = gpforce.extract_interface_loads(
            nids, eids,
            coord_out, model.coords,
            nid_cp_cd, icd_transform,
            xyz_cid0,
            #summation_point: Optional[NDArray3float]=None,
            consider_rxf=True, itime=0,
            debug=True, log=log)
        #assert force_out.size == 0, force_out
        #assert moment_out.size == 0, moment_out
        assert not np.any(np.isfinite(force_out_sum)), force_out_sum
        assert not np.any(np.isfinite(moment_out_sum)), moment_out_sum
        #coord0 = model.coords[0]
        #gpforce.extract_interface_loads(nids: np.ndarray,
                                        #eids: np.ndarray,
                                        #coord_out=coord0,
                                        #model.coords,
                                        #nid_cd,
                                        #icd_transform,
                                        #xyz_cid0,
                                        #summation_point=None,
                                        #consider_rxf=True,
                                        #itime=0,
                                        #debug=True,
                                        #log=model.log,
                                        #idtype='int32')
        # ----------------------------------------
        nodes_list = list(model.nodes.keys())
        nids = np.array(nodes_list, dtype='int32')
        nids.sort()
        #eids = np.ndarray(list(model.elements.keys()), dtype='int32')
        #eids.sort()
        # bar is [0,10] in x
        force_sum, moment_sum = gpforce.shear_moment_diagram(
                                        xyz_cid0,
                                        all_eids,
                                        nids,
                                        icd_transform,
                                        element_centroids_cid0,
                                        model.coords,
                                        nid_cp_cd,
                                        stations,
                                        coord_out,
                                        idir=0, itime=0,
                                        debug=True, log=model.log)
        force_sum_expected = np.array([
            [0.,  0., -9.5],
            [0.,  0., -9.5],
            [0.,  0., -9.5],
            [0.,  0., -9.5],
            [0.,  0., -9.5],
            [0.,  0., -8.5],
            [0.,  0., -8.5],
            [0.,  0., -8.5],
            [0.,  0., -8.5],
            [0.,  0., -8.5],
            [0.,  0., -7.5],
            [0.,  0., -7.5],
            [0.,  0., -7.5],
            [0.,  0., -7.5],
            [0.,  0., -7.5],
            [0.,  0., -6.5],
            [0.,  0., -6.5],
            [0.,  0., -6.5],
            [0.,  0., -6.5],
            [0.,  0., -6.5],
            [0.,  0., -5.5],
            [0.,  0., -5.5],
            [0.,  0., -5.5],
            [0.,  0., -5.5],
            [0.,  0., -5.5],
            [0.,  0., -4.5],
            [0.,  0., -4.5],
            [0.,  0., -4.5],
            [0.,  0., -4.5],
            [0.,  0., -4.5],
            [0.,  0., -3.5],
            [0.,  0., -3.5],
            [0.,  0., -3.5],
            [0.,  0., -3.5],
            [0.,  0., -3.5],
            [0.,  0., -2.5],
            [0.,  0., -2.5],
            [0.,  0., -2.5],
            [0.,  0., -2.5],
            [0.,  0., -2.5],
            [0.,  0., -1.5],
            [0.,  0., -1.5],
            [0.,  0., -1.5],
            [0.,  0., -1.5],
            [0.,  0., -1.5],
            [0.,  0., -0.5],
            [0.,  0., -0.5],
            [0.,  0., -0.5]])
        moment_sum_expected = np.array([
            [0.0,  4.42166672e+01,  0.0],
            [0.0,  4.23166695e+01,  0.0],
            [0.0,  4.04166679e+01,  0.0],
            [0.0,  3.85166664e+01,  0.0],
            [0.0,  3.66166687e+01,  0.0],
            [0.0,  3.53166695e+01,  0.0],
            [0.0,  3.36166687e+01,  0.0],
            [0.0,  3.19166679e+01,  0.0],
            [0.0,  3.02166672e+01,  0.0],
            [0.0,  2.85166683e+01,  0.0],
            [0.0,  2.74166679e+01,  0.0],
            [0.0,  2.59166679e+01,  0.0],
            [0.0,  2.44166679e+01,  0.0],
            [0.0,  2.29166679e+01,  0.0],
            [0.0,  2.14166679e+01,  0.0],
            [0.0,  2.05166683e+01,  0.0],
            [0.0,  1.92166672e+01,  0.0],
            [0.0,  1.79166679e+01,  0.0],
            [0.0,  1.66166687e+01,  0.0],
            [0.0,  1.53166676e+01,  0.0],
            [0.0,  1.46166677e+01,  0.0],
            [0.0,  1.35166683e+01,  0.0],
            [0.0,  1.24166679e+01,  0.0],
            [0.0,  1.13166676e+01,  0.0],
            [0.0,  1.02166681e+01,  0.0],
            [0.0,  9.71666813e+00,  0.0],
            [0.0,  8.81666756e+00,  0.0],
            [0.0,  7.91666794e+00,  0.0],
            [0.0,  7.01666784e+00,  0.0],
            [0.0,  6.11666775e+00,  0.0],
            [0.0,  5.81666803e+00,  0.0],
            [0.0,  5.11666775e+00,  0.0],
            [0.0,  4.41666794e+00,  0.0],
            [0.0,  3.71666789e+00,  0.0],
            [0.0,  3.01666784e+00,  0.0],
            [0.0,  2.91666794e+00,  0.0],
            [0.0,  2.41666794e+00,  0.0],
            [0.0,  1.91666794e+00,  0.0],
            [0.0,  1.41666794e+00,  0.0],
            [0.0,  9.16667938e-01,  0.0],
            [0.0,  1.01666796e+00,  0.0],
            [0.0,  7.16667950e-01,  0.0],
            [0.0,  4.16667938e-01,  0.0],
            [0.0,  1.16667941e-01,  0.0],
            [0.0, -1.83332056e-01,  0.0],
            [0.0,  1.16670445e-01,  0.0],
            [0.0,  1.66695174e-02,  0.0],
            [0.0, -8.33295286e-02,  0.0]])
        assert np.allclose(force_sum[3:, :], force_sum_expected), force_out_sum
        assert np.allclose(moment_sum[3:, :], moment_sum_expected), moment_out_sum
        if IS_MATPLOTLIB:  # pragma: no cover
            M2 = moment_sum[:, 1]
            ax.plot(stations, M2, '*-', label='SMT')
            ax.legend()
            fig.show()
            x = 1
Exemplo n.º 3
0
def smt_setup(model: BDF):
    nids, nid_cd, icd_transform, xyz_cid0 = get_nid_cd_xyz_cid0(model)
    eids, element_centroids_cid0 = get_element_centroids(model)
    return nids, nid_cd, xyz_cid0, icd_transform, eids, element_centroids_cid0
    def plot_shear_moment_torque(self,
                                 model_name,
                                 gpforce: RealGridPointForcesArray,
                                 p1,
                                 p2,
                                 p3,
                                 zaxis,
                                 method: str = 'Z-Axis Projection',
                                 cid_p1: int = 0,
                                 cid_p2: int = 0,
                                 cid_p3: int = 0,
                                 cid_zaxis: int = 0,
                                 nplanes: int = 20,
                                 plane_color=None,
                                 plane_opacity=0.5,
                                 csv_filename=None,
                                 show=True,
                                 stop_on_failure=False):
        """
        Creates a shear moment torque plot for the active plot result

        Parameters
        ----------
        model_name : str
            the name of the model
        p1: (3,) float ndarray
            defines the starting point for the shear, moment, torque plot
        p3: (3,) float ndarray
            defines the end point for the shear, moment, torque plot
        p2: (3,) float ndarray
            defines the XZ plane for the shears/moments
        zaxis: (3,) float ndarray
            the direction of the z-axis
        cid_p1 / cid_p2 / cid_p3
            the coordinate systems for p1, p2, and p3
        method : str
           'CORD2R' : typical CORD2R
            'Z-Axis Projection' : project p2 on the z-axis
        """
        log = self.gui.log
        if plane_color is None:
            plane_color = PURPLE_FLOAT
        assert len(plane_color) == 3, plane_color

        model = self.gui.models[model_name]
        nids, nid_cd, icd_transform, xyz_cid0 = get_nid_cd_xyz_cid0(model)
        #xyz1, xyz2, xyz3, i, k, origin, xzplane, dim_max, stations
        try:
            xyz1, xyz2, xyz3, i, k, coord_out, iaxis_march, dim_max, stations = setup_coord_from_plane(
                model,
                xyz_cid0,
                p1,
                p2,
                p3,
                zaxis,
                method=method,
                cid_p1=cid_p1,
                cid_p2=cid_p2,
                cid_p3=cid_p3,
                cid_zaxis=cid_zaxis,
                nplanes=nplanes,
            )
        except ValueError as verror:
            model.log.error(str(verror))
            if stop_on_failure:
                raise
            return
        coord = coord_out
        #try:
        ## i/j/k vector is nan
        #coord = CORD2R(1, rid=0, origin=origin, zaxis=zaxis, xzplane=xzplane,
        #comment='')
        #except:
        #log.error('The coordinate system is invalid; check your cutting plane.')
        #if stop_on_failure:
        #raise
        #return None, None

        # the plane actor defines the plane of the output results,
        # not the plane of the march direction
        # xyz1: origin
        # xyz2: xzplane
        unused_plane_actor, unused_prop = self.create_plane_actor(
            xyz1,
            xyz2,
            coord,
            i,
            k,
            dim_max,
            plane_color,
            plane_opacity,
        )
        #if 0:
        #point_actor = self.gui.create_point_actor_from_points(
        #[xyz1, xyz3], point_size=8, actor_name='smt_points')
        #prop = point_actor.GetProperty()
        #prop.SetColor(*plane_color)
        #prop.SetOpacity(plane_opacity) # 0=transparent, 1=solid
        #point_actor.VisibilityOn()
        self.gui.rend.Render()
        self.gui.Render()

        eids, element_centroids_cid0 = get_element_centroids(model)
        force_sum, moment_sum, new_coords, nelems, nnodes = gpforce.shear_moment_diagram(
            nids,
            xyz_cid0,
            nid_cd,
            icd_transform,
            eids,
            element_centroids_cid0,
            stations,
            model.coords,
            coord,
            iaxis_march=iaxis_march,
            itime=0,
            debug=False,
            log=log)
        plot_smt(stations, force_sum, moment_sum, nelems, nnodes, show=show)
        return force_sum, moment_sum
Exemplo n.º 5
0
def smt_setup(model: BDF) -> Tuple[NDArrayNint, NDArrayN2int, NDArrayN3float,
                                   Dict[int, NDArrayNint], NDArrayNint, NDArrayN3float]:
    nids, nid_cd, icd_transform, xyz_cid0 = get_nid_cd_xyz_cid0(model)
    eids, element_centroids_cid0 = get_element_centroids(model, fdtype='float64')
    return nids, nid_cd, xyz_cid0, icd_transform, eids, element_centroids_cid0
Exemplo n.º 6
0
headers = force.get_headers()
istation = headers.index('station')
itime = 0
#ibending_moment1 = headers.index('bending_moment1')
ibending_moment2 = headers.index('bending_moment2')
#station = force.data[itime, :, istation]
#bending_moment1 = force.data[itime, :, ibending_moment1]
bending_moment2 = force.data[itime, :, ibending_moment2]

coord_out = model.coords[0]
nid_cp_cd, xyz_cid0, xyz_cp, icd_transform, icp_transform = model.get_xyz_in_coord_array(
    cid=0, fdtype='float64', idtype='int32')
all_nids = nid_cp_cd[:, 0]

all_eids, element_centroids_cid0 = get_element_centroids(model,
                                                         idtype='int32',
                                                         fdtype='float64')
stations = element_centroids_cid0[:-1, 0]
stations = np.linspace(0., 10., num=51)
#model.log.level = 'warning'
#print(stations)

nids_bar = []
nids_beam = []
for eid, elem in sorted(model.elements.items()):
    if elem.type == 'CBAR':
        nids_bar.append(elem.nodes)
    elif elem.type == 'BEAM':
        nids_beam.append(elem.nodes)
nids_bar = np.array(nids_bar, dtype='int32')
nids_beam = np.array(nids_beam, dtype='int32')