Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-matrix-vector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
agnumpde
dune-matrix-vector
Commits
c0d7b6e0
Commit
c0d7b6e0
authored
7 years ago
by
Max Kahnt
Browse files
Options
Downloads
Patches
Plain Diff
Add getScalar to extract the scale factor of some scaling.
parent
a557ccd7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/matrix-vector/CMakeLists.txt
+2
-1
2 additions, 1 deletion
dune/matrix-vector/CMakeLists.txt
dune/matrix-vector/getscalar.hh
+83
-0
83 additions, 0 deletions
dune/matrix-vector/getscalar.hh
with
85 additions
and
1 deletion
dune/matrix-vector/CMakeLists.txt
+
2
−
1
View file @
c0d7b6e0
add_subdirectory
(
test
)
add_subdirectory
(
test
)
add_subdirectory
(
traits
)
add_subdirectory
(
traits
)
#install headers
#install headers
...
@@ -12,6 +12,7 @@ install(FILES
...
@@ -12,6 +12,7 @@ install(FILES
concepts.hh
concepts.hh
crossproduct.hh
crossproduct.hh
genericvectortools.hh
genericvectortools.hh
getscalar.hh
ldlt.hh
ldlt.hh
promote.hh
promote.hh
singlenonzerocolumnmatrix.hh
singlenonzerocolumnmatrix.hh
...
...
This diff is collapsed.
Click to expand it.
dune/matrix-vector/getscalar.hh
0 → 100644
+
83
−
0
View file @
c0d7b6e0
#
ifndef
DUNE_MATRIX_VECTOR_GETSCALAR_HH
#define DUNE_MATRIX_VECTOR_GETSCALAR_HH
#include
<utility>
#include
<dune/common/fmatrix.hh>
#include
<dune/istl/scaledidmatrix.hh>
#include
<dune/matrix-vector/traits/utilities.hh>
namespace
Dune
{
namespace
MatrixVector
{
template
<
class
,
class
Enable
=
void
>
struct
Helper
;
/**
* \brief Extract the scalar of some scale provider.
* \param tol Is the acceptable difference for ambiguous extracted scalings.
**/
template
<
class
Scalar
,
class
Provider
>
static
Scalar
getScalar
(
Provider
&&
p
,
Scalar
tol
=
0.0
)
{
static_assert
(
isScalar
<
Scalar
>
(),
"Type not know as scalar."
);
return
Helper
<
std
::
decay_t
<
Provider
>>::
template
get
<
Scalar
>(
std
::
forward
<
Provider
>
(
p
),
tol
);
}
//! \brief If the scaling is given by a scalar, that is what we return.
template
<
class
Provider
>
struct
Helper
<
Provider
,
EnableScalar
<
Provider
>>
{
template
<
class
Scalar
,
class
Provider_
>
static
Scalar
get
(
Provider_
&&
p
,
Scalar
)
{
return
p
;
}
};
//! \brief If the scaling is given by a matrix a*Id, extract a.
//! Fail if given matrix is not a multiple of Id.
template
<
class
Provider
>
struct
Helper
<
Provider
,
EnableMatrix
<
Provider
>>
{
template
<
class
Scalar
,
class
K
,
int
n
>
static
Scalar
get
(
const
ScaledIdentityMatrix
<
K
,
n
>&
m
,
Scalar
)
{
return
m
.
scalar
();
}
template
<
class
Scalar
,
class
K
,
int
n
>
static
Scalar
get
(
const
FieldMatrix
<
K
,
n
,
n
>&
m
,
Scalar
tol
)
{
// TODO make istl-with-checking like mechanism where one avoids all
// the following computations and just returns the first value.
using
namespace
std
;
Scalar
result_min
=
std
::
numeric_limits
<
Scalar
>::
infinity
();
Scalar
result_max
=
-
std
::
numeric_limits
<
Scalar
>::
infinity
();
Scalar
others_max
=
0
;
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
n
;
++
j
)
{
if
(
i
==
j
)
{
result_min
=
min
(
result_min
,
m
[
i
][
j
]);
result_max
=
max
(
result_max
,
m
[
i
][
j
]);
}
else
{
others_max
=
max
(
others_max
,
fabs
(
m
[
i
][
j
]));
}
}
}
if
(
others_max
>
tol
)
DUNE_THROW
(
Exception
,
"Offdiagonal is not (close enought to) zero."
);
if
(
fabs
(
result_max
-
result_min
)
>
tol
)
DUNE_THROW
(
Exception
,
"Diagonal scaling is (too) ambiguous."
);
return
result_max
;
}
template
<
class
Scalar
,
class
M
>
static
Scalar
get
(
const
M
&
,
Scalar
)
{
static_assert
(
AlwaysFalse
<
M
>::
value
,
"Not yet implemented."
);
return
1.0
;
}
};
}
// end namespace MatrixVector
}
// end namespace Dune
#endif // DUNE_MATRIX_VECTOR_GETSCALAR_HH
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