Skip to content
Snippets Groups Projects
Commit af4fc861 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

don't crash if system is empty

parent c9ce5938
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "linearSystem.h" #include "linearSystem.h"
#include "sparsityPattern.h" #include "sparsityPattern.h"
typedef int INDEX_TYPE ; typedef int INDEX_TYPE ;
typedef struct { typedef struct {
int nmax; int nmax;
...@@ -52,9 +51,8 @@ class linearSystemCSR : public linearSystem<scalar> { ...@@ -52,9 +51,8 @@ class linearSystemCSR : public linearSystem<scalar> {
_sparsity.insertEntry (i,j); _sparsity.insertEntry (i,j);
} }
virtual void preAllocateEntries (); virtual void preAllocateEntries ();
virtual void addToMatrix(int il, int ic, const scalar &val) virtual void addToMatrix(int il, int ic, const scalar &val)
{ {
if (!_entriesPreAllocated) if (!_entriesPreAllocated)
preAllocateEntries(); preAllocateEntries();
INDEX_TYPE *jptr = (INDEX_TYPE*) _jptr->array; INDEX_TYPE *jptr = (INDEX_TYPE*) _jptr->array;
...@@ -125,18 +123,22 @@ class linearSystemCSR : public linearSystem<scalar> { ...@@ -125,18 +123,22 @@ class linearSystemCSR : public linearSystem<scalar> {
} }
virtual void addToRightHandSide(int row, const scalar &val) virtual void addToRightHandSide(int row, const scalar &val)
{ {
if (!_b) return;
if(val != scalar()) (*_b)[row] += val; if(val != scalar()) (*_b)[row] += val;
} }
virtual void addToSolution(int row, const scalar &val) virtual void addToSolution(int row, const scalar &val)
{ {
if (!_x) return;
if(val != scalar()) (*_x)[row] += val; if(val != scalar()) (*_x)[row] += val;
} }
virtual void getFromRightHandSide(int row, scalar &val) const virtual void getFromRightHandSide(int row, scalar &val) const
{ {
if (!_b) return;
val = (*_b)[row]; val = (*_b)[row];
} }
virtual void getFromSolution(int row, scalar &val) const virtual void getFromSolution(int row, scalar &val) const
{ {
if (!_x) return;
val = (*_x)[row]; val = (*_x)[row];
} }
virtual void zeroMatrix() virtual void zeroMatrix()
...@@ -156,9 +158,9 @@ class linearSystemCSR : public linearSystem<scalar> { ...@@ -156,9 +158,9 @@ class linearSystemCSR : public linearSystem<scalar> {
if (!_x) return; if (!_x) return;
for(unsigned int i = 0; i < _x->size(); i++) (*_x)[i] = scalar(); for(unsigned int i = 0; i < _x->size(); i++) (*_x)[i] = scalar();
} }
virtual double normInfRightHandSide() const virtual double normInfRightHandSide() const
{ {
if (!_b) return 0.;
double nor = 0.; double nor = 0.;
double temp; double temp;
for(unsigned int i = 0; i < _b->size(); i++){ for(unsigned int i = 0; i < _b->size(); i++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment