35#include "../parallelization/omp_structure.hpp"
36#include "../parallelization/mpi_structure.hpp"
49template <
class Scalar_t,
bool WithMPI = true>
54 static_assert(std::is_floating_point<Scalar>::value,
"");
59 enum :
size_t { BLOCK_SIZE = 1024 };
60 std::vector<su2matrix<Scalar> > X, R;
66 void shiftHistoryLeft() {
67 for (
Index i = 1; i < X.size(); ++i) {
70 std::swap(X[i - 1], X[i]);
71 std::swap(R[i - 1], R[i]);
75 void computeNormalEquations() {
77 const auto end = std::min<Index>(nPtDomain, work.
rows()) * work.
cols();
84 while (end - begin >= BLOCK_SIZE) {
85 computeNormalEquations<BLOCK_SIZE>(mat, rhs, begin);
91 computeNormalEquations<0>(mat, rhs, begin, end - begin);
100 mat = std::move(tmp);
107 template <Index StaticSize>
110 const auto blkSize = StaticSize ? StaticSize : dynSize;
112 for (
Index i = 0; i < iSample; ++i) {
113 const auto ri1 = R[i + 1].data() + start;
114 const auto ri0 = R[i].data() + start;
116 for (
Index j = 0; j < i; ++j) {
117 const auto rj1 = R[j + 1].data() + start;
118 const auto rj0 = R[j].data() + start;
122 for (
Index k = 0; k < blkSize; ++k) {
123 sum += (ri1[k] - ri0[k]) * (rj1[k] - rj0[k]);
126 const auto iCoeff = i * (i + 1) / 2 + j;
131 const auto r = R[iSample].
data() + start;
133 for (
Index k = 0; k < blkSize; ++k) {
134 diag +=
pow(ri1[k] - ri0[k], 2);
135 res += (ri1[k] - ri0[k]) * r[k];
137 mat(i * (i + 3) / 2) += diag;
148 resize(nsample, npt, nvar, nptdomain);
161 nPtDomain = nptdomain ? nptdomain : npt;
165 for (
Index i = 0; i < nsample; ++i) {
166 X.emplace_back(npt, nvar);
167 R.emplace_back(npt, nvar);
171 mat.
resize(nsample * (nsample - 1) / 2);
181 std::swap(X[0], X[iSample]);
210 for (
Index i = 0; i < work.
size(); ++i) {
211 R[iSample].data()[i] = work.
data()[i] - X[iSample].data()[i];
217 computeNormalEquations();
219 for (
Index i = 0, k = 0; i < iSample; ++i)
220 for (
Index j = 0; j <= i; ++j) pseudoInv(i, j) = mat(k++);
225 for (
Index k = 0; k < iSample; ++k) {
226 const auto x1 = X[k + 1].data();
227 const auto r1 = R[k + 1].data();
228 const auto x0 = X[k].data();
229 const auto r0 = R[k].data();
231 for (
Index i = 0; i < work.
size(); ++i) {
232 Scalar dy = r1[i] - r0[i] + x1[i] - x0[i];
233 work.
data()[i] += sol(k) * dy;
239 if (iSample + 1 == X.size()) {
246 for (
Index i = 0; i < work.
size(); ++i) work.
data()[i] += R[iSample].data()[i] + X[iSample].data()[i];
247 std::swap(X[++iSample], work);
CNewtonIntegration::Scalar Scalar
Definition CNewtonIntegration.cpp:31
Dense symmetric matrix, used for example in RBF interpolation.
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
C2DContainer & resize(const Index_t size1, const Index_t size2=1) noexcept
Request a change of size.
Definition C2DContainer.hpp:541
size_t size() const noexcept
Definition C2DContainer.hpp:222
Index_t cols() const noexcept
Definition C2DContainer.hpp:222
Index_t Index
Definition C2DContainer.hpp:387
Index_t rows() const noexcept
Definition C2DContainer.hpp:222
Definition mpi_structure.hpp:501
static Comm GetComm()
Definition mpi_structure.hpp:530
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
A quasi-Newton fixed-point (FP) accelerator based on IQN-ILS.
Definition CQuasiNewtonInvLeastSquares.hpp:50
Index size() const
Size of the object, the number of samples.
Definition CQuasiNewtonInvLeastSquares.hpp:177
Scalar_t Scalar
Definition CQuasiNewtonInvLeastSquares.hpp:52
Scalar & operator()(Index iPt, Index iVar)
Definition CQuasiNewtonInvLeastSquares.hpp:200
CQuasiNewtonInvLeastSquares(Index nsample, Index npt, Index nvar, Index nptdomain=0)
Construction with allocation, see "resize".
Definition CQuasiNewtonInvLeastSquares.hpp:147
su2matrix< Scalar > & solution()
Access the current solution approximation.
Definition CQuasiNewtonInvLeastSquares.hpp:198
const Scalar & FPresult(Index iPt, Index iVar) const
Definition CQuasiNewtonInvLeastSquares.hpp:192
void reset()
Discard all history, keeping the current solution.
Definition CQuasiNewtonInvLeastSquares.hpp:180
const su2matrix< Scalar > & FPresult() const
Definition CQuasiNewtonInvLeastSquares.hpp:190
const Scalar & operator()(Index iPt, Index iVar) const
Definition CQuasiNewtonInvLeastSquares.hpp:201
Scalar & FPresult(Index iPt, Index iVar)
Definition CQuasiNewtonInvLeastSquares.hpp:191
const su2matrix< Scalar > & solution() const
Definition CQuasiNewtonInvLeastSquares.hpp:199
su2matrix< Scalar > & FPresult()
Access the current fixed-point result.
Definition CQuasiNewtonInvLeastSquares.hpp:189
void resize(Index nsample, Index npt, Index nvar, Index nptdomain=0)
Resize the object.
Definition CQuasiNewtonInvLeastSquares.hpp:158
typename su2matrix< Scalar >::Index Index
Definition CQuasiNewtonInvLeastSquares.hpp:53
CQuasiNewtonInvLeastSquares()=default
Default construction without allocation.
const su2matrix< Scalar > & compute()
Compute and return a new approximation.
Definition CQuasiNewtonInvLeastSquares.hpp:207
The matrix is symmetric but full storage is used as that gives much better performance for some BLAS ...
Definition CSymmetricMatrix.hpp:38
void MatVecMult(ForwardIt vec_in, ForwardIt vec_out) const
Definition CSymmetricMatrix.hpp:68
void Invert(bool is_spd=false)
Definition CSymmetricMatrix.cpp:160
Scalar_t * data() noexcept
Definition C2DContainer.hpp:222
FORCEINLINE ARRAY_T pow(const ARRAY_T &a, const ARRAY_T &b)
Definition special_vectorization.hpp:179
#define MPI_FLOAT
Definition mpi_structure.hpp:483
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
#define MPI_SUM
Definition mpi_structure.hpp:486
#define MPI_DOUBLE
Definition mpi_structure.hpp:484
#define SU2_OMP_SIMD
Definition omp_structure.hpp:125