Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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
 Provide verbose output and root if parallel. More...
 
bool m_verbose
 
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...
 

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:218
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 189 of file GlobalLinSysIterativeFull.cpp.

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

192  {
193  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
194  // Perform matrix-vector operation A*d_i
195  expList->GeneralMatrixOp(m_linSysKey,
196  pInput, pOutput, eGlobal);
197 
198  // retrieve robin boundary condition information and apply robin
199  // boundary conditions to the solution.
200  const std::map<int, RobinBCInfoSharedPtr> vRobinBCInfo
201  = expList->GetRobinBCInfo();
202  if(vRobinBCInfo.size() > 0)
203  {
204  ASSERTL0(false,
205  "Robin boundaries not set up in IterativeFull solver.");
206  int nGlobal = m_locToGloMap->GetNumGlobalCoeffs();
207  int nLocal = m_locToGloMap->GetNumLocalCoeffs();
208  int nDir = m_locToGloMap->GetNumGlobalDirBndCoeffs();
209  int nNonDir = nGlobal - nDir;
210  Array<OneD, NekDouble> robin_A(nGlobal, 0.0);
211  Array<OneD, NekDouble> robin_l(nLocal, 0.0);
212  Array<OneD, NekDouble> tmp;
213  NekVector<NekDouble> robin(nNonDir,
214  tmp = robin_A + nDir, eWrapper);
215 
216  // Operation: p_A = A * d_A
217  // First map d_A to local solution
218  m_locToGloMap->GlobalToLocal(pInput, robin_l);
219 
220  // Iterate over all the elements computing Robin BCs where
221  // necessary
222  for (int n = 0; n < expList->GetNumElmts(); ++n)
223  {
224  int nel = expList->GetOffset_Elmt_Id(n);
225  int offset = expList->GetCoeff_Offset(n);
226  int ncoeffs = expList->GetExp(nel)->GetNcoeffs();
227 
228  if(vRobinBCInfo.count(nel) != 0) // add robin mass matrix
229  {
231  Array<OneD, NekDouble> tmp;
232  StdRegions::StdExpansionSharedPtr vExp = expList->GetExp(nel);
233 
234  // add local matrix contribution
235  for(rBC = vRobinBCInfo.find(nel)->second;rBC; rBC = rBC->next)
236  {
237  vExp->AddRobinEdgeContribution(rBC->m_robinID,rBC->m_robinPrimitiveCoeffs, tmp = robin_l + offset);
238  }
239  }
240  else
241  {
242  Vmath::Zero(ncoeffs, &robin_l[offset], 1);
243  }
244  }
245 
246  // Map local Robin contribution back to global coefficients
247  m_locToGloMap->LocalToGlobal(robin_l, robin_A);
248  // Add them to the output of the GeneralMatrixOp
249  Vmath::Vadd(nGlobal, pOutput, 1, robin_A, 1, pOutput, 1);
250  }
251 
252  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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:359
boost::shared_ptr< StdExpansion > StdExpansionSharedPtr
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:285
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()->AllReduce(nDirTotal, LibUtilities::ReduceSum);
140 
141  Array<OneD, NekDouble> tmp(nGlobDofs), tmp2;
142 
143  if(nDirTotal)
144  {
145  // calculate the Dirichlet forcing
146  if(dirForcCalculated)
147  {
148  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
149  pDirForcing.get(), 1,
150  tmp.get(), 1);
151  }
152  else
153  {
154  // Calculate the dirichlet forcing B_b (== X_b) and
155  // substract it from the rhs
156  expList->GeneralMatrixOp(
157  m_linSysKey, pOutput, tmp, eGlobal);
158 
159  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
160  tmp.get(), 1,
161  tmp.get(), 1);
162  }
163  if (vCG)
164  {
165  Array<OneD, NekDouble> out(nGlobDofs,0.0);
166 
167  // solve for perturbation from intiial guess in pOutput
169  nGlobDofs, tmp, out, pLocToGloMap, nDirDofs);
170  Vmath::Vadd(nGlobDofs-nDirDofs, &out [nDirDofs], 1,
171  &pOutput[nDirDofs], 1, &pOutput[nDirDofs], 1);
172  }
173  else
174  {
175  ASSERTL0(false, "Need DG solve if using Dir BCs");
176  }
177  }
178  else
179  {
180  Vmath::Vcopy(nGlobDofs, pInput, 1, tmp, 1);
181  SolveLinearSystem(nGlobDofs, tmp, pOutput, pLocToGloMap);
182  }
183  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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:199
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:329
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
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:285
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 257 of file GlobalLinSysIterativeFull.cpp.

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

258  {
259  m_map = m_locToGloMap->GetGlobalToUniversalMapUnique();
260  }
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().