Nektar++
GlobalLinSysXxtStaticCond.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GlobalLinSysIterativeStaticCond.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: GlobalLinSysIterativeStaticCond definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
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  */
57  "XxtStaticCond",
59  "Iterative static condensation.");
60 
63  "XxtMultiLevelStaticCond",
65  "Xxt multi-level static condensation.");
66 
67  /**
68  * For a matrix system of the form @f[
69  * \left[ \begin{array}{cc}
70  * \boldsymbol{A} & \boldsymbol{B}\\
71  * \boldsymbol{C} & \boldsymbol{D}
72  * \end{array} \right]
73  * \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2}
74  * \end{array}\right]
75  * = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2}
76  * \end{array}\right],
77  * @f]
78  * where @f$\boldsymbol{D}@f$ and
79  * @f$(\boldsymbol{A-BD^{-1}C})@f$ are invertible, store and assemble
80  * a static condensation system, according to a given local to global
81  * mapping. #m_linSys is constructed by AssembleSchurComplement().
82  * @param mKey Associated matrix key.
83  * @param pLocMatSys LocalMatrixSystem
84  * @param locToGloMap Local to global mapping.
85  */
87  const GlobalLinSysKey &pKey,
88  const boost::weak_ptr<ExpList> &pExpList,
89  const boost::shared_ptr<AssemblyMap>
90  &pLocToGloMap)
91  : GlobalLinSys (pKey, pExpList, pLocToGloMap),
92  GlobalLinSysXxt (pKey, pExpList, pLocToGloMap),
93  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
94  {
97  "This constructor is only valid when using static "
98  "condensation");
100  == pLocToGloMap->GetGlobalSysSolnType(),
101  "The local to global map is not set up for the requested "
102  "solution type");
103  }
104 
105 
106  /**
107  *
108  */
110  const GlobalLinSysKey &pKey,
111  const boost::weak_ptr<ExpList> &pExpList,
112  const DNekScalBlkMatSharedPtr pSchurCompl,
113  const DNekScalBlkMatSharedPtr pBinvD,
114  const DNekScalBlkMatSharedPtr pC,
115  const DNekScalBlkMatSharedPtr pInvD,
116  const boost::shared_ptr<AssemblyMap>
117  &pLocToGloMap)
118  : GlobalLinSys (pKey, pExpList, pLocToGloMap),
119  GlobalLinSysXxt (pKey, pExpList, pLocToGloMap),
120  GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
121  {
122  m_schurCompl = pSchurCompl;
123  m_BinvD = pBinvD;
124  m_C = pC;
125  m_invD = pInvD;
126  m_locToGloMap = pLocToGloMap;
127  }
128 
129 
130  /**
131  *
132  */
134  {
135 
136  }
137 
138  /**
139  * Create the inverse multiplicity map.
140  * @param locToGloMap Local to global mapping information.
141  */
143  const boost::shared_ptr<AssemblyMap> &pLocToGloMap)
144  {
145  const Array<OneD, const int> &vMap
146  = pLocToGloMap->GetLocalToGlobalBndMap();
147  unsigned int nGlo = pLocToGloMap->GetNumGlobalBndCoeffs();
148  unsigned int nEntries = pLocToGloMap->GetNumLocalBndCoeffs();
149  unsigned int i;
150 
151  // Count the multiplicity of each global DOF on this process
152  Array<OneD, NekDouble> vCounts(nGlo, 0.0);
153  for (i = 0; i < nEntries; ++i)
154  {
155  vCounts[vMap[i]] += 1.0;
156  }
157 
158  // Get universal multiplicity by globally assembling counts
159  pLocToGloMap->UniversalAssembleBnd(vCounts);
160 
161  // Construct a map of 1/multiplicity for use in XXT solve
163  for (i = 0; i < nEntries; ++i)
164  {
165  m_locToGloSignMult[i] = 1.0/vCounts[vMap[i]];
166  }
167 
168  m_map = pLocToGloMap->GetLocalToGlobalBndMap();
169  }
170 
171  /**
172  * Construct the local matrix row index, column index and value index
173  * arrays and initialize the XXT data structure with this information.
174  * @param locToGloMap Local to global mapping information.
175  */
177  boost::shared_ptr<AssemblyMap> pLocToGloMap)
178  {
179  CreateMap(pLocToGloMap);
180 
181  ExpListSharedPtr vExp = m_expList.lock();
182  unsigned int nElmt = m_schurCompl->GetNumberOfBlockRows();
183  DNekScalMatSharedPtr loc_mat;
184  unsigned int iCount = 0;
185  unsigned int rCount = 0;
186  unsigned int nRows = 0;
187  unsigned int nEntries = 0;
188  unsigned int numDirBnd = pLocToGloMap->GetNumGlobalDirBndCoeffs();
189  unsigned int nLocal = pLocToGloMap->GetNumLocalBndCoeffs();
190  const Array<OneD, NekDouble> &vMapSign
191  = pLocToGloMap->GetLocalToGlobalBndSign();
192  bool doSign = pLocToGloMap->GetSignChange();
193  unsigned int i = 0, j = 0, k = 0, n = 0;
194  int gid1;
195  Array<OneD, unsigned int> vSizes(nElmt);
196 
197  // First construct a map of the number of local DOFs in each block
198  // and the number of matrix entries for each block
199  for (n = 0; n < nElmt; ++n)
200  {
201  loc_mat = m_schurCompl->GetBlock(n,n);
202  vSizes[n] = loc_mat->GetRows();
203  nEntries += vSizes[n]*vSizes[n];
204  }
205 
206  // Set up i-index, j-index and value arrays
207  m_Ai = Array<OneD, unsigned int>(nEntries);
208  m_Aj = Array<OneD, unsigned int>(nEntries);
209  m_Ar = Array<OneD, double>(nEntries, 0.0);
210 
211  // Set up the universal ID array for XXT
212  Array<OneD, unsigned long> vId(nLocal);
213 
214  // Loop over each elemental block, extract matrix indices and value
215  // and set the universal ID array
216  for(n = iCount = 0; n < nElmt; ++n)
217  {
218  loc_mat = m_schurCompl->GetBlock(n,n);
219  nRows = loc_mat->GetRows();
220 
221  for(i = 0; i < nRows; ++i)
222  {
223  gid1 = pLocToGloMap->GetLocalToGlobalBndMap(iCount + i);
224  for(j = 0; j < nRows; ++j)
225  {
226  k = rCount + i*vSizes[n] + j;
227  m_Ai[k] = iCount + i;
228  m_Aj[k] = iCount + j;
229  m_Ar[k] = (*loc_mat)(i,j);
230  if (doSign)
231  {
232  m_Ar[k] *= vMapSign[iCount+i]*vMapSign[iCount+j];
233  }
234  }
235 
236  // Dirichlet DOFs are not included in the solve, so we set
237  // these to the special XXT id=0.
238  if (gid1 < numDirBnd)
239  {
240  vId[iCount + i] = 0;
241  }
242  else
243  {
244  vId[iCount + i]
245  = pLocToGloMap->GetGlobalToUniversalBndMap()[gid1];
246  }
247  }
248  iCount += vSizes[n];
249  rCount += vSizes[n]*vSizes[n];
250  }
251 
252  // Set up XXT and output some stats
253  LibUtilities::CommSharedPtr vComm = pLocToGloMap->GetComm()->GetRowComm();
254  m_crsData = Xxt::Init(nLocal, vId, m_Ai, m_Aj, m_Ar, vComm);
256  }
257 
259  const GlobalLinSysKey &mkey,
260  const boost::weak_ptr<ExpList> &pExpList,
261  const DNekScalBlkMatSharedPtr pSchurCompl,
262  const DNekScalBlkMatSharedPtr pBinvD,
263  const DNekScalBlkMatSharedPtr pC,
264  const DNekScalBlkMatSharedPtr pInvD,
265  const boost::shared_ptr<AssemblyMap> &l2gMap)
266  {
268  GlobalLinSysXxtStaticCond>::AllocateSharedPtr(
269  mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
270  sys->Initialise(l2gMap);
271  return sys;
272  }
273  }
274 }
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
DNekScalBlkMatSharedPtr m_schurCompl
Block Schur complement matrix.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
DNekScalBlkMatSharedPtr m_C
Block matrix.
boost::shared_ptr< GlobalLinSysXxtStaticCond > GlobalLinSysXxtStaticCondSharedPtr
static GlobalLinSysSharedPtr create(const GlobalLinSysKey &pLinSysKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
DNekScalBlkMatSharedPtr m_invD
Block matrix.
virtual void v_AssembleSchurComplement(boost::shared_ptr< AssemblyMap > locToGloMap)
Assemble the Schur complement matrix.
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Definition: ExpList.h:1340
boost::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
Definition: NekTypeDefs.hpp:74
Describe a linear system.
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:157
GlobalLinSysXxtStaticCond(const GlobalLinSysKey &mkey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &locToGloMap)
Constructor for full direct matrix solve.
Array< OneD, unsigned int > m_Aj
A global linear system.
Definition: GlobalLinSys.h:70
virtual GlobalLinSysStaticCondSharedPtr v_Recurse(const GlobalLinSysKey &mkey, const boost::weak_ptr< ExpList > &pExpList, const DNekScalBlkMatSharedPtr pSchurCompl, const DNekScalBlkMatSharedPtr pBinvD, const DNekScalBlkMatSharedPtr pC, const DNekScalBlkMatSharedPtr pInvD, const boost::shared_ptr< AssemblyMap > &locToGloMap)
Array< OneD, unsigned int > m_Ai
boost::shared_ptr< AssemblyMap > m_locToGloMap
Local to global map.
GlobalLinSysFactory & GetGlobalLinSysFactory()
void nektar_crs_stats(struct crs_data *data)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:191
void CreateMap(const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
DNekScalBlkMatSharedPtr m_BinvD
Block matrix.
Array< OneD, NekDouble > m_locToGloSignMult
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215
boost::shared_ptr< GlobalLinSysStaticCond > GlobalLinSysStaticCondSharedPtr
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:125