MFEM  v4.6.0
Finite element discretization library
complexstaticcond.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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_COMPLEX_BLOCK_STATIC_CONDENSATION
13 #define MFEM_COMPLEX_BLOCK_STATIC_CONDENSATION
14 
15 #include "mfem.hpp"
16 
17 namespace mfem
18 {
19 
20 
21 /** @brief Class that performs static condensation of interior dofs for
22  multiple FE spaces for complex systems (see BlockStaticCondensation). It's used
23  by the class ComplexDPGWeakForm. */
25 {
26  int height, width;
27  int nblocks; // original number of blocks
28  int rblocks; // reduces number of blocks
29  Mesh * mesh = nullptr;
30  bool parallel = false;
31  // original set of Finite Element Spaces
33  // indicates if the original space is already a trace space
34  Array<bool> IsTraceSpace;
35 
36  // New set of "reduced" Finite Element Spaces
37  // (after static condensation)
39 
40  Array<int> dof_offsets;
41  Array<int> tdof_offsets;
42 
43  Array<int> rdof_offsets;
44  Array<int> rtdof_offsets;
45 
46  // Schur complement matrix
47  // S = A_ii - A_ib (A_bb)^{-1} A_bi.
48  BlockMatrix * S_r = nullptr;
49  BlockMatrix * S_i = nullptr;
50  BlockMatrix * S_e_r = nullptr;
51  BlockMatrix * S_e_i = nullptr;
52  ComplexOperator * S = nullptr;
53 
54  BlockVector * y_r = nullptr;
55  BlockVector * y_i = nullptr;
56  Vector * y = nullptr;
57 
59  Array<Vector * > lvec;
60 
61  Array<int> rdof_edof; // Map from reduced dofs to exposed dofs
62  Array<int> ess_rtdof_list;
63 
64  BlockMatrix * P = nullptr; // Block Prolongation
65  BlockMatrix * R = nullptr; // Block Restriction
66 
67 #ifdef MFEM_USE_MPI
68  BlockOperator * pS_r = nullptr;
69  BlockOperator * pS_e_r = nullptr;
70  BlockOperator * pS_i = nullptr;
71  BlockOperator * pS_e_i = nullptr;
72  // Block HypreParMatrix for Prolongation
73  BlockOperator * pP = nullptr;
74 #endif
75 
76  bool Parallel() const { return parallel; }
77 
78 
79  // tr_idx (trace dofs indices)
80  // int_idx (interior dof indices)
81  void GetReduceElementIndicesAndOffsets(int el, Array<int> & tr_idx,
82  Array<int> & int_idx,
83  Array<int> & offsets) const;
84 
85  void GetReduceElementVDofs(int el, Array<int> & rdofs) const;
86  void GetElementVDofs(int el, Array<int> & vdofs) const;
87 
88 
89  // S = A_ii - A_ib (A_bb)^{-1} A_bi.
90  // y = y_i - A_ib (A_bb)^{-1} y_b
91  ComplexDenseMatrix * GetLocalShurComplement(int el, const Array<int> & tr_idx,
92  const Array<int> & int_idx,
93  const ComplexDenseMatrix & elmat,
94  const Vector & elvect_r,
95  const Vector & elvect_i,
96  Vector & rvect_r,
97  Vector & rvect_i);
98 
99  void ComputeOffsets();
100 
101  void BuildProlongation();
102 #ifdef MFEM_USE_MPI
103  void BuildParallelProlongation();
104 #endif
105 
106  // ess_tdof list for each space
107  Array<Array<int> *> ess_tdofs;
108  void FillEssTdofLists(const Array<int> & ess_tdof_list);
109 
110  void ConformingAssemble(int skip_zeros);
111 
112  /** Restrict a marker Array on the true FE spaces dofs to a marker Array on
113  the reduced/trace true FE spaces dofs. */
114  void ConvertMarkerToReducedTrueDofs(Array<int> & tdof_marker,
115  Array<int> & rtdof_marker);
116 
117  void SetSpaces(Array<FiniteElementSpace*> & fes_);
118 
119  void Init();
120 
121 public:
122 
124 
126 
127  /** Assemble the contribution to the Schur complement from the given
128  element matrix @a elmat. Save the other blocks internally: A_bb_inv, A_bi,
129  and A_bi. */
130  void AssembleReducedSystem(int el, ComplexDenseMatrix &elmat,
131  Vector & elvect_r, Vector & elvect_i);
132 
133  /// Finalize the construction of the Schur complement matrix.
134  void Finalize(int skip_zeros = 0);
135 
136  /// Determine and save internally essential reduced true dofs.
137  void SetEssentialTrueDofs(const Array<int> &ess_tdof_list);
138 
139  /// Eliminate the given reduced true dofs from the Schur complement matrix S.
140  void EliminateReducedTrueDofs(const Array<int> &ess_rtdof_list,
141  Matrix::DiagonalPolicy dpolicy);
142 
143  bool HasEliminatedBC() const
144  {
145 #ifndef MFEM_USE_MPI
146  return S_e_r;
147 #else
148  return S_e_r || pS_e_r;
149 #endif
150 
151  }
152 
153  /// Return the serial Schur complement matrix.
154  BlockMatrix &GetSchurMatrix_r() { return *S_r; }
155  BlockMatrix &GetSchurMatrix_i() { return *S_i; }
157  {
158  if (!S)
159  {
160 #ifndef MFEM_USE_MPI
161  S = new ComplexOperator(S_r,S_i,false,false);
162 #else
163  if (parallel)
164  {
165  S = new ComplexOperator(pS_r,pS_i,false,false);
166  }
167  else
168  {
169  S = new ComplexOperator(S_r,S_i,false,false);
170  }
171 #endif
172  }
173  return *S;
174  }
175 
176  /// Return the eliminated part of the serial Schur complement matrix.
177  BlockMatrix &GetSchurMatrixElim_r() { return *S_e_r; }
178  BlockMatrix &GetSchurMatrixElim_i() { return *S_e_i; }
179 
180 #ifdef MFEM_USE_MPI
181  /// Return the parallel Schur complement matrix.
184 
185  /// Return the eliminated part of the parallel Schur complement matrix.
188 
189  void ParallelAssemble(BlockMatrix *m_r, BlockMatrix*m_i);
190 #endif
191 
192  /** Form the global reduced system matrix using the given @a diag_policy.
193  This method can be called after Assemble() is called. */
194  void FormSystemMatrix(Operator::DiagonalPolicy diag_policy);
195 
196  /** Restrict a solution vector on the full FE space dofs to a vector on the
197  reduced/trace true FE space dofs. */
198  void ReduceSolution(const Vector &sol, Vector &sc_sol) const;
199 
200  /** @brief Set the reduced solution `X` and r.h.s `B` vectors from the full
201  linear system solution `x` and r.h.s. `b` vectors.
202  This method should be called after the internal reduced essential dofs
203  have been set using SetEssentialTrueDofs() and both the Schur complement
204  and its eliminated part have been finalized. */
205  void ReduceSystem(Vector &x, Vector &X, Vector &B,
206  int copy_interior = 0) const;
207 
208  /** Restrict a list of true FE space dofs to a list of reduced/trace true FE
209  space dofs. */
210  void ConvertListToReducedTrueDofs(const Array<int> &ess_tdof_list,
211  Array<int> &ess_rtdof_list) const;
212 
213  /** Given a solution of the reduced system 'sc_sol' and the RHS 'b' for the
214  full linear system, compute the solution of the full system 'sol'. */
215  void ComputeSolution(const Vector &sc_sol, Vector &sol) const;
216 
217 };
218 
219 }
220 
221 #endif
void SetEssentialTrueDofs(const Array< int > &ess_tdof_list)
Determine and save internally essential reduced true dofs.
Class that performs static condensation of interior dofs for multiple FE spaces for complex systems (...
A class to handle Vectors in a block fashion.
Definition: blockvector.hpp:30
BlockOperator & GetParallelSchurMatrix_r()
Return the parallel Schur complement matrix.
Mimic the action of a complex operator using two real operators.
void ParallelAssemble(BlockMatrix *m_r, BlockMatrix *m_i)
ComplexBlockStaticCondensation(Array< FiniteElementSpace *> &fes_)
void ReduceSystem(Vector &x, Vector &X, Vector &B, int copy_interior=0) const
Set the reduced solution X and r.h.s B vectors from the full linear system solution x and r...
void ReduceSolution(const Vector &sol, Vector &sc_sol) const
void ComputeSolution(const Vector &sc_sol, Vector &sol) const
BlockMatrix & GetSchurMatrix_r()
Return the serial Schur complement matrix.
BlockOperator & GetParallelSchurMatrixElim_r()
Return the eliminated part of the parallel Schur complement matrix.
void AssembleReducedSystem(int el, ComplexDenseMatrix &elmat, Vector &elvect_r, Vector &elvect_i)
A class to initialize the size of a Tensor.
Definition: dtensor.hpp:54
void ConvertListToReducedTrueDofs(const Array< int > &ess_tdof_list, Array< int > &ess_rtdof_list) const
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition: operator.hpp:47
void Finalize(int skip_zeros=0)
Finalize the construction of the Schur complement matrix.
void EliminateReducedTrueDofs(const Array< int > &ess_rtdof_list, Matrix::DiagonalPolicy dpolicy)
Eliminate the given reduced true dofs from the Schur complement matrix S.
void FormSystemMatrix(Operator::DiagonalPolicy diag_policy)
Vector data type.
Definition: vector.hpp:58
BlockMatrix & GetSchurMatrixElim_r()
Return the eliminated part of the serial Schur complement matrix.
A class to handle Block systems in a matrix-free implementation.
Specialization of the ComplexOperator built from a pair of Dense Matrices. The purpose of this specia...