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 SolverSSOLIII_T::make_mesh()
20 {
21  GridIn<3> gridin;
22 
23  gridin.attach_triangulation(Solver1<3, 0>::triangulation);
24  std::ifstream ifs("../../gmsh/data/sphere_r" + std::to_string(r) + ".msh");
25  gridin.read_msh(ifs);
26 
27  Solver1<3, 0>::triangulation.reset_all_manifolds();
28 
29  for (auto cell : Solver1<3, 0>::triangulation.active_cell_iterators()) {
30  cell->set_material_id(mid_1); // The cell is outside the coil and the core.
31 
32  if ((cell->center().norm() > a1) && (cell->center().norm() < b1))
33  cell->set_material_id(mid_2); // The cell is inside the core.
34 
35  if ((cell->center().norm() > a2) && (cell->center().norm() < b2))
36  cell->set_material_id(mid_3); // The cell is inside the coil.
37 
38  for (unsigned int f = 0; f < GeometryInfo<3>::faces_per_cell; f++) {
39  double dif_norm = 0.0;
40  for (unsigned int v = 1; v < GeometryInfo<3>::vertices_per_face; v++)
41  dif_norm += std::abs(cell->face(f)->vertex(0).norm() -
42  cell->face(f)->vertex(v).norm());
43 
44  if ((dif_norm < eps) && (cell->center().norm() > rd1))
45  cell->face(f)->set_all_manifold_ids(1);
46  }
47  }
48 
49  Solver1<3, 0>::triangulation.set_manifold(1, sphere);
50 }
51 
52 void
53 SolverSSOLIII_T::fill_dirichlet_stack()
54 {
55  Solver1<3, 0>::dirichlet_stack = { { 1, &dirichlet_bc } };
56 }
57 
58 void
59 SolverSSOLIII_T::solve()
60 {
61  SolverControl control(1000 * Solver1<3, 0>::system_rhs.size(),
62  1e-6 * Solver1<3, 0>::system_rhs.l2_norm(),
63  false,
64  false);
65 
66  if (log_cg_convergence)
67  control.enable_history_data();
68 
69  GrowingVectorMemory<Vector<double>> memory;
70  SolverCG<Vector<double>> cg(control, memory);
71 
72  PreconditionSSOR<SparseMatrix<double>> preconditioner;
73  preconditioner.initialize(Solver1<3, 0>::system_matrix, 1.2);
74 
78  preconditioner);
79 
81 
83  const std::vector<double> history_data = control.get_history_data();
84 
85  std::ofstream ofs(fname + "_cg_convergence.csv");
86 
87  unsigned int i = 1;
88  for (auto item : history_data) {
89  ofs << i << ", " << item << "\n";
90  i++;
91  }
92  ofs.close();
93  }
94 }
95 
96 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
99 
100 void
101 SolverSSOLIII_A::fill_dirichlet_stack()
102 {
104 }
105 
106 void
107 SolverSSOLIII_A::solve()
108 {
109  SolverControl control(1000 * Solver2<3, 2>::system_rhs.size(),
110  1e-6 * Solver2<3, 2>::system_rhs.l2_norm(),
111  false,
112  false);
113 
114  if (log_cg_convergence)
115  control.enable_history_data();
116 
117  GrowingVectorMemory<Vector<double>> memory;
118  SolverCG<Vector<double>> cg(control, memory);
119 
120  PreconditionSSOR<SparseMatrix<double>> preconditioner;
121  preconditioner.initialize(Solver2<3, 2>::system_matrix, 1.2);
122 
126  preconditioner);
127 
129 
131  const std::vector<double> history_data = control.get_history_data();
132 
133  std::ofstream ofs(fname + "_cg_convergence.csv");
134 
135  unsigned int i = 1;
136  for (auto item : history_data) {
137  ofs << i << ", " << item << "\n";
138  i++;
139  }
140  ofs.close();
141  }
142 }
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:152
Solves static vector boundary value problem.
Solves static vector boundary value problem.