예제 #1
0
PROBLEM* add_new_problem(const char* name, int number){
	static BOOL problems_initialized = FALSE;
	PROBLEM* prob;
	
	if(problems_initialized == FALSE){
		problems = ll_create(&problem_free);
		problems_initialized = TRUE;
	}
	
	prob = problem_initialize(name, number);
	ll_push_back(problems, prob);
	
	return prob;
}
예제 #2
0
파일: laplacian.c 프로젝트: hovr2pi/MASA
int main(int argc, char *argv[])
{
    int n;
    double length;
    pstruct model;		/* primary model data structure */
    int solver;

    /* Parse command-line */

    if(argc < 3)
    {
        printf("\nUsage: laplacian [num_pts] [length] [gauss/cg]\n\n");
        printf("\"num_pts\" is the desired number of mesh points \n");
        printf("\"length\" is the physical length-scale dimension in one direction\n");
        printf("\"gauss/cg\" is which method is used: \n");
        printf("                                    0 --> Gauss-Seidel \n");
        printf("                                    1 --> Conjugate Gradient. \n\n");
        exit(1);
    }
    else if(argc == 3)
    {
        n      = atoi(argv[1]);
        length = (double) atof(argv[2]);
        solver = 0; // default to gauss
    }
    else
    {
        n      = atoi(argv[1]);
        length = (double) atof(argv[2]);
        solver = atoi(argv[3]);

        if(solver > 1 || solver < 0)
        {
            printf("solver only accepts 0,1 for input");
            exit(1);
        }
    }

    /* Problem Initialization */

    problem_initialize (n,length,&model);
    assemble_matrix    (central_2nd_order,&model);
    //assemble_matrix    (central_4th_order,&model);
    init_masa          (&model);
    apply_bcs          (&model);

    print_matrix(&model);

    /* Solve */

    if(solver == 1)
    {
        solve_cg   (&model);
    }
    else
    {
        solve_gauss(&model);
    }

    /* Compute Error */

    printf("\n** Error Analysis\n");
    printf("   --> npts     = %i\n",model.npts);
    printf("   --> h        = %12.5e\n",model.h);
    printf("   --> l2 error = %12.5e\n",compute_l2_error(&model));

    return 0;
}