Example #1
0
    def setUp(self):
        if not os.access('.', os.W_OK):
            raise RuntimeError('Cannot write to current directory')

        self.test_dir = 'file_LTIGalerkinProj_DELETE_ME'
        if parallel.is_rank_zero() and not os.path.exists(self.test_dir):
            os.mkdir(self.test_dir)
        parallel.barrier()

        self.basis_vec_path = join(self.test_dir, 'basis_vec_%02d.txt')
        self.adjoint_basis_vec_path = join(self.test_dir,
                                           'adjoint_basis_vec_%02d.txt')
        self.A_on_basis_vec_path = join(self.test_dir, 'A_on_mode_%02d.txt')
        self.B_on_basis_path = join(self.test_dir, 'B_on_basis_%02d.txt')
        self.C_on_basis_vec_path = join(self.test_dir, 'C_on_mode_%02d.txt')

        self.num_basis_vecs = 10
        self.num_adjoint_basis_vecs = 10
        self.num_states = 11
        self.num_inputs = 3
        self.num_outputs = 2

        self.generate_data_set(self.num_basis_vecs,
                               self.num_adjoint_basis_vecs, self.num_states,
                               self.num_inputs, self.num_outputs)

        self.LTI_proj = lgp.LTIGalerkinProjectionHandles(
            np.vdot,
            self.basis_vec_handles,
            adjoint_basis_vec_handles=self.adjoint_basis_vec_handles,
            is_basis_orthonormal=True,
            verbosity=0)
Example #2
0
 def test_adjoint_basis_vec_optional(self):
     """Test that adjoint modes default to direct modes"""
     no_adjoints_LTI_proj = lgp.LTIGalerkinProjectionHandles(
         np.vdot,
         self.basis_vec_handles,
         is_basis_orthonormal=True,
         verbosity=0)
     np.testing.assert_equal(no_adjoints_LTI_proj.adjoint_basis_vec_handles,
                             self.basis_vec_handles)
Example #3
0
    def test_reduce_B(self):
        """Given modes, test reduced B matrix, orthogonal and non-orthogonal."""
        B_returned = self.LTI_proj.reduce_B(self.B_on_standard_basis_handles)
        np.testing.assert_allclose(B_returned, self.B_true)

        LTI_proj = LGP.LTIGalerkinProjectionHandles(np.vdot,
            self.basis_vec_handles, self.adjoint_basis_vec_handles,
            is_basis_orthonormal=False, verbosity=0)
        B_returned = LTI_proj.reduce_B(self.B_on_standard_basis_handles)
        np.testing.assert_allclose(B_returned, self.B_true_nonorth)
Example #4
0
    def test_reduce_A(self):
        """Reduction of A array for Array, LookUp operators and in_memory."""
        A_returned = self.LTI_proj.reduce_A(self.A_on_basis_vec_handles)
        np.testing.assert_allclose(A_returned, self.A_true)

        LTI_proj = lgp.LTIGalerkinProjectionHandles(
            np.vdot,
            self.basis_vec_handles,
            adjoint_basis_vec_handles=self.adjoint_basis_vec_handles,
            is_basis_orthonormal=False,
            verbosity=0)
        A_returned = LTI_proj.reduce_A(self.A_on_basis_vec_handles)
        np.testing.assert_allclose(LTI_proj._proj_array, self.proj_array)
        np.testing.assert_allclose(A_returned, self.A_true_non_orth)
Example #5
0
    def test_reduce_A(self):
        """Reduction of A matrix for Matrix, LookUp operators and in_memory."""
        # Precomputed operations A object with vec handles
        A_returned = self.LTI_proj.reduce_A(self.A_on_basis_vec_handles)
        np.testing.assert_allclose(A_returned, self.A_true)

        # Precomputed operations A object with vec handles, non-orthonormal
        # modes
        LTI_proj = LGP.LTIGalerkinProjectionHandles(
            np.vdot, self.basis_vec_handles, self.adjoint_basis_vec_handles,
            is_basis_orthonormal=False, verbosity=0)
        A_returned = LTI_proj.reduce_A(self.A_on_basis_vec_handles)
        np.testing.assert_allclose(LTI_proj._proj_mat, self.proj_mat)
        np.testing.assert_allclose(A_returned, self.A_true_nonorth)