phaseflow
FEM solver for the Navier-Stokes-Boussinesq equations coupled with enthalpy-based phase change
 All Classes Namespaces Files Functions Variables Macros Pages
pf_solve_nonlinear_problem.h
Go to the documentation of this file.
1 #ifndef _pf_solve_nonlinear_problem_h_
2 #define _pf_solve_nonlinear_problem_h_
3 
4 
6 template<int dim>
7 void Phaseflow<dim>::step_newton()
8 {
9  this->old_newton_solution = this->newton_solution;
10 
11  this->assemble_system();
12 
13  this->apply_boundary_values_and_constraints();
14 
15  this->solve_linear_system();
16 
17  this->newton_solution -= this->newton_residual;
18 }
19 
21 template<int dim>
22 bool Phaseflow<dim>::solve_nonlinear_problem()
23 {
24  this->newton_solution = this->solution;
25 
26  bool converged = false;
27 
28  unsigned int i;
29 
30  double old_norm_residual = 1.e32;
31 
32  for (i = 0; i < this->params.nonlinear_solver.max_iterations; ++i)
33  {
34  this->step_newton();
35 
36  Output::write_solution_to_vtk( // @todo Debugging
37  "newton_residual.vtk",
38  this->dof_handler,
39  this->newton_residual);
40 
41  Output::write_solution_to_vtk( // @todo Debugging
42  "newton_solution.vtk",
43  this->dof_handler,
44  this->newton_solution);
45 
46  double norm_residual = this->newton_residual.l2_norm()/this->newton_solution.l2_norm();
47 
48  std::cout << "Newton iteration: L2 norm of relative residual, || w_w || / || w_k || = " << norm_residual << std::endl;
49 
50  if (norm_residual > old_norm_residual)
51  {
52  converged = false;
53 
54  std::cout << "Newton iteration diverged." << std::endl;
55 
56  Output::write_solution_to_vtk( // @todo Debugging
57  "diverged_newton_solution.vtk",
58  this->dof_handler,
59  this->newton_solution);
60 
61  if (this->time_step_size == this->params.time.min_step_size)
62  {
63  assert(converged);
64  }
65 
66  return converged;
67  }
68 
69  old_norm_residual = norm_residual;
70 
71  if (norm_residual < this->params.nonlinear_solver.tolerance)
72  {
73  converged = true;
74  break;
75  }
76 
77  }
78 
79  if ((this->time_step_size > this->params.time.min_step_size) & !converged)
80  {
81  return converged;
82  }
83 
84  assert(converged);
85 
86  std::cout << "Newton method converged after " << i + 1 << " iterations." << std::endl;
87 
88  this->solution = this->newton_solution;
89 
90  return converged;
91 }
92 
93 #endif
void write_solution_to_vtk(const std::string filename, DoFHandler< dim > &dof_handler, Vector< double > &solution)
Definition: output.h:16