Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Nektar::MultiRegions::GlobalLinSysIterativeFull Class Reference

A global linear system. More...

#include <GlobalLinSysIterativeFull.h>

Inheritance diagram for Nektar::MultiRegions::GlobalLinSysIterativeFull:
Inheritance graph
[legend]
Collaboration diagram for Nektar::MultiRegions::GlobalLinSysIterativeFull:
Collaboration graph
[legend]

Public Member Functions

 GlobalLinSysIterativeFull (const GlobalLinSysKey &pLinSysKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSysIterativeFull ()
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSysIterative
 GlobalLinSysIterative (const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSysIterative ()
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
 GlobalLinSys (const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
virtual ~GlobalLinSys ()
 
const GlobalLinSysKeyGetKey (void) const
 Returns the key associated with the system. More...
 
const boost::weak_ptr< ExpList > & GetLocMat (void) const
 
void InitObject ()
 
void Initialise (const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 
void Solve (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
 Solve the linear system for given input and output vectors using a specified local to global map. More...
 
boost::shared_ptr< GlobalLinSysGetSharedThisPtr ()
 Returns a shared pointer to the current object. More...
 
int GetNumBlocks ()
 
DNekScalMatSharedPtr GetBlock (unsigned int n)
 
DNekScalBlkMatSharedPtr GetStaticCondBlock (unsigned int n)
 
void DropStaticCondBlock (unsigned int n)
 
void SolveLinearSystem (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir=0)
 Solve the linear system for given input and output vectors. More...
 

Static Public Member Functions

static GlobalLinSysSharedPtr create (const GlobalLinSysKey &pLinSysKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of class. More...
 

Private Member Functions

virtual void v_Solve (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
 Solve the linear system for given input and output vectors using a specified local to global map. More...
 
virtual void v_DoMatrixMultiply (const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
 
virtual void v_UniqueMap ()
 

Private Attributes

boost::shared_ptr< AssemblyMapm_locToGloMap
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSysIterative
void DoAconjugateProjection (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)
 A-conjugate projection technique. More...
 
void DoConjugateGradient (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)
 Actual iterative solve. More...
 
void Set_Rhs_Magnitude (const NekVector< NekDouble > &pIn)
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
virtual int v_GetNumBlocks ()
 Get the number of blocks in this system. More...
 
virtual DNekScalMatSharedPtr v_GetBlock (unsigned int n)
 Retrieves the block matrix from n-th expansion using the matrix key provided by the m_linSysKey. More...
 
virtual DNekScalBlkMatSharedPtr v_GetStaticCondBlock (unsigned int n)
 Retrieves a the static condensation block matrices from n-th expansion using the matrix key provided by the m_linSysKey. More...
 
virtual void v_DropStaticCondBlock (unsigned int n)
 Releases the static condensation block matrices from NekManager of n-th expansion using the matrix key provided by the m_linSysKey. More...
 
PreconditionerSharedPtr CreatePrecon (AssemblyMapSharedPtr asmMap)
 Create a preconditioner object from the parameters defined in the supplied assembly map. More...
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSysIterative
Array< OneD, int > m_map
 Global to universal unique map. More...
 
int m_maxiter
 maximum iterations More...
 
NekDouble m_tolerance
 Tolerance of iterative solver. More...
 
NekDouble m_rhs_magnitude
 dot product of rhs to normalise stopping criterion More...
 
NekDouble m_rhs_mag_sm
 cnt to how many times rhs_magnitude is called More...
 
PreconditionerSharedPtr m_precon
 
MultiRegions::PreconditionerType m_precontype
 
int m_totalIterations
 
bool m_useProjection
 Whether to apply projection technique. More...
 
bool m_root
 Root if parallel. More...
 
boost::circular_buffer< Array
< OneD, NekDouble > > 
m_prevLinSol
 Storage for solutions to previous linear problems. More...
 
int m_numPrevSols
 Total counter of previous solutions. More...
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSys
const GlobalLinSysKey m_linSysKey
 Key associated with this linear system. More...
 
const boost::weak_ptr< ExpListm_expList
 Local Matrix System. More...
 
const std::map< int,
RobinBCInfoSharedPtr
m_robinBCInfo
 Robin boundary info. More...
 
bool m_verbose
 

Detailed Description

A global linear system.

Definition at line 48 of file GlobalLinSysIterativeFull.h.

Constructor & Destructor Documentation

Nektar::MultiRegions::GlobalLinSysIterativeFull::GlobalLinSysIterativeFull ( const GlobalLinSysKey pKey,
const boost::weak_ptr< ExpList > &  pExp,
const boost::shared_ptr< AssemblyMap > &  pLocToGloMap 
)

Constructor for full direct matrix solve.

Constructor for full direct matrix solve.

Parameters
pKeyKey specifying matrix to solve.
pExpShared pointer to expansion list for applying matrix evaluations.
pLocToGloMapLocal to global mapping.

Definition at line 71 of file GlobalLinSysIterativeFull.cpp.

References ASSERTL1, Nektar::MultiRegions::eIterativeFull, Nektar::MultiRegions::GlobalLinSysKey::GetGlobalSysSolnType(), and Nektar::MultiRegions::GlobalLinSys::m_linSysKey.

75  : GlobalLinSys (pKey, pExp, pLocToGloMap),
76  GlobalLinSysIterative(pKey, pExp, pLocToGloMap)
77  {
79  "This routine should only be used when using an Iterative "
80  "conjugate gradient matrix solve.");
81  }
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.
GlobalLinSysIterative(const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
GlobalLinSys(const GlobalLinSysKey &pKey, const boost::weak_ptr< ExpList > &pExpList, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
Nektar::MultiRegions::GlobalLinSysIterativeFull::~GlobalLinSysIterativeFull ( )
virtual

Definition at line 87 of file GlobalLinSysIterativeFull.cpp.

88  {
89 
90  }

Member Function Documentation

static GlobalLinSysSharedPtr Nektar::MultiRegions::GlobalLinSysIterativeFull::create ( const GlobalLinSysKey pLinSysKey,
const boost::weak_ptr< ExpList > &  pExpList,
const boost::shared_ptr< AssemblyMap > &  pLocToGloMap 
)
inlinestatic

Creates an instance of this class.

Definition at line 52 of file GlobalLinSysIterativeFull.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

57  {
59  ::AllocateSharedPtr(pLinSysKey, pExpList, pLocToGloMap);
60  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::MultiRegions::GlobalLinSysIterativeFull::v_DoMatrixMultiply ( const Array< OneD, NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput 
)
privatevirtual

Implements Nektar::MultiRegions::GlobalLinSysIterative.

Definition at line 190 of file GlobalLinSysIterativeFull.cpp.

References ASSERTL0, Nektar::MultiRegions::eGlobal, Nektar::eWrapper, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, m_locToGloMap, Nektar::MultiRegions::GlobalLinSys::m_robinBCInfo, Vmath::Vadd(), and Vmath::Zero().

193  {
194  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
195  // Perform matrix-vector operation A*d_i
196  expList->GeneralMatrixOp(m_linSysKey,
197  pInput, pOutput, eGlobal);
198 
199  // Apply robin boundary conditions to the solution.
200  if(m_robinBCInfo.size() > 0)
201  {
202  ASSERTL0(false,
203  "Robin boundaries not set up in IterativeFull solver.");
204  int nGlobal = m_locToGloMap->GetNumGlobalCoeffs();
205  int nLocal = m_locToGloMap->GetNumLocalCoeffs();
206  int nDir = m_locToGloMap->GetNumGlobalDirBndCoeffs();
207  int nNonDir = nGlobal - nDir;
208  Array<OneD, NekDouble> robin_A(nGlobal, 0.0);
209  Array<OneD, NekDouble> robin_l(nLocal, 0.0);
210  Array<OneD, NekDouble> tmp;
211  NekVector<NekDouble> robin(nNonDir,
212  tmp = robin_A + nDir, eWrapper);
213 
214  // Operation: p_A = A * d_A
215  // First map d_A to local solution
216  m_locToGloMap->GlobalToLocal(pInput, robin_l);
217 
218  // Iterate over all the elements computing Robin BCs where
219  // necessary
220  for (int n = 0; n < expList->GetNumElmts(); ++n)
221  {
222  int nel = n;
223  int offset = expList->GetCoeff_Offset(n);
224  int ncoeffs = expList->GetExp(nel)->GetNcoeffs();
225 
226  if(m_robinBCInfo.count(nel) != 0) // add robin mass matrix
227  {
229  Array<OneD, NekDouble> tmp;
230  StdRegions::StdExpansionSharedPtr vExp = expList->GetExp(nel);
231 
232  // add local matrix contribution
233  for(rBC = m_robinBCInfo.find(nel)->second;rBC; rBC = rBC->next)
234  {
235  vExp->AddRobinEdgeContribution(rBC->m_robinID,rBC->m_robinPrimitiveCoeffs, tmp = robin_l + offset);
236  }
237  }
238  else
239  {
240  Vmath::Zero(ncoeffs, &robin_l[offset], 1);
241  }
242  }
243 
244  // Map local Robin contribution back to global coefficients
245  m_locToGloMap->LocalToGlobal(robin_l, robin_A);
246  // Add them to the output of the GeneralMatrixOp
247  Vmath::Vadd(nGlobal, pOutput, 1, robin_A, 1, pOutput, 1);
248  }
249 
250  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
boost::shared_ptr< RobinBCInfo > RobinBCInfoSharedPtr
Global coefficients.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:373
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:131
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:299
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129
void Nektar::MultiRegions::GlobalLinSysIterativeFull::v_Solve ( const Array< OneD, const NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const AssemblyMapSharedPtr pLocToGloMap,
const Array< OneD, const NekDouble > &  pDirForcing = NullNekDouble1DArray 
)
privatevirtual

Solve the linear system for given input and output vectors using a specified local to global map.

Solve a global linear system with Dirichlet forcing using a conjugate gradient method. This routine performs handling of the Dirichlet forcing terms and wraps the underlying iterative solver used for the remaining degrees of freedom.

Consider solving for $x$, the matrix system $Ax=b$, where $b$ is known. To enforce the Dirichlet terms we instead solve

\[A(x-x_0) = b - Ax_0 \]

where $x_0$ is the Dirichlet forcing.

Parameters
pInputRHS of linear system, $b$.
pOutputOn input, values of dirichlet degrees of freedom with initial guess on other values. On output, the solution $x$.
pLocToGloMapLocal to global mapping.
pDirForcingPrecalculated Dirichlet forcing.

Implements Nektar::MultiRegions::GlobalLinSys.

Definition at line 111 of file GlobalLinSysIterativeFull.cpp.

References ASSERTL0, Nektar::MultiRegions::eGlobal, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, m_locToGloMap, Nektar::LibUtilities::ReduceSum, Nektar::MultiRegions::GlobalLinSys::SolveLinearSystem(), Vmath::Vadd(), Vmath::Vcopy(), and Vmath::Vsub().

116  {
117  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
118  bool vCG;
119  if ((m_locToGloMap = boost::dynamic_pointer_cast<AssemblyMapCG>(
120  pLocToGloMap)))
121  {
122  vCG = true;
123  }
124  else if ((m_locToGloMap = boost::dynamic_pointer_cast<
125  AssemblyMapDG>(pLocToGloMap)))
126  {
127  vCG = false;
128  }
129  else
130  {
131  ASSERTL0(false, "Unknown map type");
132  }
133 
134  bool dirForcCalculated = (bool) pDirForcing.num_elements();
135  int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
136  int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
137  int nDirTotal = nDirDofs;
138 
139  expList->GetComm()->GetRowComm()
140  ->AllReduce(nDirTotal, LibUtilities::ReduceSum);
141 
142  Array<OneD, NekDouble> tmp(nGlobDofs), tmp2;
143 
144  if(nDirTotal)
145  {
146  // calculate the Dirichlet forcing
147  if(dirForcCalculated)
148  {
149  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
150  pDirForcing.get(), 1,
151  tmp.get(), 1);
152  }
153  else
154  {
155  // Calculate the dirichlet forcing B_b (== X_b) and
156  // substract it from the rhs
157  expList->GeneralMatrixOp(
158  m_linSysKey, pOutput, tmp, eGlobal);
159 
160  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
161  tmp.get(), 1,
162  tmp.get(), 1);
163  }
164  if (vCG)
165  {
166  Array<OneD, NekDouble> out(nGlobDofs,0.0);
167 
168  // solve for perturbation from intiial guess in pOutput
170  nGlobDofs, tmp, out, pLocToGloMap, nDirDofs);
171  Vmath::Vadd(nGlobDofs-nDirDofs, &out [nDirDofs], 1,
172  &pOutput[nDirDofs], 1, &pOutput[nDirDofs], 1);
173  }
174  else
175  {
176  ASSERTL0(false, "Need DG solve if using Dir BCs");
177  }
178  }
179  else
180  {
181  Vmath::Vcopy(nGlobDofs, pInput, 1, tmp, 1);
182  SolveLinearSystem(nGlobDofs, tmp, pOutput, pLocToGloMap);
183  }
184  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
void SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir=0)
Solve the linear system for given input and output vectors.
Definition: GlobalLinSys.h:201
Global coefficients.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:127
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:343
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:299
const boost::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:129
void Nektar::MultiRegions::GlobalLinSysIterativeFull::v_UniqueMap ( )
privatevirtual

Implements Nektar::MultiRegions::GlobalLinSysIterative.

Definition at line 255 of file GlobalLinSysIterativeFull.cpp.

References m_locToGloMap, and Nektar::MultiRegions::GlobalLinSysIterative::m_map.

256  {
257  m_map = m_locToGloMap->GetGlobalToUniversalMapUnique();
258  }
Array< OneD, int > m_map
Global to universal unique map.

Member Data Documentation

string Nektar::MultiRegions::GlobalLinSysIterativeFull::className
static
Initial value:
"IterativeFull",
"Iterative solver for full matrix system.")

Name of class.

Registers the class with the Factory.

Definition at line 63 of file GlobalLinSysIterativeFull.h.

boost::shared_ptr<AssemblyMap> Nektar::MultiRegions::GlobalLinSysIterativeFull::m_locToGloMap
private

Definition at line 76 of file GlobalLinSysIterativeFull.h.

Referenced by v_DoMatrixMultiply(), v_Solve(), and v_UniqueMap().