Debian Codegraph @

miniapps/diag-smoothers/ds-common.hpp

raw
1 // Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11
12 #ifndef MFEM_DS_COMMON_HPP
13 #define MFEM_DS_COMMON_HPP
14
15 #include "mfem.hpp"
16 #include "../common/mfem-common.hpp"
17 #include <fstream>
18 #include <iostream>
19
20 using namespace std;
21 using namespace mfem;
22
23 namespace ds_common
24 {
25
26 extern int MONITOR_DIGITS;
27 extern int MG_MAX_ITER;
28 extern real_t MG_REL_TOL;
29
30 extern int dim;
31 extern int space_dim;
32 extern real_t freq;
33 extern real_t kappa;
34
35 // Enumerator for the different solvers to implement
36 enum SolverType
37 {
38 sli,
39 cg,
40 num_solvers, // last
41 };
42
43 // Enumerator for the different integrators to implement
44 enum IntegratorType
45 {
46 mass,
47 diffusion,
48 maxwell,
49 num_integrators, // last
50 };
51
52 // Enumerator for the different types of preconditioners
53 enum PCType
54 {
55 none,
56 abs_global,
57 pq_element,
58 num_pc, // last
59 };
60
61 /// @brief Custom monitor that prints a csv-formatted file
62 class DataMonitor : public IterativeSolverMonitor
63 {
64 private:
65 ofstream os;
66 int precision;
67 public:
68 DataMonitor(string file_name, int ndigits);
69 void MonitorResidual(int it, real_t norm, const Vector &x, bool final);
70 void MonitorSolution(int it, real_t norm, const Vector &x, bool final);
71 };
72
73
74 /// @brief Abs-L(1)-Jacobi custom general geometric multigrid method.
75 ///
76 /// Intermediate levels use Abs-L(1)-Jacobi preconditioner by applying the
77 /// level matrix to the constant vector one. These are wrapped by an
78 /// OperatorJacobiSmoother. Coarsest level uses a used-selected solver
79 /// with an Abs-L(1)-Jacobi smoother. The assembly level is user-defined.
80 ///
81 /// @warning The construction of the smoother is based on the application of
82 /// AbsMult, which usually unfolds component-wise. E.g., if `A = B C`, then
83 /// `|A|x = |B|(|C| x)`.
84 class AbsL1GeometricMultigrid : public GeometricMultigrid
85 {
86 public:
87 AbsL1GeometricMultigrid(ParFiniteElementSpaceHierarchy& fes_hierarchy,
88 Array<int>& ess_bdr,
89 IntegratorType it,
90 SolverType st,
91 AssemblyLevel al);
92
93 ~AbsL1GeometricMultigrid() { delete coarse_pc; }
94
95 bool GetOwnershipLevelOperators() const { return mg_owned; }
96
97 private:
98 IntegratorType integrator_type;
99 SolverType solver_type;
100 AssemblyLevel assembly_level;
101 bool mg_owned;
102 OperatorJacobiSmoother* coarse_pc;
103 ConstantCoefficient one;
104
105 void ConstructCoarseOperatorAndSolver(ParFiniteElementSpace& coarse_fespace);
106
107 void ConstructOperatorAndSmoother(ParFiniteElementSpace& fespace, int level);
108
109 void ConstructBilinearForm(ParFiniteElementSpace& fespace);
110
111 };
112
113 void AssembleElementLpqJacobiDiag(ParBilinearForm& form, real_t p, real_t q,
114 Vector& diag);
115
116 real_t diffusion_solution(const Vector &x);
117 real_t diffusion_source(const Vector &x);
118
119 void maxwell_solution(const Vector &x, Vector &u);
120 void maxwell_source(const Vector &x, Vector &f);
121
122 } // namespace ds_common
123
124 #endif // MFEM_DS_COMMON_HPP