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 SolverMMSV_H__
13 #define SolverMMSV_H__
14 
15 #include <deal.II/grid/grid_in.h>
16 #include <deal.II/grid/grid_out.h>
17 #include <deal.II/grid/grid_tools.h>
18 #include <deal.II/grid/manifold_lib.h>
19 
20 #include <string>
21 
22 #include "exact_solution.hpp"
23 #include "settings.hpp"
24 #include "static_vector_solver_i.hpp"
25 
26 using namespace StaticVectorSolver;
27 
32 template<int dim>
34  : public SettingsMMSV
35  , public Solver1<dim>
36 {
37 public:
38  SolverMMSV() = delete;
39 
53  SolverMMSV(unsigned int p,
54  unsigned int mapping_degree,
55  unsigned int r,
56  std::string fname)
57  : Solver1<dim>(p,
58  mapping_degree,
59  3,
60  0.0,
61  fname,
62  &exact_solution,
63  print_time_tables,
64  project_exact_solution,
65  true)
66  , r(r)
67  , fname(fname)
68  {
69  if (DIMENSION__ == 2) {
70  if (HYPERCUBE__ == 1) {
71  fname_mesh = "../../gmsh/data/square_r" + std::to_string(r) + ".msh";
72  } else {
73  fname_mesh = "../../gmsh/data/circle_r" + std::to_string(r) + ".msh";
74  }
75  } else {
76  if (HYPERCUBE__ == 1) {
77  fname_mesh = "../../gmsh/data/cube_r" + std::to_string(r) + ".msh";
78  } else {
79  fname_mesh = "../../gmsh/data/sphere_r" + std::to_string(r) + ".msh";
80  }
81  }
82 
84  }
85 
86  ~SolverMMSV() = default;
87 
88 private:
89  const unsigned int r;
90  const std::string fname;
91  std::string fname_mesh;
92 
93  const ExactSolutionMMSV_A<dim> exact_solution;
94 
95  virtual void make_mesh() override final;
96  virtual void fill_dirichlet_stack() override final;
97  virtual void solve() override final;
98 
99  const SphericalManifold<dim> sphere;
100 };
101 
102 template<int dim>
103 void
104 SolverMMSV<dim>::fill_dirichlet_stack()
105 {
106  Solver1<dim>::dirichlet_stack = { { bid_dirichlet, &exact_solution } };
107 }
108 
109 template<int dim>
110 void
112 {
113  SolverControl control(1000 * Solver1<dim>::system_rhs.size(),
114  1e-6 * Solver1<dim>::system_rhs.l2_norm(),
115  false,
116  false);
117 
118  if (log_cg_convergence)
119  control.enable_history_data();
120 
121  GrowingVectorMemory<Vector<double>> memory;
122  SolverCG<Vector<double>> cg(control, memory);
123 
124  // PreconditionJacobi<SparseMatrix<double>> preconditioner;
125  // preconditioner.initialize(Solver1<dim>::system_matrix, 1.0);
126 
127  PreconditionSSOR<SparseMatrix<double>> preconditioner;
128  preconditioner.initialize(Solver1<dim>::system_matrix, 1.2);
129 
133  preconditioner);
134 
136 
137  if (log_cg_convergence) {
138  const std::vector<double> history_data = control.get_history_data();
139 
140  std::ofstream ofs(fname + "_cg_convergence.csv");
141 
142  unsigned int i = 1;
143  for (auto item : history_data) {
144  ofs << i << ", " << item << "\n";
145  i++;
146  }
147  ofs.close();
148  }
149 }
150 
151 template<int dim>
152 void
154 {
155  GridIn<dim> gridin;
156  gridin.attach_triangulation(Solver1<dim>::triangulation);
157 
158  std::ifstream ifs(fname_mesh);
159  gridin.read_msh(ifs);
160 
161  Solver1<dim>::triangulation.reset_all_manifolds();
162 
163  if (HYPERCUBE__ != 1) {
164  for (auto cell : Solver1<dim>::triangulation.active_cell_iterators()) {
165 
166  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; f++) {
167 
168  double dif_norm = 0.0;
169  for (unsigned int v = 1; v < GeometryInfo<dim>::vertices_per_face; v++)
170  dif_norm += std::abs(cell->face(f)->vertex(0).norm() -
171  cell->face(f)->vertex(v).norm());
172 
173  if ((dif_norm < eps) && (cell->center().norm() > rd1))
174  cell->face(f)->set_all_manifold_ids(1);
175  }
176  }
177  }
178 
179  Solver1<dim>::triangulation.set_manifold(1, sphere);
180 }
181 #endif
Describes exact solutions, , of the Method of manufactured solutions, vector potential (mms-v/) numer...
Global settings for the Method of manufactured solutions, vector potential (mms-v/) numerical experim...
Definition: settings.hpp:26
Implements the Method of manufactured solutions, vector potential (mms-v/) numerical experiment.
Definition: solver.hpp:36
SolverMMSV(unsigned int p, unsigned int mapping_degree, unsigned int r, std::string fname)
Definition: solver.hpp:53
Solves static vector boundary value problem.
void run()
Runs the simulation.