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 StaticScalarSolver;
17 
18 void
19 SolverCVPII::make_mesh()
20 {
21  GridIn<2> gridin;
22  gridin.attach_triangulation(Solver<2>::triangulation);
23 
24  std::ifstream ifs("../../gmsh/data/circle_r" + std::to_string(r) + ".msh");
25  gridin.read_msh(ifs);
26 
27  for (auto cell : Solver<2>::triangulation.active_cell_iterators()) {
28  cell->set_material_id(mid_1); // The cell is outside the
29  // current-carrying region.
30 
31  if ((cell->center().norm() > a) && (cell->center().norm() < b))
32  cell->set_material_id(mid_2); // The cell is inside the
33  // current-carrying region.
34 
35  for (unsigned int f = 0; f < GeometryInfo<2>::faces_per_cell; f++) {
36  double dif_norm = 0.0;
37  for (unsigned int v = 1; v < GeometryInfo<2>::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  Solver<2>::triangulation.set_manifold(1, sphere);
47 }
48 
49 void
50 SolverCVPII::fill_dirichlet_stack()
51 {
52  Solver<2>::dirichlet_stack = { { bid_dirichlet, &dirichlet_bc } };
53 }
54 
55 void
56 SolverCVPII::solve()
57 {
58  SolverControl control(Solver<2>::system_rhs.size(),
59  1e-12 * Solver<2>::system_rhs.l2_norm(),
60  false,
61  false);
62 
64  control.enable_history_data();
65 
66  GrowingVectorMemory<Vector<double>> memory;
67  SolverCG<Vector<double>> cg(control, memory);
68 
69  PreconditionSSOR<SparseMatrix<double>> preconditioner;
70  preconditioner.initialize(Solver<2>::system_matrix, 1.2);
71 
72  cg.solve(Solver<2>::system_matrix,
75  preconditioner);
76 
78 
80  const std::vector<double> history_data = control.get_history_data();
81 
82  std::ofstream ofs(fname + "_cg_convergence.csv");
83 
84  unsigned int i = 1;
85  for (auto item : history_data) {
86  ofs << i << ", " << item << "\n";
87  i++;
88  }
89  ofs.close();
90  }
91 }
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:107
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:89
Solves static scalar boundary value problem.