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
73c63286
Commit
73c63286
authored
11 years ago
by
Elias Pipping
Committed by
pipping
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Dune:Solvers::CG: Add preconditioning
[[Imported from SVN: r11960]]
parent
c624daee
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/solvers/iterationsteps/cgstep.cc
+21
-3
21 additions, 3 deletions
dune/solvers/iterationsteps/cgstep.cc
dune/solvers/iterationsteps/cgstep.hh
+15
-3
15 additions, 3 deletions
dune/solvers/iterationsteps/cgstep.hh
with
36 additions
and
6 deletions
dune/solvers/iterationsteps/cgstep.cc
+
21
−
3
View file @
73c63286
template
<
class
MatrixType
,
class
VectorType
>
void
CGStep
<
MatrixType
,
VectorType
>::
check
()
const
{
if
(
preconditioner_
)
preconditioner_
->
check
();
}
template
<
class
MatrixType
,
class
VectorType
>
void
CGStep
<
MatrixType
,
VectorType
>::
preprocess
()
{
// Compute the residual (r starts out as the rhs)
matrix_
.
mmv
(
x_
,
r_
);
p_
=
r_
;
if
(
preconditioner_
)
{
preconditioner_
->
setMatrix
(
matrix_
);
preconditioner_
->
apply
(
p_
,
r_
);
}
else
p_
=
r_
;
r_squared_old
=
p_
*
r_
;
}
...
...
@@ -17,9 +30,14 @@ void CGStep<MatrixType, VectorType>::iterate()
x_
.
axpy
(
alpha
,
p_
);
// x_1 = x_0 + alpha_0 p_0
r_
.
axpy
(
-
alpha
,
q
);
// r_1 = r_0 - alpha_0 Ap_0
const
double
r_squared
=
r_
*
r_
;
if
(
preconditioner_
)
preconditioner_
->
apply
(
q
,
r_
);
else
q
=
r_
;
const
double
r_squared
=
q
*
r_
;
const
double
beta
=
r_squared
/
r_squared_old
;
// beta_0 = r_1*r_1/ (r_0*r_0)
p_
*=
beta
;
// p_1 = r_1 + beta_0 p_0
p_
+=
r_
;
p_
+=
q
;
r_squared_old
=
r_squared
;
}
This diff is collapsed.
Click to expand it.
dune/solvers/iterationsteps/cgstep.hh
+
15
−
3
View file @
73c63286
#ifndef DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH
#define DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH
#include
<dune/solvers/common/preconditioner.hh>
#include
<dune/solvers/iterationsteps/iterationstep.hh>
namespace
Dune
{
namespace
Solvers
{
//! A conjugate gradient solver
template
<
class
MatrixType
,
class
VectorType
>
class
CGStep
:
public
IterationStep
<
VectorType
>
{
public:
CGStep
(
const
MatrixType
&
matrix
,
VectorType
&
x
,
const
VectorType
&
rhs
)
:
p_
(
rhs
.
size
()),
r_
(
rhs
),
x_
(
x
),
matrix_
(
matrix
)
VectorType
&
x
,
const
VectorType
&
rhs
)
:
p_
(
rhs
.
size
()),
r_
(
rhs
),
x_
(
x
),
matrix_
(
matrix
),
preconditioner_
(
nullptr
)
{}
CGStep
(
const
MatrixType
&
matrix
,
VectorType
&
x
,
const
VectorType
&
rhs
,
Preconditioner
<
MatrixType
,
VectorType
>&
preconditioner
)
:
p_
(
rhs
.
size
()),
r_
(
rhs
),
x_
(
x
),
matrix_
(
matrix
),
preconditioner_
(
&
preconditioner
)
{}
void
check
()
const
;
...
...
@@ -28,6 +39,7 @@ namespace Dune {
VectorType
&
x_
;
const
MatrixType
&
matrix_
;
double
r_squared_old
;
Preconditioner
<
MatrixType
,
VectorType
>*
preconditioner_
;
};
#include
"cgstep.cc"
...
...
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