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 
16 #include <iostream>
17 #include <string>
18 
19 #include "misc.hpp"
20 #include "project_PHI_to_D.hpp"
21 #include "project_PHI_to_E.hpp"
22 #include "solver.hpp"
23 
24 using namespace Misc;
25 
31 class BatchMMS : public SettingsMMS
32 {
33 public:
34  void run()
35  {
36  if (nr_threads_max > 0)
37  MultithreadInfo::set_thread_limit(nr_threads_max);
38 
39  Assert(DIMENSION__ > 1, ExcInternalError());
40  Assert(DIMENSION__ < 4, ExcInternalError());
41 
42  std::string dir;
43  std::string fname;
44 
45  if (HYPERCUBE__ == 1) {
46  dir = (DIMENSION__ == 2) ? "Data/square/" : "Data/cube/";
47  } else {
48  dir = (DIMENSION__ == 2) ? "Data/circle/" : "Data/sphere/";
49  }
50 
51  std::cout << "Program: mms\n"
52  << "Dimensions: " << DIMENSION__ << "\n"
53  << "Writing to: " << dir << "\n";
54 
55  MainOutputTable table_PHI(DIMENSION__);
56  MainOutputTable table_E(DIMENSION__);
57  MainOutputTable table_D(DIMENSION__);
58 
59  for (unsigned int p = 1; p < 4; p++) {
60  table_PHI.clear();
61  table_E.clear();
62  table_D.clear();
63 
64 #if DIMENSION__ == 2
65  for (unsigned int r = 9; r < 13; r++)
66 #endif
67 #if DIMENSION__ == 3
68  for (unsigned int r = 8; r < 12; r++)
69 #endif
70  {
71  fname = dir + "solution_PHI_p" + std::to_string(p) + "_r" +
72  std::to_string(r);
73 
74  // Calculating potential
75  table_PHI.add_value("r", r);
76  table_PHI.add_value("p", p);
77 
79  std::cout << "Time table PHI \n";
80 
81  SolverMMS<DIMENSION__> problem(p, 1, r, fname);
82  table_PHI.add_value("ndofs", problem.get_n_dofs());
83  table_PHI.add_value("ncells", problem.get_n_cells());
84  table_PHI.add_value("L2", problem.get_L2_norm());
85  table_PHI.add_value("H1", problem.get_H1_norm());
86 
87  problem.clear();
88 
89  { // Calculating electrostatic field
90  fname = dir + "solution_E_p" + std::to_string(p) + "_r" +
91  std::to_string(r);
92 
93  table_E.add_value("r", r);
94  table_E.add_value("p", p);
95 
97  std::cout << "Time table E \n";
98 
99  ExactSolutionMMS_E<DIMENSION__> exact_solution;
100 
101  ProjectPHItoE projector(p - 1,
102  problem.get_mapping_degree(),
103  problem.get_tria(),
104  problem.get_dof_handler(),
105  problem.get_solution(),
106  fname,
107  &exact_solution,
108  false,
112 
113  table_E.add_value("ndofs", projector.get_n_dofs());
114  table_E.add_value("ncells", projector.get_n_cells());
115  table_E.add_value("L2", projector.get_L2_norm());
116  table_E.add_value("H1", 0.0);
117  }
118  { // Calculating displacement
119  fname = dir + "solution_D_p" + std::to_string(p) + "_r" +
120  std::to_string(r);
121 
122  table_D.add_value("r", r);
123  table_D.add_value("p", p);
124 
126  std::cout << "Time table D \n";
127 
128  ExactSolutionMMS_D<DIMENSION__> exact_solution;
129 
130  ProjectPHItoD projector(p - 1,
131  problem.get_mapping_degree(),
132  problem.get_tria(),
133  problem.get_dof_handler(),
134  problem.get_solution(),
135  fname,
136  &exact_solution,
137  false,
141 
142  table_D.add_value("ndofs", projector.get_n_dofs());
143  table_D.add_value("ncells", projector.get_n_cells());
144  table_D.add_value("L2", projector.get_L2_norm() / ep_0);
145  table_D.add_value("H1", 0.0);
146  }
147  }
148  // Saving convergence tables
149  std::cout << "Table PHI\n";
150  table_PHI.save(dir + "table_PHI_p" + std::to_string(p));
151 
152  std::cout << "Table E\n";
153  table_E.save(dir + "table_E_p" + std::to_string(p));
154 
155  std::cout << "Table D\n";
156  table_D.save(dir + "table_D_p" + std::to_string(p));
157  }
158  }
159 };
160 
161 int
162 main()
163 {
164  try {
165  BatchMMS batch;
166  batch.run();
167  } catch (std::exception& exc) {
168  std::cerr << std::endl
169  << std::endl
170  << "----------------------------------------------------"
171  << std::endl;
172  std::cerr << "Exception on processing: " << std::endl
173  << exc.what() << std::endl
174  << "Aborting!" << std::endl
175  << "----------------------------------------------------"
176  << std::endl;
177  return 1;
178  } catch (...) {
179  std::cerr << std::endl
180  << std::endl
181  << "----------------------------------------------------"
182  << std::endl;
183  std::cerr << "Unknown exception!" << std::endl
184  << "Aborting!" << std::endl
185  << "----------------------------------------------------"
186  << std::endl;
187  return 1;
188  }
189  return 0;
190 }
This is a wrap-around class. It contains the main loop of the program that implements the Method of m...
Definition: main.cpp:32
Describes exact solution, , of the Method of manufactured solutions (mms/) numerical experiment in tw...
Describes exact solution, , of the Method of manufactured solutions (mms/) numerical experiment in tw...
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
Global settings for the Method of manufactured solutions (mms/) numerical experiment.
Definition: settings.hpp:25
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
Implements the solver of the Method of manufactured solutions (mms/) numerical experiment.
Definition: solver.hpp:33
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.
unsigned int get_mapping_degree() const
Returns degree of the interpolating Lagrange polynomials used for mapping from the reference cell to ...