Files
solver/OndselSolver/LDUSpMat.cpp
John Dupuy 87ed8700e2 modify code to suppress or fix warnings in gcc and clang (#41)
* first fix to start branch PR

* explicit conversion from sizet to int

* Array.h and DiagonalMatrix.h

* many sizet to int conversions

* removed some unused variables and added expl overrides

* removed many unused parameters

* more typing

* even more

* last of the easy changes
2023-12-08 10:00:00 -07:00

84 lines
2.2 KiB
C++

/***************************************************************************
* Copyright (c) 2023 Ondsel, Inc. *
* *
* This file is part of OndselSolver. *
* *
* See LICENSE file for details about copyright. *
***************************************************************************/
#include "LDUSpMat.h"
#include "FullColumn.h"
using namespace MbD;
FColDsptr LDUSpMat::basicSolvewithsaveOriginal(SpMatDsptr spMat, FColDsptr fullCol, bool saveOriginal)
{
this->decomposesaveOriginal(spMat, saveOriginal);
FColDsptr answer = this->forAndBackSubsaveOriginal(fullCol, saveOriginal);
return answer;
}
void LDUSpMat::decomposesaveOriginal(FMatDsptr, bool)
{
assert(false);
}
void LDUSpMat::decomposesaveOriginal(SpMatDsptr, bool)
{
assert(false);
}
FColDsptr LDUSpMat::forAndBackSubsaveOriginal(FColDsptr, bool)
{
assert(false);
return FColDsptr();
}
double LDUSpMat::getmatrixArowimaxMagnitude(int i)
{
return matrixA->at(i)->maxMagnitude();
}
void LDUSpMat::forwardSubstituteIntoL()
{
//"L is lower triangular with nonzero and ones in diagonal."
auto vectorc = std::make_shared<FullColumn<double>>(n);
vectorc->at(0) = rightHandSideB->at(0);
for (int i = 1; i < n; i++)
{
auto rowi = matrixA->at(i);
double sum = 0.0;
for (auto const& keyValue : *rowi) {
int j = keyValue.first;
double duij = keyValue.second;
sum += duij * vectorc->at(j);
}
vectorc->at(i) = rightHandSideB->at(i) - sum;
}
rightHandSideB = vectorc;
}
void LDUSpMat::backSubstituteIntoDU()
{
//"DU is upper triangular with nonzero diagonals."
double sum, duij;
for (int i = 0; i < m; i++)
{
rightHandSideB->at(i) = rightHandSideB->at(i) / matrixD->at(i);
}
answerX = std::make_shared<FullColumn<double>>(m);
answerX->at(n - 1) = rightHandSideB->at(m - 1);
for (int i = n - 2; i >= 0; i--)
{
auto rowi = matrixU->at(i);
sum = 0.0;
for (auto const& keyValue : *rowi) {
auto j = keyValue.first;
duij = keyValue.second;
sum += answerX->at(j) * duij;
}
answerX->at(i) = rightHandSideB->at(i) - sum;
}
}