Logbook  (07-04-2025)
Static problems
solver.hpp
1 /******************************************************************************
2  * Copyright (C) Siarhei Uzunbajakau, 2023.
3  *
4  * This program is free software. You can use, modify, and redistribute it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation, either version 3 or (at your option) any later version.
7  * This program is distributed without any warranty.
8  *
9  * Refer to COPYING.LESSER for more details.
10  ******************************************************************************/
11 
12 #ifndef SolverPLS_H__
13 #define SolverPLS_H__
14 
15 #define BOOST_ALLOW_DEPRECATED_HEADERS
16 
17 #include <deal.II/base/function.h>
18 #include <deal.II/grid/grid_generator.h>
19 #include <deal.II/grid/grid_in.h>
20 
21 #include <deal.II/numerics/fe_field_function.h>
22 
23 #include "exact_solution.hpp"
24 #include "settings.hpp"
25 #include "static_scalar_solver.hpp"
26 
27 #define TMR(__name) TimerOutput::Scope timer_section(timer, __name)
28 
29 using namespace StaticScalarSolver;
30 
35 template<int dim>
36 class SolverPLS
37  : public SettingsPLS
38  , public Solver<dim>
39 {
40 public:
41  SolverPLS() = delete;
42 
56  SolverPLS(unsigned int p, unsigned int r, std::string fname)
57  : Solver<dim>(p,
58  1,
59  1,
60  fname,
61  &exact_solution,
62  false,
63  false,
64  print_time_tables,
65  project_exact_solution)
66  , r(r)
67  , fname(fname)
68  {
69  TimerOutput::OutputFrequency tf =
70  (print_time_tables) ? TimerOutput::summary : TimerOutput::never;
71 
72  TimerOutput timer(std::cout, tf, TimerOutput::cpu_and_wall_times_grouped);
73 
74  {
75  TMR("Solver run");
77  }
78  }
79 
80  ~SolverPLS() = default;
81 
82 private:
83  const unsigned int r;
84  const std::string fname;
85 
86  const ExactSolutionPLS_PHI<dim> exact_solution;
87 
88  virtual void make_mesh() override final;
89  virtual void fill_dirichlet_stack() override final;
90  virtual void solve() override final;
91 };
92 
93 template<int dim>
94 void
95 SolverPLS<dim>::solve()
96 {
97  SolverControl control(Solver<dim>::system_rhs.size(),
98  1e-8 * Solver<dim>::system_rhs.l2_norm(),
99  false,
100  false);
101 
102  if (log_cg_convergence)
103  control.enable_history_data();
104 
105  GrowingVectorMemory<Vector<double>> memory;
106  SolverCG<Vector<double>> cg(control, memory);
107 
108  PreconditionJacobi<SparseMatrix<double>> preconditioner;
109  preconditioner.initialize(Solver<dim>::system_matrix, 1.0);
110 
114  preconditioner);
115 
117 
118  if (log_cg_convergence) {
119  const std::vector<double> history_data = control.get_history_data();
120 
121  std::ofstream ofs(fname + "_cg_convergence.csv");
122 
123  unsigned int i = 1;
124  for (auto item : history_data) {
125  ofs << i << ", " << item << "\n";
126  i++;
127  }
128  ofs.close();
129  }
130 }
131 #endif
Describes the exact solution, , of the Planes of symmetry (pls/) numerical experiment in two and thre...
Global settings for the Planes of symmetry (pls/) numerical experiment.
Definition: settings.hpp:26
Implements the Planes of symmetry (pls/) numerical experiment.
Definition: solver.hpp:39
SolverPLS(unsigned int p, unsigned int r, std::string fname)
Definition: solver.hpp:56
Solves static scalar boundary value problem.
void run()
Runs the simulation.