35 #include <boost/core/ignore_unused.hpp>
43 namespace MultiRegions
60 return int(x > 0.0 ? x + 0.5 : x - 0.5);
66 int size = inarray.size();
67 ASSERTL1(outarray.size()>=size,
"Array sizes not compatible");
70 for(
int i = 0; i < size; i++)
73 outarray[i] = int(x > 0.0 ? x + 0.5 : x - 0.5);
80 AssemblyMap::AssemblyMap():
84 m_numLocalBndCoeffs(0),
85 m_numGlobalBndCoeffs(0),
86 m_numLocalDirBndCoeffs(0),
87 m_numGlobalDirBndCoeffs(0),
89 m_bndSystemBandWidth(0),
91 m_linSysIterSolver(
"ConjugateGradient"),
99 const std::string variable):
101 m_comm(pSession->GetComm()),
103 m_numLocalBndCoeffs(0),
104 m_numGlobalBndCoeffs(0),
105 m_numLocalDirBndCoeffs(0),
106 m_numGlobalDirBndCoeffs(0),
107 m_bndSystemBandWidth(0),
109 m_linSysIterSolver(
"ConjugateGradient"),
120 if(pSession->DefinesGlobalSysSolnInfo(variable,
"GlobalSysSoln"))
122 std::string sysSoln = pSession->GetGlobalSysSolnInfo(variable,
125 "GlobalSysSoln", sysSoln);
128 if(pSession->DefinesGlobalSysSolnInfo(variable,
"Preconditioner"))
130 std::string precon = pSession->GetGlobalSysSolnInfo(variable,
133 "Preconditioner", precon);
136 if(pSession->DefinesGlobalSysSolnInfo(variable,
137 "IterativeSolverTolerance"))
140 pSession->GetGlobalSysSolnInfo(variable,
141 "IterativeSolverTolerance").c_str());
145 pSession->LoadParameter(
"IterativeSolverTolerance",
151 if(pSession->DefinesGlobalSysSolnInfo(variable,
155 pSession->GetGlobalSysSolnInfo(variable,
156 "MaxIterations").c_str());
160 pSession->LoadParameter(
"MaxIterations",
166 if(pSession->DefinesGlobalSysSolnInfo(variable,
"SuccessiveRHS"))
169 pSession->GetGlobalSysSolnInfo(variable,
170 "SuccessiveRHS").c_str());
174 pSession->LoadParameter(
"SuccessiveRHS",
178 if (pSession->DefinesGlobalSysSolnInfo(variable,
"LinSysIterSolver"))
181 variable,
"LinSysIterSolver");
183 else if (pSession->DefinesSolverInfo(
"LinSysIterSolver"))
200 m_session(oldLevelMap->m_session),
201 m_comm(oldLevelMap->GetComm()),
203 m_solnType(oldLevelMap->m_solnType),
204 m_preconType(oldLevelMap->m_preconType),
205 m_maxIterations(oldLevelMap->m_maxIterations),
206 m_iterativeTolerance(oldLevelMap->m_iterativeTolerance),
207 m_successiveRHS(oldLevelMap->m_successiveRHS),
208 m_linSysIterSolver(oldLevelMap->m_linSysIterSolver),
209 m_gsh(oldLevelMap->m_gsh),
210 m_bndGsh(oldLevelMap->m_bndGsh),
211 m_lowestStaticCondLevel(oldLevelMap->m_lowestStaticCondLevel)
232 int newLevel = staticCondLevelOld+1;
253 multiLevelGraph->MaskPatches(newLevel,globHomPatchMask);
261 locPatchMask_NekDouble);
273 int numPatchesWithIntNew = multiLevelGraph->GetNpatchesWithInterior(newLevel);
274 int numPatchesNew = numPatchesWithIntNew;
278 std::map<int, int> numLocalBndCoeffsPerPatchNew;
279 for(
int i = 0; i < numPatchesNew; i++)
281 numLocalBndCoeffsPerPatchNew[i] = 0;
287 for(i = cnt = 0; i < numPatchesOld; i++)
300 minval = *min_element(&locPatchMask[cnt],
301 &locPatchMask[cnt]+numLocalBndCoeffsPerPatchOld[i]);
302 maxval = *max_element(&locPatchMask[cnt],
303 &locPatchMask[cnt]+numLocalBndCoeffsPerPatchOld[i]);
304 ASSERTL0((minval==maxval)||(minval==-1),
"These values should never be the same");
308 curPatch = numPatchesNew;
309 numLocalBndCoeffsPerPatchNew[curPatch] = 0;
317 for(j = 0; j < numLocalBndCoeffsPerPatchOld[i]; j++ )
319 ASSERTL0((locPatchMask[cnt]==maxval)||(locPatchMask[cnt]==minval),
320 "These values should never be the same");
321 if(locPatchMask[cnt] == -1)
323 ++numLocalBndCoeffsPerPatchNew[curPatch];
352 "This method should only be called for in "
353 "case of multi-level static condensation.");
396 numLocalBndCoeffsPerPatchOffset[i] +=
397 numLocalBndCoeffsPerPatchOffset[i-1] +
398 numLocalBndCoeffsPerPatchNew[i-1];
401 int additionalPatchCnt = numPatchesWithIntNew;
408 for(i = cnt = 0; i < numPatchesOld; i++)
410 minval = *min_element(&locPatchMask[cnt],
411 &locPatchMask[cnt]+numLocalBndCoeffsPerPatchOld[i]);
412 maxval = *max_element(&locPatchMask[cnt],
413 &locPatchMask[cnt]+numLocalBndCoeffsPerPatchOld[i]);
414 ASSERTL0((minval==maxval)||(minval==-1),
415 "These values should never be the same");
419 curPatch = additionalPatchCnt;
420 additionalPatchCnt++;
427 for(j = 0; j < numLocalBndCoeffsPerPatchOld[i]; j++ )
429 ASSERTL0((locPatchMask[cnt]==maxval)||
430 (locPatchMask[cnt]==minval),
431 "These values should never be the same");
435 if(locPatchMask[cnt] == -1)
437 newid = numLocalBndCoeffsPerPatchOffset[curPatch];
447 blockid = bndDofPerPatchCnt[curPatch];
450 numLocalBndCoeffsPerPatchOffset[curPatch]++;
451 bndDofPerPatchCnt[curPatch]++;
460 multiLevelGraph->GetInteriorOffset(newLevel,curPatch);
523 for(j = 0; j < locSize; j++)
538 bwidth = (bwidth>(maxId-minId))?bwidth:(maxId-minId);
549 boost::ignore_unused(i);
551 "Not defined for this type of mapping.");
557 boost::ignore_unused(i);
559 "Not defined for this type of mapping.");
565 boost::ignore_unused(i);
567 "Not defined for this type of mapping.");
574 "Not defined for this type of mapping.");
582 "Not defined for this type of mapping.");
590 "Not defined for this type of mapping.");
597 boost::ignore_unused(i);
599 "Not defined for this type of mapping.");
606 "Not defined for this type of mapping.");
616 boost::ignore_unused(
loc, global, useComm);
618 "Not defined for this type of mapping.");
626 boost::ignore_unused(
loc, global, useComm);
628 "Not defined for this type of mapping.");
636 boost::ignore_unused(
loc, global);
638 "Not defined for this type of mapping.");
645 boost::ignore_unused(
loc, global);
647 "Not defined for this type of mapping.");
654 boost::ignore_unused(
loc, global);
656 "Not defined for this type of mapping.");
663 boost::ignore_unused(
loc, global);
665 "Not defined for this type of mapping.");
671 boost::ignore_unused(pGlobal);
679 boost::ignore_unused(pGlobal);
688 boost::ignore_unused(pGlobal, offset);
696 "Not defined for this type of mapping.");
703 "Not defined for this type of mapping.");
710 "Not defined for this type of mapping.");
717 "Not defined for this type of mapping.");
724 "Not defined for this type of mapping.");
731 "Not defined for this type of mapping.");
738 "Not defined for this type of mapping.");
745 "Not defined for this type of mapping.");
752 "Not defined for this type of mapping.");
760 boost::ignore_unused(locexp, solnType);
762 "Not defined for this type of mapping.");
763 static std::shared_ptr<AssemblyMap> result;
890 if(global.data() ==
loc.data())
901 local.get(), map.get(), global.get());
914 if(global.data() ==
loc.data())
934 if(global.data() ==
loc.data())
949 map.get(), global.get());
1070 "Index out of range.");
1175 int offset,
bool UseComm)
const
1341 if (offset > 0)
Vmath::Vcopy(offset, pGlobal, 1, tmp, 1);
1343 if (offset > 0)
Vmath::Vcopy(offset, tmp, 1, pGlobal, 1);
1439 std::ostream &out, std::string variable,
bool printHeader)
const
1443 bool isRoot = vRowComm->GetRank() == 0;
1444 int n = vRowComm->GetSize();
1448 int globBndCnt = 0, globDirCnt = 0;
1474 int totGlobDof = globCnt;
1475 int totGlobBndDof = globBndCnt;
1476 int totGlobDirDof = globDirCnt;
1481 int meanValence = 0;
1483 int minValence = 10000000;
1491 if (tmpGlob[i] > maxValence)
1493 maxValence = tmpGlob[i];
1495 if (tmpGlob[i] < minValence)
1497 minValence = tmpGlob[i];
1499 meanValence += tmpGlob[i];
1512 meanValence /= totGlobBndDof;
1518 out <<
"Assembly map statistics for field " << variable
1522 out <<
" - Number of local/global dof : "
1523 << totLocalDof <<
" " << totGlobDof << endl;
1524 out <<
" - Number of local/global boundary dof : "
1525 << totLocalBndDof <<
" " << totGlobBndDof << endl;
1526 out <<
" - Number of local/global Dirichlet dof : "
1527 << totLocalDirDof <<
" " << totGlobDirDof << endl;
1528 out <<
" - dof valency (min/max/mean) : "
1529 << minValence <<
" " << maxValence <<
" " << meanValence
1538 for (i = 1; i < n; ++i)
1540 vRowComm->Recv(i, tmp);
1542 mean2 += tmp[0]*tmp[0];
1544 if (tmp[0] > maxval)
1548 if (tmp[0] < minval)
1556 out <<
" - Local dof dist. (min/max/mean/dev) : "
1557 << minval <<
" " << maxval <<
" " << (mean / n)
1558 <<
" " <<
sqrt(mean2/n - mean*mean/n/n) << endl;
1564 mean2 = mean * mean;
1566 for (i = 1; i < n; ++i)
1568 vRowComm->Recv(i, tmp);
1570 mean2 += tmp[0]*tmp[0];
1572 if (tmp[0] > maxval)
1576 if (tmp[0] < minval)
1582 out <<
" - Local bnd dof dist. (min/max/mean/dev) : "
1583 << minval <<
" " << maxval <<
" " << (mean / n) <<
" "
1584 <<
sqrt(mean2/n - mean*mean/n/n) << endl;
1591 vRowComm->Send(0, tmp);
1594 vRowComm->Send(0, tmp);
1606 while (tmp->m_nextLevelLocalToGlobalMap)
1608 tmp = tmp->m_nextLevelLocalToGlobalMap;
1621 for (i = 1; i < n; ++i)
1623 vRowComm->Recv(i, tmpRecv);
1625 mean2 += tmpRecv[0]*tmpRecv[0];
1627 if (tmpRecv[0] > maxval)
1629 maxval = (int)(tmpRecv[0] + 0.5);
1631 if (tmpRecv[0] < minval)
1633 minval = (int)(tmpRecv[0] + 0.5);
1637 out <<
" - M-level sc. dist. (min/max/mean/dev) : "
1638 << minval <<
" " << maxval <<
" " << (mean / n) <<
" "
1639 <<
sqrt(mean2/n - mean*mean/n/n) << endl;
1645 vRowComm->Send(0, tmpSend);
1650 out <<
" - Number of static cond. levels : "
1656 out <<
"Stats at lowest static cond. level:" << endl;
1658 tmp->PrintStats(out, variable,
false);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#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
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Base class for constructing local to global mapping of degrees of freedom.
void PatchLocalToGlobal(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global) const
const Array< OneD, const int > & GetExtraDirEdges()
GlobalSysSolnType m_solnType
The solution type of the global system.
int GetNumPatches() const
Returns the number of patches in this static condensation level.
PreconditionerType m_preconType
Type type of preconditioner to use in iterative solver.
const Array< OneD, const int > & GetGlobalToUniversalMapUnique()
int GetNumGlobalCoeffs() const
Returns the total number of global coefficients.
int m_numLocalCoeffs
Total number of local coefficients.
const Array< OneD, const unsigned int > & GetNumLocalBndCoeffsPerPatch()
Returns the number of local boundary coefficients in each patch.
virtual const Array< OneD, const int > & v_GetExtraDirEdges()
int GetNumDirFaces() const
int GetNumLocalCoeffs() const
Returns the total number of local coefficients.
const Array< OneD, const unsigned int > & GetNumLocalIntCoeffsPerPatch()
Returns the number of local interior coefficients in each patch.
int GetNumNonDirFaceModes() const
virtual void v_Assemble(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global) const
Array< OneD, int > m_globalToUniversalBndMap
Integer map of process coeffs to universal space.
bool m_signChange
Flag indicating if modes require sign reversal.
void Assemble(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global) const
NekDouble GetLocalToGlobalBndSign(const int i) const
Retrieve the sign change of a given local boundary mode.
virtual std::shared_ptr< AssemblyMap > v_LinearSpaceMap(const ExpList &locexp, GlobalSysSolnType solnType)
Generate a linear space mapping from existing mapping.
void AssembleBnd(const NekVector< NekDouble > &loc, NekVector< NekDouble > &global, int offset) const
virtual void v_LocalToGlobal(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global, bool useComm) const
PreconditionerType GetPreconType() const
Array< OneD, int > m_bndCondCoeffsToLocalCoeffsMap
Integer map of bnd cond coeffs to local coefficients.
PatchMapSharedPtr m_patchMapFromPrevLevel
Mapping information for previous level in MultiLevel Solver.
int m_maxIterations
Maximum iterations for iterative solver.
virtual const Array< OneD, const int > & v_GetGlobalToUniversalMapUnique()
NekDouble m_iterativeTolerance
Tolerance for iterative solver.
NekDouble GetIterativeTolerance() const
int m_numGlobalCoeffs
Total number of global coefficients.
std::string m_linSysIterSolver
Iterative solver: Conjugate Gradient, GMRES.
bool AtLastLevel() const
Returns true if this is the last level in the multi-level static condensation.
Array< OneD, int > m_localToGlobalBndMap
Integer map of local coeffs to global Boundary Dofs.
void UniversalAssembleBnd(Array< OneD, NekDouble > &pGlobal) const
const Array< OneD, const int > & GetLocalToGlobalMap()
const Array< OneD, const int > & GetBndCondCoeffsToLocalTraceMap()
Retrieves the local indices corresponding to the boundary expansion modes to global trace.
int GetNumNonDirEdgeModes() const
virtual const Array< OneD, const int > & v_GetGlobalToUniversalMap()
void PatchAssemble(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global) const
int m_successiveRHS
sucessive RHS for iterative solver
std::shared_ptr< AssemblyMap > LinearSpaceMap(const ExpList &locexp, GlobalSysSolnType solnType)
virtual int v_GetNumNonDirVertexModes() const
void CalculateBndSystemBandWidth()
Calculates the bandwidth of the boundary system.
void LocalToGlobal(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global, bool useComm=true) const
int GetNumNonDirEdges() const
void UniversalAbsMaxBnd(Array< OneD, NekDouble > &bndvals)
Array< OneD, unsigned int > m_numLocalBndCoeffsPerPatch
The number of bnd dofs per patch.
virtual const Array< OneD, const int > & v_GetLocalToGlobalMap()
const Array< OneD, const int > & GetGlobalToUniversalMap()
int GetNumNonDirFaces() const
std::string GetLinSysIterSolver() const
virtual int v_GetNumNonDirEdgeModes() const
virtual int v_GetNumDirFaces() const
LibUtilities::SessionReaderSharedPtr m_session
Session object.
virtual const Array< OneD, NekDouble > & v_GetLocalToGlobalSign() const
int GetNumGlobalDirBndCoeffs() const
Returns the number of global Dirichlet boundary coefficients.
const Array< OneD, NekDouble > & GetBndCondCoeffsToLocalCoeffsSign()
Returns the modal sign associated with a given boundary expansion mode.
int m_numLocalBndCoeffs
Number of local boundary coefficients.
void LocalToLocalBnd(const Array< OneD, const NekDouble > &local, Array< OneD, NekDouble > &locbnd) const
const Array< OneD, const int > & GetBndCondCoeffsToLocalCoeffsMap()
Retrieves the local indices corresponding to the boundary expansion modes.
void PrintStats(std::ostream &out, std::string variable, bool printHeader=true) const
AssemblyMapSharedPtr m_nextLevelLocalToGlobalMap
Map from the patches of the previous level to the patches of the current level.
const Array< OneD, const int > & GetLocalToGlobalBndMap()
Retrieve the global indices of the local boundary modes.
int m_staticCondLevel
The level of recursion in the case of multi-level static condensation.
int GetSuccessiveRHS() const
Array< OneD, NekDouble > m_localToGlobalBndSign
Integer sign of local boundary coeffs to global space.
int m_bndSystemBandWidth
The bandwith of the global bnd system.
Array< OneD, int > m_localToLocalIntMap
Integer map of local boundary coeffs to local interior system numbering.
const Array< OneD, const int > & GetGlobalToUniversalBndMapUnique()
void GlobalToLocal(const Array< OneD, const NekDouble > &global, Array< OneD, NekDouble > &loc) const
GlobalSysSolnType GetGlobalSysSolnType() const
Returns the method of solving global systems.
int GetMaxIterations() const
int m_numLocalDirBndCoeffs
Number of Local Dirichlet Boundary Coefficients.
bool GetSingularSystem() const
Retrieves if the system is singular (true) or not (false)
virtual int v_GetNumNonDirFaceModes() const
void PatchGlobalToLocal(const Array< OneD, const NekDouble > &global, Array< OneD, NekDouble > &loc) const
virtual int v_GetFullSystemBandWidth() const
int m_numGlobalDirBndCoeffs
Number of Global Dirichlet Boundary Coefficients.
LibUtilities::CommSharedPtr GetComm()
Retrieves the communicator.
Array< OneD, unsigned int > m_numLocalIntCoeffsPerPatch
The number of int dofs per patch.
const AssemblyMapSharedPtr GetNextLevelLocalToGlobalMap() const
Returns the local to global mapping for the next level in the multi-level static condensation.
int GetBndSystemBandWidth() const
Returns the bandwidth of the boundary system.
virtual void v_UniversalAssemble(Array< OneD, NekDouble > &pGlobal) const
int GetStaticCondLevel() const
Returns the level of static condensation for this map.
void GlobalToLocalBndWithoutSign(const Array< OneD, const NekDouble > &global, Array< OneD, NekDouble > &loc)
int GetNumNonDirVertexModes() const
bool m_systemSingular
Flag indicating if the system is singular or not.
size_t GetHash() const
Retrieves the hash of this map.
int GetLocalToGlobalBndMap(const int i) const
Retrieve the global index of a given local boundary mode.
virtual ~AssemblyMap()
Destructor.
Gs::gs_data * m_dirBndGsh
gs gather communication to impose Dirhichlet BCs.
virtual void v_GlobalToLocal(const Array< OneD, const NekDouble > &global, Array< OneD, NekDouble > &loc) const
const Array< OneD, NekDouble > & GetLocalToGlobalSign() const
int GetNumLocalDirBndCoeffs() const
Returns the number of local Dirichlet boundary coefficients.
int GetNumDirEdges() const
size_t m_hash
Hash for map.
Array< OneD, const NekDouble > GetLocalToGlobalBndSign() const
Retrieve the sign change for all local boundary modes.
void LocalBndToLocal(const Array< OneD, const NekDouble > &locbnd, Array< OneD, NekDouble > &local) const
AssemblyMap()
Default constructor.
Array< OneD, NekDouble > m_bndCondCoeffsToLocalCoeffsSign
Integer map of sign of bnd cond coeffs to local coefficients.
virtual int v_GetNumNonDirEdges() const
virtual int v_GetNumDirEdges() const
const PatchMapSharedPtr & GetPatchMapFromPrevLevel(void) const
Returns the patch map from the previous level of the multi-level static condensation.
LibUtilities::CommSharedPtr m_comm
Communicator.
int GetNumGlobalBndCoeffs() const
Returns the total number of global boundary coefficients.
Array< OneD, int > m_localToLocalBndMap
Integer map of local boundary coeffs to local boundary system numbering.
Array< OneD, int > m_globalToUniversalBndMapUnique
Integer map of unique process coeffs to universal space (signed)
int GetFullSystemBandWidth() const
const Array< OneD, const int > & GetGlobalToUniversalBndMap()
const Array< OneD, const int > & GetBndCondIDToGlobalTraceID()
void LocalBndToGlobal(const Array< OneD, const NekDouble > &loc, Array< OneD, NekDouble > &global, int offset, bool UseComm=true) const
void UniversalAssemble(Array< OneD, NekDouble > &pGlobal) const
int m_numPatches
The number of patches (~elements) in the current level.
void LocalToLocalInt(const Array< OneD, const NekDouble > &local, Array< OneD, NekDouble > &locint) const
Array< OneD, int > m_bndCondIDToGlobalTraceID
Integer map of bnd cond trace number to global trace number.
virtual int v_GetNumNonDirFaces() const
bool GetSignChange()
Returns true if using a modal expansion requiring a change of sign of some modes.
Array< OneD, int > m_bndCondCoeffsToLocalTraceMap
Integer map of bnd cond coeff to local trace coeff.
void LocalIntToLocal(const Array< OneD, const NekDouble > &locbnd, Array< OneD, NekDouble > &local) const
void GlobalToLocalBnd(const NekVector< NekDouble > &global, NekVector< NekDouble > &loc, int offset) const
int GetNumLocalBndCoeffs() const
Returns the total number of local boundary coefficients.
int m_numGlobalBndCoeffs
Total number of global boundary coefficients.
Base class for all multi-elemental spectral/hp expansions.
Array< OneD, DataType > & GetPtr()
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.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
@ eIterativeMultiLevelStaticCond
@ eNoSolnType
No Solution type specified.
@ eDirectMultiLevelStaticCond
@ eXxtMultiLevelStaticCond
@ ePETScMultiLevelStaticCond
std::shared_ptr< BottomUpSubStructuredGraph > BottomUpSubStructuredGraphSharedPtr
void RoundNekDoubleToInt(const Array< OneD, const NekDouble > inarray, Array< OneD, int > outarray)
Rounds an array of double precision numbers to integers.
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
std::shared_ptr< PatchMap > PatchMapSharedPtr
int RoundNekDoubleToInt(NekDouble x)
Rounds a double precision number to an integer.
static const NekDouble kNekIterativeTol
The above copyright notice and this permission notice shall be included.
void Scatr(int n, const T *x, const int *y, T *z)
Scatter vector z[y[i]] = x[i].
void Gathr(int n, const T *sign, const T *x, const int *y, T *z)
Gather vector z[i] = sign[i]*x[y[i]].
void Assmb(int n, const T *x, const int *y, T *z)
Assemble z[y[i]] += x[i]; z should be zero'd first.
void Zero(int n, T *x, const int incx)
Zero vector.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)