Logbook  (07-04-2025)
Static problems
main.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 <deal.II/base/multithread_info.h>
15 #include <deal.II/base/timer.h>
16 
17 #include <iostream>
18 #include <string>
19 
20 #include "misc.hpp"
21 #include "project_Axy_to_Bz.hpp"
22 #include "project_Tz_to_Jxy.hpp"
23 #include "solver.hpp"
24 
25 #include "settings.hpp"
26 
27 using namespace Misc;
28 using namespace StaticScalarSolver;
29 using namespace StaticVectorSolver;
30 
37 {
38 public:
39  void run()
40  {
41  if (nr_threads_max > 0)
42  MultithreadInfo::set_thread_limit(nr_threads_max);
43 
44 #if DOMAIN__ == 0
45  const unsigned int mapping_degree = 1;
46  std::string dir = "Data/square/";
47 #endif
48 
49 #if DOMAIN__ == 1
50  const unsigned int mapping_degree = 2;
51  std::string dir = "Data/circle/";
52 #endif
53 
54  std::cout << "Program: mss-vt-ii\n"
55  << "Dimensions: "
56  << "2\n"
57  << "Domain type: " << DOMAIN__ << "\n"
58  << "Writing to: " << dir << "\n";
59 
60  MainOutputTable table_T(2);
61  MainOutputTable table_J(2);
62  MainOutputTable table_B(2);
63 
64  for (unsigned int p = 0; p < 3; p++) {
65  table_T.clear();
66  table_J.clear();
67  table_B.clear();
68 
69  for (unsigned int r = 9; r < 13; r++) {
70  table_T.add_value("r", r);
71  table_T.add_value("p", p);
72 
73  table_J.add_value("r", r);
74  table_J.add_value("p", p);
75 
76  table_B.add_value("r", r);
77  table_B.add_value("p", p);
78 
79  // Stage 0 -------------------------------------------------------------
80  std::cout << "Stage 0: solving for T ...\n";
81 
82  SolverMMSVTII_T stage0(p + 1,
83  mapping_degree,
84  r,
85  dir + "solution_T_p" + std::to_string(p) + "_r" +
86  std::to_string(r));
87 
88  stage0.clear();
89  table_T.add_value("ndofs", stage0.get_n_dofs());
90  table_T.add_value("ncells", stage0.get_n_cells());
91  table_T.add_value("L2", stage0.get_L2_norm());
92  table_T.add_value("H1", stage0.get_H1_norm());
93 
94  // Stage 1 -------------------------------------------------------------
95  std::cout << "Stage 1: projecting T in H(curl) to Jf in H(div) ...\n";
96 
97  ExactSolutionMMSVTII_Jf exact_solution_Jf;
98 
99  ProjectTzToJxy<1> stage1(p,
100  mapping_degree,
101  stage0.get_tria(),
102  stage0.get_dof_handler(),
103  stage0.get_solution(),
104  dir + "solution_J_p" + std::to_string(p) +
105  "_r" + std::to_string(r),
106  &exact_solution_Jf,
110  true);
111 
112  table_J.add_value("ndofs", stage0.get_n_dofs());
113  table_J.add_value("ncells", stage0.get_n_cells());
114  table_J.add_value("L2", stage1.get_L2_norm());
115  table_J.add_value("H1", 0.0);
116 
117  stage1.clear();
118 
119  // Stage 2 -------------------------------------------------------------
120  std::cout << "Stage 2: solving for A ...\n";
121 
122  SolverMMSVTII_A stage2(p,
123  mapping_degree,
124  stage0.get_tria(),
125  stage0.get_dof_handler(),
126  stage0.get_solution(),
127  r,
128  dir + "solution_A_p" + std::to_string(p) + "_r" +
129  std::to_string(r));
130 
131  stage2.clear();
132 
133  // Stage 3 -------------------------------------------------------------
134  std::cout << "Stage 3: projecting A in H(curl) to B in H(div) ...\n";
135 
136  ExactSolutionMMSVTII_B exact_solution_B;
137 
138  ProjectAxyToBz<3> stage3(p,
139  mapping_degree,
140  stage0.get_tria(),
141  stage2.get_dof_handler(),
142  stage2.get_solution(),
143  dir + "solution_B_p" + std::to_string(p) +
144  "_r" + std::to_string(r),
145  &exact_solution_B,
149  true);
150 
151  table_B.add_value("ndofs", stage0.get_n_dofs());
152  table_B.add_value("ncells", stage0.get_n_cells());
153  table_B.add_value("L2", stage3.get_L2_norm());
154  table_B.add_value("H1", 0.0);
155  }
156  std::cout << "Table T \n";
157  table_T.save(dir + "main_table_T_p" + std::to_string(p));
158 
159  std::cout << "Table J \n";
160  table_J.save(dir + "main_table_J_p" + std::to_string(p));
161 
162  std::cout << "Table B \n";
163  table_B.save(dir + "main_table_B_p" + std::to_string(p));
164  }
165  }
166 };
167 
168 int
169 main()
170 {
171  try {
172  BatchMMSVTII batch;
173  batch.run();
174  } catch (std::exception& exc) {
175  std::cerr << std::endl
176  << std::endl
177  << "----------------------------------------------------"
178  << std::endl;
179  std::cerr << "Exception on processing: " << std::endl
180  << exc.what() << std::endl
181  << "Aborting!" << std::endl
182  << "----------------------------------------------------"
183  << std::endl;
184  return 1;
185  } catch (...) {
186  std::cerr << std::endl
187  << std::endl
188  << "----------------------------------------------------"
189  << std::endl;
190  std::cerr << "Unknown exception!" << std::endl
191  << "Aborting!" << std::endl
192  << "----------------------------------------------------"
193  << std::endl;
194  return 1;
195  }
196  return 0;
197 }
This is a wrap-around class. It contains the main loop of the program that implements the Method of m...
Definition: main.cpp:37
Describes exact solution, , of the Method of manufactured solutions, vector potential (mms-vt-ii/) nu...
Describes exact solution, , of the Method of manufactured solutions, vector potential (mms-vt-ii/) nu...
The convergence table used in multiple numerical experiments.
Definition: misc.hpp:25
void save(std::string fname)
Saves the data in text and tex formats, and prints the data on screen.
Definition: misc.cpp:47
const bool project_exact_solution
If set to true, the program will project the exact solution.
Definition: settings.hpp:80
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
const bool print_time_tables
If set to true, the program will print time tables on the screen.
Definition: settings.hpp:70
Global settings for the Method of manufactured solutions, vector potential (mms-vt-ii/) numerical exp...
Definition: settings.hpp:26
Implements the solver for magnetic vector potential, , in the Method of manufactured solutions,...
Definition: solver.hpp:110
Implements the solver for current vector potential, , in the Method of manufactured solutions,...
Definition: solver.hpp:47
void clear()
Releases computer memory associated with system matrix and right-hand side.
Computes the two-dimensional free-current density as a vector curl of the current vector potential,...
const Triangulation< dim > & get_tria() const
Returns a reference to triangulation.
const Vector< double > & get_solution() const
Returns a reference to the solution.
double get_L2_norm() const
Returns error norm.
void clear()
Releases computer memory associated with the system matrix and right-hand side.
const DoFHandler< dim > & get_dof_handler() const
Returns a reference to dof handler.
double get_H1_norm() const
Returns error norm.
unsigned int get_n_dofs() const
Returns the total amount of the degrees of freedom.
unsigned int get_n_cells() const
Returns the number of active cells in the mesh.
Computes an out-of-plane magnetic field, , as a scalar curl of an in-plane magnetic vector potential,...
double get_L2_norm()
Returns error norm.
void clear()
Releases computer memory associated with system matrix and right-hand side.
const Vector< double > & get_solution() const
Returns a reference to solution.
const DoFHandler< dim > & get_dof_handler() const
Returns a reference to a dof handler.