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_A_to_B.hpp"
22 #include "project_Axy_to_Bz.hpp"
23 #include "settings.hpp"
24 #include "solver.hpp"
25 
26 using namespace Misc;
27 using namespace StaticVectorSolver;
28 
34 class BatchMMSV : public SettingsMMSV
35 {
36 public:
37  void run()
38  {
39  if (nr_threads_max > 0)
40  MultithreadInfo::set_thread_limit(nr_threads_max);
41 
42  Assert(DIMENSION__ < 4, ExcInternalError());
43  Assert(DIMENSION__ > 1, ExcInternalError());
44 
45  std::string dir;
46  std::string fname;
47 
48  unsigned int mapping_degree;
49 
50  if (HYPERCUBE__ == 1) {
51  dir = (DIMENSION__ == 2) ? "Data/square/" : "Data/cube/";
52  mapping_degree = 1;
53  } else {
54  dir = (DIMENSION__ == 2) ? "Data/circle/" : "Data/sphere/";
55  mapping_degree = 2;
56  }
57 
58  std::cout << "Program: mms-v\n"
59  << "Dimensions: " << DIMENSION__ << "\n"
60  << "Writing to: " << dir << "\n";
61 
62  MainOutputTable table(DIMENSION__);
63 
64  ExactSolutionMMSV_B<DIMENSION__> exact_solution;
65 
66  for (unsigned int p = 0; p < 3; p++) {
67  table.clear();
68  for (unsigned int r = 5; r < 9; r++) {
69  std::cout << "Solving for A ...\n";
70 
71  fname =
72  dir + "solution_A_p" + std::to_string(p) + "_r" + std::to_string(r);
73 
74  table.add_value("r", r);
75  table.add_value("p", p);
76 
77  SolverMMSV<DIMENSION__> problem(p, mapping_degree, r, fname);
78 
79  std::cout << "Projecting A in H(curl) to B in H(div) ...\n";
80 
81 #if DIMENSION__ == 3
82  fname =
83  dir + "solution_B_p" + std::to_string(p) + "_r" + std::to_string(r);
84 
85  ProjectAtoB projector(p,
86  mapping_degree,
87  problem.get_tria(),
88  problem.get_dof_handler(),
89  problem.get_solution(),
90  fname,
91  &exact_solution,
95  true);
96 #endif
97 #if DIMENSION__ == 2
98  fname =
99  dir + "solution_B_p" + std::to_string(p) + "_r" + std::to_string(r);
100 
101  ProjectAxyToBz projector(p,
102  mapping_degree,
103  problem.get_tria(),
104  problem.get_dof_handler(),
105  problem.get_solution(),
106  fname,
107  &exact_solution,
111  true);
112 #endif
113  table.add_value("ndofs", problem.get_n_dofs());
114  table.add_value("ncells", problem.get_n_cells());
115  table.add_value("L2", projector.get_L2_norm());
116  table.add_value("H1", 0.0);
117  }
118  table.save(dir + "main_table_p" + std::to_string(p));
119  }
120  }
121 };
122 
123 int
124 main()
125 {
126  try {
127  BatchMMSV batch;
128  batch.run();
129  } catch (std::exception& exc) {
130  std::cerr << std::endl
131  << std::endl
132  << "----------------------------------------------------"
133  << std::endl;
134  std::cerr << "Exception on processing: " << std::endl
135  << exc.what() << std::endl
136  << "Aborting!" << std::endl
137  << "----------------------------------------------------"
138  << std::endl;
139  return 1;
140  } catch (...) {
141  std::cerr << std::endl
142  << std::endl
143  << "----------------------------------------------------"
144  << std::endl;
145  std::cerr << "Unknown exception!" << std::endl
146  << "Aborting!" << std::endl
147  << "----------------------------------------------------"
148  << std::endl;
149  return 1;
150  }
151  return 0;
152 }
This is a wrap-around class. It contains the main loop of the program that implements the Method of m...
Definition: main.cpp:35
Describes exact solutions, , of the Method of manufactured solutions, vector potential (mms-v/) numer...
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-v/) numerical experim...
Definition: settings.hpp:26
Implements the Method of manufactured solutions, vector potential (mms-v/) numerical experiment.
Definition: solver.hpp:36
Computes the magnetic field as a curl of the magnetic vector potential, , i.e., .
Computes an out-of-plane magnetic field, , as a scalar curl of an in-plane magnetic vector potential,...
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.
const DoFHandler< dim > & get_dof_handler() const
Returns a reference to dof handler.
const Vector< double > & get_solution() const
Returns a reference to solution.
const Triangulation< dim > & get_tria() const
Returns a reference to triangulation.