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 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 69 of file GlobalLinSysIterativeFull.cpp.

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

73  : GlobalLinSys (pKey, pExp, pLocToGloMap),
74  GlobalLinSysIterative(pKey, pExp, pLocToGloMap)
75  {
77  "This routine should only be used when using an Iterative "
78  "conjugate gradient matrix solve.");
79  }
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:191
Nektar::MultiRegions::GlobalLinSysIterativeFull::~GlobalLinSysIterativeFull ( )
virtual

Definition at line 85 of file GlobalLinSysIterativeFull.cpp.

86  {
87 
88  }

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 187 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().

190  {
191  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
192  // Perform matrix-vector operation A*d_i
193  expList->GeneralMatrixOp(m_linSysKey,
194  pInput, pOutput, eGlobal);
195 
196  // retrieve robin boundary condition information and apply robin
197  // boundary conditions to the solution.
198  const std::map<int, RobinBCInfoSharedPtr> vRobinBCInfo
199  = expList->GetRobinBCInfo();
200  if(vRobinBCInfo.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);
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 = expList->GetOffset_Elmt_Id(n);
223  int offset = expList->GetCoeff_Offset(n);
224  int ncoeffs = expList->GetExp(nel)->GetNcoeffs();
225 
226  if(vRobinBCInfo.count(nel) != 0) // add robin mass matrix
227  {
230  StdRegions::StdExpansionSharedPtr vExp = expList->GetExp(nel);
231 
232  // add local matrix contribution
233  for(rBC = vRobinBCInfo.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:161
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 109 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().

114  {
115  boost::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
116  bool vCG;
117  if ((m_locToGloMap = boost::dynamic_pointer_cast<AssemblyMapCG>(
118  pLocToGloMap)))
119  {
120  vCG = true;
121  }
122  else if ((m_locToGloMap = boost::dynamic_pointer_cast<
123  AssemblyMapDG>(pLocToGloMap)))
124  {
125  vCG = false;
126  }
127  else
128  {
129  ASSERTL0(false, "Unknown map type");
130  }
131 
132  bool dirForcCalculated = (bool) pDirForcing.num_elements();
133  int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
134  int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
135  int nDirTotal = nDirDofs;
136 
137  expList->GetComm()->AllReduce(nDirTotal, LibUtilities::ReduceSum);
138 
139  Array<OneD, NekDouble> tmp(nGlobDofs), tmp2;
140 
141  if(nDirTotal)
142  {
143  // calculate the Dirichlet forcing
144  if(dirForcCalculated)
145  {
146  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
147  pDirForcing.get(), 1,
148  tmp.get(), 1);
149  }
150  else
151  {
152  // Calculate the dirichlet forcing B_b (== X_b) and
153  // substract it from the rhs
154  expList->GeneralMatrixOp(
155  m_linSysKey, pOutput, tmp, eGlobal);
156 
157  Vmath::Vsub(nGlobDofs, pInput.get(), 1,
158  tmp.get(), 1,
159  tmp.get(), 1);
160  }
161  if (vCG)
162  {
163  Array<OneD, NekDouble> out(nGlobDofs,0.0);
164 
165  // solve for perturbation from intiial guess in pOutput
167  nGlobDofs, tmp, out, pLocToGloMap, nDirDofs);
168  Vmath::Vadd(nGlobDofs-nDirDofs, &out [nDirDofs], 1,
169  &pOutput[nDirDofs], 1, &pOutput[nDirDofs], 1);
170  }
171  else
172  {
173  ASSERTL0(false, "Need DG solve if using Dir BCs");
174  }
175  }
176  else
177  {
178  Vmath::Vcopy(nGlobDofs, pInput, 1, tmp, 1);
179  SolveLinearSystem(nGlobDofs, tmp, pOutput, pLocToGloMap);
180  }
181  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
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 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().