G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsIetiSystem.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsSolver/gsBlockOp.h>
17 #include <gsSolver/gsAdditiveOp.h>
18 
19 namespace gismo
20 {
21 
22 template<class T>
24 {
25  this->m_localMatrixOps.reserve(n);
26  this->m_localRhs.reserve(n);
27  this->m_localSolverOps.reserve(n);
28  this->m_jumpMatrices.reserve(n);
29 }
30 
31 template<class T>
32 void gsIetiSystem<T>::addSubdomain(JumpMatrixPtr jumpMatrix, OpPtr localMatrixOp, Matrix localRhs, OpPtr localSolverOp)
33 {
34  GISMO_ASSERT( jumpMatrix->cols() == localMatrixOp->cols()
35  && localMatrixOp->rows() == localMatrixOp->cols()
36  && localRhs.rows() == localMatrixOp->cols(),
37  "gsIetiSystem::addPatch: Dimensions do not agree." );
38 
39  GISMO_ASSERT( this->m_jumpMatrices.empty() || this->m_jumpMatrices[0]->rows() == jumpMatrix->rows(),
40  "gsIetiSystem::addPatch: The dimension of the given transfer matrix "
41  "is incompatible to the transfer matrices given previously." );
42 
43  this->m_jumpMatrices.push_back(give(jumpMatrix));
44  this->m_localMatrixOps.push_back(give(localMatrixOp));
45  this->m_localRhs.push_back(give(localRhs));
46  this->m_localSolverOps.push_back(give(localSolverOp));
47 }
48 
49 template<class T>
51 {
52  const size_t sz = this->m_localSolverOps.size();
53  for (size_t i=0; i<sz; ++i)
54  {
55  if (!m_localSolverOps[i]) // If not yet provided...
56  {
57  SparseMatrixOp* matop = dynamic_cast<SparseMatrixOp*>(this->m_localMatrixOps[i].get());
58  GISMO_ENSURE( matop, "gsIetiSystem::setupSparseLUSolvers The local solvers can only "
59  "be computed on the fly if the local systems in localMatrixOps are of type "
60  "gsMatrixOp<gsSparseMatrix<T>>. Please provide solvers via members .addSubdomain "
61  "or .solverOp" );
62  this->m_localSolverOps[i] = makeSparseLUSolver(SparseMatrix(matop->matrix()));
63  }
64  }
65 }
66 
67 template<class T>
69 {
70  const size_t sz = this->m_localMatrixOps.size();
71  typename gsBlockOp<T>::Ptr result = gsBlockOp<T>::make( sz+1, sz+1 );
72  for (size_t i=0; i<sz; ++i)
73  {
74  result->addOperator( i, i, m_localMatrixOps[i] );
75  // We hope that the transposed operator does not outlive the non-transposed one.
76  result->addOperator( i, sz, makeMatrixOp( this->m_jumpMatrices[i]->transpose() ) );
77  result->addOperator( sz, i, makeMatrixOp( this->m_jumpMatrices[i] ) );
78  }
79  return result;
80 }
81 
82 template<class T>
84 {
85  setupSparseLUSolvers();
86  return gsAdditiveOp<T>::make( this->m_jumpMatrices, this->m_localSolverOps );
87 }
88 
89 
90 template<class T>
92 {
93  setupSparseLUSolvers();
94  Matrix result;
95  result.setZero( this->nLagrangeMultipliers(), this->m_localRhs[0].cols());
96  const index_t numPatches = this->m_jumpMatrices.size();
97  for (index_t i=0; i<numPatches; ++i)
98  {
99  Matrix tmp;
100  this->m_localSolverOps[i]->apply( this->m_localRhs[i], tmp );
101  result += *(this->m_jumpMatrices[i]) * tmp;
102  }
103  return result;
104 }
105 
106 template<class T>
107 std::vector< gsMatrix<T> > gsIetiSystem<T>::constructSolutionFromLagrangeMultipliers(const Matrix& multipliers) const
108 {
109  setupSparseLUSolvers();
110 
111  const index_t numPatches = this->m_jumpMatrices.size();
112  std::vector<Matrix> result;
113  result.resize(numPatches);
114  for (index_t i=0; i<numPatches; ++i)
115  {
116  this->m_localSolverOps[i]->apply( this->m_localRhs[i]-this->m_jumpMatrices[i]->transpose()*multipliers, result[i] );
117  }
118  return result;
119 }
120 
121 template<class T>
123 {
124  const index_t sz = m_localMatrixOps.size();
125  index_t rows = nLagrangeMultipliers();
126  for (index_t k=0; k<sz; ++k)
127  rows += m_localRhs[k].rows();
128  Matrix result;
129  result.setZero(rows,m_localRhs[0].cols());
130  index_t i=0;
131  for (index_t k=0; k<sz; ++k)
132  {
133  const index_t l = m_localRhs[k].rows();
134  result.middleRows(i, l) = m_localRhs[k];
135  i += l;
136  }
137  return result;
138 }
139 
140 template<class T>
141 std::vector< gsMatrix<T> > gsIetiSystem<T>::constructSolutionFromSaddlePoint(const Matrix& x) const
142 {
143  const index_t sz = m_localMatrixOps.size();
144  std::vector<Matrix> result;
145  result.reserve(sz);
146  index_t i=0;
147  for (index_t k=0; k<sz; ++k)
148  {
149  const index_t l = m_localRhs[k].rows();
150  result.push_back( x.middleRows(i, l) );
151  i += l;
152  }
153  return result;
154 }
155 
156 
157 } // namespace gismo
memory::shared_ptr< JumpMatrix > JumpMatrixPtr
Shared pointer to sparse matrix type for jumps.
Definition: gsIetiSystem.h:76
Matrix rhsForSchurComplement() const
Returns the right-hand-side that is required for the Schur complement formulation of the IETI problem...
Definition: gsIetiSystem.hpp:91
Matrix rhsForSaddlePoint() const
Returns the right-hand-side that is required for the saddle point formulation of the IETI problem...
Definition: gsIetiSystem.hpp:122
memory::shared_ptr< Op > OpPtr
Shared pointer to linear operator.
Definition: gsIetiSystem.h:72
std::vector< Matrix > constructSolutionFromSaddlePoint(const Matrix &x) const
Returns the local solutions for the individual subdomains.
Definition: gsIetiSystem.hpp:141
Simple class create a block preconditioner structure.
Allows to set up additive Schwarz type preconditioners.
OpPtr schurComplement() const
Returns gsLinearOperator that represents the Schur complement for the IETI problem.
Definition: gsIetiSystem.hpp:83
std::vector< Matrix > constructSolutionFromLagrangeMultipliers(const Matrix &multipliers) const
Returns the local solutions for the individual subdomains.
Definition: gsIetiSystem.hpp:107
Simple adapter class to use a matrix (or matrix-like object) as a linear operator. Needed for the iterative method classes.
Definition: gsMatrixOp.h:33
NestedMatrix matrix() const
Returns the matrix.
Definition: gsMatrixOp.h:84
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void setupSparseLUSolvers() const
Setup solvers if not provided by user.
Definition: gsIetiSystem.hpp:50
void reserve(index_t n)
Reserves the memory required to store the number of subdomains.
Definition: gsIetiSystem.hpp:23
memory::shared_ptr< gsBlockOp< T > > Ptr
Shared pointer for gsBlockOp.
Definition: gsBlockOp.h:48
static uPtr make()
Definition: gsAdditiveOp.h:120
static uPtr make(index_t nRows, index_t nCols)
Make function returning a smart pointer.
Definition: gsBlockOp.h:60
void addSubdomain(JumpMatrixPtr jumpMatrix, OpPtr localMatrixOp, Matrix localRhs, OpPtr localSolverOp=OpPtr())
Definition: gsIetiSystem.hpp:32
void addOperator(index_t row, index_t col, const BasePtr &op)
Add a preconditioner to the block structure.
Definition: gsBlockOp.hpp:30
OpPtr saddlePointProblem() const
Returns gsLinearOperator that represents the IETI problem as saddle point problem.
Definition: gsIetiSystem.hpp:68