Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-solvers
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
Show more breadcrumbs
agnumpde
dune-solvers
Commits
dda688c7
Commit
dda688c7
authored
13 years ago
by
Uli Sack
Committed by
usack
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Erweiterungen und Aufräumarbeiten am LowRankOperator
[[Imported from SVN: r5253]]
parent
38d22f81
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/solvers/operators/lowrankoperator.hh
+46
-5
46 additions, 5 deletions
dune/solvers/operators/lowrankoperator.hh
dune/solvers/test/lowrankoperatortest.cc
+16
-0
16 additions, 0 deletions
dune/solvers/test/lowrankoperatortest.cc
with
62 additions
and
5 deletions
dune/solvers/operators/lowrankoperator.hh
+
46
−
5
View file @
dda688c7
...
...
@@ -2,7 +2,7 @@
#define LOWRANKOPERATOR_HH
/** \brief Class that behaves like a filled in low-rank matrix defined via a factor \f$ M\in\mathbb R^{k\times n}, k<<n \f$
/** \brief Class that behaves like a filled in
square
low-rank matrix defined via a factor \f$ M\in\mathbb R^{k\times n}, k<<n \f$
*
* The full matrix is given by \f$ A=M^TM\f$
*
...
...
@@ -14,6 +14,12 @@ class LowRankOperator
public:
//! export the type of the defining factor
typedef
LRFactorType
LowRankFactorType
;
//! export block type
typedef
typename
LRFactorType
::
block_type
block_type
;
//! export field type
typedef
typename
LRFactorType
::
field_type
field_type
;
//! export size type
typedef
typename
LRFactorType
::
size_type
size_type
;
//! constructor taking the defining factor as argument
LowRankOperator
(
LowRankFactorType
&
lrFactor
)
:
...
...
@@ -27,10 +33,33 @@ class LowRankOperator
LVectorType
temp
(
lowRankFactor_
.
N
());
lowRankFactor_
.
mv
(
x
,
temp
);
for
(
size_t
i
=
0
;
i
<
b
.
size
();
++
i
)
for
(
size_t
j
=
0
;
j
<
lowRankFactor_
.
N
();
++
j
)
if
(
lowRankFactor_
.
exists
(
j
,
i
))
lowRankFactor_
[
j
][
i
].
umv
(
temp
[
j
],
b
[
i
]);
typename
LowRankFactorType
::
RowIterator
row_end
=
lowRankFactor_
.
end
();
typename
LowRankFactorType
::
RowIterator
row_it
=
lowRankFactor_
.
begin
();
for
(;
row_it
!=
row_end
;
++
row_it
)
{
typename
LowRankFactorType
::
ColIterator
col_end
=
row_it
->
end
();
typename
LowRankFactorType
::
ColIterator
col_it
=
row_it
->
begin
();
for
(;
col_it
!=
col_end
;
++
col_it
)
lowRankFactor_
[
row_it
.
index
()][
col_it
.
index
()].
umv
(
temp
[
row_it
.
index
()],
b
[
col_it
.
index
()]);
}
}
//! b += alpha*Ax
template
<
class
LVectorType
,
class
RVectorType
>
void
usmv
(
const
field_type
&
alpha
,
const
LVectorType
&
x
,
RVectorType
&
b
)
const
{
LVectorType
temp
(
lowRankFactor_
.
N
());
lowRankFactor_
.
mv
(
x
,
temp
);
typename
LowRankFactorType
::
RowIterator
row_end
=
lowRankFactor_
.
end
();
typename
LowRankFactorType
::
RowIterator
row_it
=
lowRankFactor_
.
begin
();
for
(;
row_it
!=
row_end
;
++
row_it
)
{
typename
LowRankFactorType
::
ColIterator
col_end
=
row_it
->
end
();
typename
LowRankFactorType
::
ColIterator
col_it
=
row_it
->
begin
();
for
(;
col_it
!=
col_end
;
++
col_it
)
lowRankFactor_
[
row_it
.
index
()][
col_it
.
index
()].
usmv
(
alpha
,
temp
[
row_it
.
index
()],
b
[
col_it
.
index
()]);
}
}
//! b = Ax
...
...
@@ -41,6 +70,18 @@ class LowRankOperator
umv
(
x
,
b
);
}
//! returns number of rows
size_type
N
()
{
return
lowRankFactor_
.
M
();
}
//! returns number of columns
size_type
M
()
{
return
lowRankFactor_
.
M
();
}
//! returns the defining factor
const
LowRankFactorType
&
getLowRankFactor
()
const
{
...
...
This diff is collapsed.
Click to expand it.
dune/solvers/test/lowrankoperatortest.cc
+
16
−
0
View file @
dda688c7
...
...
@@ -80,6 +80,8 @@ bool check()
x
[
i
]
=
(
1.0
*
rand
())
/
RAND_MAX
;
b
=
ref_vec
=
0.0
;
double
alpha
=
(
1.0
*
rand
())
/
RAND_MAX
;
LowRankFactorType
lr_factor
(
m
,
n
);
std
::
cout
<<
"Checking LowRankOperator<"
<<
Dune
::
className
(
lr_factor
)
<<
" > ... "
;
...
...
@@ -142,6 +144,20 @@ bool check()
break
;
}
full_op
.
usmv
(
alpha
,
x
,
ref_vec
);
lr_op
.
usmv
(
alpha
,
x
,
b
);
for
(
size_t
i
=
0
;
i
<
b
.
size
();
++
i
)
if
((
b
[
i
]
-
ref_vec
[
i
]).
two_norm
()
/
b
[
i
].
two_norm
()
>
1e-12
)
{
std
::
cout
<<
"LowRankOperator::usmv does not yield correct result. Difference = "
<<
(
b
[
i
]
-
ref_vec
[
i
]).
two_norm
()
<<
std
::
endl
;
passed
=
false
;
for
(
size_t
j
=
0
;
j
<
b
.
size
();
++
j
)
std
::
cout
<<
b
[
j
]
<<
" "
<<
ref_vec
[
j
]
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
break
;
}
LowRankFactorType
lr_factor_reborn
=
lr_op
.
getLowRankFactor
();
if
(
passed
)
...
...
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