Exemple #1
0
    def _compute_linear_coeff_sparse(self):
        """Compute M, K and C matrices of the Lagrangian DS
        K = Omega^2
        C = 2.Gamma
        """
        mass = sk.SimpleMatrix(self.ndof, self.ndof, sk.SPARSE, self.ndof)
        for i in range(self.ndof):
            mass.setValue(i, i, 1.)
        indices = np.arange(self.ndof)
        # --- Omega^2 matrix ---
        omega = npw.asrealarray(
            [1. + self.stiffness_coeff * j**2 for j in range(self.ndof)])
        coeff = (indices * math.pi * self.c0 / self.length)**2
        omega *= coeff
        stiffness_mat = sk.SimpleMatrix(self.ndof, self.ndof, sk.SPARSE,
                                        self.ndof)
        for i in range(self.ndof):
            stiffness_mat.setValue(i, i, omega[i])

        # 2.S.Gamma.S-1
        sigma = self.compute_damping(np.sqrt(omega) / (2. * math.pi))
        damping_mat = sk.SimpleMatrix(self.ndof, self.ndof, sk.SPARSE,
                                      self.ndof)
        for i in range(self.ndof):
            damping_mat.setValue(i, i, 2. * sigma[i])
        return mass, stiffness_mat, damping_mat
Exemple #2
0
 def compute_s_mat(self):
     """Compute 'S' matrix (normal modes)
     """
     indices = np.arange(self.ndof)
     row = indices.reshape(1, self.ndof)
     s_mat = npw.asrealarray(row * row.T)
     s_mat *= (math.pi / self._N)
     s_mat[...] = math.sqrt(2. / self.length) * np.sin(s_mat)
     return s_mat
Exemple #3
0
 def compute_initial_state_modal(self, max_coords):
     """Set initial positions of the string,
     assuming a triangular shape, with u[imax] = umax
     and modal form.
     """
     q0 = self._compute_initial_state_std(max_coords)
     q0[...] = np.dot(self.s_mat.T, q0)
     coeff = self.length / (self.n_modes + 1)
     q0 *= coeff
     return npw.asrealarray(q0)
Exemple #4
0
 def _compute_initial_state_std(self, imax, umax):
     """Set initial positions of the string,
     assuming a triangular shape, with u[imax] = umax.
     """
     dx = self.length / self._N
     slope = umax / (imax * dx)
     q0 = [slope * i * dx for i in range(imax)]
     slope = umax / (imax * dx - self.length)
     q0 += [slope * (i * dx - self.length) for i in range(imax, self.ndof)]
     return npw.asrealarray(q0)
Exemple #5
0
    def _compute_linear_coeff_dense(self):
        """Compute M, K and C matrices of the Lagrangian DS
        K = Omega^2
        C = 2.Gamma
        """
        mass = np.identity(self.ndof, dtype=np.float64)

        # --- Omega^2 matrix ---
        omega = npw.asrealarray(
            [1. + self.stiffness_coeff * j**2 for j in range(self.ndof)])
        indices = np.arange(self.ndof)
        coeff = (indices * math.pi * self.c0 / self.length)**2
        omega *= coeff
        stiffness_mat = npw.asrealarray(np.diag(omega))

        # 2.S.Gamma.S-1
        sigma = self.compute_damping(np.sqrt(omega) / (2. * math.pi))
        damping_mat = npw.asrealarray(np.diag(sigma))
        damping_mat *= 2.
        return mass, stiffness_mat, damping_mat
Exemple #6
0
    def compute_linear_coeff(self):
        """Compute M, K and C operators of the Lagrangian DS
        K = Omega^2
        C = 2.Gamma
        M = I
        """
        #mass = np.ones(self.n_modes, dtype=np.float64)
        # --- Omega^2 vector ---
        omega2 = npw.asrealarray([1. + self.stiffness_coeff * (j ** 2)
                                  for j in range(1, self.n_modes + 1)])
        indices = np.arange(1, self.n_modes + 1)
        coeff = (indices * math.pi * self.c0 / self.length) ** 2
        omega2 *= coeff
        stiffness_mat = npw.asrealarray(omega2)

        # 2.S.Gamma.S-1
        sigma = self.compute_damping(np.sqrt(omega2) / (2. * math.pi))
        damping_mat = npw.asrealarray(sigma)
        damping_mat *= 2.
        return stiffness_mat, damping_mat
Exemple #7
0
    def read_linear_coeff(self, radix):
        """Read K and C operators of the Lagrangian DS
        K = Omega^2
        C = 2.Gamma
        from matlab files
        """

        freq_file = radix + '_frequs.mat'
        damp_file = radix + '_amortissements.mat'
        nuj = scipy.io.loadmat(freq_file)['frequs'][:, 0]
        assert nuj.size == self.n_modes
        omega2 = (2. * np.pi * nuj)**2
        stiffness_mat = npw.asrealarray(omega2)
        if os.path.exists(damp_file):
            sigmas = scipy.io.loadmat(damp_file)['sig0'][:, 0]
            assert sigmas.size == self.n_modes
            damping_mat = 2. * npw.asrealarray(sigmas)
        else:
            print("Warning: no input for damping. Set damping matrix to zero.")
            damping_mat = None
        return stiffness_mat, damping_mat
Exemple #8
0
 def _compute_initial_state_std(self, max_coords):
     """Set initial positions of the string,
     assuming a triangular shape, with u[imax] = umax.
     """
     umax = max_coords[0]
     # index of the max
     dx = self.space_step
     imax = int(round(max_coords[1] / dx))
     slope = umax / (imax * dx)
     u0 = [slope * i * dx for i in range(imax)]
     slope = umax / (imax * dx - self.length)
     u0 += [slope * (i * dx - self.length)
            for i in range(imax, self.n_modes + 2)]
     return npw.asrealarray(u0[1:-1])
Exemple #9
0
 def compute_initial_state_modal(self, max_coords):
     """Set initial positions of the string,
     assuming a triangular shape, with u[imax] = umax
     and modal form.
     """
     if max_coords is None:
         assert self.matlab_input is not None
         inputfile = self.matlab_input + '_q2.mat'
         q0 = scipy.io.loadmat(inputfile)['q2'][:, 0].copy()
         self.u0 = np.dot(self.s_mat, q0)
         self.max_coords = (self.u0.max(), self.x[self.u0.argmax()])
         return q0
     else:
         self.u0 = self._compute_initial_state_std(max_coords)
         q0 = np.dot(self.s_mat.T, self.u0)
         coeff = self.length / (self.n_modes + 1)
         q0 *= coeff
         return npw.asrealarray(q0)