Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GlobalLinSysPETScFull.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File GlobalLinSysPETScFull.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: GlobalLinSysPETScFull definition
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <MultiRegions/ExpList.h>
38 
39 #include "petscao.h"
40 #include "petscis.h"
41 
42 namespace Nektar
43 {
44  namespace MultiRegions
45  {
46  /**
47  * @class GlobalLinSysPETScFull
48  */
49 
50  /**
51  * Registers the class with the Factory.
52  */
55  "PETScFull",
57  "PETSc Full Matrix.");
58 
59 
60  /// Constructor for full direct matrix solve.
62  const GlobalLinSysKey &pLinSysKey,
63  const boost::weak_ptr<ExpList> &pExp,
64  const boost::shared_ptr<AssemblyMap> &pLocToGloMap)
65  : GlobalLinSys (pLinSysKey, pExp, pLocToGloMap),
66  GlobalLinSysPETSc(pLinSysKey, pExp, pLocToGloMap)
67  {
69  "This routine should only be used when using a Full PETSc"
70  " matrix solve");
71 
72  const int nDofs = pLocToGloMap->GetNumGlobalCoeffs();
73  const int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
74 
75  int i, j, n, cnt, gid1, gid2, loc_lda;
76  NekDouble sign1, sign2, value;
77  DNekScalMatSharedPtr loc_mat;
78 
79  // CALCULATE REORDERING MAPPING
80  CalculateReordering(pLocToGloMap->GetGlobalToUniversalMap(),
81  pLocToGloMap->GetGlobalToUniversalMapUnique(),
82  pLocToGloMap);
83 
84  // SET UP VECTORS AND MATRIX
85  SetUpMatVec();
86 
87  // POPULATE MATRIX
88  for(n = cnt = 0; n < m_expList.lock()->GetNumElmts(); ++n)
89  {
90  loc_mat = GetBlock(m_expList.lock()->GetOffset_Elmt_Id(n));
91  loc_lda = loc_mat->GetRows();
92 
93  for(i = 0; i < loc_lda; ++i)
94  {
95  gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt+i) - nDirDofs;
96  sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
97  if(gid1 >= 0)
98  {
99  int gid1ro = m_reorderedMap[gid1];
100  for(j = 0; j < loc_lda; ++j)
101  {
102  gid2 = pLocToGloMap->GetLocalToGlobalMap(cnt + j)
103  - nDirDofs;
104  sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
105  if(gid2 >= 0)
106  {
107  int gid2ro = m_reorderedMap[gid2];
108  value = sign1*sign2*(*loc_mat)(i,j);
109  MatSetValue(
110  m_matrix, gid1ro, gid2ro, value, ADD_VALUES);
111  }
112  }
113  }
114  }
115  cnt += loc_lda;
116  }
117 
118  // ASSEMBLE MATRIX
119  MatAssemblyBegin(m_matrix, MAT_FINAL_ASSEMBLY);
120  MatAssemblyEnd (m_matrix, MAT_FINAL_ASSEMBLY);
121 
122  // SET UP SCATTER OBJECTS
123  SetUpScatter();
124 
125  // CONSTRUCT KSP OBJECT
126  SetUpSolver(pLocToGloMap->GetIterativeTolerance());
127  }
128 
129 
131  {
132 
133  }
134 
135 
136  /**
137  * Solve the linear system using a full global matrix system.
138  */
140  const Array<OneD, const NekDouble> &pInput,
141  Array<OneD, NekDouble> &pOutput,
142  const AssemblyMapSharedPtr &pLocToGloMap,
143  const Array<OneD, const NekDouble> &pDirForcing)
144  {
145  bool dirForcCalculated = (bool) pDirForcing.num_elements();
146  int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
147  int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
148  Array<OneD, NekDouble> tmp(nGlobDofs), tmp2;
149 
150  int nDirTotal = nDirDofs;
151  m_expList.lock()->GetComm()->GetRowComm()->AllReduce(
152  nDirTotal, LibUtilities::ReduceSum);
153 
154  if(nDirTotal)
155  {
156  // calculate the dirichlet forcing
157  if(dirForcCalculated)
158  {
159  Vmath::Vsub(nGlobDofs,
160  pInput.get(), 1,
161  pDirForcing.get(), 1,
162  tmp.get(), 1);
163  }
164  else
165  {
166  // Calculate the dirichlet forcing and substract it
167  // from the rhs
168  m_expList.lock()->GeneralMatrixOp(
169  m_linSysKey, pOutput, tmp, eGlobal);
170 
171  Vmath::Vsub(nGlobDofs,
172  pInput.get(), 1,
173  tmp.get(), 1,
174  tmp.get(), 1);
175  }
176 
177  Array<OneD, NekDouble> out(nGlobDofs,0.0);
178  SolveLinearSystem(nGlobDofs, tmp, out, pLocToGloMap, nDirDofs);
179  Vmath::Vadd(nGlobDofs-nDirDofs, &out [nDirDofs], 1,
180  &pOutput[nDirDofs], 1, &pOutput[nDirDofs], 1);
181  }
182  else
183  {
184  SolveLinearSystem(nDirDofs, pInput, pOutput, pLocToGloMap);
185  }
186  }
187  }
188 }