48 namespace MultiRegions
57 "Block Diagonal Preconditioning");
66 const boost::shared_ptr<GlobalLinSys> &plinsys,
70 m_preconType(pLocToGloMap->GetPreconType()),
71 m_locToGloMap(pLocToGloMap)
80 "Solver type not valid");
120 int nel, i, j, k, n, cnt, gId;
121 int meshVertId, meshEdgeId, meshFaceId;
123 const int nExp = expList->GetExpSize();
124 const int nDirBnd =
m_locToGloMap->GetNumGlobalDirBndCoeffs();
128 PeriodicMap periodicVerts, periodicEdges, periodicFaces;
129 expList->GetPeriodicEntities(
130 periodicVerts, periodicEdges, periodicFaces);
137 vector<map<int, vector<NekDouble> > > idMats(3);
141 vector<map<int, int> > gidMeshIds(3);
145 vector<map<int, int> > gidDofs(3);
160 for (cnt = n = 0; n < nExp; ++n)
162 nel = expList->GetOffset_Elmt_Id(n);
163 exp = expList->GetExp(nel);
167 m_linsys.lock()->GetStaticCondBlock(n)->GetBlock(0,0);
171 for (i = 0; i < exp->GetNverts(); ++i)
173 meshVertId = exp->GetGeom()->GetVid(i);
174 int locId = exp->GetVertexMap(i);
178 cnt + locId) - nDirBnd;
189 NekDouble vertVal = (*schurMat)(locId,locId);
193 gIt = idMats[0].find(gId);
195 if (gIt == idMats[0].end())
198 idMats[0][gId] = vector<NekDouble>(1, vertVal);
204 gIt->second[0] += vertVal;
211 pIt = periodicVerts.find(meshVertId);
212 if (pIt != periodicVerts.end())
214 for (j = 0; j < pIt->second.size(); ++j)
216 meshVertId = min(meshVertId, pIt->second[j].id);
222 gidMeshIds[0][gId] = meshVertId;
223 maxVertIds[0] = max(maxVertIds[0], meshVertId);
229 for (i = 0; i < exp->GetNedges(); ++i)
231 meshEdgeId = exp->GetGeom()->GetEid(i);
236 exp->GetGeom()->GetEorient(i);
240 pIt = periodicEdges.find(meshEdgeId);
241 if (pIt != periodicEdges.end())
243 pair<int, StdRegions::Orientation> idOrient =
245 meshEdgeId, edgeOrient, pIt->second);
246 meshEdgeId = idOrient.first;
247 edgeOrient = idOrient.second;
253 exp->GetEdgeInteriorMap(i, edgeOrient, bmap, sign);
254 bmap2 = exp->GetEdgeInverseBoundaryMap(i);
257 const int nEdgeCoeffs = bmap.num_elements();
258 vector<NekDouble> tmpStore(nEdgeCoeffs*nEdgeCoeffs);
262 for (j = 0; j < nEdgeCoeffs; ++j)
284 for (k = 0; k < nEdgeCoeffs; ++k)
286 tmpStore[k+j*nEdgeCoeffs] =
287 sign1*sign[k]*(*schurMat)(bmap2[j], bmap2[k]);
296 gidDofs[1][gId] = nEdgeCoeffs;
299 gIt = idMats[1].find(gId);
300 if (gIt == idMats[1].end())
302 idMats[1][gId] = tmpStore;
306 ASSERTL1(tmpStore.size() == gIt->second.size(),
307 "Number of modes mismatch");
308 Vmath::Vadd(nEdgeCoeffs*nEdgeCoeffs, &gIt->second[0], 1,
309 &tmpStore[0], 1, &gIt->second[0], 1);
312 gidMeshIds[1][gId] = meshEdgeId;
313 maxVertIds[2] = max(maxVertIds[2], meshEdgeId);
314 maxVertIds[3] = max(maxVertIds[3], nEdgeCoeffs);
319 for (i = 0; i < exp->GetNfaces(); ++i)
321 meshFaceId = exp->GetGeom()->GetFid(i);
326 exp->GetGeom()->GetForient(i);
330 pIt = periodicFaces.find(meshFaceId);
331 if (pIt != periodicFaces.end())
333 meshFaceId = min(meshFaceId, pIt->second[0].id);
335 faceOrient, pIt->second[0].orient);
338 exp->GetFaceInteriorMap(i, faceOrient, bmap, sign);
339 bmap2 = exp->GetFaceInverseBoundaryMap(i);
342 const int nFaceCoeffs = bmap.num_elements();
343 vector<NekDouble> tmpStore(nFaceCoeffs*nFaceCoeffs);
347 for (j = 0; j < nFaceCoeffs; ++j)
364 for (k = 0; k < nFaceCoeffs; ++k)
366 tmpStore[k+j*nFaceCoeffs] =
367 sign1*sign[k]*(*schurMat)(bmap2[j], bmap2[k]);
376 gidDofs[2][gId] = nFaceCoeffs;
379 gIt = idMats[2].find(gId);
380 if (gIt == idMats[2].end())
382 idMats[2][gId] = tmpStore;
386 ASSERTL1(tmpStore.size() == gIt->second.size(),
387 "Number of modes mismatch");
388 Vmath::Vadd(nFaceCoeffs*nFaceCoeffs, &gIt->second[0], 1,
389 &tmpStore[0], 1, &gIt->second[0], 1);
392 gidMeshIds[2][gId] = meshFaceId;
393 maxVertIds[4] = max(maxVertIds[4], meshFaceId);
394 maxVertIds[5] = max(maxVertIds[5], nFaceCoeffs);
397 cnt += exp->GetNcoeffs();
402 m_comm = expList->GetSession()->GetComm()->GetRowComm();
407 vector<NekDouble> storageBuf;
408 vector<long> globalToUniversal;
410 for (i = 0, cnt = 1; i < 3; ++i)
412 const int maxDofs = maxVertIds[2*i+1];
417 for (gIt = idMats[i].begin(); gIt != idMats[i].end(); ++gIt)
420 storageBuf.insert(storageBuf.end(),
421 gIt->second.begin(), gIt->second.end());
424 ASSERTL1(gidMeshIds[i].count(gIt->first) > 0,
425 "Unable to find global ID " +
426 boost::lexical_cast<string>(gIt->first) +
428 meshVertId = gidMeshIds[i][gIt->first];
430 for (j = 0; j < gIt->second.size(); ++j)
432 globalToUniversal.push_back(
433 cnt + meshVertId*maxDofs*maxDofs + j);
440 cnt += (maxVertIds[2*i]+1)*maxDofs*maxDofs;
443 ASSERTL1(storageBuf.size() == globalToUniversal.size(),
444 "Storage buffer and global to universal map size does "
448 storageBuf.size(), &storageBuf[0]);
450 globalToUniversal.size(), &globalToUniversal[0]);
458 1 + idMats[1].size() + idMats[2].size());
461 n_blks[0] = idMats[0].size();
466 for (i = 1; i < 3; ++i)
468 for (gIt = idMats[i].begin(); gIt != idMats[i].end(); ++gIt)
470 ASSERTL1(gidDofs[i].count(gIt->first) > 0,
471 "Unable to find number of degrees of freedom for "
472 "global ID " + boost::lexical_cast<string>(
475 n_blks[cnt++] = gidDofs[i][gIt->first];
490 for (gIt = idMats[0].begin(); gIt != idMats[0].end(); ++gIt, ++cnt)
492 (*vertMat)(cnt, cnt) = 1.0/storageData[cnt];
501 for (i = 1; i < 3; ++i)
503 for (gIt = idMats[i].begin(); gIt != idMats[i].end();
506 int nDofs = gidDofs[i][gIt->first];
511 for (j = 0; j < nDofs; ++j)
513 for (k = 0; k < nDofs; ++k)
515 (*tmp)(j,k) = storageData[k+j*nDofs + cnt];
522 m_blkMat->SetBlock(cnt2, cnt2, tmp);
542 boost::shared_ptr<MultiRegions::ExpList>
543 expList = ((
m_linsys.lock())->GetLocMat()).lock();
544 boost::shared_ptr<MultiRegions::ExpList> trace = expList->GetTrace();
552 int i, j, k, n, cnt, cnt2;
555 int nTrace = expList->GetTrace()->GetExpSize();
558 for (cnt = n = 0; n < nTrace; ++n)
565 cnt += trace->GetExp(n)->GetNcoeffs();
572 int maxTraceSize = -1;
573 map<int, int> arrayOffsets;
575 for (cnt = 0, n = nDir; n < nTrace; ++n)
577 int nCoeffs = trace->GetExp(n)->GetNcoeffs();
578 int nCoeffs2 = nCoeffs * nCoeffs;
580 arrayOffsets[n] = cnt;
583 if (maxTraceSize < nCoeffs2)
585 maxTraceSize = nCoeffs2;
590 m_comm = expList->GetSession()->GetComm()->GetRowComm();
597 for (cnt = n = 0; n < expList->GetExpSize(); ++n)
599 int elmt = expList->GetOffset_Elmt_Id(n);
600 locExpansion = expList->GetExp(elmt);
603 asmMap->GetElmtToTrace()[elmt];
606 loc_mat = (
m_linsys.lock())->GetStaticCondBlock(n);
607 bnd_mat = loc_mat->GetBlock(0,0);
609 int nFacets = locExpansion->GetNumBases() == 2 ?
610 locExpansion->GetNedges() : locExpansion->GetNfaces();
612 for (cnt2 = i = 0; i < nFacets; ++i)
614 int nCoeffs = elmtToTraceMap[i]->GetNcoeffs();
615 int elmtId = elmtToTraceMap[i]->GetElmtId ();
625 NekDouble *off = &tmpStore[arrayOffsets[elmtId]];
627 for (j = 0; j < nCoeffs; ++j)
629 NekDouble sign1 = asmMap->GetLocalToGlobalBndSign(
631 for (k = 0; k < nCoeffs; ++k)
633 NekDouble sign2 = asmMap->GetLocalToGlobalBndSign(
635 off[j*nCoeffs + k] +=
636 (*bnd_mat)(cnt2+j, cnt2+k) * sign1 * sign2;
647 for (cnt = 0, n = nDir; n < nTrace; ++n)
650 int nCoeffs = traceExp->GetNcoeffs();
651 int geomId = traceExp->GetGeom()->GetGlobalID();
653 for (i = 0; i < nCoeffs*nCoeffs; ++i)
655 uniIds[cnt++] = geomId * maxTraceSize + i + 1;
665 for (n = 0; n < nTrace - nDir; ++n)
667 n_blks[n] = trace->GetExp(n + nDir)->GetNcoeffs();
673 for (n = 0; n < nTrace - nDir; ++n)
675 int nCoeffs = trace->GetExp(n + nDir)->GetNcoeffs();
678 NekDouble *off = &tmpStore[arrayOffsets[n+nDir]];
680 for (i = 0; i < nCoeffs; ++i)
682 for (j = 0; j < nCoeffs; ++j)
684 (*tmp)(i,j) = off[i*nCoeffs + j];
703 int nNonDir = nGlobal-nDir;
virtual void v_BuildPreconditioner()
boost::shared_ptr< AssemblyMapDG > AssemblyMapDGSharedPtr
LibUtilities::CommSharedPtr m_comm
#define ASSERTL0(condition, msg)
virtual void v_DoPreconditioner(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput)
Apply preconditioner to pInput and store the result in pOutput.
static void Gather(Nektar::Array< OneD, NekDouble > pU, gs_op pOp, gs_data *pGsh, Nektar::Array< OneD, NekDouble > pBuffer=NullNekDouble1DArray)
Performs a gather-scatter operation of the provided values.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::map< int, vector< PeriodicEntity > > PeriodicMap
#define sign(a, b)
return the sign(b)*a
boost::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
static gs_data * Init(const Nektar::Array< OneD, long > pId, const LibUtilities::CommSharedPtr &pComm)
Initialise Gather-Scatter map.
static std::string className
Name of class.
DNekBlkMatSharedPtr m_blkMat
PreconFactory & GetPreconFactory()
boost::shared_ptr< DNekMat > DNekMatSharedPtr
boost::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
StdRegions::Orientation DeterminePeriodicFaceOrient(StdRegions::Orientation faceOrient, StdRegions::Orientation perFaceOrient)
Determine relative orientation between two faces.
boost::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
pair< int, StdRegions::Orientation > DeterminePeriodicEdgeOrientId(int meshEdgeId, StdRegions::Orientation edgeOrient, const vector< PeriodicEntity > &periodicEdges)
Determine orientation of an edge to its periodic equivalents, as well as the ID of the representative...
boost::shared_ptr< Expansion > ExpansionSharedPtr
void BlockPreconditionerHDG(void)
static PreconditionerSharedPtr create(const boost::shared_ptr< GlobalLinSys > &plinsys, const boost::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
Describe a linear system.
boost::shared_ptr< AssemblyMap > m_locToGloMap
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.
virtual void v_InitObject()
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void BlockPreconditionerCG(void)
Construct a block preconditioner from for the continuous Galerkin system.
const boost::weak_ptr< GlobalLinSys > m_linsys
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
PreconditionerBlock(const boost::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.