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
37
38using namespace std;
39
40namespace Nektar
41{
42namespace MultiRegions
43{
44/**
45 * @class GlobalLinSysIterativeStaticCond
46 *
47 * Solves a linear system iteratively using single- or multi-level
48 * static condensation.
49 */
50
51/**
52 * Registers the class with the Factory.
53 */
56 "XxtStaticCond", GlobalLinSysXxtStaticCond::create,
57 "Iterative static condensation.");
58
61 "XxtMultiLevelStaticCond", GlobalLinSysXxtStaticCond::create,
62 "Xxt multi-level static condensation.");
63
64/**
65 * For a matrix system of the form @f[
66 * \left[ \begin{array}{cc}
67 * \boldsymbol{A} & \boldsymbol{B}\\
68 * \boldsymbol{C} & \boldsymbol{D}
69 * \end{array} \right]
70 * \left[ \begin{array}{c} \boldsymbol{x_1}\\ \boldsymbol{x_2}
71 * \end{array}\right]
72 * = \left[ \begin{array}{c} \boldsymbol{y_1}\\ \boldsymbol{y_2}
73 * \end{array}\right],
74 * @f]
75 * where @f$\boldsymbol{D}@f$ and
76 * @f$(\boldsymbol{A-BD^{-1}C})@f$ are invertible, store and assemble
77 * a static condensation system, according to a given local to global
78 * mapping. #m_linSys is constructed by AssembleSchurComplement().
79 * @param mKey Associated matrix key.
80 * @param pLocMatSys LocalMatrixSystem
81 * @param locToGloMap Local to global mapping.
82 */
84 const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
85 const std::shared_ptr<AssemblyMap> &pLocToGloMap)
86 : GlobalLinSys(pKey, pExpList, pLocToGloMap),
87 GlobalLinSysXxt(pKey, pExpList, pLocToGloMap),
88 GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
89{
92 "This constructor is only valid when using static "
93 "condensation");
95 pLocToGloMap->GetGlobalSysSolnType(),
96 "The local to global map is not set up for the requested "
97 "solution type");
98}
99
100/**
101 *
102 */
104 const GlobalLinSysKey &pKey, const std::weak_ptr<ExpList> &pExpList,
105 const DNekScalBlkMatSharedPtr pSchurCompl,
107 const DNekScalBlkMatSharedPtr pInvD,
108 const std::shared_ptr<AssemblyMap> &pLocToGloMap)
109 : GlobalLinSys(pKey, pExpList, pLocToGloMap),
110 GlobalLinSysXxt(pKey, pExpList, pLocToGloMap),
111 GlobalLinSysStaticCond(pKey, pExpList, pLocToGloMap)
112{
113 m_schurCompl = pSchurCompl;
114 m_BinvD = pBinvD;
115 m_C = pC;
116 m_invD = pInvD;
117 m_locToGloMap = pLocToGloMap;
118}
119
120/**
121 *
122 */
124{
125}
126
127/**
128 * Construct the local matrix row index, column index and value index
129 * arrays and initialize the XXT data structure with this information.
130 * @param locToGloMap Local to global mapping information.
131 */
133 std::shared_ptr<AssemblyMap> pLocToGloMap)
134{
135 ExpListSharedPtr vExp = m_expList.lock();
136 unsigned int nElmt = m_schurCompl->GetNumberOfBlockRows();
137 DNekScalMatSharedPtr loc_mat;
138 unsigned int iCount = 0;
139 unsigned int rCount = 0;
140 unsigned int nRows = 0;
141 unsigned int nEntries = 0;
142 unsigned int numDirBnd = pLocToGloMap->GetNumGlobalDirBndCoeffs();
143 unsigned int nLocal = pLocToGloMap->GetNumLocalBndCoeffs();
144 const Array<OneD, NekDouble> &vMapSign =
145 pLocToGloMap->GetLocalToGlobalBndSign();
146 bool doSign = pLocToGloMap->GetSignChange();
147 unsigned int i = 0, j = 0, k = 0, n = 0;
148 int gid1;
149 Array<OneD, unsigned int> vSizes(nElmt);
150
151 // First construct a map of the number of local DOFs in each block
152 // and the number of matrix entries for each block
153 for (n = 0; n < nElmt; ++n)
154 {
155 loc_mat = m_schurCompl->GetBlock(n, n);
156 vSizes[n] = loc_mat->GetRows();
157 nEntries += vSizes[n] * vSizes[n];
158 }
159
160 // Set up i-index, j-index and value arrays
163 m_Ar = Array<OneD, double>(nEntries, 0.0);
164
165 // Set up the universal ID array for XXT
166 Array<OneD, unsigned long> vId(nLocal);
167
168 // Loop over each elemental block, extract matrix indices and value
169 // and set the universal ID array
170 for (n = iCount = 0; n < nElmt; ++n)
171 {
172 loc_mat = m_schurCompl->GetBlock(n, n);
173 nRows = loc_mat->GetRows();
174
175 for (i = 0; i < nRows; ++i)
176 {
177 gid1 = pLocToGloMap->GetLocalToGlobalBndMap(iCount + i);
178 for (j = 0; j < nRows; ++j)
179 {
180 k = rCount + i * vSizes[n] + j;
181 m_Ai[k] = iCount + i;
182 m_Aj[k] = iCount + j;
183 m_Ar[k] = (*loc_mat)(i, j);
184 if (doSign)
185 {
186 m_Ar[k] *= vMapSign[iCount + i] * vMapSign[iCount + j];
187 }
188 }
189
190 // Dirichlet DOFs are not included in the solve, so we set
191 // these to the special XXT id=0.
192 if (gid1 < numDirBnd)
193 {
194 vId[iCount + i] = 0;
195 }
196 else
197 {
198 vId[iCount + i] =
199 pLocToGloMap->GetGlobalToUniversalBndMap()[gid1];
200 }
201 }
202 iCount += vSizes[n];
203 rCount += vSizes[n] * vSizes[n];
204 }
205
206 // Set up XXT and output some stats
207 LibUtilities::CommSharedPtr vComm = pLocToGloMap->GetComm()->GetRowComm();
208 m_crsData = Xxt::Init(nLocal, vId, m_Ai, m_Aj, m_Ar, vComm);
209 if (m_verbose)
210 {
212 }
213}
214
216 const GlobalLinSysKey &mkey, const std::weak_ptr<ExpList> &pExpList,
217 const DNekScalBlkMatSharedPtr pSchurCompl,
219 const DNekScalBlkMatSharedPtr pInvD,
220 const std::shared_ptr<AssemblyMap> &l2gMap)
221{
224 mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
225 sys->Initialise(l2gMap);
226 return sys;
227}
228
229/// Solve the linear system for given input and output vectors.
231 const int pNumRows, const Array<OneD, const NekDouble> &pInput,
232 Array<OneD, NekDouble> &pOutput, const AssemblyMapSharedPtr &pLocToGloMap,
233 const int pNumDir)
234{
235 boost::ignore_unused(pNumRows, pNumDir);
236
237 int nLocal = pLocToGloMap->GetLocalToGlobalBndSign().size();
238 Vmath::Zero(nLocal, pOutput, 1);
239
240 if (pLocToGloMap->GetSignChange())
241 {
242 Array<OneD, NekDouble> vlocal(nLocal);
243 Vmath::Vmul(nLocal, pLocToGloMap->GetLocalToGlobalBndSign(), 1, pInput,
244 1, vlocal, 1);
245
246 Xxt::Solve(pOutput, m_crsData, vlocal);
247
248 Vmath::Vmul(nLocal, pLocToGloMap->GetLocalToGlobalBndSign(), 1, pOutput,
249 1, pOutput, 1);
250 }
251 else
252 {
253 Xxt::Solve(pOutput, m_crsData, pInput);
254 }
255}
256} // namespace MultiRegions
257} // 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, unsigned int > m_Aj
Array< OneD, unsigned int > m_Ai
virtual void v_SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir) override
Solve the linear system for given input and output vectors.
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.
static GlobalLinSysSharedPtr create(const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:57
std::shared_ptr< GlobalLinSysXxtStaticCond > GlobalLinSysXxtStaticCondSharedPtr
std::shared_ptr< GlobalLinSysStaticCond > GlobalLinSysStaticCondSharedPtr
GlobalLinSysFactory & GetGlobalLinSysFactory()
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
Definition: AssemblyMap.h:52
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 Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:207
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:487
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:158
static void Solve(Nektar::Array< OneD, NekDouble > pX, struct crs_data *pCrs, Nektar::Array< OneD, NekDouble > pB)
Solve the matrix system for a given input vector b.
Definition: Xxt.hpp:186