Nektar++
GlobalLinSysXxtStaticCond.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: GlobalLinSysXxtStaticCond.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: GlobalLinSysXxtStaticCond definition
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 namespace MultiRegions
44 {
45 /**
46  * @class GlobalLinSysIterativeStaticCond
47  *
48  * Solves a linear system iteratively using single- or multi-level
49  * static condensation.
50  */
51 
52 /**
53  * Registers the class with the Factory.
54  */
55 string GlobalLinSysXxtStaticCond::className =
57  "XxtStaticCond", GlobalLinSysXxtStaticCond::create,
58  "Iterative static condensation.");
59 
60 string GlobalLinSysXxtStaticCond::className2 =
62  "XxtMultiLevelStaticCond", GlobalLinSysXxtStaticCond::create,
63  "Xxt multi-level static condensation.");
64 
65 /**
66  * For a matrix system of the form @f[
67  * \left[ \begin{array}{cc}
68  * \boldsymbol{A} & \boldsymbol{B}\\
69  * \boldsymbol{C} & \boldsymbol{D}
70  * \end{array} \right]
71  * \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2}
72  * \end{array}\right]
73  * = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2}
74  * \end{array}\right],
75  * @f]
76  * where @f$\boldsymbol{D}@f$ and
77  * @f$(\boldsymbol{A-BD^{-1}C})@f$ are invertible, store and assemble
78  * a static condensation system, according to a given local to global
79  * mapping. #m_linSys is constructed by AssembleSchurComplement().
80  * @param mKey Associated matrix key.
81  * @param pLocMatSys LocalMatrixSystem
82  * @param locToGloMap Local to global mapping.
83  */
84 GlobalLinSysXxtStaticCond::GlobalLinSysXxtStaticCond(
85  const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
86  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
87  : GlobalLinSys(pKey, pExpList, pLocToGloMap),
88  GlobalLinSysXxt(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, const std::weak_ptr<ExpList> &pExpList,
106  const DNekScalBlkMatSharedPtr pSchurCompl,
107  const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC,
108  const DNekScalBlkMatSharedPtr pInvD,
109  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
110  : GlobalLinSys(pKey, pExpList, pLocToGloMap),
111  GlobalLinSysXxt(pKey, pExpList, pLocToGloMap),
112  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
113 {
114  m_schurCompl = pSchurCompl;
115  m_BinvD = pBinvD;
116  m_C = pC;
117  m_invD = pInvD;
118  m_locToGloMap = pLocToGloMap;
119 }
120 
121 /**
122  *
123  */
125 {
126 }
127 
128 /**
129  * Create the inverse multiplicity map.
130  * @param locToGloMap Local to global mapping information.
131  */
133  const std::shared_ptr<AssemblyMap> &pLocToGloMap)
134 {
135  const Array<OneD, const int> &vMap = pLocToGloMap->GetLocalToGlobalBndMap();
136  unsigned int nGlo = pLocToGloMap->GetNumGlobalBndCoeffs();
137  unsigned int nEntries = pLocToGloMap->GetNumLocalBndCoeffs();
138  unsigned int i;
139 
140  // Count the multiplicity of each global DOF on this process
141  Array<OneD, NekDouble> vCounts(nGlo, 0.0);
142  for (i = 0; i < nEntries; ++i)
143  {
144  vCounts[vMap[i]] += 1.0;
145  }
146 
147  // Get universal multiplicity by globally assembling counts
148  pLocToGloMap->UniversalAssembleBnd(vCounts);
149 
150  // Construct a map of 1/multiplicity for use in XXT solve
152  for (i = 0; i < nEntries; ++i)
153  {
154  m_locToGloSignMult[i] = 1.0 / vCounts[vMap[i]];
155  }
156 
157  m_map = pLocToGloMap->GetLocalToGlobalBndMap();
158 }
159 
160 /**
161  * Construct the local matrix row index, column index and value index
162  * arrays and initialize the XXT data structure with this information.
163  * @param locToGloMap Local to global mapping information.
164  */
166  std::shared_ptr<AssemblyMap> pLocToGloMap)
167 {
168  CreateMap(pLocToGloMap);
169 
170  ExpListSharedPtr vExp = m_expList.lock();
171  unsigned int nElmt = m_schurCompl->GetNumberOfBlockRows();
172  DNekScalMatSharedPtr loc_mat;
173  unsigned int iCount = 0;
174  unsigned int rCount = 0;
175  unsigned int nRows = 0;
176  unsigned int nEntries = 0;
177  unsigned int numDirBnd = pLocToGloMap->GetNumGlobalDirBndCoeffs();
178  unsigned int nLocal = pLocToGloMap->GetNumLocalBndCoeffs();
179  const Array<OneD, NekDouble> &vMapSign =
180  pLocToGloMap->GetLocalToGlobalBndSign();
181  bool doSign = pLocToGloMap->GetSignChange();
182  unsigned int i = 0, j = 0, k = 0, n = 0;
183  int gid1;
184  Array<OneD, unsigned int> vSizes(nElmt);
185 
186  // First construct a map of the number of local DOFs in each block
187  // and the number of matrix entries for each block
188  for (n = 0; n < nElmt; ++n)
189  {
190  loc_mat = m_schurCompl->GetBlock(n, n);
191  vSizes[n] = loc_mat->GetRows();
192  nEntries += vSizes[n] * vSizes[n];
193  }
194 
195  // Set up i-index, j-index and value arrays
196  m_Ai = Array<OneD, unsigned int>(nEntries);
197  m_Aj = Array<OneD, unsigned int>(nEntries);
198  m_Ar = Array<OneD, double>(nEntries, 0.0);
199 
200  // Set up the universal ID array for XXT
201  Array<OneD, unsigned long> vId(nLocal);
202 
203  // Loop over each elemental block, extract matrix indices and value
204  // and set the universal ID array
205  for (n = iCount = 0; n < nElmt; ++n)
206  {
207  loc_mat = m_schurCompl->GetBlock(n, n);
208  nRows = loc_mat->GetRows();
209 
210  for (i = 0; i < nRows; ++i)
211  {
212  gid1 = pLocToGloMap->GetLocalToGlobalBndMap(iCount + i);
213  for (j = 0; j < nRows; ++j)
214  {
215  k = rCount + i * vSizes[n] + j;
216  m_Ai[k] = iCount + i;
217  m_Aj[k] = iCount + j;
218  m_Ar[k] = (*loc_mat)(i, j);
219  if (doSign)
220  {
221  m_Ar[k] *= vMapSign[iCount + i] * vMapSign[iCount + j];
222  }
223  }
224 
225  // Dirichlet DOFs are not included in the solve, so we set
226  // these to the special XXT id=0.
227  if (gid1 < numDirBnd)
228  {
229  vId[iCount + i] = 0;
230  }
231  else
232  {
233  vId[iCount + i] =
234  pLocToGloMap->GetGlobalToUniversalBndMap()[gid1];
235  }
236  }
237  iCount += vSizes[n];
238  rCount += vSizes[n] * vSizes[n];
239  }
240 
241  // Set up XXT and output some stats
242  LibUtilities::CommSharedPtr vComm = pLocToGloMap->GetComm()->GetRowComm();
243  m_crsData = Xxt::Init(nLocal, vId, m_Ai, m_Aj, m_Ar, vComm);
244  if (m_verbose)
245  {
247  }
248 }
249 
251  const GlobalLinSysKey &mkey, const std::weak_ptr<ExpList> &pExpList,
252  const DNekScalBlkMatSharedPtr pSchurCompl,
253  const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC,
254  const DNekScalBlkMatSharedPtr pInvD,
255  const std::shared_ptr<AssemblyMap> &l2gMap)
256 {
259  mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
260  sys->Initialise(l2gMap);
261  return sys;
262 }
263 } // namespace MultiRegions
264 } // namespace Nektar
#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.
A global linear system.
Definition: GlobalLinSys.h:72
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:124
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
DNekScalBlkMatSharedPtr m_schurCompl
Block Schur complement matrix.
std::weak_ptr< AssemblyMap > m_locToGloMap
Local to global map.
DNekScalBlkMatSharedPtr m_BinvD
Block matrix.
DNekScalBlkMatSharedPtr m_C
Block matrix.
DNekScalBlkMatSharedPtr m_invD
Block matrix.
Array< OneD, NekDouble > m_locToGloSignMult
Array< OneD, unsigned int > m_Aj
Array< OneD, unsigned int > m_Ai
void CreateMap(const std::shared_ptr< AssemblyMap > &pLocToGloMap)
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 > &locToGloMap) override
GlobalLinSysXxtStaticCond(const GlobalLinSysKey &mkey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &locToGloMap)
Constructor for full direct matrix solve.
virtual void v_AssembleSchurComplement(std::shared_ptr< AssemblyMap > locToGloMap) override
Assemble the Schur complement matrix.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
std::shared_ptr< GlobalLinSysXxtStaticCond > GlobalLinSysXxtStaticCondSharedPtr
std::shared_ptr< GlobalLinSysStaticCond > GlobalLinSysStaticCondSharedPtr
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
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
void nektar_crs_stats(struct crs_data *data)
static struct crs_data * Init(unsigned int pRank, const Nektar::Array< OneD, unsigned long > pId, const Nektar::Array< OneD, unsigned int > pAi, const Nektar::Array< OneD, unsigned int > pAj, const Nektar::Array< OneD, NekDouble > pAr, const LibUtilities::CommSharedPtr &pComm)
Initialise the matrix-solve.
Definition: Xxt.hpp:161