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
37namespace Nektar
38{
39namespace 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,
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
140 {
141 if ((2 * (bwidth + 1)) < rows)
142 {
144 }
145 else
146 {
147 matStorage = ePOSITIVE_DEFINITE_SYMMETRIC;
148 }
149 }
150 break;
154 default:
155 {
156 // Current inversion techniques do not seem to
157 // allow banded matrices to be used as a linear
158 // system
159 matStorage = eFULL;
160 }
161 break;
162 }
163
164 return matStorage;
165}
166
167/**
168 * Assemble the schur complement matrix from the block matrices stored
169 * in #m_blkMatrices and the given local to global mapping information.
170 * @param locToGloMap Local to global mapping information.
171 */
173 const AssemblyMapSharedPtr pLocToGloMap)
174{
175 int i, j, n, cnt, gid1, gid2;
176 NekDouble sign1, sign2, value;
177
178 int nBndDofs = pLocToGloMap->GetNumGlobalBndCoeffs();
179 int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
180
185
186 unsigned int rows = nBndDofs - NumDirBCs;
187 unsigned int cols = nBndDofs - NumDirBCs;
188
189 DNekMatSharedPtr Gmat;
190 int bwidth = pLocToGloMap->GetBndSystemBandWidth();
191
192 MatrixStorage matStorage = DetermineMatrixStorage(pLocToGloMap);
193
194 switch (matStorage)
195 {
197 {
198 try
199 {
201 rows, cols, 0.0, matStorage, bwidth, bwidth);
202 }
203 catch (...)
204 {
206 "Insufficient memory for GlobalLinSys.");
207 }
208 break;
209 }
210
212 case eFULL:
213 {
214 Gmat = MemoryManager<DNekMat>::AllocateSharedPtr(rows, cols, 0.0,
215 matStorage);
216 break;
217 }
218
219 default:
220 {
222 "Unknown matrix storage type of type not set up");
223 }
224 }
225
226 // fill global matrix
227 DNekScalMatSharedPtr loc_mat;
228 int loc_lda;
229 for (n = cnt = 0; n < SchurCompl->GetNumberOfBlockRows(); ++n)
230 {
231 loc_mat = SchurCompl->GetBlock(n, n);
232 loc_lda = loc_mat->GetRows();
233
234 // Set up Matrix;
235 for (i = 0; i < loc_lda; ++i)
236 {
237 gid1 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + i) - NumDirBCs;
238 sign1 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + i);
239
240 if (gid1 >= 0)
241 {
242 for (j = 0; j < loc_lda; ++j)
243 {
244 gid2 = pLocToGloMap->GetLocalToGlobalBndMap(cnt + j) -
245 NumDirBCs;
246 sign2 = pLocToGloMap->GetLocalToGlobalBndSign(cnt + j);
247
248 if (gid2 >= 0)
249 {
250 // As the global matrix should be symmetric,
251 // only add the value for the upper triangular
252 // part in order to avoid entries to be entered
253 // twice
254 if ((matStorage == eFULL) || (gid2 >= gid1))
255 {
256 value = Gmat->GetValue(gid1, gid2) +
257 sign1 * sign2 * (*loc_mat)(i, j);
258 Gmat->SetValue(gid1, gid2, value);
259 }
260 }
261 }
262 }
263 }
264 cnt += loc_lda;
265 }
266
267 if (rows)
268 {
271 }
272}
273
275 const GlobalLinSysKey &mkey, const std::weak_ptr<ExpList> &pExpList,
276 const DNekScalBlkMatSharedPtr pSchurCompl,
278 const DNekScalBlkMatSharedPtr pInvD,
279 const std::shared_ptr<AssemblyMap> &l2gMap)
280{
283 mkey, pExpList, pSchurCompl, pBinvD, pC, pInvD, l2gMap);
284 sys->Initialise(l2gMap);
285 return sys;
286}
287
288/// Solve the linear system for given input and output vectors.
290 const int pNumRows, const Array<OneD, const NekDouble> &pInput,
291 Array<OneD, NekDouble> &pOutput, const AssemblyMapSharedPtr &pLocToGloMap,
292 const int pNumDir)
293{
294 Array<OneD, NekDouble> tmp(pNumRows);
295 Array<OneD, NekDouble> global(pNumRows, 0.0);
296
297 pLocToGloMap->AssembleBnd(pInput, tmp);
298
299 const int nHomDofs = pNumRows - pNumDir;
300 DNekVec Vin(nHomDofs, tmp + pNumDir);
301
302 Array<OneD, NekDouble> tmp1 = global + pNumDir;
303 DNekVec Vout(nHomDofs, tmp1, eWrapper);
304
305 m_linSys->Solve(Vin, Vout);
306
307 pLocToGloMap->GlobalToLocalBnd(global, pOutput);
308}
309} // namespace MultiRegions
310} // 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_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 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:52
std::vector< double > w(NPUPPER)
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...