Logbook  (07-04-2025)
Static problems
solver.cpp
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 #define BOOST_ALLOW_DEPRECATED_HEADERS
13 
14 #include "solver.hpp"
15 
16 using namespace StaticVectorSolver;
17 
18 void
19 SolverMMSVTI_T::make_mesh()
20 {
21  GridIn<3> gridin;
22 
23  gridin.attach_triangulation(Solver1<3, 0>::triangulation);
24 #if DOMAIN__ == 0
25  std::ifstream ifs("../../gmsh/data/cube_r" + std::to_string(r) + ".msh");
26 #elif DOMAIN__ == 1
27  std::ifstream ifs("../../gmsh/data/sphere_r" + std::to_string(r) + ".msh");
28 #endif
29  gridin.read_msh(ifs);
30 
31 #if DOMAIN__ == 1
32  Solver1<3, 0>::triangulation.reset_all_manifolds();
33 
34  for (auto cell : Solver1<3, 0>::triangulation.active_cell_iterators()) {
35  for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; f++) {
36  double dif_norm = 0.0;
37  for (unsigned int v = 1; v < GeometryInfo<3>::vertices_per_face; v++)
38  dif_norm += std::abs(cell->face(f)->vertex(0).norm() -
39  cell->face(f)->vertex(v).norm());
40 
41  if ((dif_norm < eps) && (cell->center().norm() > rd1))
42  cell->face(f)->set_all_manifold_ids(1);
43  }
44  }
45 
46  Solver1<3, 0>::triangulation.set_manifold(1, sphere);
47 #endif
48 }
49 
50 void
51 SolverMMSVTI_T::fill_dirichlet_stack()
52 {
53  Solver1<3, 0>::dirichlet_stack = { { bid_dirichlet, &dirichlet_bc } };
54 }
55 
56 void
57 SolverMMSVTI_T::solve()
58 {
59  SolverControl control(1000 * Solver1<3, 0>::system_rhs.size(),
60  1e-6 * Solver1<3, 0>::system_rhs.l2_norm(),
61  false,
62  false);
63 
64  if (log_cg_convergence)
65  control.enable_history_data();
66 
67  GrowingVectorMemory<Vector<double>> memory;
68  SolverCG<Vector<double>> cg(control, memory);
69 
70  PreconditionSSOR<SparseMatrix<double>> preconditioner;
71  preconditioner.initialize(Solver1<3, 0>::system_matrix, 1.2);
72 
76  preconditioner);
77 
79 
81  const std::vector<double> history_data = control.get_history_data();
82 
83  std::ofstream ofs(fname + "_cg_convergence.csv");
84 
85  unsigned int i = 1;
86  for (auto item : history_data) {
87  ofs << i << ", " << item << "\n";
88  i++;
89  }
90  ofs.close();
91  }
92 }
93 
94 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
97 
98 void
99 SolverMMSVTI_A::fill_dirichlet_stack()
100 {
101  Solver2<3, 2>::dirichlet_stack = { { bid_dirichlet, &dirichlet_bc } };
102 }
103 
104 void
105 SolverMMSVTI_A::solve()
106 {
107  SolverControl control(1000 * Solver2<3, 2>::system_rhs.size(),
108  1e-6 * Solver2<3, 2>::system_rhs.l2_norm(),
109  false,
110  false);
111 
112  if (log_cg_convergence)
113  control.enable_history_data();
114 
115  GrowingVectorMemory<Vector<double>> memory;
116  SolverCG<Vector<double>> cg(control, memory);
117 
118  PreconditionSSOR<SparseMatrix<double>> preconditioner;
119  preconditioner.initialize(Solver2<3, 2>::system_matrix, 1.2);
120 
124  preconditioner);
125 
127 
129  const std::vector<double> history_data = control.get_history_data();
130 
131  std::ofstream ofs(fname + "_cg_convergence.csv");
132 
133  unsigned int i = 1;
134  for (auto item : history_data) {
135  ofs << i << ", " << item << "\n";
136  i++;
137  }
138  ofs.close();
139  }
140 }
const bool log_cg_convergence
If set to true, saves the residual at each iteration of the CG solver. The names of the files fit the...
Definition: settings.hpp:98
Solves static vector boundary value problem.
Solves static vector boundary value problem.