62 const std::shared_ptr<GlobalLinSys> &plinsys,
76 "Solver type not valid");
130 int i, j, k, n, cnt, gId;
131 int meshVertId, meshEdgeId, meshFaceId;
135 const int nExp = expList->GetExpSize();
136 const int nDirBnd = asmMap->GetNumGlobalDirBndCoeffs();
139 PeriodicMap periodicVerts, periodicEdges, periodicFaces;
140 expList->GetPeriodicEntities(periodicVerts, periodicEdges, periodicFaces);
150 vector<map<int, vector<NekDouble>>> idMats(nStorage);
154 vector<map<int, int>> gidMeshIds(3);
158 vector<map<int, int>> gidDofs(nStorage);
170 for (cnt = n = 0; n < nExp; ++n)
172 exp = expList->GetExp(n);
182 auto tmpMat =
m_linsys.lock()->GetBlock(n);
185 int nBndDofs = exp->NumBndryCoeffs();
186 int nIntDofs = exp->GetNcoeffs() - nBndDofs;
191 exp->GetBoundaryMap(bndMap);
199 for (
int i = 0; i < nBndDofs; ++i)
201 for (
int j = 0; j < nBndDofs; ++j)
203 (*bndryMat)(i, j) = (*tmpMat)(bndMap[i], bndMap[j]);
214 exp->GetInteriorMap(intMap);
216 vector<NekDouble> tmpStore(nIntDofs * nIntDofs);
217 for (
int i = 0; i < nIntDofs; ++i)
219 for (
int j = 0; j < nIntDofs; ++j)
221 tmpStore[j + i * nIntDofs] =
222 (*tmpMat)(intMap[i], intMap[j]);
227 idMats[3][n] = tmpStore;
228 gidDofs[3][n] = nIntDofs;
237 schurMat =
m_linsys.lock()->GetStaticCondBlock(n)->GetBlock(0, 0);
242 for (i = 0; i < exp->GetNverts(); ++i)
244 meshVertId = exp->GetGeom()->GetVid(i);
245 int locId = exp->GetVertexMap(i);
248 gId = asmMap->GetLocalToGlobalMap(cnt + locId) - nDirBnd;
259 NekDouble vertVal = (*schurMat)(locId, locId);
263 auto gIt = idMats[0].find(gId);
265 if (gIt == idMats[0].end())
268 idMats[0][gId] = vector<NekDouble>(1, vertVal);
274 gIt->second[0] += vertVal;
281 auto pIt = periodicVerts.find(meshVertId);
282 if (pIt != periodicVerts.end())
284 for (j = 0; j < pIt->second.size(); ++j)
286 meshVertId = min(meshVertId, pIt->second[j].id);
292 gidMeshIds[0][gId] = meshVertId;
293 maxVertIds[0] = max(maxVertIds[0], meshVertId);
299 for (i = 0; i < exp->GetGeom()->GetNumEdges(); ++i)
301 meshEdgeId = exp->GetGeom()->GetEid(i);
309 auto pIt = periodicEdges.find(meshEdgeId);
310 if (pIt != periodicEdges.end())
312 pair<int, StdRegions::Orientation> idOrient =
315 meshEdgeId = idOrient.first;
316 edgeOrient = idOrient.second;
322 if (exp->GetGeom()->GetNumFaces())
325 ->GetEdgeInteriorToElementMap(i, bmap,
sign, edgeOrient);
327 ->GetEdgeInverseBoundaryMap(i);
331 exp->GetTraceInteriorToElementMap(i, bmap,
sign, edgeOrient);
333 ->GetTraceInverseBoundaryMap(i);
337 const int nEdgeCoeffs = bmap.size();
338 if (nEdgeCoeffs == 0)
344 vector<NekDouble> tmpStore(nEdgeCoeffs * nEdgeCoeffs);
346 gId = asmMap->GetLocalToGlobalMap(cnt + bmap[0]);
348 for (j = 0; j < nEdgeCoeffs; ++j)
356 asmMap->GetLocalToGlobalMap(cnt + bmap[j]) - nDirBnd);
368 for (k = 0; k < nEdgeCoeffs; ++k)
370 tmpStore[k + j * nEdgeCoeffs] =
371 sign1 *
sign[k] * (*schurMat)(bmap2[j], bmap2[k]);
380 gidDofs[1][gId] = nEdgeCoeffs;
383 auto gIt = idMats[1].find(gId);
384 if (gIt == idMats[1].end())
386 idMats[1][gId] = tmpStore;
390 ASSERTL1(tmpStore.size() == gIt->second.size(),
391 "Number of modes mismatch");
392 Vmath::Vadd(nEdgeCoeffs * nEdgeCoeffs, &gIt->second[0], 1,
393 &tmpStore[0], 1, &gIt->second[0], 1);
396 gidMeshIds[1][gId] = meshEdgeId;
397 maxVertIds[2] = max(maxVertIds[2], meshEdgeId);
398 maxVertIds[3] = max(maxVertIds[3], nEdgeCoeffs);
403 for (i = 0; i < exp->GetGeom()->GetNumFaces(); ++i)
405 meshFaceId = exp->GetGeom()->GetFid(i);
413 auto pIt = periodicFaces.find(meshFaceId);
414 if (pIt != periodicFaces.end())
416 meshFaceId = min(meshFaceId, pIt->second[0].id);
418 pIt->second[0].orient);
422 exp->GetTraceInteriorToElementMap(i, bmap,
sign, faceOrient);
424 ->GetTraceInverseBoundaryMap(i);
427 const int nFaceCoeffs = bmap.size();
428 if (nFaceCoeffs == 0)
434 vector<NekDouble> tmpStore(nFaceCoeffs * nFaceCoeffs);
436 gId = asmMap->GetLocalToGlobalMap(cnt + bmap[0]);
438 for (j = 0; j < nFaceCoeffs; ++j)
441 asmMap->GetLocalToGlobalMap(cnt + bmap[j]) - nDirBnd);
453 for (k = 0; k < nFaceCoeffs; ++k)
455 tmpStore[k + j * nFaceCoeffs] =
456 sign1 *
sign[k] * (*schurMat)(bmap2[j], bmap2[k]);
465 gidDofs[2][gId] = nFaceCoeffs;
468 auto gIt = idMats[2].find(gId);
469 if (gIt == idMats[2].end())
471 idMats[2][gId] = tmpStore;
475 ASSERTL1(tmpStore.size() == gIt->second.size(),
476 "Number of modes mismatch");
477 Vmath::Vadd(nFaceCoeffs * nFaceCoeffs, &gIt->second[0], 1,
478 &tmpStore[0], 1, &gIt->second[0], 1);
481 gidMeshIds[2][gId] = meshFaceId;
482 maxVertIds[4] = max(maxVertIds[4], meshFaceId);
483 maxVertIds[5] = max(maxVertIds[5], nFaceCoeffs);
486 cnt += exp->GetNcoeffs();
492 expList->GetSession()->GetComm()->GetRowComm();
497 vector<NekDouble> storageBuf;
498 vector<long> globalToUniversal;
500 for (i = 0, cnt = 1; i < 3; ++i)
502 const int maxDofs = maxVertIds[2 * i + 1];
507 for (
auto &gIt : idMats[i])
510 storageBuf.insert(storageBuf.end(), gIt.second.begin(),
514 ASSERTL1(gidMeshIds[i].count(gIt.first) > 0,
515 "Unable to find global ID " +
516 boost::lexical_cast<string>(gIt.first) +
518 meshVertId = gidMeshIds[i][gIt.first];
520 for (j = 0; j < gIt.second.size(); ++j)
522 globalToUniversal.push_back(cnt +
523 meshVertId * maxDofs * maxDofs + j);
530 cnt += (maxVertIds[2 * i] + 1) * maxDofs * maxDofs;
533 ASSERTL1(storageBuf.size() == globalToUniversal.size(),
534 "Storage buffer and global to universal map size does "
539 &globalToUniversal[0]);
543 Gs::Init(globalToUniversalMap, vComm,
544 expList->GetSession()->DefinesCmdLineArgument(
"verbose"));
550 int nblksSize = 1 + idMats[1].size() + idMats[2].size();
553 nblksSize += idMats[3].size();
558 n_blks[0] = idMats[0].size();
563 for (i = 1; i < nStorage; ++i)
565 for (
auto &gIt : idMats[i])
567 ASSERTL1(gidDofs[i].count(gIt.first) > 0,
568 "Unable to find number of degrees of freedom for "
570 boost::lexical_cast<string>(gIt.first));
573 if (gidDofs[i][gIt.first])
575 n_blks[cnt++] = gidDofs[i][gIt.first];
591 for (
auto gIt = idMats[0].begin(); gIt != idMats[0].end(); ++gIt, ++cnt)
593 (*vertMat)(cnt, cnt) = 1.0 / storageData[cnt];
602 for (i = 1; i < nStorage; ++i)
604 for (
auto &gIt : idMats[i])
606 int nDofs = gidDofs[i][gIt.first];
617 for (j = 0; j < nDofs; ++j)
619 for (k = 0; k < nDofs; ++k)
625 (*tmp)(j, k) = gIt.second[k + j * nDofs];
630 (*tmp)(j, k) = storageData[k + j * nDofs + cnt];
635 cnt += nDofs * nDofs;
638 m_blkMat->SetBlock(cnt2, cnt2, tmp);
659 std::shared_ptr<MultiRegions::ExpList> expList =
660 ((
m_linsys.lock())->GetLocMat()).lock();
661 std::shared_ptr<MultiRegions::ExpList> trace = expList->GetTrace();
667 std::dynamic_pointer_cast<AssemblyMapDG>(
m_locToGloMap.lock());
669 int i, j, k, n, cnt, cnt2;
672 int nTrace = expList->GetTrace()->GetExpSize();
673 int nDir = asmMap->GetNumGlobalDirBndCoeffs();
675 for (cnt = n = 0; n < nTrace; ++n)
682 cnt += trace->GetExp(n)->GetNcoeffs();
689 int maxTraceSize = -1;
690 map<int, int> arrayOffsets;
692 for (cnt = 0, n = nDir; n < nTrace; ++n)
694 int nCoeffs = trace->GetExp(n)->GetNcoeffs();
695 int nCoeffs2 = nCoeffs * nCoeffs;
697 arrayOffsets[n] = cnt;
700 if (maxTraceSize < nCoeffs2)
702 maxTraceSize = nCoeffs2;
708 expList->GetSession()->GetComm()->GetRowComm();
715 for (cnt = n = 0; n < expList->GetExpSize(); ++n)
718 locExpansion = expList->GetExp(elmt);
721 asmMap->GetElmtToTrace()[elmt];
724 loc_mat = (
m_linsys.lock())->GetStaticCondBlock(n);
725 bnd_mat = loc_mat->GetBlock(0, 0);
727 int nFacets = locExpansion->GetNtraces();
729 for (cnt2 = i = 0; i < nFacets; ++i)
731 int nCoeffs = elmtToTraceMap[i]->GetNcoeffs();
732 int elmtId = elmtToTraceMap[i]->GetElmtId();
742 NekDouble *off = &tmpStore[arrayOffsets[elmtId]];
744 for (j = 0; j < nCoeffs; ++j)
746 NekDouble sign1 = asmMap->GetLocalToGlobalBndSign(cnt + j);
747 for (k = 0; k < nCoeffs; ++k)
749 NekDouble sign2 = asmMap->GetLocalToGlobalBndSign(cnt + k);
750 off[j * nCoeffs + k] +=
751 (*bnd_mat)(cnt2 + j, cnt2 + k) * sign1 * sign2;
762 for (cnt = 0, n = nDir; n < nTrace; ++n)
765 int nCoeffs = traceExp->GetNcoeffs();
766 int geomId = traceExp->GetGeom()->GetGlobalID();
768 for (i = 0; i < nCoeffs * nCoeffs; ++i)
770 uniIds[cnt++] = geomId * maxTraceSize + i + 1;
777 expList->GetSession()->DefinesCmdLineArgument(
"verbose"));
782 for (n = 0; n < nTrace - nDir; ++n)
784 n_blks[n] = trace->GetExp(n + nDir)->GetNcoeffs();
790 for (n = 0; n < nTrace - nDir; ++n)
792 int nCoeffs = trace->GetExp(n + nDir)->GetNcoeffs();
795 NekDouble *off = &tmpStore[arrayOffsets[n + nDir]];
797 for (i = 0; i < nCoeffs; ++i)
799 for (j = 0; j < nCoeffs; ++j)
801 (*tmp)(i, j) = off[i * nCoeffs + j];
822 int nGlobal =
m_isFull ? asmMap->GetNumGlobalCoeffs()
823 : asmMap->GetNumGlobalBndCoeffs();
824 int nDir = asmMap->GetNumGlobalDirBndCoeffs();
825 int nNonDir = nGlobal - nDir;
834 asmMap->Assemble(pInput, wk);
842 asmMap->GlobalToLocal(wk1, pOutput);
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define sign(a, b)
return the sign(b)*a
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Describe a linear system.
StdRegions::MatrixType GetMatrixType() const
Return the matrix type.
void BlockPreconditionerCG(void)
Construct a block preconditioner from for the continuous Galerkin system.
static PreconditionerSharedPtr create(const std::shared_ptr< GlobalLinSys > &plinsys, const std::shared_ptr< AssemblyMap > &pLocToGloMap)
Creates an instance of this class.
void v_DoPreconditioner(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &isLocal=false) override
Apply preconditioner to pInput and store the result in pOutput.
void BlockPreconditionerHDG(void)
Construct a block preconditioner for the hybridized discontinuous Galerkin system.
PreconditionerBlock(const std::shared_ptr< GlobalLinSys > &plinsys, const AssemblyMapSharedPtr &pLocToGloMap)
void v_InitObject() override
static std::string className
Name of class.
DNekBlkMatSharedPtr m_blkMat
void v_BuildPreconditioner() override
Gs::gs_data * m_gs_mapping
const std::weak_ptr< GlobalLinSys > m_linsys
std::weak_ptr< AssemblyMap > m_locToGloMap
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 gs_data * Init(const Nektar::Array< OneD, long > pId, const LibUtilities::CommSharedPtr &pComm, bool verbose=true)
Initialise Gather-Scatter map.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::shared_ptr< Expansion > ExpansionSharedPtr
std::shared_ptr< AssemblyMapDG > AssemblyMapDGSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
PreconFactory & GetPreconFactory()
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...
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
std::map< int, std::vector< PeriodicEntity > > PeriodicMap
StdRegions::Orientation DeterminePeriodicFaceOrient(StdRegions::Orientation faceOrient, StdRegions::Orientation perFaceOrient)
Determine relative orientation between two faces.
std::vector< double > z(NPUPPER)
std::shared_ptr< DNekScalMat > DNekScalMatSharedPtr
std::shared_ptr< DNekScalBlkMat > DNekScalBlkMatSharedPtr
std::shared_ptr< DNekMat > DNekMatSharedPtr
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.
void Zero(int n, T *x, const int incx)
Zero vector.