int main(int argc, char* argv[]) { // Load the mesh. Hermes::Hermes2D::Mesh mesh; Hermes::Hermes2D::H2DReader mloader; mloader.load("domain.mesh", &mesh); // Perform initial mesh refinements (optional). int refinement_type = 2; // Split elements vertically. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(refinement_type); // Show the mesh. Hermes::Hermes2D::Views::MeshView mview("Mesh", new Hermes::Hermes2D::Views::WinGeom(0, 0, 900, 250)); if (HERMES_VISUALIZATION) { mview.show(&mesh); //mview.wait(); } // Initialize the weak formulation. CustomWeakFormPoisson wf("Al", new Hermes::Hermes1DFunction<double>(LAMBDA_AL), "Cu", new Hermes::Hermes1DFunction<double>(LAMBDA_CU), new Hermes::Hermes2DFunction<double>(-VOLUME_HEAT_SRC)); // Initialize essential boundary conditions. Hermes::Hermes2D::DefaultEssentialBCConst<double> bc_essential(Hermes::vector<std::string>("Left", "Right"), FIXED_BDY_TEMP); Hermes::Hermes2D::EssentialBCs<double> bcs(&bc_essential); // Create an H1 space with default shapeset. Hermes::Hermes2D::H1Space<double> space(&mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); info("ndof = %d", ndof); // Initialize the FE problem. Hermes::Hermes2D::DiscreteProblem<double> dp(&wf, &space); // Initial coefficient vector for the Newton's method. double* coeff_vec = new double[ndof]; memset(coeff_vec, 0, ndof*sizeof(double)); // Perform Newton's iteration and translate the resulting coefficient vector into a Solution. Hermes::Hermes2D::Solution<double> sln; Hermes::Hermes2D::NewtonSolver<double> newton(&dp, matrix_solver_type); if (!newton.solve(coeff_vec)) error("Newton's iteration failed."); else Hermes::Hermes2D::Solution<double>::vector_to_solution(newton.get_sln_vector(), &space, &sln); // Get info about time spent during assembling in its respective parts. dp.get_all_profiling_output(std::cout); // VTK output. if (VTK_VISUALIZATION) { // Output solution in VTK format. Hermes::Hermes2D::Views::Linearizer<double> lin; bool mode_3D = true; lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D); info("Solution in VTK format saved to file %s.", "sln.vtk"); // Output mesh and element orders in VTK format. Hermes::Hermes2D::Views::Orderizer ord; ord.save_orders_vtk(&space, "ord.vtk"); info("Element orders in VTK format saved to file %s.", "ord.vtk"); } // Visualize the solution. if (HERMES_VISUALIZATION) { Hermes::Hermes2D::Views::ScalarView<double> view("Solution", new Hermes::Hermes2D::Views::WinGeom(0, 300, 900, 350)); // Hermes uses adaptive FEM to approximate higher-order FE solutions with linear // triangles for OpenGL. The second parameter of View::show() sets the error // tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default), // HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows // considerably with more accurate representation, so use it wisely. view.show(&sln, Hermes::Hermes2D::Views::HERMES_EPS_HIGH); Hermes::Hermes2D::Views::View::wait(); } // Clean up. delete [] coeff_vec; return 0; }
int main(int argc, char* argv[]) { // Load the mesh. Hermes::Hermes2D::Mesh mesh; Hermes::Hermes2D::H2DReader mloader; mloader.load("domain.mesh", &mesh); // Perform initial mesh refinements (optional). for (int i=0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); // Initialize the weak formulation. CustomWeakFormPoissonNewton wf("Aluminum", new Hermes::Hermes2D::HermesFunction<double>(LAMBDA_AL), "Copper", new Hermes::Hermes2D::HermesFunction<double>(LAMBDA_CU), new Hermes::Hermes2D::HermesFunction<double>(-VOLUME_HEAT_SRC), "Outer", ALPHA, T_EXTERIOR); // Initialize boundary conditions. CustomDirichletCondition bc_essential(Hermes::vector<std::string>("Bottom", "Inner", "Left"), BDY_A_PARAM, BDY_B_PARAM, BDY_C_PARAM); Hermes::Hermes2D::EssentialBCs<double> bcs(&bc_essential); // Create an H1 space with default shapeset. Hermes::Hermes2D::H1Space<double> space(&mesh, &bcs, P_INIT); int ndof = space.get_num_dofs(); info("ndof = %d", ndof); // Initialize the FE problem. Hermes::Hermes2D::DiscreteProblem<double> dp(&wf, &space); // Initial coefficient vector for the Newton's method. double* coeff_vec = new double[ndof]; memset(coeff_vec, 0, ndof*sizeof(double)); // Perform Newton's iteration and translate the resulting coefficient vector into a Solution. Hermes::Hermes2D::Solution<double> sln; Hermes::Hermes2D::NewtonSolver<double> newton(&dp, matrix_solver_type); if (!newton.solve(coeff_vec)) error("Newton's iteration failed."); else Hermes::Hermes2D::Solution<double>::vector_to_solution(newton.get_sln_vector(), &space, &sln); // VTK output. if (VTK_VISUALIZATION) { // Output solution in VTK format. Hermes::Hermes2D::Views::Linearizer<double> lin; bool mode_3D = true; lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D); info("Solution in VTK format saved to file %s.", "sln.vtk"); // Output mesh and element orders in VTK format. Hermes::Hermes2D::Views::Orderizer ord; ord.save_orders_vtk(&space, "ord.vtk"); info("Element orders in VTK format saved to file %s.", "ord.vtk"); } // Visualize the solution. if (HERMES_VISUALIZATION) { Hermes::Hermes2D::Views::ScalarView<double> view("Solution", new Hermes::Hermes2D::Views::WinGeom(0, 0, 440, 350)); view.show(&sln, Hermes::Hermes2D::Views::HERMES_EPS_VERYHIGH); Hermes::Hermes2D::Views::View::wait(); } // Clean up. delete [] coeff_vec; return 0; }