Skip to content
Snippets Groups Projects
Commit 1cc3931a authored by Tom Fischer's avatar Tom Fischer Committed by Norihiro Watanabe
Browse files

Used specific properties of dense matrices in applyKnownSolution().

parent afc68b5c
No related branches found
No related tags found
No related merge requests found
......@@ -17,41 +17,41 @@
namespace MathLib
{
void applyKnownSolution(DenseMatrix<double> &eqsA, DenseVector<double> &eqsRHS, std::size_t k, double x)
void applyKnownSolution(DenseMatrix<double> &eqsA, DenseVector<double> &eqsRHS, std::size_t k,
double val)
{
const size_t n_rows = eqsA.getNRows();
const size_t n_cols = eqsA.getNCols();
//A(k, j) = 0.
for (size_t j=0; j<n_cols; j++)
const std::size_t n_rows = eqsA.getNRows();
const std::size_t n_cols = eqsA.getNCols();
// set all entries of the k-th row of the matrix to zero
// except the diagonal entry that is set to one
for (std::size_t j=0; j<n_cols; j++)
eqsA(k, j) = .0;
//A(k, k) = 1,
eqsA(k,k) = 1.0;
//b_i -= A(i,k)*val, i!=k
for (size_t i=0; i<n_rows; ++i)
{
if (i==k) continue;
double v_i_k = .0;
for (size_t j=0; j<n_cols; ++j)
{
if (j==k) {
v_i_k = eqsA(i, k);
eqsA(i, k) = .0;
break;
} else if (j>k) {
break;
}
}
eqsRHS[i] -= v_i_k*x;
}
//b_k = val
eqsRHS[k] = x;
// b_i -= A(i,k)*val, i!=k and
// set the entries of the k-th column of the matrix to zero
// except the diagonal entry A(k,k)
for (std::size_t i = 0; i < k; ++i)
{
eqsRHS[i] -= eqsA(i, k) * val;
eqsA(i, k) = 0.0;
}
for (std::size_t i = k+1; i < n_rows; ++i)
{
eqsRHS[i] -= eqsA(i, k) * val;
eqsA(i, k) = 0.0;
}
// b_k = val
eqsRHS[k] = val;
}
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b, const std::vector<std::size_t> &_vec_knownX_id, const std::vector<double> &_vec_knownX_x)
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b, const std::vector<std::size_t> &vec_knownX_id, const std::vector<double> &vec_knownX_x)
{
const std::size_t n_bc = _vec_knownX_id.size();
const std::size_t n_bc = vec_knownX_id.size();
for (std::size_t i_bc=0; i_bc<n_bc; i_bc++) {
applyKnownSolution(A, b, _vec_knownX_id[i_bc], _vec_knownX_x[i_bc]);
applyKnownSolution(A, b, vec_knownX_id[i_bc], vec_knownX_x[i_bc]);
}
}
......
......@@ -23,30 +23,35 @@ namespace MathLib
{
/**
* apply known solutions to a system of linear equations
* Apply known solutions to a system of linear equations.
*
* This function introduces the given constrain by diagonalizing a coefficient matrix.
* Symmetricity of the matrix is preserved.
* This function introduces the given constrains by diagonalizing a coefficient matrix.
* Symmetry of the matrix is preserved.
*
* @param A Coefficient matrix
* @param b RHS vector
* @param _vec_knownX_id a vector of known solution entry IDs
* @param _vec_knownX_x a vector of known solutions
* @param A Coefficient matrix
* @param b RHS vector
* @param vec_knownX_id a vector of known solution entry IDs
* @param vec_knownX_x a vector of known solutions
*/
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b, const std::vector<std::size_t> &_vec_knownX_id, const std::vector<double> &_vec_knownX_x);
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b,
const std::vector<std::size_t> &vec_knownX_id, const std::vector<double> &vec_knownX_x);
/**
* apply known solutions to a system of linear equations
* Apply known solutions to a system of linear equations \f$A x = b\f$.
*
* This function introduces the given constrain by diagonalizing a coefficient matrix.
* Symmetricity of the matrix is preserved.
* This function introduces the given constrain into the system of linear
* equations. For this purpose it modifies the entries of \f$A\f$ in the
* \f$k\f$-th row and column, i.e. all those entries are set to zero except
* the diagonal entry that is set to one. The right
* hand side \f$b\f$ is modified, too. The symmetry of \f$A\f$ is preserved.
*
* @param A Coefficient matrix
* @param b RHS vector
* @param row_id a known solution entry ID
* @param x a known solution
* @param val a known solution
*/
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b, std::size_t row_id, double x);
void applyKnownSolution(DenseMatrix<double> &A, DenseVector<double> &b, std::size_t row_id,
double val);
} // MathLib
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment