v0.14.0
Loading...
Searching...
No Matches
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
16namespace 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
77protected:
78
79 template <typename I>
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
96struct SCHUR_DSYSV; ///< SY symmetric
97struct SCHUR_DGESV; ///< GE general (i.e., nonsymmetric, in some cases
98 ///< rectangular)
99
100/**
101 * @brief Assemble Schur complement
102 *
103 */
104template <typename I> struct OpSchurAssembleEnd;
105
106template <>
109 MoFEMErrorCode doWork(int side, EntityType type,
111};
112
113template <>
116 MoFEMErrorCode doWork(int side, EntityType type,
118};
119
120/**
121 * @brief Schur complement data storage
122 *
123 */
124struct 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
148private:
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<
161 indexed_by<
162
163 ordered_unique<
164 tag<uid_mi_tag>,
165 composite_key<
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
187template <>
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
195template <>
198 const VectorDouble &nf, InsertMode iora) {
199 return VecSetValues<EssentialBcStorage>(V, data, nf, iora);
200}
201
202template <>
203inline 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
210template <>
211inline 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__
static Index< 'M', 3 > M
ForcesAndSourcesCore::UserDataOperator UserDataOperator
@ NOSPACE
Definition: definitions.h:83
FTensor::Index< 'n', SPACE_DIM > n
FTensor::Index< 'm', SPACE_DIM > m
MoFEMErrorCode VecSetValues< EssentialBcStorage >(Vec V, const EntitiesFieldData::EntData &data, const double *ptr, InsertMode iora)
Set values to vector in operator.
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
uint128_t UId
Unique Id.
Definition: Types.hpp:31
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEMErrorCode VecSetValues< SchurL2Mats >(Vec V, const EntitiesFieldData::EntData &data, const VectorDouble &nf, InsertMode iora)
Definition: Schur.hpp:197
MoFEMErrorCode MatSetValues< SchurL2Mats >(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.hpp:189
Data on single entity (This is passed as argument to DataOperator::doWork)
@ OPSPACE
operator do Work is execute on space data
structure to get information form mofem into EntitiesFieldData
Clear Schur complement internal data.
Definition: Schur.hpp:22
MoFEMErrorCode doWork(int side, EntityType type, EntitiesFieldData::EntData &data)
Operator for linear form, usually to calculate values on right hand side.
Definition: Schur.cpp:180
Assemble Schur complement.
Definition: Schur.hpp:104
Assemble Schur complement (Implementation)
Definition: Schur.hpp:35
MatrixDouble offMatInvDiagOffMat
Definition: Schur.hpp:92
std::vector< boost::shared_ptr< Range > > fieldEnts
Definition: Schur.hpp:84
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
static MatSetValuesRaw matSetValuesSchurRaw
Definition: Schur.hpp:41
MoFEMErrorCode doWorkImpl(int side, EntityType type, EntitiesFieldData::EntData &data)
Definition: Schur.cpp:223
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:210
std::vector< bool > symSchur
Definition: Schur.hpp:87
std::vector< std::string > fieldsName
Definition: Schur.hpp:83
MatrixDouble invDiagOffMat
Definition: Schur.hpp:91
std::vector< SmartPetscObj< Mat > > sequenceOfMats
Definition: Schur.hpp:86
std::vector< SmartPetscObj< AO > > sequenceOfAOs
Definition: Schur.hpp:85
MatrixDouble transOffMatInvDiagOffMat
Definition: Schur.hpp:93
std::vector< double > diagEps
Definition: Schur.hpp:88
Schur complement data storage.
Definition: Schur.hpp:124
virtual ~SchurL2Mats()=default
const UId uidCol
Definition: Schur.hpp:130
const UId uidRow
Definition: Schur.hpp:129
static MatSetValuesPtr matSetValuesPtr
backend assembly function
Definition: Schur.hpp:141
static boost::ptr_vector< VectorInt > rowIndices
Definition: Schur.hpp:182
friend OpSchurAssembleEndImpl
Definition: Schur.hpp:152
static SchurL2Storage schurL2Storage
Definition: Schur.hpp:184
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
static boost::ptr_vector< VectorInt > colIndices
Definition: Schur.hpp:183
const size_t iDX
Definition: Schur.hpp:149
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
auto & getMat() const
Definition: Schur.hpp:132
static MoFEMErrorCode MatSetValues(Mat M, const EntitiesFieldData::EntData &row_data, const EntitiesFieldData::EntData &col_data, const MatrixDouble &mat, InsertMode iora)
Definition: Schur.cpp:35
friend OpSchurAssembleBegin
Definition: Schur.hpp:151
static boost::ptr_vector< MatrixDouble > locMats
Definition: Schur.hpp:181
auto & getRowInd() const
Definition: Schur.hpp:133
auto & getColInd() const
Definition: Schur.hpp:134
intrusive_ptr for managing petsc objects