Nektar++
GlobalLinSysDirectStaticCond.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GlobalLinSys.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: GlobalLinSys 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",
55  "Direct static condensation.");
56 
59  "DirectMultiLevelStaticCond",
61  "Direct multi-level static condensation.");
62 
63  /**
64  * For a matrix system of the form @f[
65  * \left[ \begin{array}{cc}
66  * \boldsymbol{A} & \boldsymbol{B}\\
67  * \boldsymbol{C} & \boldsymbol{D}
68  * \end{array} \right]
69  * \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2}
70  * \end{array}\right]
71  * = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2}
72  * \end{array}\right],
73  * @f]
74  * where @f$\boldsymbol{D}@f$ and
75  * @f$(\boldsymbol{A-BD^{-1}C})@f$ are invertible, store and assemble
76  * a static condensation system, according to a given local to global
77  * mapping. #m_linSys is constructed by AssembleSchurComplement().
78  * @param mKey Associated matrix key.
79  * @param pLocMatSys LocalMatrixSystem
80  * @param locToGloMap Local to global mapping.
81  */
83  const GlobalLinSysKey &pKey,
84  const std::weak_ptr<ExpList> &pExpList,
85  const std::shared_ptr<AssemblyMap>
86  &pLocToGloMap)
87  : GlobalLinSys (pKey, pExpList, pLocToGloMap),
88  GlobalLinSysDirect (pKey, pExpList, pLocToGloMap),
89  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
90  {
93  "This constructor is only valid when using static "
94  "condensation");
96  == pLocToGloMap->GetGlobalSysSolnType(),
97  "The local to global map is not set up for the requested "
98  "solution type");
99  }
100 
101  /**
102  *
103  */
105  const GlobalLinSysKey &pKey,
106  const std::weak_ptr<ExpList> &pExpList,
107  const DNekScalBlkMatSharedPtr pSchurCompl,
108  const DNekScalBlkMatSharedPtr pBinvD,
109  const DNekScalBlkMatSharedPtr pC,
110  const DNekScalBlkMatSharedPtr pInvD,
111  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
112  : GlobalLinSys (pKey, pExpList, pLocToGloMap),
113  GlobalLinSysDirect (pKey, pExpList, pLocToGloMap),
114  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
115  {
116  m_schurCompl = pSchurCompl;
117  m_BinvD = pBinvD;
118  m_C = pC;
119  m_invD = pInvD;
120  }
121 
122 
123  /**
124  *
125  */
127  {
128 
129  }
130 
131 
133  const AssemblyMapSharedPtr &pLocToGloMap)
134  {
135  int nBndDofs = pLocToGloMap->GetNumGlobalBndCoeffs();
136  int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
137  unsigned int rows = nBndDofs - NumDirBCs;
138  int bwidth = pLocToGloMap->GetBndSystemBandWidth();
139 
140  MatrixStorage matStorage;
141 
142  switch(m_linSysKey.GetMatrixType())
143  {
144  // case for all symmetric matices
145  case StdRegions::eMass:
149  {
150  if( (2*(bwidth+1)) < rows)
151  {
153  }
154  else
155  {
156  matStorage = ePOSITIVE_DEFINITE_SYMMETRIC;
157  }
158  }
159  break;
162  default:
163  {
164  // Current inversion techniques do not seem to
165  // allow banded matrices to be used as a linear
166  // system
167  matStorage = eFULL;
168  }
169  break;
170  }
171 
172  return matStorage;
173  }
174 
175  /**
176  * Assemble the schur complement matrix from the block matrices stored
177  * in #m_blkMatrices and the given local to global mapping information.
178  * @param locToGloMap Local to global mapping information.
179  */
181  const AssemblyMapSharedPtr pLocToGloMap)
182  {
183  int i, j, n, cnt, gid1, gid2;
184  NekDouble sign1, sign2, value;
185 
186  int nBndDofs = pLocToGloMap->GetNumGlobalBndCoeffs();
187  int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
188 
193 
194  unsigned int rows = nBndDofs - NumDirBCs;
195  unsigned int cols = nBndDofs - NumDirBCs;
196 
197  DNekMatSharedPtr Gmat;
198  int bwidth = pLocToGloMap->GetBndSystemBandWidth();
199 
200  MatrixStorage matStorage = DetermineMatrixStorage(pLocToGloMap);
201 
202  switch(matStorage)
203  {
205  {
206  try {
208  ::AllocateSharedPtr(rows, cols, 0.0,
209  matStorage,
210  bwidth, bwidth);
211  }
212  catch (...) {
214  "Insufficient memory for GlobalLinSys.");
215  }
216  break;
217  }
218 
220  case eFULL:
221  {
223  ::AllocateSharedPtr(rows, cols, 0.0, matStorage);
224  break;
225  }
226 
227  default:
228  {
230  "Unknown matrix storage type of type not set up");
231  }
232  }
233 
234  // fill global matrix
235  DNekScalMatSharedPtr loc_mat;
236  int loc_lda;
237  for(n = cnt = 0; n < SchurCompl->GetNumberOfBlockRows(); ++n)
238  {
239  loc_mat = SchurCompl->GetBlock(n,n);
240  loc_lda = loc_mat->GetRows();
241 
242  // Set up Matrix;
243  for(i = 0; i < loc_lda; ++i)
244  {
245  gid1 = pLocToGloMap->GetLocalToGlobalBndMap (cnt + i)
246  - NumDirBCs;
247  sign1 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + i);
248 
249  if(gid1 >= 0)
250  {
251  for(j = 0; j < loc_lda; ++j)
252  {
253  gid2 = pLocToGloMap->GetLocalToGlobalBndMap(cnt+j)
254  - NumDirBCs;
255  sign2 = pLocToGloMap->GetLocalToGlobalBndSign(cnt+j);
256 
257  if(gid2 >= 0)
258  {
259  // As the global matrix should be symmetric,
260  // only add the value for the upper triangular
261  // part in order to avoid entries to be entered
262  // twice
263  if((matStorage == eFULL)||(gid2 >= gid1))
264  {
265  value = Gmat->GetValue(gid1,gid2)
266  + sign1*sign2*(*loc_mat)(i,j);
267  Gmat->SetValue(gid1,gid2,value);
268  }
269  }
270  }
271  }
272  }
273  cnt += loc_lda;
274  }
275 
276  if(rows)
277  {
280  }
281  }
282 
284  const GlobalLinSysKey &mkey,
285  const std::weak_ptr<ExpList> &pExpList,
286  const DNekScalBlkMatSharedPtr pSchurCompl,
287  const DNekScalBlkMatSharedPtr pBinvD,
288  const DNekScalBlkMatSharedPtr pC,
289  const DNekScalBlkMatSharedPtr pInvD,
290  const std::shared_ptr<AssemblyMap> &l2gMap)
291  {
293  GlobalLinSysDirectStaticCond>::AllocateSharedPtr(
294  mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
295  sys->Initialise(l2gMap);
296  return sys;
297  }
298  }
299 }
#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:250
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
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.
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)
virtual void v_AssembleSchurComplement(std::shared_ptr< AssemblyMap > pLocToGloMap)
MatrixStorage DetermineMatrixStorage(const std::shared_ptr< AssemblyMap > &locToGloMap)
Matrix Storage type for known matrices.
A global linear system.
Definition: GlobalLinSys.h:73
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:125
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:52
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:73
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
std::shared_ptr< DNekMat > DNekMatSharedPtr
Definition: NekTypeDefs.hpp:69
double NekDouble
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...