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
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Tobias Leibner
dune-common
Commits
b3a810e3
Commit
b3a810e3
authored
9 years ago
by
Elias Pipping
Browse files
Options
Downloads
Patches
Plain Diff
Fix vector norm computation with NaN values
parent
2535cbc1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/densevector.hh
+72
-24
72 additions, 24 deletions
dune/common/densevector.hh
with
72 additions
and
24 deletions
dune/common/densevector.hh
+
72
−
24
View file @
b3a810e3
...
...
@@ -91,6 +91,76 @@ namespace Dune {
}
};
template
<
typename
V
,
bool
hasNaN
=
std
::
is_floating_point
<
typename
FieldTraits
<
typename
DenseMatVecTraits
<
V
>
::
value_type
>::
real_type
>::
value
>
struct
InfinityNormComputer
{
using
value_type
=
typename
DenseMatVecTraits
<
V
>::
value_type
;
using
real_type
=
typename
FieldTraits
<
value_type
>::
real_type
;
real_type
static
infinity_norm
(
V
const
&
v
)
{
using
std
::
abs
;
using
std
::
max
;
real_type
norm
=
0.0
;
for
(
auto
&&
x
:
v
)
{
real_type
const
a
=
abs
(
x
);
norm
=
max
(
a
,
norm
);
}
return
norm
;
}
real_type
static
infinity_norm_real
(
V
const
&
v
)
{
using
std
::
max
;
real_type
norm
=
0.0
;
for
(
auto
&&
x
:
v
)
{
real_type
const
a
=
absreal
(
x
);
norm
=
max
(
a
,
norm
);
}
return
norm
;
}
};
template
<
typename
V
>
struct
InfinityNormComputer
<
V
,
true
>
{
using
value_type
=
typename
DenseMatVecTraits
<
V
>::
value_type
;
using
real_type
=
typename
FieldTraits
<
value_type
>::
real_type
;
real_type
static
infinity_norm
(
V
const
&
v
)
{
using
std
::
abs
;
using
std
::
max
;
real_type
norm
=
0.0
;
real_type
isNaN
=
1.0
;
for
(
auto
&&
x
:
v
)
{
real_type
const
a
=
abs
(
x
);
norm
=
max
(
a
,
norm
);
isNaN
+=
a
;
}
isNaN
/=
isNaN
;
return
norm
*
isNaN
;
}
real_type
static
infinity_norm_real
(
V
const
&
v
)
{
using
std
::
max
;
real_type
norm
=
0.0
;
real_type
isNaN
=
1.0
;
for
(
auto
&&
x
:
v
)
{
real_type
const
a
=
absreal
(
x
);
norm
=
max
(
a
,
norm
);
isNaN
+=
a
;
}
isNaN
/=
isNaN
;
return
norm
*
isNaN
;
}
};
/**
\private
\memberof Dune::DenseVector
...
...
@@ -606,35 +676,13 @@ namespace Dune {
//! infinity norm (maximum of absolute values of entries)
typename
FieldTraits
<
value_type
>::
real_type
infinity_norm
()
const
{
using
std
::
abs
;
using
std
::
max
;
typedef
typename
FieldTraits
<
value_type
>::
real_type
real_type
;
if
(
size
()
==
0
)
return
0.0
;
ConstIterator
it
=
begin
();
real_type
max_val
=
abs
(
*
it
);
for
(
it
=
it
+
1
;
it
!=
end
();
++
it
)
max_val
=
max
(
max_val
,
real_type
(
abs
(
*
it
)));
return
max_val
;
return
fvmeta
::
InfinityNormComputer
<
V
>::
infinity_norm
(
*
this
);
}
//! simplified infinity norm (uses Manhattan norm for complex values)
typename
FieldTraits
<
value_type
>::
real_type
infinity_norm_real
()
const
{
using
std
::
max
;
if
(
size
()
==
0
)
return
0.0
;
ConstIterator
it
=
begin
();
typename
FieldTraits
<
value_type
>::
real_type
max_val
=
fvmeta
::
absreal
(
*
it
);
for
(
it
=
it
+
1
;
it
!=
end
();
++
it
)
max_val
=
max
(
max_val
,
fvmeta
::
absreal
(
*
it
));
return
max_val
;
return
fvmeta
::
InfinityNormComputer
<
V
>::
infinity_norm_real
(
*
this
);
}
//===== sizes
...
...
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