Beispiel #1
0
value_array_type create_b_vector(
    idx nv,
    idx_array_type kok_xadj,
    idx_edge_array_type kok_adj,
    value_array_type kok_mtx_vals,
    value_array_type x_vector){


  value_array_type b_vector ("B VECTOR", nv);
  Kokkos::parallel_for (Kokkos::RangePolicy<MyExecSpace> (0, nv) ,
      SPMV(
          kok_xadj,
          kok_adj,
          kok_mtx_vals,
          x_vector,
          b_vector));
  return b_vector;
}
Beispiel #2
0
TEUCHOS_UNIT_TEST( MCSA, one_step_solve_test)
{
    int N = 100;
    int problem_size = N*N;

    // Build the diffusion operator.
    double bc_val = 10.0;
    double dx = 0.01;
    double dy = 0.01;
    double dt = 0.01;
    double alpha = 0.01;
    HMCSA::DiffusionOperator diffusion_operator( 5,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	bc_val, bc_val, bc_val, bc_val,
	N, N,
	dx, dy, dt, alpha );

    Teuchos::RCP<Epetra_CrsMatrix> A = diffusion_operator.getCrsMatrix();
    Epetra_Map map = A->RowMap();

    // Solution Vectors.
    std::vector<double> x_vector( problem_size );
    Epetra_Vector x( View, map, &x_vector[0] );

    std::vector<double> x_aztec_vector( problem_size );
    Epetra_Vector x_aztec( View, map, &x_aztec_vector[0] );
    
    // Build source - set intial and Dirichlet boundary conditions.
    std::vector<double> b_vector( problem_size, 1.0 );
    int idx;
    for ( int j = 1; j < N-1; ++j )
    {
	int i = 0;
	idx = i + j*N;
	b_vector[idx] = bc_val;
    }
    for ( int j = 1; j < N-1; ++j )
    {
	int i = N-1;
	idx = i + j*N;
	b_vector[idx] = bc_val;
    }
    for ( int i = 0; i < N; ++i )
    {
	int j = 0;
	idx = i + j*N;
	b_vector[idx] = bc_val;
    }
    for ( int i = 0; i < N; ++i )
    {
	int j = N-1;
	idx = i + j*N;
	b_vector[idx] = bc_val;
    }
    Epetra_Vector b( View, map, &b_vector[0] );

    // MCSA Linear problem.
    Teuchos::RCP<Epetra_LinearProblem> linear_problem = Teuchos::rcp(
    	new Epetra_LinearProblem( A.getRawPtr(), &x, &b ) );

    // MCSA Jacobi precondition.
    Teuchos::RCP<Epetra_CrsMatrix> H = buildH( A );
    double spec_rad_H = HMCSA::OperatorTools::spectralRadius( H );
    std::cout << std::endl << std::endl
    	      << "---------------------" << std::endl
    	      << "Iteration matrix spectral radius: " 
    	      << spec_rad_H << std::endl;

    HMCSA::JacobiPreconditioner preconditioner( linear_problem );
    preconditioner.precondition();

    H = buildH( preconditioner.getOperator() );
    double spec_rad_precond_H = 
    	HMCSA::OperatorTools::spectralRadius( H );
    std::cout << "Preconditioned iteration matrix spectral radius: "
    	      << spec_rad_precond_H << std::endl
    	      << "---------------------" << std::endl;
}
Beispiel #3
0
//---------------------------------------------------------------------------//
int main( int argc, char** argv )
{
    // Problem parameters.
    int xN = 201;
    int yN = 201;
    int problem_size = xN*yN;

    double x_min = 0.0;
    double x_max = 2.0;
    double y_min = 0.0;
    double y_max = 2.0;

    double ic_val = 0.0;
    double bc_val_xmin = 0.0;
    double bc_val_xmax = 0.0;
    double bc_val_ymin = 10.0;
    double bc_val_ymax = 10.0;

    int num_steps = 1;
    double T = 0.01;

    double dx = (x_max-x_min)/(xN-1);
    double dy = (y_max-y_min)/(yN-1);
    double dt = T / num_steps;

    double alpha = 0.01;

    int max_iters = 1000;
    double tolerance = 1.0e-8;
    int num_histories = 40000;
    double weight_cutoff = 1.0e-12;

    // Setup up a VTK mesh for output.
    HMCSA::VtkWriter vtk_writer( x_min, x_max, y_min, y_max,
				 dx, dy, xN, yN );

    // Build the Diffusion operator.
    HMCSA::DiffusionOperator diffusion_operator(
	5,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	HMCSA::HMCSA_DIRICHLET,
	bc_val_xmin, bc_val_xmax, bc_val_ymin, bc_val_ymax,
	xN, yN,
	dx, dy, dt, alpha );

    Teuchos::RCP<Epetra_CrsMatrix> A = diffusion_operator.getCrsMatrix();
    Epetra_Map map = A->RowMap();

    // Solution Vector.
    std::vector<double> x_vector( problem_size );
    Epetra_Vector x( View, map, &x_vector[0] );
    
    // Build source - set intial and Dirichlet boundary conditions.
    std::vector<double> b_vector( problem_size, ic_val );
    buildIC( b_vector, xN, yN,
	     bc_val_xmin, bc_val_xmax, bc_val_ymin, bc_val_ymax );
    Epetra_Vector b( View, map, &b_vector[0] );

    // Linear problem.
    Teuchos::RCP<Epetra_LinearProblem> linear_problem = Teuchos::rcp(
    	new Epetra_LinearProblem( A.getRawPtr(), &x, &b ) );

    // Time step.
    HMCSA::TimeIntegrator time_integrator( linear_problem, vtk_writer );
    time_integrator.integrate( true, num_steps, max_iters, 
			       tolerance, num_histories,
			       weight_cutoff );    

    return 0;
}
TEUCHOS_UNIT_TEST( MCSA, MCSA_test)
{
    int problem_size = 16;

    Epetra_SerialComm comm;
    Epetra_Map map( problem_size, 0, comm );

    std::vector<double> x_vector( problem_size );
    Epetra_Vector x( View, map, &x_vector[0] );

    std::vector<double> x_aztec_vector( problem_size );
    Epetra_Vector x_aztec( View, map, &x_aztec_vector[0] );

    std::vector<double> b_vector( problem_size, 0.4 );
    Epetra_Vector b( View, map, &b_vector[0] );

    Teuchos::RCP<Epetra_CrsMatrix> A = 
	Teuchos::rcp( new Epetra_CrsMatrix( Copy, map, problem_size ) );
    double lower_diag = -0.1;
    double diag = 2.4;
    double upper_diag = -0.1;
    int global_row = 0;
    int lower_row = 0;
    int upper_row = 0;
    for ( int i = 0; i < problem_size; ++i )
    {
	global_row = A->GRID(i);
	lower_row = i-1;
	upper_row = i+1;
	if ( lower_row > -1 )
	{
	    A->InsertGlobalValues( global_row, 1, &lower_diag, &lower_row );
	}
	A->InsertGlobalValues( global_row, 1, &diag, &global_row );
	if ( upper_row < problem_size )
	{
	    A->InsertGlobalValues( global_row, 1, &upper_diag, &upper_row );
	}
    }
    A->FillComplete();

    double spec_rad_A = HMCSA::OperatorTools::spectralRadius( A );
    std::cout << std::endl <<
	"Operator spectral radius: " << spec_rad_A << std::endl;

    Teuchos::RCP<Epetra_LinearProblem> linear_problem = Teuchos::rcp(
	new Epetra_LinearProblem( A.getRawPtr(), &x, &b ) );

    HMCSA::JacobiPreconditioner preconditioner( linear_problem );
    preconditioner.precondition();

    HMCSA::MCSA mcsa_solver( linear_problem );
    mcsa_solver.iterate( 100, 1.0e-8, 100, 1.0e-8 );
    std::cout << "MCSA ITERS: " << mcsa_solver.getNumIters() << std::endl;

    Epetra_LinearProblem aztec_linear_problem( A.getRawPtr(), &x_aztec, &b );
    AztecOO aztec_solver( aztec_linear_problem );
    aztec_solver.SetAztecOption( AZ_solver, AZ_gmres );
    aztec_solver.Iterate( 100, 1.0e-8 );

    std::vector<double> error_vector( problem_size );
    Epetra_Vector error( View, map, &error_vector[0] );
    for (int i = 0; i < problem_size; ++i)
    {
	error[i] = x[i] - x_aztec[i];
    }
    double error_norm;
    error.Norm2( &error_norm );
    std::cout << std::endl << 
	"Aztec GMRES vs. MCSA absolute error L2 norm: " << 
	error_norm << std::endl;    
}