Exemple #1
0
/* *************************************************************** */
N_les *create_solve_les(N_geom_data * geom, N_gwflow_data2d * data,
			N_les_callback_2d * call, const char *solver,
			int maxit, double error, double sor)
{

    N_les *les;

    /*assemble the linear equation system */
    if (param.sparse->answer)
	les =
	    N_assemble_les_2d_dirichlet(N_SPARSE_LES, geom, data->status,
					data->phead, (void *)data, call);
    else
	les =
	    N_assemble_les_2d_dirichlet(N_NORMAL_LES, geom, data->status,
					data->phead, (void *)data, call);

    N_les_integrate_dirichlet_2d(les, geom, data->status, data->phead);

    /*solve the equation system */
    if (strcmp(solver, N_SOLVER_ITERATIVE_JACOBI) == 0)
	N_solver_jacobi(les, maxit, sor, error);

    if (strcmp(solver, N_SOLVER_ITERATIVE_SOR) == 0)
	N_solver_SOR(les, maxit, sor, error);

    if (strcmp(solver, N_SOLVER_ITERATIVE_CG) == 0)
	N_solver_cg(les, maxit, error);

    if (strcmp(solver, N_SOLVER_ITERATIVE_PCG) == 0)
	N_solver_pcg(les, maxit, error, N_DIAGONAL_PRECONDITION);

    if (strcmp(solver, N_SOLVER_ITERATIVE_BICGSTAB) == 0)
	N_solver_bicgstab(les, maxit, error);

    if (strcmp(solver, N_SOLVER_DIRECT_LU) == 0)
	N_solver_lu(les);

    if (strcmp(solver, N_SOLVER_DIRECT_CHOLESKY) == 0)
	N_solver_cholesky(les);

    if (strcmp(solver, N_SOLVER_DIRECT_GAUSS) == 0)
	N_solver_gauss(les);

    if (les == NULL)
	G_fatal_error(_("Unable to create and solve the linear equation system"));

    return les;
}
/* *************************************************************** */
int test_matrix_assemble_2d(void)
{

    N_geom_data *geom;
    N_les *les;
    N_les_callback_2d *call;
    N_array_2d *status;
    N_array_2d *start_val;

    /*set the callback to default */
    call = N_alloc_les_callback_2d();

    status = create_status_array_2d();
    start_val = create_value_array_2d();

    geom = N_alloc_geom_data();

    geom->dx = 1;
    geom->dy = 1;

    geom->Az = 1;

    geom->rows = TEST_N_NUM_ROWS;
    geom->cols = TEST_N_NUM_COLS;

    /*Assemble the matrix */
    les = N_assemble_les_2d(N_SPARSE_LES, geom, status, start_val, NULL, call);
    N_free_les(les);
    les = N_assemble_les_2d_active(N_SPARSE_LES, geom, status, start_val, NULL, call);
    N_free_les(les);
    les = N_assemble_les_2d_dirichlet(N_SPARSE_LES, geom, status, start_val, NULL, call);
    N_les_integrate_dirichlet_2d(les, geom, status, start_val);
    N_free_les(les);

    les = N_assemble_les_2d(N_NORMAL_LES, geom, status, start_val, NULL, call);
    N_free_les(les);
    les = N_assemble_les_2d_active(N_NORMAL_LES, geom, status, start_val, NULL, call);
    N_free_les(les);
    les = N_assemble_les_2d_dirichlet(N_NORMAL_LES, geom, status, start_val, NULL, call);
    N_les_integrate_dirichlet_2d(les, geom, status, start_val);
    N_free_les(les);

    G_free(geom);
    G_free(call);

    return 0;
}