void example_2d() { const double Ly = 2*M_PI; const double Lx = 2*M_PI; const ptrdiff_t N0 = 100; const ptrdiff_t N1 = 100; const double dy = Ly/N0; const double dx = Lx/N1; FFTWPoisson2DMPI solver(N0, Ly, N1, Lx); const int nx = solver.get_nx(); const int ny = solver.get_ny(); const int y0 = solver.get_y0(); double *x = new double[nx*ny]; double *s = new double[nx*ny]; build_problem(x, y0, ny, dy, 0, nx, dx, 10); build_solution(s, y0, ny, dy, 0, nx, dx, 10); solver.solve(x); double err = 0; for(int i=0; i<nx*ny; i++) err = std::max(err, std::abs(x[i]-s[i])); std::cout << err << std::endl; delete x, s; }
void hypre_example_2d() { const double Ly = 2*M_PI; const double Lx = 2*M_PI; const ptrdiff_t N0 = 100; const ptrdiff_t N1 = 100; const double dy = Ly/(N0+1); const double dx = Lx/(N1+1); HypreSolver2D solver(N0, Ly, N1, Lx); const int nx = solver.get_nx(); const int ny = solver.get_ny(); const int y0 = solver.get_y0(); double *x = new double[nx*ny]; double *s = new double[nx*ny]; build_problem(x, y0+1, ny, dy, 1, nx, dx, 10); build_solution(s, y0+1, ny, dy, 1, nx, dx, 10); solver.solve(&x[0]); // I want to make sure that it works multiple times. // It is not always clear from the hypre function calls // that this will work as expected build_problem(x, y0+1, ny, dy, 1, nx, dx, 10); solver.solve(&x[0]); int num_iterations = solver.get_num_iterations(); double final_res_norm = solver.get_final_res_norm(); double err = 0; for(int i=0; i<nx*ny; i++) err = std::max(err, std::abs(x[i]-s[i])); std::cout << err << ' ' << num_iterations << ' ' << final_res_norm << std::endl; delete x, s; }
void hypre_example_3d() { const double Lz = 2*M_PI; const double Ly = 2*M_PI; const double Lx = 2*M_PI; const ptrdiff_t N0 = 100; const ptrdiff_t N1 = 100; const ptrdiff_t N2 = 100; const double dz = Lz/(N0+1); const double dy = Ly/(N1+1); const double dx = Lx/(N2+1); HypreSolver3D solver(N0, Lz, N1, Ly, N2, Lx); const int nz = solver.get_nz(); const int nx = solver.get_nx(); const int ny = solver.get_ny(); const int z0 = solver.get_z0(); double *x = new double[nx*ny*nz]; double *s = new double[nx*ny*nz]; build_problem(x, z0+1, nz, dz, 1, ny, dy, 1, nx, dx, 10); build_solution(s, z0+1, nz, dz, 1, ny, dy, 1, nx, dx, 10); solver.solve(x); int num_iterations = solver.get_num_iterations(); double final_res_norm = solver.get_final_res_norm(); double err = 0; for(int i=0; i<nx*ny*nz; i++) err = std::max(err, std::abs(x[i]-s[i])); std::cout << err << ' ' << num_iterations << ' ' << final_res_norm << std::endl; delete x, s; }
void example_3d() { const double Lz = 2*M_PI; const double Ly = 2*M_PI; const double Lx = 2*M_PI; const ptrdiff_t N0 = 100; const ptrdiff_t N1 = 100; const ptrdiff_t N2 = 100; const double dz = Lz/N0; const double dy = Ly/N1; const double dx = Lx/N2; FFTWPoisson3DMPI solver(N0, Lz, N1, Ly, N2, Lx); const int nz = solver.get_nz(); const int nx = solver.get_nx(); const int ny = solver.get_ny(); const int z0 = solver.get_z0(); double *x = new double[nx*ny*nz]; double *s = new double[nx*ny*nz]; build_problem(x, z0, nz, dz, 0, ny, dy, 0, nx, dx, 10); build_solution(s, z0, nz, dz, 0, ny, dy, 0, nx, dx, 10); solver.solve(x); double err = 0; for(int i=0; i<nx*ny*nz; i++) err = std::max(err, std::abs(x[i]-s[i])); std::cout << err << std::endl; delete x, s; }
int main () { double tau = 0.001; int N = 11; char flag = 0, taskf = 0, flag_print = 0; int temp = 0, task = 0, print = 0; double K = 1., mu = 1., A = 0., B = 10., T = 1.; FIX_UNUSED (temp); printf ("enter task number(A,B,C):\n"); while (taskf != 'A' && taskf != 'B' && taskf != 'C') { temp = scanf ("%c", &taskf); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } } if (taskf == 'A') task = 0; if (taskf == 'B') task = 1; if (taskf == 'C') task = 2; printf ("enter N:\n"); temp = scanf ("%d", &N); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("enter tau:\n"); temp = scanf ("%lf", &tau); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("change additional parameters? (y, n)\n"); while (flag != 'y' && flag != 'n') { temp = scanf ("%c", &flag); } if (flag == 'y') { printf ("enter A:\n"); temp = scanf ("%lf", &A); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("enter B:\n"); temp = scanf ("%lf", &B); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("enter T:\n"); temp = scanf ("%lf", &T); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("enter K:\n"); temp = scanf ("%lf", &K); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("enter mu:\n"); temp = scanf ("%lf", &mu); if (temp <= 0) { printf ("incorrect input data\n"); return -1; } printf ("print result? (y, n)\n"); while (flag_print != 'y' && flag_print != 'n') { temp = scanf ("%c", &flag_print); } if (flag_print == 'y') print = 1; else print = 0; } build_solution (tau, A, B, N, K, mu, (int)(T / tau), task, print); }
int main(int argc, char *argv[]) { int c; while (EOF != (c = getopt(argc, argv, "dPXACSp:"))) switch (c) { case 'd': if (debuglevel == LOG_DEBUG) { debuglevel++; } else { debuglevel = LOG_DEBUG; } break; case 'P': support_enable = false; break; case 'X': axes_enable = false; break; case 'A': axessupport_enable = false; break; case 'C': characteristics_enable = false; break; case 'S': solution_enable = false; break; case 'p': prefix = std::string(optarg); break; } Nef_nary_union unioner; // solution try { if (solution_enable) { unioner.add_polyhedron(build_solution(thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s", x.what()); } // characteristics try { if (characteristics_enable) { unioner.add_polyhedron(build_characteristics()); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add charactistics: %s", x.what()); } // add the cut support try { if (support_enable) { unioner.add_polyhedron( build_cutsupport(2 * thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add cut supports: %s", x.what()); } // add the axes support try { if (axessupport_enable) { unioner.add_polyhedron( build_axessupport(thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes supports: %s", x.what()); } // axes try { if (axes_enable) { unioner.add_polyhedron(build_axes()); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes: %s", x.what()); } // extract debug(LOG_DEBUG, DEBUG_LOG, 0, "extracting image"); Nef_polyhedron image = unioner.get_union(); // output debug(LOG_DEBUG, DEBUG_LOG, 0, "convert for output"); Polyhedron P; image.convert_to_polyhedron(P); std::cout << P; // output halves if (prefix.size() > 0) { PartWriter pw(prefix); pw(PartWriter::BACK_PART, image, offset); pw(PartWriter::FRONT_PART, image, offset); pw(PartWriter::LEFT_PART, image, offset); pw(PartWriter::RIGHT_PART, image, offset); pw(PartWriter::TOP_PART, image, offset); pw(PartWriter::BOTTOM_PART, image, offset); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete"); return EXIT_SUCCESS; }
/** * \brief main function for example6 */ int main(int argc, char *argv[]) { int c; while (EOF != (c = getopt(argc, argv, "dSACIXNPFxp:"))) switch (c) { case 'd': if (debuglevel == LOG_DEBUG) { debuglevel++; } else { debuglevel = LOG_DEBUG; } break; case 'S': show_solution = !show_solution; break; case 'A': show_alternatives = !show_alternatives; break; case 'C': show_characteristics = !show_characteristics; break; case 'I': show_initial = !show_initial; break; case 'X': show_axes = !show_axes; break; case 'N': show_negative = !show_negative; break; case 'F': show_fcurve = !show_fcurve; break; case 'P': show_support = !show_support; break; case 'p': prefix = std::string(optarg); break; case 'x': yzslicing = false; break; } debug(LOG_DEBUG, DEBUG_LOG, 0, "nonuniqueness of solution of a " "partial differential equation"); // start building up the union of things to be restricted to a box Nef_nary_union unioner; // create a the solution surface try { if (show_solution) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding solution surface"); unioner.add_polyhedron(build_solution(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "solution surface added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s", x.what()); } // create an alternative solution surface try { if (show_alternatives) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding alternatives"); unioner.add_polyhedron(build_alternative(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "alternatives added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add alternatives: %s", x.what()); } // add additional characteristics try { if (show_characteristics) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding characteristics"); unioner.add_polyhedron(build_characteristics()); debug(LOG_DEBUG, DEBUG_LOG, 0, "characteristics added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add characteristics: %s", x.what()); } // add negative characteristics try { if (show_negative) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding neg characteristics"); unioner.add_polyhedron(build_xcharacteristics()); debug(LOG_DEBUG, DEBUG_LOG, 0, "neg characteristics added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add negative characteristics: %s", x.what()); } // add the FCurve try { if (show_fcurve) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding fcurve"); unioner.add_polyhedron(build_fcurve()); debug(LOG_DEBUG, DEBUG_LOG, 0, "fcurve added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add fcurve: %s", x.what()); } // add the support sheet try { if (show_support) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding support"); unioner.add_polyhedron(build_support(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "support added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add support: %s", x.what()); } // add the initial curve if (show_initial) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding initial curve"); unioner.add_polyhedron(build_initialcurve()); debug(LOG_DEBUG, DEBUG_LOG, 0, "initial curve added"); } // extract union debug(LOG_DEBUG, DEBUG_LOG, 0, "extract the image component union"); Nef_polyhedron image = unioner.get_union(); debug(LOG_DEBUG, DEBUG_LOG, 0, "base image constructed"); // restrict everything to a box debug(LOG_DEBUG, DEBUG_LOG, 0, "restrict to a box"); Build_Box box(point(-0.1, -2, -2), point(4, 2, 2)); Polyhedron boxp; boxp.delegate(box); image = image * boxp; debug(LOG_DEBUG, DEBUG_LOG, 0, "restriction complete"); // add axes if (show_axes) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding axes"); image = image + build_axes(); debug(LOG_DEBUG, DEBUG_LOG, 0, "axes added"); } // output Polyhedron P; debug(LOG_DEBUG, DEBUG_LOG, 0, "convert to polyhedron for output"); image.convert_to_polyhedron(P); std::cout << P; // write parts if (prefix.size() > 0) { PartWriter pw(prefix); pw(PartWriter::LEFT_PART, image); pw(PartWriter::RIGHT_PART, image); pw(PartWriter::FRONT_PART, image); pw(PartWriter::BACK_PART, image); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed"); } // that's it debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete"); return EXIT_SUCCESS; }