Nektar++
GlobalLinSysDirectStaticCond.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: GlobalLinSysDirectStaticCond.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: GlobalLinSysDirectStaticCond definition
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 namespace Nektar
38 {
39 namespace MultiRegions
40 {
41 /**
42  * @class GlobalLinSysDirect
43  *
44  * Solves a linear system using single- or multi-level static
45  * condensation.
46  */
47 
48 /**
49  * Registers the class with the Factory.
50  */
53  "DirectStaticCond", GlobalLinSysDirectStaticCond::create,
54  "Direct static condensation.");
55 
58  "DirectMultiLevelStaticCond", GlobalLinSysDirectStaticCond::create,
59  "Direct multi-level static condensation.");
60 
61 /**
62  * For a matrix system of the form @f[
63  * \left[ \begin{array}{cc}
64  * \boldsymbol{A} & \boldsymbol{B}\\
65  * \boldsymbol{C} & \boldsymbol{D}
66  * \end{array} \right]
67  * \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2}
68  * \end{array}\right]
69  * = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2}
70  * \end{array}\right],
71  * @f]
72  * where @f$\boldsymbol{D}@f$ and
73  * @f$(\boldsymbol{A-BD^{-1}C})@f$ are invertible, store and assemble
74  * a static condensation system, according to a given local to global
75  * mapping. #m_linSys is constructed by AssembleSchurComplement().
76  * @param mKey Associated matrix key.
77  * @param pLocMatSys LocalMatrixSystem
78  * @param locToGloMap Local to global mapping.
79  */
81  const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
82  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
83  : GlobalLinSys(pKey, pExpList, pLocToGloMap),
84  GlobalLinSysDirect(pKey, pExpList, pLocToGloMap),
85  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
86 {
89  "This constructor is only valid when using static "
90  "condensation");
92  pLocToGloMap->GetGlobalSysSolnType(),
93  "The local to global map is not set up for the requested "
94  "solution type");
95 }
96 
97 /**
98  *
99  */
101  const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
102  const DNekScalBlkMatSharedPtr pSchurCompl,
103  const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC,
104  const DNekScalBlkMatSharedPtr pInvD,
105  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
106  : GlobalLinSys(pKey, pExpList, pLocToGloMap),
107  GlobalLinSysDirect(pKey, pExpList, pLocToGloMap),
108  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
109 {
110  m_schurCompl = pSchurCompl;
111  m_BinvD = pBinvD;
112  m_C = pC;
113  m_invD = pInvD;
114 }
115 
116 /**
117  *
118  */
120 {
121 }
122 
124  const AssemblyMapSharedPtr &pLocToGloMap)
125 {
126  int nBndDofs = pLocToGloMap->GetNumGlobalBndCoeffs();
127  int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
128  unsigned int rows = nBndDofs - NumDirBCs;
129  int bwidth = pLocToGloMap->GetBndSystemBandWidth();
130 
131  MatrixStorage matStorage;
132 
133  switch (m_linSysKey.GetMatrixType())
134  {
135  // case for all symmetric matices
136  case StdRegions::eMass:
140  {
141  if ((2 * (bwidth + 1)) < rows)
142  {
144  }
145  else
146  {
147  matStorage = ePOSITIVE_DEFINITE_SYMMETRIC;
148  }
149  }
150  break;
153  default:
154  {
155  // Current inversion techniques do not seem to
156  // allow banded matrices to be used as a linear
157  // system
158  matStorage = eFULL;
159  }
160  break;
161  }
162 
163  return matStorage;
164 }
165 
166 /**
167  * Assemble the schur complement matrix from the block matrices stored
168  * in #m_blkMatrices and the given local to global mapping information.
169  * @param locToGloMap Local to global mapping information.
170  */
172  const AssemblyMapSharedPtr pLocToGloMap)
173 {
174  int i, j, n, cnt, gid1, gid2;
175  NekDouble sign1, sign2, value;
176 
177  int nBndDofs = pLocToGloMap->GetNumGlobalBndCoeffs();
178  int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
179 
184 
185  unsigned int rows = nBndDofs - NumDirBCs;
186  unsigned int cols = nBndDofs - NumDirBCs;
187 
188  DNekMatSharedPtr Gmat;
189  int bwidth = pLocToGloMap->GetBndSystemBandWidth();
190 
191  MatrixStorage matStorage = DetermineMatrixStorage(pLocToGloMap);
192 
193  switch (matStorage)
194  {
196  {
197  try
198  {
200  rows, cols, 0.0, matStorage, bwidth, bwidth);
201  }
202  catch (...)
203  {
205  "Insufficient memory for GlobalLinSys.");
206  }
207  break;
208  }
209 
211  case eFULL:
212  {
213  Gmat = MemoryManager<DNekMat>::AllocateSharedPtr(rows, cols, 0.0,
214  matStorage);
215  break;
216  }
217 
218  default:
219  {
221  "Unknown matrix storage type of type not set up");
222  }
223  }
224 
225  // fill global matrix
226  DNekScalMatSharedPtr loc_mat;
227  int loc_lda;
228  for (n = cnt = 0; n < SchurCompl->GetNumberOfBlockRows(); ++n)
229  {
230  loc_mat = SchurCompl->GetBlock(n, n);
231  loc_lda = loc_mat->GetRows();
232 
233  // Set up Matrix;
234  for (i = 0; i < loc_lda; ++i)
235  {
236  gid1 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + i) - NumDirBCs;
237  sign1 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + i);
238 
239  if (gid1 >= 0)
240  {
241  for (j = 0; j < loc_lda; ++j)
242  {
243  gid2 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + j) -
244  NumDirBCs;
245  sign2 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + j);
246 
247  if (gid2 >= 0)
248  {
249  // As the global matrix should be symmetric,
250  // only add the value for the upper triangular
251  // part in order to avoid entries to be entered
252  // twice
253  if ((matStorage == eFULL) || (gid2 >= gid1))
254  {
255  value = Gmat->GetValue(gid1, gid2) +
256  sign1 * sign2 * (*loc_mat)(i, j);
257  Gmat->SetValue(gid1, gid2, value);
258  }
259  }
260  }
261  }
262  }
263  cnt += loc_lda;
264  }
265 
266  if (rows)
267  {
270  }
271 }
272 
274  const GlobalLinSysKey &mkey, const std::weak_ptr<ExpList> &pExpList,
275  const DNekScalBlkMatSharedPtr pSchurCompl,
276  const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC,
277  const DNekScalBlkMatSharedPtr pInvD,
278  const std::shared_ptr<AssemblyMap> &l2gMap)
279 {
282  mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
283  sys->Initialise(l2gMap);
284  return sys;
285 }
286 } // namespace MultiRegions
287 } // namespace Nektar
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
DNekLinSysSharedPtr m_linSys
Basic linear system object.
static GlobalLinSysSharedPtr create(const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
GlobalLinSysDirectStaticCond(const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &locToGloMap)
Constructor for full direct matrix solve.
MatrixStorage DetermineMatrixStorage(const std::shared_ptr< AssemblyMap > &locToGloMap)
Matrix Storage type for known matrices.
virtual GlobalLinSysStaticCondSharedPtr v_Recurse(const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const DNekScalBlkMatSharedPtr pSchurCompl, const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC, const DNekScalBlkMatSharedPtr pInvD, const std::shared_ptr< AssemblyMap > &l2gMap) override
virtual void v_AssembleSchurComplement(std::shared_ptr< AssemblyMap > pLocToGloMap) override
A global linear system.
Definition: GlobalLinSys.h:72
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:122
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
DNekScalBlkMatSharedPtr m_schurCompl
Block Schur complement matrix.
DNekScalBlkMatSharedPtr m_BinvD
Block matrix.
DNekScalBlkMatSharedPtr m_C
Block matrix.
DNekScalBlkMatSharedPtr m_invD
Block matrix.
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.
std::shared_ptr< GlobalLinSysDirectStaticCond > GlobalLinSysDirectStaticCondSharedPtr
std::shared_ptr< GlobalLinSysStaticCond > GlobalLinSysStaticCondSharedPtr
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:51
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:79
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:75
double NekDouble
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...