@@ -32,9 +32,9 @@ const bool HERMES_VISUALIZATION = true;
32
32
// Set to "true" to enable VTK output.
33
33
const bool VTK_VISUALIZATION = false ;
34
34
// Uniform polynomial degree of mesh elements.
35
- const int P_INIT = 3 ;
35
+ const int P_INIT = 10 ;
36
36
// Number of initial uniform mesh refinements.
37
- const int INIT_REF_NUM = 3 ;
37
+ const int INIT_REF_NUM = 4 ;
38
38
39
39
// Problem parameters.
40
40
// Thermal cond. of Al for temperatures around 20 deg Celsius.
@@ -49,81 +49,91 @@ const double FIXED_BDY_TEMP = 20;
49
49
int main (int argc, char * argv[])
50
50
{
51
51
#ifdef WITH_PARALUTION
52
- HermesCommonApi.set_integral_param_value (matrixSolverType, SOLVER_PARALUTION_ITERATIVE);
52
+ HermesCommonApi.set_integral_param_value (matrixSolverType, SOLVER_PARALUTION_ITERATIVE);
53
53
#endif
54
54
55
- // Load the mesh.
56
- MeshSharedPtr mesh (new Mesh);
57
- Hermes::Hermes2D::MeshReaderH2DXML mloader;
58
- mloader.load (" domain.xml" , mesh);
59
-
60
- // Refine all elements, do it INIT_REF_NUM-times.
61
- for (unsigned int i = 0 ; i < INIT_REF_NUM; i++)
62
- mesh->refine_all_elements ();
63
-
64
- // Initialize essential boundary conditions.
65
- Hermes::Hermes2D::DefaultEssentialBCConst<double > bc_essential ({ " Bottom" , " Inner" , " Outer" , " Left" }, FIXED_BDY_TEMP);
66
- Hermes::Hermes2D::EssentialBCs<double > bcs (&bc_essential);
67
-
68
- // Initialize space.
69
- SpaceSharedPtr<double > space (new Hermes::Hermes2D::H1Space<double >(mesh, &bcs, P_INIT));
70
-
71
- std::cout << " Ndofs: " << space->get_num_dofs () << std::endl;
72
-
73
- // Initialize the weak formulation.
74
- WeakFormSharedPtr<double > wf (new CustomWeakFormPoisson (" Aluminum" , new Hermes::Hermes1DFunction<double >(LAMBDA_AL), " Copper" ,
75
- new Hermes::Hermes1DFunction<double >(LAMBDA_CU), new Hermes::Hermes2DFunction<double >(VOLUME_HEAT_SRC)));
76
-
77
- // Initialize the solution.
78
- MeshFunctionSharedPtr<double > sln (new Solution<double >);
79
-
80
- // Initialize linear solver.
81
- Hermes::Hermes2D::LinearSolver<double > linear_solver (wf, space);
82
-
83
- // Solve the linear problem.
84
- try
85
- {
86
- linear_solver.solve ();
87
-
88
- // Get the solution vector.
89
- double * sln_vector = linear_solver.get_sln_vector ();
90
-
91
- // Translate the solution vector into the previously initialized Solution.
92
- Hermes::Hermes2D::Solution<double >::vector_to_solution (sln_vector, space, sln);
93
-
94
- // VTK output.
95
- if (VTK_VISUALIZATION)
96
- {
97
- // Output solution in VTK format.
98
- Hermes::Hermes2D::Views::Linearizer lin (FileExport);
99
- bool mode_3D = false ;
100
- lin.save_solution_vtk (sln, " sln.vtk" , " Temperature" , mode_3D, 1 );
101
-
102
- // Output mesh and element orders in VTK format.
103
- Hermes::Hermes2D::Views::Orderizer ord;
104
- ord.save_mesh_vtk (space, " mesh.vtk" );
105
- ord.save_orders_vtk (space, " ord.vtk" );
106
- ord.save_markers_vtk (space, " markers.vtk" );
107
- }
108
-
109
- if (HERMES_VISUALIZATION)
110
- {
111
- // Visualize the solution.
112
- Hermes::Hermes2D::Views::ScalarView viewS (" Solution" , new Hermes::Hermes2D::Views::WinGeom (0 , 0 , 500 , 400 ));
113
- Hermes::Hermes2D::Views::OrderView viewSp (" Space" , new Hermes::Hermes2D::Views::WinGeom (0 , 400 , 500 , 400 ));
114
- viewS.get_linearizer ()->set_criterion (Views::LinearizerCriterionFixed (0 ));
115
- viewS.show (sln);
116
- viewSp.show (space);
117
- viewS.wait_for_close ();
118
- }
119
- }
120
- catch (Exceptions::Exception& e)
121
- {
122
- std::cout << e.info ();
123
- }
124
- catch (std::exception & e)
125
- {
126
- std::cout << e.what ();
127
- }
128
- return 0 ;
55
+ // Load the mesh.
56
+ MeshSharedPtr mesh (new Mesh);
57
+ Hermes::Hermes2D::MeshReaderH2DXML mloader;
58
+ mloader.load (" domain.xml" , mesh);
59
+
60
+ // Refine all elements, do it INIT_REF_NUM-times.
61
+ for (unsigned int i = 0 ; i < INIT_REF_NUM; i++)
62
+ mesh->refine_all_elements ();
63
+
64
+ // Initialize essential boundary conditions.
65
+ Hermes::Hermes2D::DefaultEssentialBCConst<double > bc_essential ({ " Bottom" , " Inner" , " Outer" , " Left" }, FIXED_BDY_TEMP);
66
+ Hermes::Hermes2D::EssentialBCs<double > bcs (&bc_essential);
67
+
68
+ // Initialize space.
69
+ SpaceSharedPtr<double > space (new Hermes::Hermes2D::H1Space<double >(mesh, &bcs, P_INIT));
70
+ std::cout << " Ndofs: " << space->get_num_dofs () << std::endl;
71
+
72
+ // Initialize the weak formulation.
73
+ WeakFormSharedPtr<double > wf (new CustomWeakFormPoisson (" Aluminum" , new Hermes::Hermes1DFunction<double >(LAMBDA_AL), " Copper" ,
74
+ new Hermes::Hermes1DFunction<double >(LAMBDA_CU), new Hermes::Hermes2DFunction<double >(VOLUME_HEAT_SRC)));
75
+
76
+ // Initialize the solution.
77
+ MeshFunctionSharedPtr<double > sln (new Solution<double >);
78
+
79
+ // Initialize linear solver.
80
+ Hermes::Hermes2D::LinearSolver<double > linear_solver (wf, space);
81
+
82
+ #ifdef WITH_PARALUTION
83
+ linear_solver.get_linear_matrix_solver ()->as_IterSolver ()->set_solver_type (Hermes::Solvers::IterSolverType::BiCGStab);
84
+ linear_solver.get_linear_matrix_solver ()->as_IterSolver ()->set_precond (new Hermes::Preconditioners::ParalutionPrecond<double >(Hermes::Preconditioners::PreconditionerType::Jacobi));
85
+ linear_solver.get_linear_matrix_solver ()->as_IterSolver ()->set_tolerance (1e-8 , Hermes::Solvers::AbsoluteTolerance);
86
+ linear_solver.get_linear_matrix_solver ()->as_IterSolver ()->set_verbose_output (true );
87
+ #endif
88
+
89
+ // Store the matrix.
90
+ linear_solver.output_matrix ();
91
+ linear_solver.set_matrix_export_format (Hermes::Algebra::MatrixExportFormat::EXPORT_FORMAT_MATRIX_MARKET);
92
+
93
+ // Solve the linear problem.
94
+ try
95
+ {
96
+ linear_solver.solve ();
97
+
98
+ // Get the solution vector.
99
+ double * sln_vector = linear_solver.get_sln_vector ();
100
+
101
+ // Translate the solution vector into the previously initialized Solution.
102
+ Hermes::Hermes2D::Solution<double >::vector_to_solution (sln_vector, space, sln);
103
+
104
+ // VTK output.
105
+ if (VTK_VISUALIZATION)
106
+ {
107
+ // Output solution in VTK format.
108
+ Hermes::Hermes2D::Views::Linearizer lin (FileExport);
109
+ bool mode_3D = false ;
110
+ lin.save_solution_vtk (sln, " sln.vtk" , " Temperature" , mode_3D, 1 );
111
+
112
+ // Output mesh and element orders in VTK format.
113
+ Hermes::Hermes2D::Views::Orderizer ord;
114
+ ord.save_mesh_vtk (space, " mesh.vtk" );
115
+ ord.save_orders_vtk (space, " ord.vtk" );
116
+ ord.save_markers_vtk (space, " markers.vtk" );
117
+ }
118
+
119
+ if (HERMES_VISUALIZATION)
120
+ {
121
+ // Visualize the solution.
122
+ Hermes::Hermes2D::Views::ScalarView viewS (" Solution" , new Hermes::Hermes2D::Views::WinGeom (0 , 0 , 500 , 400 ));
123
+ Hermes::Hermes2D::Views::OrderView viewSp (" Space" , new Hermes::Hermes2D::Views::WinGeom (0 , 400 , 500 , 400 ));
124
+ viewS.get_linearizer ()->set_criterion (Views::LinearizerCriterionFixed (0 ));
125
+ viewS.show (sln);
126
+ viewSp.show (space);
127
+ viewS.wait_for_close ();
128
+ }
129
+ }
130
+ catch (Exceptions::Exception& e)
131
+ {
132
+ std::cout << e.info ();
133
+ }
134
+ catch (std::exception & e)
135
+ {
136
+ std::cout << e.what ();
137
+ }
138
+ return 0 ;
129
139
}
0 commit comments