v0.14.0
Schur.hpp
Go to the documentation of this file.
1 /**
2  * @file Schur.hpp
3  * @brief Assemble Schur complement
4  * @date 2023-02-02
5  *
6  * @copyright Copyright (c) 2023
7  *
8  * To create nested system of Schur complements, you push sequence of operator,
9  * to set up data on entities, and then assemble complements.
10  *
11  */
12 
13 #ifndef __SCHUR_HPP__
14 #define __SCHUR_HPP__
15 
16 namespace MoFEM {
17 
18 /**
19  * @brief Clear Schur complement internal data
20  *
21  */
23 
26 
27  MoFEMErrorCode doWork(int side, EntityType type,
29 };
30 
31 /**
32  * @brief Assemble Schur complement (Implementation)
33  *
34  */
36 
37  using MatSetValuesRaw = boost::function<MoFEMErrorCode(
38  Mat mat, PetscInt m, const PetscInt idxm[], PetscInt n,
39  const PetscInt idxn[], const PetscScalar v[], InsertMode addv)>;
40 
42 
43  /**
44  * @brief Construct a new Op Schur Assemble End object
45  *
46  * @param fields_name list of fields
47  * @param field_ents list of entities on which schur complement is applied (can be empty)
48  * @param sequence_of_aos list of maps from base problem to Schur complement matrix
49  * @param sequence_of_mats list of Schur complement matrices
50  * @param sym_schur true if Schur complement is symmetric
51  * @param symm_op true if block diagonal is symmetric
52  */
53  OpSchurAssembleEndImpl(std::vector<std::string> fields_name,
54  std::vector<boost::shared_ptr<Range>> field_ents,
55  std::vector<SmartPetscObj<AO>> sequence_of_aos,
56  std::vector<SmartPetscObj<Mat>> sequence_of_mats,
57  std::vector<bool> sym_schur, bool symm_op = true);
58 
59  /**
60  * @brief Construct a new Op Schur Assemble End object
61  *
62  * @param fields_name list of fields
63  * @param field_ents list of entities on which schur complement is applied (can be empty)
64  * @param sequence_of_aos list of maps from base problem to Schur complement matrix
65  * @param sequence_of_mats list of Schur complement matrices
66  * @param sym_schur true if Schur complement is symmetric
67  * @param diag_eps add epsilon on diagonal of inverted matrix
68  * @param symm_op true if block diagonal is symmetric
69  */
70  OpSchurAssembleEndImpl(std::vector<std::string> fields_name,
71  std::vector<boost::shared_ptr<Range>> field_ents,
72  std::vector<SmartPetscObj<AO>> sequence_of_aos,
73  std::vector<SmartPetscObj<Mat>> sequence_of_mats,
74  std::vector<bool> sym_schur,
75  std::vector<double> diag_eps, bool symm_op = true);
76 
77 protected:
78 
79  template <typename I>
80  MoFEMErrorCode doWorkImpl(int side, EntityType type,
82 
83  std::vector<std::string> fieldsName;
84  std::vector<boost::shared_ptr<Range>> fieldEnts;
85  std::vector<SmartPetscObj<AO>> sequenceOfAOs;
86  std::vector<SmartPetscObj<Mat>> sequenceOfMats;
87  std::vector<bool> symSchur;
88  std::vector<double> diagEps;
89 
94 };
95 
96 struct SCHUR_DSYSV; ///< SY symmetric
97 struct SCHUR_DGESV; ///< GE general (i.e., nonsymmetric, in some cases
98  ///< rectangular)
99 
100 /**
101  * @brief Assemble Schur complement
102  *
103  */
104 template <typename I> struct OpSchurAssembleEnd;
105 
106 template <>
109  MoFEMErrorCode doWork(int side, EntityType type,
111 };
112 
113 template <>
116  MoFEMErrorCode doWork(int side, EntityType type,
118 };
119 
120 /**
121  * @brief Schur complement data storage
122  *
123  */
124 struct SchurL2Mats : public boost::enable_shared_from_this<SchurL2Mats> {
125 
126  SchurL2Mats(const size_t idx, const UId uid_row, const UId uid_col);
127  virtual ~SchurL2Mats() = default;
128 
129  const UId uidRow;
130  const UId uidCol;
131 
132  inline auto &getMat() const { return locMats[iDX]; }
133  inline auto &getRowInd() const { return rowIndices[iDX]; }
134  inline auto &getColInd() const { return colIndices[iDX]; }
135 
136  using MatSetValuesPtr = boost::function<MoFEMErrorCode(
137  Mat M, const EntitiesFieldData::EntData &row_data,
138  const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat,
139  InsertMode iora)>;
140 
141  static MatSetValuesPtr matSetValuesPtr; ///< backend assembly function
142 
143  static MoFEMErrorCode MatSetValues(Mat M,
144  const EntitiesFieldData::EntData &row_data,
145  const EntitiesFieldData::EntData &col_data,
146  const MatrixDouble &mat, InsertMode iora);
147 
148 private:
149  const size_t iDX;
150 
153 
154  struct idx_mi_tag {};
155  struct uid_mi_tag {};
156  struct row_mi_tag {};
157  struct col_mi_tag {};
158 
159  using SchurL2Storage = multi_index_container<
160  SchurL2Mats,
161  indexed_by<
162 
163  ordered_unique<
164  tag<uid_mi_tag>,
165  composite_key<
166  SchurL2Mats,
167 
168  member<SchurL2Mats, const UId, &SchurL2Mats::uidRow>,
169  member<SchurL2Mats, const UId, &SchurL2Mats::uidCol>
170 
171  >>,
172 
173  ordered_non_unique<tag<row_mi_tag>, member<SchurL2Mats, const UId,
175 
176  ordered_non_unique<tag<col_mi_tag>, member<SchurL2Mats, const UId,
178 
179  >>;
180 
181  static boost::ptr_vector<MatrixDouble> locMats;
182  static boost::ptr_vector<VectorInt> rowIndices;
183  static boost::ptr_vector<VectorInt> colIndices;
185 };
186 
187 template <>
188 inline MoFEMErrorCode
190  const EntitiesFieldData::EntData &col_data,
191  const MatrixDouble &mat, InsertMode iora) {
192  return SchurL2Mats::MatSetValues(M, row_data, col_data, mat, iora);
193 }
194 
195 template <>
196 inline MoFEMErrorCode
198  const VectorDouble &nf, InsertMode iora) {
199  return VecSetValues<EssentialBcStorage>(V, data, nf, iora);
200 }
201 
202 template <>
203 inline MoFEMErrorCode MatSetValues<AssemblyTypeSelector<SCHUR>>(
204  Mat M, const EntitiesFieldData::EntData &row_data,
205  const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat,
206  InsertMode iora) {
207  return MatSetValues<SchurL2Mats>(M, row_data, col_data, mat, iora);
208 }
209 
210 template <>
211 inline MoFEMErrorCode VecSetValues<AssemblyTypeSelector<SCHUR>>(
212  Vec V, const EntitiesFieldData::EntData &data, const VectorDouble &nf,
213  InsertMode iora) {
214  return VecSetValues<SchurL2Mats>(V, data, nf, iora);
215 }
216 
217 } // namespace MoFEM
218 
219 #endif //__SCHUR_HPP__
NOSPACE
@ NOSPACE
Definition: definitions.h:83
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:127
MoFEM::SchurL2Mats::matSetValuesPtr
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition: Schur.hpp:141
MoFEM::OpSchurAssembleEndImpl::offMatInvDiagOffMat
MatrixDouble offMatInvDiagOffMat
Definition: Schur.hpp:92
MoFEM::SchurL2Mats::SchurL2Mats
SchurL2Mats(const size_t idx, const UId uid_row, const UId uid_col)
Definition: Schur.cpp:17
MoFEM::ForcesAndSourcesCore::UserDataOperator::OPSPACE
@ OPSPACE
operator do Work is execute on space data
Definition: ForcesAndSourcesCore.hpp:570
MoFEM::OpSchurAssembleEndImpl::matSetValuesSchurRaw
static MatSetValuesRaw matSetValuesSchurRaw
Definition: Schur.hpp:41
MoFEM::OpSchurAssembleBegin::OpSchurAssembleBegin
OpSchurAssembleBegin()
Definition: Schur.hpp:24
MoFEM::SchurL2Mats::getColInd
auto & getColInd() const
Definition: Schur.hpp:134
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::SchurL2Mats::idx_mi_tag
Definition: Schur.hpp:154
MoFEM::SchurL2Mats::uidCol
const UId uidCol
Definition: Schur.hpp:130
MoFEM::SCHUR_DSYSV
Definition: Schur.cpp:510
PlasticOps::M
FTensor::Index< 'M', 3 > M
Definition: PlasticOps.hpp:117
MoFEM::OpSchurAssembleEndImpl::fieldEnts
std::vector< boost::shared_ptr< Range > > fieldEnts
Definition: Schur.hpp:84
MoFEM::OpSchurAssembleBegin
Clear Schur complement internal data.
Definition: Schur.hpp:22
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::VecSetValues< SchurL2Mats >
MoFEMErrorCode VecSetValues< SchurL2Mats >(Vec V, const EntitiesFieldData::EntData &data, const VectorDouble &nf, InsertMode iora)
Definition: Schur.hpp:197
MoFEM::SchurL2Mats::schurL2Storage
static SchurL2Storage schurL2Storage
Definition: Schur.hpp:184
MoFEM::SchurL2Mats::iDX
const size_t iDX
Definition: Schur.hpp:149
MoFEM::ForcesAndSourcesCore::UserDataOperator
Definition: ForcesAndSourcesCore.hpp:549
MoFEM::Types::UId
uint128_t UId
Unique Id.
Definition: Types.hpp:31
MoFEM::SchurL2Mats::MatSetValues
static MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:35
convert.type
type
Definition: convert.py:64
MoFEM::SchurL2Mats::row_mi_tag
Definition: Schur.hpp:156
MoFEM::OpSchurAssembleBegin::doWork
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: Schur.cpp:177
MoFEM::OpSchurAssembleEndImpl::diagEps
std::vector< double > diagEps
Definition: Schur.hpp:88
MoFEM::OpSchurAssembleEndImpl::invMat
MatrixDouble invMat
Definition: Schur.hpp:90
MoFEM::MatSetValues< SchurL2Mats >
MoFEMErrorCode MatSetValues< SchurL2Mats >(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.hpp:189
MoFEM::SchurL2Mats::getMat
auto & getMat() const
Definition: Schur.hpp:132
MoFEM::OpSchurAssembleEndImpl::transOffMatInvDiagOffMat
MatrixDouble transOffMatInvDiagOffMat
Definition: Schur.hpp:93
MoFEM::SchurL2Mats::MatSetValuesPtr
boost::function< MoFEMErrorCode(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)> MatSetValuesPtr
Definition: Schur.hpp:139
convert.n
n
Definition: convert.py:82
MoFEM::SchurL2Mats::uidRow
const UId uidRow
Definition: Schur.hpp:129
MoFEM::ForcesAndSourcesCore
structure to get information form mofem into EntitiesFieldData
Definition: ForcesAndSourcesCore.hpp:22
MoFEM::SchurL2Mats::getRowInd
auto & getRowInd() const
Definition: Schur.hpp:133
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
MoFEM::OpSchurAssembleEndImpl
Assemble Schur complement (Implementation)
Definition: Schur.hpp:35
MoFEM::SchurL2Mats::rowIndices
static boost::ptr_vector< VectorInt > rowIndices
Definition: Schur.hpp:182
MoFEM::SchurL2Mats::locMats
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.hpp:181
MoFEM::OpSchurAssembleEndImpl::fieldsName
std::vector< std::string > fieldsName
Definition: Schur.hpp:83
MoFEM::OpSchurAssembleEnd
Assemble Schur complement.
Definition: Schur.hpp:104
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
MoFEM::SCHUR_DGESV
Definition: Schur.cpp:540
MoFEM::OpSchurAssembleEndImpl::doWorkImpl
MoFEMErrorCode doWorkImpl(int side, EntityType type, EntitiesFieldData::EntData &data)
Definition: Schur.cpp:220
MoFEM::SchurL2Mats::~SchurL2Mats
virtual ~SchurL2Mats()=default
MoFEM::SchurL2Mats::OpSchurAssembleBegin
friend OpSchurAssembleBegin
Definition: Schur.hpp:151
MoFEM::OpSchurAssembleEndImpl::sequenceOfAOs
std::vector< SmartPetscObj< AO > > sequenceOfAOs
Definition: Schur.hpp:85
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MoFEM::OpSchurAssembleEndImpl::MatSetValuesRaw
boost::function< MoFEMErrorCode(Mat mat, PetscInt m, const PetscInt idxm[], PetscInt n, const PetscInt idxn[], const PetscScalar v[], InsertMode addv)> MatSetValuesRaw
Definition: Schur.hpp:39
MoFEM::OpSchurAssembleEndImpl::sequenceOfMats
std::vector< SmartPetscObj< Mat > > sequenceOfMats
Definition: Schur.hpp:86
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEM::OpSchurAssembleEndImpl::OpSchurAssembleEndImpl
OpSchurAssembleEndImpl(std::vector< std::string > fields_name, std::vector< boost::shared_ptr< Range >> field_ents, std::vector< SmartPetscObj< AO >> sequence_of_aos, std::vector< SmartPetscObj< Mat >> sequence_of_mats, std::vector< bool > sym_schur, bool symm_op=true)
Construct a new Op Schur Assemble End object.
Definition: Schur.cpp:207
MoFEM::SchurL2Mats
Schur complement data storage.
Definition: Schur.hpp:124
MoFEM::SchurL2Mats::SchurL2Storage
multi_index_container< SchurL2Mats, indexed_by< ordered_unique< tag< uid_mi_tag >, composite_key< SchurL2Mats, member< SchurL2Mats, const UId, &SchurL2Mats::uidRow >, member< SchurL2Mats, const UId, &SchurL2Mats::uidCol > > >, ordered_non_unique< tag< row_mi_tag >, member< SchurL2Mats, const UId, &SchurL2Mats::uidRow > >, ordered_non_unique< tag< col_mi_tag >, member< SchurL2Mats, const UId, &SchurL2Mats::uidCol > > > > SchurL2Storage
Definition: Schur.hpp:179
MoFEM::OpSchurAssembleEndImpl::symSchur
std::vector< bool > symSchur
Definition: Schur.hpp:87
MoFEM::SmartPetscObj< AO >
MoFEM::SchurL2Mats::colIndices
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.hpp:183
MoFEM::SchurL2Mats::col_mi_tag
Definition: Schur.hpp:157
MoFEM::OpSchurAssembleEndImpl::invDiagOffMat
MatrixDouble invDiagOffMat
Definition: Schur.hpp:91
MoFEM::SchurL2Mats::OpSchurAssembleEndImpl
friend OpSchurAssembleEndImpl
Definition: Schur.hpp:152
MoFEM::VecSetValues< EssentialBcStorage >
MoFEMErrorCode VecSetValues< EssentialBcStorage >(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Set values to vector in operator.
Definition: FormsIntegrators.cpp:76
MoFEM::SchurL2Mats::uid_mi_tag
Definition: Schur.hpp:155