Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | List of all members
Nektar::MultiRegions::GlobalLinSysDirectFull Class Reference

A global linear system. More...

#include <GlobalLinSysDirectFull.h>

Inheritance diagram for Nektar::MultiRegions::GlobalLinSysDirectFull:
[legend]

Public Member Functions

 GlobalLinSysDirectFull (const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysDirectFull () override=default
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSysDirect
 GlobalLinSysDirect (const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExp, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Constructor for full direct matrix solve. More...
 
 ~GlobalLinSysDirect () override
 
- Public Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
 GlobalLinSys (const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::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 std::weak_ptr< ExpList > & GetLocMat (void) const
 
void InitObject ()
 
void Initialise (const std::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...
 
std::shared_ptr< GlobalLinSysGetSharedThisPtr ()
 Returns a shared pointer to the current object. More...
 
int GetNumBlocks ()
 
DNekScalMatSharedPtr GetBlock (unsigned int n)
 
void DropBlock (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 std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 Creates an instance of this class. More...
 

Static Public Attributes

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

Protected Member Functions

void v_Solve (const Array< OneD, const NekDouble > &pLocInput, Array< OneD, NekDouble > &pLocalOutput, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray) override
 Solve the linear system for given input and output vectors using a specified local to global map. More...
 
- Protected Member Functions inherited from Nektar::MultiRegions::GlobalLinSys
virtual void v_Solve (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out, const AssemblyMapSharedPtr &locToGloMap, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)=0
 Solve a linear system based on mapping. More...
 
virtual void v_SolveLinearSystem (const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir)=0
 Solve a basic matrix system. More...
 
virtual void v_InitObject ()
 
virtual void v_Initialise (const std::shared_ptr< AssemblyMap > &pLocToGloMap)
 
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 void v_DropBlock (unsigned int n)
 Releases the local block matrix from NekManager of 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...
 

Private Member Functions

void AssembleFullMatrix (const std::shared_ptr< AssemblyMap > &locToGloMap)
 
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. More...
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSysDirect
DNekLinSysSharedPtr m_linSys
 Basic linear system object. More...
 
- Protected Attributes inherited from Nektar::MultiRegions::GlobalLinSys
const GlobalLinSysKey m_linSysKey
 Key associated with this linear system. More...
 
const std::weak_ptr< ExpListm_expList
 Local Matrix System. More...
 
const std::map< int, RobinBCInfoSharedPtrm_robinBCInfo
 Robin boundary info. More...
 
bool m_verbose
 

Detailed Description

A global linear system.

Definition at line 49 of file GlobalLinSysDirectFull.h.

Constructor & Destructor Documentation

◆ GlobalLinSysDirectFull()

Nektar::MultiRegions::GlobalLinSysDirectFull::GlobalLinSysDirectFull ( const GlobalLinSysKey pLinSysKey,
const std::weak_ptr< ExpList > &  pExpList,
const std::shared_ptr< AssemblyMap > &  pLocToGloMap 
)

Constructor for full direct matrix solve.

Definition at line 75 of file GlobalLinSysDirectFull.cpp.

78 : GlobalLinSys(pLinSysKey, pExp, pLocToGloMap),
79 GlobalLinSysDirect(pLinSysKey, pExp, pLocToGloMap)
80{
81
83 "This routine should only be used when using a Full Direct"
84 " matrix solve");
85 ASSERTL1(pExp.lock()->GetComm()->GetSize() == 1,
86 "Direct full matrix solve can only be used in serial.");
87
88 AssembleFullMatrix(pLocToGloMap);
89}
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
void AssembleFullMatrix(const std::shared_ptr< AssemblyMap > &locToGloMap)
GlobalLinSysDirect(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExp, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
GlobalLinSys(const GlobalLinSysKey &pKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Constructor for full direct matrix solve.
const GlobalLinSysKey m_linSysKey
Key associated with this linear system.
Definition: GlobalLinSys.h:120
GlobalSysSolnType GetGlobalSysSolnType() const
Return the associated solution type.

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

◆ ~GlobalLinSysDirectFull()

Nektar::MultiRegions::GlobalLinSysDirectFull::~GlobalLinSysDirectFull ( )
overridedefault

Member Function Documentation

◆ AssembleFullMatrix()

void Nektar::MultiRegions::GlobalLinSysDirectFull::AssembleFullMatrix ( const std::shared_ptr< AssemblyMap > &  locToGloMap)
private

Assemble a full matrix from the block matrix stored in #m_blkMatrices and the given local to global mapping information.

Parameters
locToGloMapLocal to global mapping information.

Definition at line 167 of file GlobalLinSysDirectFull.cpp.

169{
170 int i, j, n, cnt, gid1, gid2;
171 NekDouble sign1, sign2, value;
172 int totDofs = pLocToGloMap->GetNumGlobalCoeffs();
173 int NumDirBCs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
174
175 unsigned int rows = totDofs - NumDirBCs;
176 unsigned int cols = totDofs - NumDirBCs;
177 NekDouble zero = 0.0;
178
179 DNekMatSharedPtr Gmat;
180 int bwidth = pLocToGloMap->GetFullSystemBandWidth();
181 MatrixStorage matStorage = eFULL;
182
183 switch (m_linSysKey.GetMatrixType())
184 {
185 // case for all symmetric matices
190 {
191 if ((2 * (bwidth + 1)) < rows)
192 {
195 rows, cols, zero, matStorage, bwidth, bwidth);
196 }
197 else
198 {
199 matStorage = ePOSITIVE_DEFINITE_SYMMETRIC;
201 rows, cols, zero, matStorage);
202 }
203 break;
204 }
207 {
208 matStorage = eFULL;
209 Gmat = MemoryManager<DNekMat>::AllocateSharedPtr(rows, cols, zero,
210 matStorage);
211 break;
212 }
213 default:
214 {
215 NEKERROR(ErrorUtil::efatal, "Add MatrixType to switch "
216 "statement");
217 }
218 }
219
220 // fill global matrix
221 DNekScalMatSharedPtr loc_mat;
222
223 int loc_lda;
224 for (n = cnt = 0; n < m_expList.lock()->GetNumElmts(); ++n)
225 {
226 loc_mat = GetBlock(n);
227 loc_lda = loc_mat->GetRows();
228
229 for (i = 0; i < loc_lda; ++i)
230 {
231 gid1 = pLocToGloMap->GetLocalToGlobalMap(cnt + i) - NumDirBCs;
232 sign1 = pLocToGloMap->GetLocalToGlobalSign(cnt + i);
233 if (gid1 >= 0)
234 {
235 for (j = 0; j < loc_lda; ++j)
236 {
237 gid2 =
238 pLocToGloMap->GetLocalToGlobalMap(cnt + j) - NumDirBCs;
239 sign2 = pLocToGloMap->GetLocalToGlobalSign(cnt + j);
240 if (gid2 >= 0)
241 {
242 // When global matrix is symmetric,
243 // only add the value for the upper
244 // triangular part in order to avoid
245 // entries to be entered twice
246 if ((matStorage == eFULL) || (gid2 >= gid1))
247 {
248 value = Gmat->GetValue(gid1, gid2) +
249 sign1 * sign2 * (*loc_mat)(i, j);
250 Gmat->SetValue(gid1, gid2, value);
251 }
252 }
253 }
254 }
255 }
256 cnt += loc_lda;
257 }
258
259 if (rows)
260 {
263 }
264}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
DNekLinSysSharedPtr m_linSys
Basic linear system object.
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
Definition: GlobalLinSys.h:122
DNekScalMatSharedPtr GetBlock(unsigned int n)
Definition: GlobalLinSys.h:209
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.
std::vector< double > w(NPUPPER)
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
@ 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...

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::ErrorUtil::efatal, Nektar::eFULL, Nektar::StdRegions::eHelmholtz, Nektar::StdRegions::eHybridDGHelmBndLam, Nektar::StdRegions::eLaplacian, Nektar::StdRegions::eLinearAdvectionDiffusionReaction, Nektar::StdRegions::eLinearAdvectionReaction, Nektar::StdRegions::eMass, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC_BANDED, Nektar::eWrapper, Nektar::MultiRegions::GlobalLinSys::GetBlock(), Nektar::MultiRegions::GlobalMatrixKey::GetMatrixType(), Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSysDirect::m_linSys, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, NEKERROR, and Nektar::UnitTests::w().

Referenced by GlobalLinSysDirectFull().

◆ create()

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

Creates an instance of this class.

Definition at line 53 of file GlobalLinSysDirectFull.h.

57 {
59 pLinSysKey, pExpList, pLocToGloMap);
60 }

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

◆ v_Solve()

void Nektar::MultiRegions::GlobalLinSysDirectFull::v_Solve ( const Array< OneD, const NekDouble > &  pLocInput,
Array< OneD, NekDouble > &  pLocOutput,
const AssemblyMapSharedPtr pLocToGloMap,
const Array< OneD, const NekDouble > &  pDirForcing = NullNekDouble1DArray 
)
overrideprotectedvirtual

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

Solve the linear system using a full global matrix system.

Implements Nektar::MultiRegions::GlobalLinSys.

Definition at line 94 of file GlobalLinSysDirectFull.cpp.

99{
100 bool dirForcCalculated = (bool)pDirForcing.size();
101 int nDirDofs = pLocToGloMap->GetNumGlobalDirBndCoeffs();
102 int nGlobDofs = pLocToGloMap->GetNumGlobalCoeffs();
103 int nLocDofs = pLocToGloMap->GetNumLocalCoeffs();
104
105 if (nDirDofs)
106 {
107 std::shared_ptr<MultiRegions::ExpList> expList = m_expList.lock();
108 Array<OneD, NekDouble> rhs(nLocDofs);
109
110 // Calculate the Dirichlet forcing
111 if (dirForcCalculated)
112 {
113 // Assume pDirForcing is in local space
114 ASSERTL0(
115 pDirForcing.size() >= nLocDofs,
116 "DirForcing is not of sufficient size. Is it in local space?");
117 Vmath::Vsub(nLocDofs, pLocInput, 1, pDirForcing, 1, rhs, 1);
118 }
119 else
120 {
121 // Calculate initial condition and Dirichlet forcing and subtract it
122 // from the rhs
123 expList->GeneralMatrixOp(m_linSysKey, pLocOutput, rhs);
124
125 // Iterate over all the elements computing Robin BCs where
126 // necessary
127 for (auto &r : m_robinBCInfo) // add robin mass matrix
128 {
130 Array<OneD, NekDouble> rhsloc;
131
132 int n = r.first;
133 int offset = expList->GetCoeff_Offset(n);
134
135 LocalRegions::ExpansionSharedPtr vExp = expList->GetExp(n);
136 // Add local matrix contribution
137 for (rBC = r.second; rBC; rBC = rBC->next)
138 {
139 vExp->AddRobinTraceContribution(
140 rBC->m_robinID, rBC->m_robinPrimitiveCoeffs,
141 pLocOutput + offset, rhsloc = rhs + offset);
142 }
143 }
144 Vmath::Vsub(nLocDofs, pLocInput, 1, rhs, 1, rhs, 1);
145 }
146
147 Array<OneD, NekDouble> diff(nLocDofs);
148
149 // Solve for perturbation from initial guess in pOutput
150 SolveLinearSystem(nGlobDofs, rhs, diff, pLocToGloMap, nDirDofs);
151
152 // Add back initial and boundary condition
153 Vmath::Vadd(nLocDofs, diff, 1, pLocOutput, 1, pLocOutput, 1);
154 }
155 else
156 {
157 SolveLinearSystem(nGlobDofs, pLocInput, pLocOutput, pLocToGloMap,
158 nDirDofs);
159 }
160}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
const std::map< int, RobinBCInfoSharedPtr > m_robinBCInfo
Robin boundary info.
Definition: GlobalLinSys.h:124
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:190
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66
std::shared_ptr< RobinBCInfo > RobinBCInfoSharedPtr
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.hpp:180
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.hpp:220

References ASSERTL0, Nektar::MultiRegions::GlobalLinSys::m_expList, Nektar::MultiRegions::GlobalLinSys::m_linSysKey, Nektar::MultiRegions::GlobalLinSys::m_robinBCInfo, Nektar::MultiRegions::GlobalLinSys::SolveLinearSystem(), Vmath::Vadd(), and Vmath::Vsub().

◆ v_SolveLinearSystem()

void Nektar::MultiRegions::GlobalLinSysDirectFull::v_SolveLinearSystem ( const int  pNumRows,
const Array< OneD, const NekDouble > &  pInput,
Array< OneD, NekDouble > &  pOutput,
const AssemblyMapSharedPtr locToGloMap,
const int  pNumDir 
)
overrideprivatevirtual

Solve the linear system for given input and output vectors.

Implements Nektar::MultiRegions::GlobalLinSys.

Definition at line 267 of file GlobalLinSysDirectFull.cpp.

271{
272 Array<OneD, NekDouble> tmp(pNumRows);
273 Array<OneD, NekDouble> global(pNumRows, 0.0);
274
275 pLocToGloMap->Assemble(pInput, tmp);
276
277 const int nHomDofs = pNumRows - pNumDir;
278 DNekVec Vin(nHomDofs, tmp + pNumDir);
279
280 Array<OneD, NekDouble> tmp1 = global + pNumDir;
281 DNekVec Vout(nHomDofs, tmp1, eWrapper);
282
283 m_linSys->Solve(Vin, Vout);
284
285 pLocToGloMap->GlobalToLocal(global, pOutput);
286}
NekVector< NekDouble > DNekVec
Definition: NekTypeDefs.hpp:48

References Nektar::eWrapper, and Nektar::MultiRegions::GlobalLinSysDirect::m_linSys.

Member Data Documentation

◆ className

string Nektar::MultiRegions::GlobalLinSysDirectFull::className
static
Initial value:
=
"DirectFull", GlobalLinSysDirectFull::create, "Direct Full.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
static GlobalLinSysSharedPtr create(const GlobalLinSysKey &pLinSysKey, const std::weak_ptr< ExpList > &pExpList, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
GlobalLinSysFactory & GetGlobalLinSysFactory()

Name of class.

Registers the class with the Factory.

Definition at line 63 of file GlobalLinSysDirectFull.h.