Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Koch
dune-common
Commits
6408dc90
Commit
6408dc90
authored
20 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
* improved ostream operator for spmatrix
* using exceptions instead of cerr [[Imported from SVN: r802]]
parent
caf36b0f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/exceptions.hh
+13
-0
13 additions, 0 deletions
common/exceptions.hh
fem/feop/spmatrix.cc
+27
-10
27 additions, 10 deletions
fem/feop/spmatrix.cc
fem/feop/spmatrix.hh
+1
-1
1 addition, 1 deletion
fem/feop/spmatrix.hh
with
41 additions
and
11 deletions
common/exceptions.hh
+
13
−
0
View file @
6408dc90
...
...
@@ -146,6 +146,19 @@ namespace Dune {
*/
class
MathError
:
public
Exception
{};
/*! default exception class for Range errors
This is the superclass for all errors which are caused because
the user tries to access data, that was not allocated before.
These can be problems like
- accessing array entries behind the last entry
- adding the fourth non zero entry in a sparse matrix
with only three non zero entries per row
*/
class
RangeError
:
public
Exception
{};
}
// end namespace
#endif
This diff is collapsed.
Click to expand it.
fem/feop/spmatrix.cc
+
27
−
10
View file @
6408dc90
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include
<cmath>
#include
<limits>
#include
<dune/common/exceptions.hh>
namespace
Dune
{
...
...
@@ -184,8 +186,10 @@ namespace Dune
int
whichCol
=
colIndex
(
row
,
col
);
if
(
whichCol
<
0
)
{
std
::
cerr
<<
"Error in SparseRowMatrix::set: Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!
\n
"
;
DUNE_THROW
(
RangeError
,
"Error in SparseRowMatrix::set: Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!"
);
}
else
{
...
...
@@ -197,14 +201,19 @@ namespace Dune
template
<
class
T
>
void
SparseRowMatrix
<
T
>::
add
(
int
row
,
int
col
,
const
T
&
val
)
{
if
(
std
::
numeric_limits
<
T
>::
has_quiet_NaN
&&
std
::
numeric_limits
<
T
>::
quiet_NaN
()
==
val
)
DUNE_THROW
(
MathError
,
"trying to add NAN to a matrix entry."
);
if
(
std
::
abs
(
val
)
<
EPS
)
return
;
int
whichCol
=
colIndex
(
row
,
col
);
if
(
whichCol
<
0
)
{
std
::
cerr
<<
"Error in SparseRowMatrix::add: Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!
\n
"
;
DUNE_THROW
(
RangeError
,
"Error in SparseRowMatrix::add: Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!"
);
}
else
{
...
...
@@ -219,8 +228,10 @@ namespace Dune
int
whichCol
=
colIndex
(
row
,
col
);
if
(
whichCol
<
0
)
{
std
::
cerr
<<
"Error in SparseRowMatrix::multScalar: Entry Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!
\n
"
;
DUNE_THROW
(
RangeError
,
"Error in SparseRowMatrix::multScalar: Entry Entry ("
<<
row
<<
", "
<<
col
<<
") "
<<
"could neither be found nor newly allocated!"
);
}
else
{
...
...
@@ -434,15 +445,21 @@ namespace Dune
template
<
class
T
>
void
SparseRowMatrix
<
T
>::
print
(
std
::
ostream
&
s
)
const
void
SparseRowMatrix
<
T
>::
print
(
std
::
ostream
&
s
,
int
width
)
const
{
char
txt
[
20
];
for
(
int
row
=
0
;
row
<
dim_
[
0
];
row
++
)
{
for
(
int
col
=
0
;
col
<
dim_
[
1
];
col
++
)
{
s
<<
(
*
this
)(
row
,
col
)
<<
" "
;
T
t
=
(
*
this
)(
row
,
col
);
if
(
t
==
0.0
)
snprintf
(
txt
,
20
,
"%*i.0 "
,
width
+
5
,
0
);
else
snprintf
(
txt
,
20
,
"% 1.*e "
,
width
,
t
);
s
<<
txt
;
}
s
<<
"
\n
"
;
s
<<
std
::
endl
;
}
}
...
...
@@ -495,7 +512,7 @@ namespace Dune
// non zero values before this line
nzval_
.
resize
(
dim_
[
0
]
+
1
);
for
(
int
i
=
0
;
i
<
nzval_
.
size
();
i
++
)
nzval_
[
i
]
=
3
*
i
;
nzval_
[
i
]
=
nz_
*
i
;
// fill missing entries
for
(
int
row
=
0
;
row
<
dim_
[
0
];
row
++
)
{
...
...
This diff is collapsed.
Click to expand it.
fem/feop/spmatrix.hh
+
1
−
1
View file @
6408dc90
...
...
@@ -209,7 +209,7 @@ namespace Dune
SparseRowMatrix
<
T
>
applyFromLeftAndRightTo
(
const
SparseRowMatrix
<
T
>&
A
)
const
;
//! Prints the complete matrix including the nonzero entries
void
print
(
std
::
ostream
&
s
)
const
;
void
print
(
std
::
ostream
&
s
,
int
width
=
3
)
const
;
//! Just prints the nonzero entries
void
printReal
(
std
::
ostream
&
s
)
const
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment