Skip to content
Snippets Groups Projects
Commit 81107a36 authored by Oliver Sander's avatar Oliver Sander
Browse files

Assert that the input vectors match the matrix size

Otherwise, if the matrix is smaller than the vectors, you may never find
out that you are computing wrong results.
parent d589b66b
No related branches found
No related tags found
No related merge requests found
...@@ -17,11 +17,16 @@ public: ...@@ -17,11 +17,16 @@ public:
H1SemiNorm(const Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> >& matrix) H1SemiNorm(const Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> >& matrix)
: matrix_(&matrix) : matrix_(&matrix)
{} {
assert(matrix.N() == matrix.M());
}
//! Compute the norm of the difference of two vectors //! Compute the norm of the difference of two vectors
double diff(const VectorType& u1, const VectorType& u2) const double diff(const VectorType& u1, const VectorType& u2) const
{ {
assert(u1.size()==u2.size());
assert(u1.size()==matrix_->N());
double sum = 0; double sum = 0;
for (size_t i=0; i<matrix_->N(); i++) for (size_t i=0; i<matrix_->N(); i++)
...@@ -42,6 +47,9 @@ public: ...@@ -42,6 +47,9 @@ public:
{ {
if (matrix_ == NULL) if (matrix_ == NULL)
DUNE_THROW(Dune::Exception, "You have not supplied neither a matrix nor an IterationStep to the EnergyNorm routine!"); DUNE_THROW(Dune::Exception, "You have not supplied neither a matrix nor an IterationStep to the EnergyNorm routine!");
assert(u.size()==matrix_->N());
// we compute sqrt{uAu^t}. We have implemented this by hand because the matrix is // we compute sqrt{uAu^t}. We have implemented this by hand because the matrix is
// always scalar but the vectors may not be // always scalar but the vectors may not be
double sum = 0; double sum = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment