int main (void) { OS_ERR err; #if (CPU_CFG_NAME_EN == DEF_ENABLED) CPU_ERR cpu_err; #endif CPU_Init(); /* Initialize the CPU abstraction layer. */ Mem_Init(); /* Initialize the Memory Management Module. */ Math_Init(); /* Initialize the Mathematical Module. */ #if (CPU_CFG_NAME_EN == DEF_ENABLED) CPU_NameSet((CPU_CHAR *)"MKL46Z256VLL4", (CPU_ERR *)&cpu_err); #endif BSP_IntDisAll(); /* Disable all interrupts. */ #if (defined(TRACE_CFG_EN) && (TRACE_CFG_EN > 0u)) TRACE_INIT(); /* Initialize the µC/Trace recorder. */ TRACE_START(); /* Start recording. */ #endif OSInit(&err); /* Initialize "uC/OS-III, The Real-Time Kernel". */ OSMutexCreate((OS_MUTEX *)&AppMutex, (CPU_CHAR *)"My App. Mutex", (OS_ERR *)&err); OSQCreate ((OS_Q *)&AppQ, (CPU_CHAR *)"My App Queue", (OS_MSG_QTY )10, (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&App_TaskStartTCB, /* Create the startup task. */ (CPU_CHAR *)"Startup Task", (OS_TASK_PTR ) App_TaskStart, (void *) 0, (OS_PRIO ) APP_CFG_TASK_START_PRIO, (CPU_STK *)&App_TaskStartStk[0], (CPU_STK )(APP_CFG_TASK_START_STK_SIZE / 10u), (CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE, (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */ while(DEF_ON) { /* Should Never Get Here */ }; }
//--------------------------------------------------------------------------------------------------- // Main //--------------------------------------------------------------------------------------------------- int main (void) { OS_ERR aErr; SCB_SHPR2=(3<<30); #if (CPU_CFG_NAME_EN == DEF_ENABLED) CPU_ERR aCpuErr; #endif // Initialize the CPU abstraction layer CPU_Init(); //Initialize the Memory Management Module Mem_Init(); // Initialize the Mathematical Module Math_Init(); #if (CPU_CFG_NAME_EN == DEF_ENABLED) CPU_NameSet((CPU_CHAR *)"MKL46Z256VLL4",(CPU_ERR *)&aCpuErr); #endif // Disable all interrupts BSP_IntDisAll(); #if (defined(TRACE_CFG_EN) && (TRACE_CFG_EN > 0u)) TRACE_INIT(); // Initialize the µC/Trace recorder TRACE_START(); // Start recording #endif // Initialize "uC/OS-III, The Real-Time Kernel" OSInit(&aErr); // Création de la tâche de démarrage OSTaskCreate((OS_TCB *)&sAppTaskStartTCB, (CPU_CHAR *)"Startup Task", (OS_TASK_PTR ) AppTaskStart, (void *) 0, (OS_PRIO ) kStartTaskPr, (CPU_STK *)&sAppTaskStartStk[0], (CPU_STK )(kStackSize / 10u), (CPU_STK_SIZE) kStackSize, (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&aErr); // Démarrage du multitâche OSStart(&aErr); // On ne doit jamais se trouver ici... while(1); }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); TRACE_START("trace.txt"); DEBUG_OUTPUT_ON; SET_VERBOSE_LEVEL(0); if (argc < 2) error("Not enough parameters."); ECopyType copy_type = parse_copy_type(args[1]); if (copy_type == CT_NONE) error("Unknown copy type (%s).\n", args[1]); Mesh mesh; H3DReader mesh_loader; if (!mesh_loader.load(args[2], &mesh)) error("Loading mesh file '%s'\n", args[2]); // apply refinements bool ok = true; for (int k = 3; k < argc && ok; k += 2) { int elem_id, reft_id; sscanf(args[k], "%d", &elem_id); reft_id = parse_reft(args[k + 1]); ok = mesh.refine_element(elem_id, reft_id); } if (ok) { Mesh dup; switch (copy_type) { case CT_COPY: dup.copy(mesh); break; case CT_COPY_BASE: dup.copy_base(mesh); break; default: break; } dup.dump(); } else { warning("Unable to refine a mesh."); res = ERR_FAILURE; } #ifdef WITH_PETSC PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); TRACE_START("trace.txt"); DEBUG_OUTPUT_ON; SET_VERBOSE_LEVEL(0); if (argc < 1) error("Not enough parameters"); Mesh mesh; Mesh3DReader mesh_loader; if (!mesh_loader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]); // apply refinements bool ok = true; for (int k = 2; k < argc && ok; k += 2) { int elem_id, reft_id; sscanf(args[k], "%d", &elem_id); reft_id = parse_reft(args[k + 1]); ok = mesh.refine_element(elem_id, reft_id); } if (ok) { mesh.dump(); } else { warning("Unable to refine a mesh."); res = ERR_FAILURE; } #ifdef WITH_PETSC PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); TRACE_START("trace.txt"); DEBUG_OUTPUT_ON; SET_VERBOSE_LEVEL(0); if (argc < 5) error("Not enough parameters"); sscanf(args[2], "%d", &m); sscanf(args[3], "%d", &n); sscanf(args[4], "%d", &o); printf("* Loading mesh '%s'\n", args[1]); Mesh mesh; Mesh3DReader mloader; if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]); H1ShapesetLobattoHex shapeset; printf("* Setting the space up\n"); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); int mx = maxn(4, m, n, o, 4); order3_t order(mx, mx, mx); // order3_t order(1, 1, 1); // order3_t order(m, n, o); printf(" - Setting uniform order to (%d, %d, %d)\n", mx, mx, mx); space.set_uniform_order(order); int ndofs = space.assign_dofs(); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf; wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<ord_t, ord_t>); LinearProblem lp(&wf, &space); // assemble stiffness matrix printf(" - assembling...\n"); fflush(stdout); Timer assemble_timer; assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); printf("%s (%lf secs)\n", assemble_timer.get_human_time(), assemble_timer.get_seconds()); // solve the stiffness matrix printf(" - solving... "); fflush(stdout); Timer solve_timer; solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); printf("%s (%lf secs)\n", solve_timer.get_human_time(), solve_timer.get_seconds()); // mat.dump(stdout, "a"); // rhs.dump(stdout, "b"); if (solved) { Solution sln(&mesh); sln.set_coeff_vector(&space, solver.get_solution()); // printf("* Solution:\n"); // double *s = solver.get_solution(); // for (int i = 1; i <= ndofs; i++) { // printf(" x[% 3d] = % lf\n", i, s[i]); // } ExactSolution ex_sln(&mesh, exact_solution); // norm double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &ex_sln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &ex_sln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); if (h1_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #if 0 //def OUTPUT_DIR printf("* Output\n"); // output const char *of_name = OUTPUT_DIR "/solution.pos"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { ExactSolution ex_sln(&mesh, exact_solution); DiffFilter eh(&sln, &ex_sln); // DiffFilter eh_dx(&mesh, &sln, &ex_sln, FN_DX, FN_DX); // DiffFilter eh_dy(&mesh, &sln, &ex_sln, FN_DY, FN_DY); // DiffFilter eh_dz(&mesh, &sln, &ex_sln, FN_DZ, FN_DZ); GmshOutputEngine output(ofile); output.out(&sln, "Uh"); // output.out(&sln, "Uh dx", FN_DX_0); // output.out(&sln, "Uh dy", FN_DY_0); // output.out(&sln, "Uh dz", FN_DZ_0); output.out(&eh, "Eh"); // output.out(&eh_dx, "Eh dx"); // output.out(&eh_dy, "Eh dy"); // output.out(&eh_dz, "Eh dz"); output.out(&ex_sln, "U"); // output.out(&ex_sln, "U dx", FN_DX_0); // output.out(&ex_sln, "U dy", FN_DY_0); // output.out(&ex_sln, "U dz", FN_DZ_0); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } else res = ERR_FAILURE; #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(NULL, NULL, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); TRACE_START("trace.txt"); DEBUG_OUTPUT_ON; SET_VERBOSE_LEVEL(0); try { for (int i = 0; i < 48; i++) { for (int j = 0; j < 48; j++) { // int i = 5; { // int j = 0; { printf("Config: %d, %d ", i, j); Mesh mesh; for (Word_t k = 0; k < countof(vtcs); k++) mesh.add_vertex(vtcs[k].x, vtcs[k].y, vtcs[k].z); Word_t h1[] = { hexs[0][i][0] + 1, hexs[0][i][1] + 1, hexs[0][i][2] + 1, hexs[0][i][3] + 1, hexs[0][i][4] + 1, hexs[0][i][5] + 1, hexs[0][i][6] + 1, hexs[0][i][7] + 1 }; mesh.add_hex(h1); Word_t h2[] = { hexs[1][j][0] + 1, hexs[1][j][1] + 1, hexs[1][j][2] + 1, hexs[1][j][3] + 1, hexs[1][j][4] + 1, hexs[1][j][5] + 1, hexs[1][j][6] + 1, hexs[1][j][7] + 1 }; mesh.add_hex(h2); // bc for (Word_t k = 0; k < countof(bnd); k++) { Word_t facet_idxs[Quad::NUM_VERTICES] = { bnd[k][0] + 1, bnd[k][1] + 1, bnd[k][2] + 1, bnd[k][3] + 1 }; mesh.add_quad_boundary(facet_idxs, bnd[k][4]); } mesh.ugh(); // mesh.dump(); // Element *hx[] = { mesh.elements[1], mesh.elements[2] }; // printf("[%d, %d]\n", hx[0]->get_face_orientation(1), hx[1]->get_face_orientation(2)); // Word_t fidx[4]; // hx[1]->get_face_vertices(2, fidx); // printf("FI: %d, %d, %d, %d\n", fidx[0], fidx[1], fidx[2], fidx[3]); printf("\n"); #ifdef OUTPUT_DIR BEGIN_BLOCK // output the mesh const char *of_name = OUTPUT_DIR "/ref.msh"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { GmshOutputEngine output(ofile); output.out(&mesh); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } END_BLOCK #endif H1ShapesetLobattoHex shapeset; // printf("* Setting the space up\n"); H1Space space(&mesh, &shapeset); space.set_bc_types(bc_types); space.set_essential_bc_values(essential_bc_values); #ifdef XM_YN_ZO order3_t ord(4, 4, 4); #elif defined XM_YN_ZO_2 order3_t ord(4, 4, 4); #elif defined X2_Y2_Z2 order3_t ord(2, 2, 2); #endif // printf(" - Setting uniform order to (%d, %d, %d)\n", dir_x, dir_y, dir_z); space.set_uniform_order(ord); space.assign_dofs(); // printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoLinearSolver solver; #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf; #ifdef DIRICHLET wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>); #elif defined NEWTON wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<ord_t, ord_t>, SYM); wf.add_matrix_form_surf(bilinear_form_surf<double, scalar>, bilinear_form_surf<ord_t, ord_t>); wf.add_vector_form(linear_form<double, scalar>, linear_form<ord_t, ord_t>); wf.add_vector_form_surf(linear_form_surf<double, scalar>, linear_form_surf<ord_t, ord_t>); #endif LinProblem lp(&wf); lp.set_space(&space); // assemble stiffness matrix lp.assemble(&mat, &rhs); // solve the stiffness matrix bool solved = solver.solve(); if (!solved) throw ERR_FAILURE; // { // char file_name[1024]; // sprintf(file_name, "%s/matrix-%d-%d", OUTPUT_DIR, i, j); // FILE *file = fopen(file_name, "w"); // if (file != NULL) { // solver.dump_matrix(file, "A"); // solver.dump_rhs(file, "b"); // // fclose(file); // } // } Solution sln(&mesh); sln.set_fe_solution(&space, solver.get_solution()); ExactSolution exsln(&mesh, exact_solution); // norm double h1_sln_norm = h1_norm(&sln); double h1_err_norm = h1_error(&sln, &exsln); printf(" - H1 solution norm: % le\n", h1_sln_norm); printf(" - H1 error norm: % le\n", h1_err_norm); double l2_sln_norm = l2_norm(&sln); double l2_err_norm = l2_error(&sln, &exsln); printf(" - L2 solution norm: % le\n", l2_sln_norm); printf(" - L2 error norm: % le\n", l2_err_norm); assert(h1_sln_norm > 0 && h1_err_norm > 0); assert(l2_sln_norm > 0 && l2_err_norm > 0); // // out fn // char fname[4096]; // sprintf(fname, "%s/cfg-%d-%d.pos", OUTPUT_DIR, i, j); // FILE *fnf = fopen(fname, "w"); // assert(fnf != NULL); // GmshOutputEngine out(fnf); // char var[64]; // sprintf(var, "%d_%d", i, j); // out.out(&sln, var); // fclose(fnf); // // char mfname[4096]; // sprintf(mfname, "%s/mesh-%d-%d.ref", OUTPUT_DIR, i, j); // FILE *mfnf = fopen(mfname, "w"); // assert(mfnf != NULL); // GmshOutputEngine outm(mfnf); // outm.out(&mesh); // fclose(mfnf); if (h1_err_norm > EPS || l2_err_norm > EPS) { // calculated solution is not enough precise printf("Solution is not precise enough.\n"); throw ERR_FAILURE; } printf("Passed\n"); } } } catch (int e) { res = e; printf("Failed\n"); } #ifdef WITH_PETSC PetscFinalize(); #endif TRACE_END; return res; }