41 template <
int nVarsFixed>
45 using TU = Eigen::Vector<real, nVarsFixed>;
46 using tComponent = Eigen::Matrix<real, nVarsFixed, nVarsFixed>;
52 bool hasInvert{
false};
75 _data.
InitPair(
"JacobianLocalLU::SetModeAndInit::_data", mock.
father->getMPI());
76 _data.
father->Resize(mock.
father->Size(), nVarsC, nVarsC);
77 _data.
son->Resize(mock.
son->Size() * 0, nVarsC, nVarsC);
78 _dataInvert.
InitPair(
"JacobianLocalLU::SetModeAndInit::_dataInvert", mock.
father->getMPI());
79 _dataInvert.
father->Resize(mock.
father->Size(), nVarsC, nVarsC);
80 _dataInvert.
son->Resize(mock.
son->Size() * 0, nVarsC, nVarsC);
84 _dataDiag.
InitPair(
"JacobianLocalLU::SetModeAndInit::_dataDiag", mock.
father->getMPI());
85 _dataDiag.
father->Resize(mock.
father->Size(), nVarsC, 1);
86 _dataDiag.
son->Resize(mock.
son->Size() * 0, nVarsC, 1);
87 _dataDiagInvert.
InitPair(
"JacobianLocalLU::SetModeAndInit::_dataDiagInvert", mock.
father->getMPI());
88 _dataDiagInvert.
father->Resize(mock.
father->Size(), nVarsC, 1);
89 _dataDiagInvert.
son->Resize(mock.
son->Size() * 0, nVarsC, 1);
115 return _dataDiag[iCell];
131 return _dataDiag[iCell].asDiagonal();
140 return _dataDiag.
Size();
157#if defined(DNDS_DIST_MT_USE_OMP)
158#pragma omp parallel for schedule(runtime)
160 for (
index iCell = 0; iCell <
Size(); iCell++)
163 DNDS_assert(_data[iCell].diagonal().array().abs().minCoeff() != 0);
164 tComponent preCon = _data[iCell].diagonal().array().inverse().matrix().asDiagonal() * _data[iCell];
165 auto luDiag = preCon.fullPivLu();
167 _dataInvert[iCell] = luDiag.inverse() * _data[iCell].diagonal().array().inverse().matrix().asDiagonal();
168 if (!_dataInvert[iCell].allFinite() || _dataInvert[iCell].hasNaN())
172 std::cout << _data[iCell] <<
"\n";
173 std::cout << preCon <<
"\n";
174 std::cout << luDiag.inverse() <<
"\n";
175 std::cout << std::endl;
181 DNDS_assert(_dataDiag[iCell].array().abs().minCoeff() != 0);
182 _dataDiagInvert[iCell] = _dataDiag[iCell].array().inverse();
199 return _data[iCell] *
v;
201 return _dataDiag[iCell].asDiagonal() *
v;
218 return _dataInvert[iCell] *
v;
220 return _dataDiagInvert[iCell].asDiagonal() *
v;
228#if defined(DNDS_DIST_MT_USE_OMP)
229#pragma omp parallel for schedule(static)
236#if defined(DNDS_DIST_MT_USE_OMP)
237#pragma omp parallel for schedule(static)
239 for (
index i = 0; i < _dataDiag.
Size(); i++)
240 _dataDiag[i].setZero();
267 template <
int nVarsFixed>
270 JacobianLocalLU<nVarsFixed>,
271 Eigen::Matrix<real, nVarsFixed, nVarsFixed>,
272 ArrayDOFV<nVarsFixed>>
275 using tComponent = Eigen::Matrix<real, nVarsFixed, nVarsFixed>;
279 Eigen::Matrix<real, nVarsFixed, nVarsFixed>,
306 for (
auto &
v :
LDU[iCell])
316#if defined(DNDS_DIST_MT_USE_OMP)
317#pragma omp parallel for schedule(runtime)
320 for (
auto &
v :
LDU[iCell])
335 return LDU(i, 1 + iInLow);
348 log() <<
"nz Entries with Diag part inverse-ed" << std::endl;
351 log() <<
"=== Row " << iCell << std::endl
352 << std::setprecision(10);
353 for (
auto &
v :
LDU[iCell])
354 log() <<
v << std::endl
373 DNDS_assert(
v.diagonal().array().abs().minCoeff() != 0);
374 tComponent preCon =
v.diagonal().array().inverse().matrix().asDiagonal() *
v;
375 auto luDiag = preCon.fullPivLu();
378 std::cerr << v <<
"\n\n" << preCon <<
"\n\n";
379 return
"=== error info ==="; }());
380 AI = luDiag.inverse() *
v.diagonal().array().inverse().matrix().asDiagonal();
408 template <
int nVarsFixed>
411 JacobianLocalLDLT<nVarsFixed>,
412 Eigen::Matrix<real, nVarsFixed, nVarsFixed>,
413 ArrayDOFV<nVarsFixed>>
416 using tComponent = Eigen::Matrix<real, nVarsFixed, nVarsFixed>;
420 Eigen::Matrix<real, nVarsFixed, nVarsFixed>,
449 for (
auto &
v :
LDU[iCell])
459#if defined(DNDS_DIST_MT_USE_OMP)
460#pragma omp parallel for schedule(static)
463 for (
auto &
v :
LDU[iCell])
478 return LDU(i, 1 + iInLow);
484 log() <<
"nz Entries with Diag part inverse-ed" << std::endl;
487 log() <<
"=== Row " << iCell << std::endl
488 << std::setprecision(10);
489 for (
auto &
v :
LDU[iCell])
490 log() <<
v << std::endl
508 DNDS_assert(
v.diagonal().array().abs().minCoeff() != 0);
509 tComponent preCon =
v.diagonal().array().inverse().matrix().asDiagonal() *
v;
510 auto luDiag = preCon.fullPivLu();
512 AI = luDiag.inverse() *
v.diagonal().array().inverse().matrix().asDiagonal();
Batch of uniform-sized Eigen matrices per row, with variable batch count.
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Core type definitions, enumerations, and distributed array wrappers for compressible Navier-Stokes / ...
void Resize(index n_size, int r, int c)
void ResizeRow(index i, rowsize b_size)
void Compress()
Layout-polymorphic compress: no-op for non-CSR, calls CSRCompress for CSR.
MPI-parallel distributed array of per-cell Degrees-of-Freedom (conservative variable vectors).
Per-cell diagonal or block-diagonal Jacobian storage for implicit time stepping.
Eigen::Vector< real, nVarsFixed > tComponentDiag
Diagonal vector type.
auto getBlock(index iCell)
Access the full nVars×nVars block matrix for cell iCell (block mode only).
TU MatVecLeftInvert(index iCell, TV v)
Left-multiply a vector by the inverse Jacobian block for cell iCell.
void clearValues()
Zero all stored values and invalidate the cached inverse.
Eigen::Vector< real, nVarsFixed > TU
State vector type.
TU MatVecLeft(index iCell, TV v)
Left-multiply a vector by the Jacobian block for cell iCell.
Eigen::Matrix< real, nVarsFixed, nVarsFixed > tComponent
Full block matrix type.
auto getDiag(index iCell)
Access the diagonal vector for cell iCell (scalar-diagonal mode only).
bool isBlock() const
Return true if using matrix-block mode, false for scalar-diagonal.
tComponent getValue(index iCell) const
Return the Jacobian as a full matrix for cell iCell (either mode).
index Size()
Return the number of cells in the local partition.
JacobianDiagBlock()
Default constructor; mode and storage are uninitialized until SetModeAndInit().
void GetInvert()
Compute and cache the inverse of every cell's Jacobian block.
void SetModeAndInit(int mode, int nVarsC, ArrayDOFV< nVarsFixed > &mock)
Select the storage mode and allocate arrays matching mock's layout.
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
std::ostream & log()
Return the current DNDSR log stream (either std::cout or the installed file).
Convenience bundle of a father, son, and attached ArrayTransformer.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
index Size() const
Combined row count (father->Size() + son->Size()).
void InitPair(const std::string &name, Args &&...args)
Allocate both father and son arrays, forwarding all args to TArray constructor.
ssp< TArray > son
Ghost-side array (sized automatically by createMPITypes / BorrowAndPull).
ssp< Direct::SerialSymLUStructure > symLU
ssp< Direct::SerialSymLUStructure > symLU
Symmetric LDLT factorization of the cell-local Jacobian.
auto GetLower(index i, int iInLow)
Return lower-triangular block iInLow for row i (compliant with LocalLDLTBase CRTP).
void setZero()
Zero all D and L blocks and mark the factorization as not yet decomposed.
auto GetDiag(index i)
Return the diagonal block for row i (compliant with LocalLDLTBase CRTP).
tLocalMat LDU
Sparse row storage for D and L blocks.
JacobianLocalLDLT(const ssp< Direct::SerialSymLUStructure > &nMesh, int nVarsC)
Construct and allocate the LDLT storage for the given adjacency structure.
Eigen::Matrix< real, nVarsFixed, nVarsFixed > tComponent
Single block matrix type.
void PrintLog()
Print all non-zero entries (with diagonal inverted) to the log stream.
tComponent InvertDiag(const tComponent &v)
Invert a diagonal block using diagonal-preconditioned full-pivot LU.
Complete LU factorization of the cell-local Jacobian for GMRES preconditioning.
tLocalMat LDU
Sparse row storage for D, L, U blocks.
auto GetLower(index i, int iInLow)
Return lower-triangular block iInLow for row i (compliant with LocalLUBase CRTP).
tComponent InvertDiag(const tComponent &v)
Invert a diagonal block using diagonal-preconditioned full-pivot LU.
JacobianLocalLU(const ssp< Direct::SerialSymLUStructure > &nMesh, int nVarsC)
Construct and allocate the LU storage for the given adjacency structure.
auto GetDiag(index i)
Return the diagonal block for row i (compliant with LocalLUBase CRTP).
Eigen::Matrix< real, nVarsFixed, nVarsFixed > tComponent
Single block matrix type.
auto GetUpper(index i, int iInUpp)
Return upper-triangular block iInUpp for row i (compliant with LocalLUBase CRTP).
void PrintLog()
Print all non-zero entries (with diagonal inverted) to the log stream.
void setZero()
Zero all D, L, U blocks and mark the factorization as not yet decomposed.
Eigen::Matrix< real, 5, 1 > v