def _execute_eigen_direct_complex_solver_test(self, class_name, solver_type): # check if solver is available if (not hasattr(EigenSolversApplication, class_name)): self.skipTest( class_name + " is not included in the compilation of the EigenSolversApplication" ) space = KratosMultiphysics.UblasComplexSparseSpace() settings = KratosMultiphysics.Parameters( '{ "solver_type" : "EigenSolversApplication.' + solver_type + '" }') solver = ConstructSolver(settings) a = KratosMultiphysics.CompressedMatrix() this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname( os.path.dirname(os.path.dirname(this_file_dir))) matrix_file_path = os.path.join(base_dir, "kratos", "tests", "auxiliar_files_for_python_unittest", "sparse_matrix_files", "A.mm") file_read = KratosMultiphysics.ReadMatrixMarketMatrix( matrix_file_path, a) # symmetric test matrix self.assertTrue(file_read, msg="The MatrixFile could not be read") a = KratosMultiphysics.ComplexCompressedMatrix(a) dimension = a.Size1() self.assertEqual(dimension, 900) b_exp = KratosMultiphysics.ComplexVector(dimension) for i in range(dimension): b_exp[i] = complex(i + 1, i - 1) x = KratosMultiphysics.ComplexVector(dimension) solver.Solve(a, x, b_exp) b_act = KratosMultiphysics.ComplexVector(dimension) space.Mult(a, x, b_act) for i in range(dimension): self.assertAlmostEqual(b_act[i], b_exp[i], 7)
def _execute_eigen_direct_solver_test(self, class_name, solver_type): # check if solver is available if (not hasattr(EigenSolversApplication, class_name)): self.skipTest( class_name + " is not included in the compilation of the EigenSolversApplication" ) space = KratosMultiphysics.UblasSparseSpace() settings = KratosMultiphysics.Parameters( '{ "solver_type" : "EigenSolversApplication.' + solver_type + '" }') solver = ConstructSolver(settings) a = KratosMultiphysics.CompressedMatrix() this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname( os.path.dirname(os.path.dirname(this_file_dir))) matrix_file_path = os.path.join(base_dir, "kratos", "tests", "A.mm") KratosMultiphysics.ReadMatrixMarketMatrix(matrix_file_path, a) # symmetric test matrix dimension = a.Size1() self.assertEqual(dimension, 900) b_exp = KratosMultiphysics.Vector( dimension) # [1, 2, ..., dimension-1, dimension] for i in range(dimension): b_exp[i] = i + 1 x = KratosMultiphysics.Vector(dimension) solver.Solve(a, x, b_exp) b_act = KratosMultiphysics.Vector(dimension) space.Mult(a, x, b_act) for i in range(dimension): self.assertAlmostEqual(b_act[i], b_exp[i], 7)
def _create_linear_solver(self): from KratosMultiphysics.python_linear_solver_factory import ConstructSolver return ConstructSolver(self.settings["linear_solver_settings"])