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
d2b3344e
There was a problem fetching the pipeline summary.
Commit
d2b3344e
authored
9 years ago
by
Max Kahnt
Browse files
Options
Downloads
Patches
Plain Diff
Refactor test.
parent
ae2acb3f
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/solvers/test/gssteptest.cc
+53
-61
53 additions, 61 deletions
dune/solvers/test/gssteptest.cc
with
53 additions
and
61 deletions
dune/solvers/test/gssteptest.cc
+
53
−
61
View file @
d2b3344e
...
@@ -16,34 +16,6 @@
...
@@ -16,34 +16,6 @@
#include
"common.hh"
#include
"common.hh"
template
<
class
Vector
>
class
Analyser
{
public:
Analyser
(
Vector
const
&
reference
,
Norm
<
Vector
>
const
&
norm
,
double
tolerance
)
:
reference_
(
reference
),
norm_
(
norm
),
tolerance_
(
tolerance
)
{}
bool
analyse
(
Vector
const
&
candidate
,
std
::
string
testCase
)
{
const
auto
normDiff
=
norm_
.
diff
(
reference_
,
candidate
);
const
std
::
string
s
=
Dune
::
formatString
(
"%*s"
,
-
40
,
testCase
.
c_str
());
std
::
cout
<<
"error for solver
\"
"
<<
s
<<
"
\"
: "
<<
normDiff
<<
std
::
endl
;
if
(
normDiff
>
tolerance_
)
{
std
::
cerr
<<
"Error too large for solver
\"
"
<<
s
<<
"
\"
."
<<
std
::
endl
;
return
false
;
}
return
true
;
}
private
:
Vector
const
&
reference_
;
Norm
<
Vector
>
const
&
norm_
;
double
const
tolerance_
;
};
/** \brief test for the GSStep classes
/** \brief test for the GSStep classes
*
*
* This test tests if the Dirichlet problem for a Laplace operator
* This test tests if the Dirichlet problem for a Laplace operator
...
@@ -55,34 +27,24 @@ struct GSTestSuite
...
@@ -55,34 +27,24 @@ struct GSTestSuite
template
<
class
GridType
>
template
<
class
GridType
>
bool
check
(
const
GridType
&
grid
)
bool
check
(
const
GridType
&
grid
)
{
{
double
stepTol
=
1e-12
;
// termination criterion
double
solveTol
=
1.3e-5
;
// error in the solution
int
maxIterations
=
10000
;
bool
passed
=
true
;
bool
passed
=
true
;
using
Problem
=
using
Problem
=
SymmetricSampleProblem
<
1
,
typename
GridType
::
LevelGridView
>
;
SymmetricSampleProblem
<
1
,
typename
GridType
::
LevelGridView
>
;
Problem
p
(
grid
.
levelGridView
(
grid
.
maxLevel
()));
Problem
p
(
grid
.
levelGridView
(
grid
.
maxLevel
()));
const
auto
verbosity
=
Solver
::
REDUCED
;
const
auto
verbosity
=
Solver
::
QUIET
;
const
bool
relativeErrors
=
false
;
const
bool
relativeErrors
=
false
;
using
Matrix
=
typename
Problem
::
Matrix
;
using
Matrix
=
typename
Problem
::
Matrix
;
using
Vector
=
typename
Problem
::
Vector
;
using
Vector
=
typename
Problem
::
Vector
;
Analyser
<
Vector
>
analyser
(
p
.
u_ex
,
p
.
energyNorm
,
solveTol
);
using
LoopSolver
=
::
LoopSolver
<
Vector
>
;
using
LoopSolver
=
::
LoopSolver
<
Vector
>
;
using
Step
=
LinearIterationStep
<
Matrix
,
Vector
>
;
using
Step
=
LinearIterationStep
<
Matrix
,
Vector
>
;
auto
test
=
[
&
](
Step
*
step
,
std
::
string
name
)
{
auto
solve
=
[
&
](
Step
*
step
,
double
stepTol
,
size_t
maxIterations
)
{
Vector
u_copy
=
p
.
u
;
Vector
u_copy
=
p
.
u
;
Vector
rhs_copy
=
p
.
rhs
;
step
->
setProblem
(
p
.
A
,
u_copy
,
p
.
rhs
);
step
->
ignoreNodes_
=
&
p
.
ignore
;
step
->
setProblem
(
p
.
A
,
u_copy
,
rhs_copy
);
typename
Step
::
BitVector
ignore
(
u_copy
.
size
(),
false
);
step
->
ignoreNodes_
=
&
ignore
;
LoopSolver
solver
(
step
,
maxIterations
,
stepTol
,
LoopSolver
solver
(
step
,
maxIterations
,
stepTol
,
&
p
.
energyNorm
,
verbosity
,
relativeErrors
);
&
p
.
energyNorm
,
verbosity
,
relativeErrors
);
...
@@ -90,7 +52,25 @@ struct GSTestSuite
...
@@ -90,7 +52,25 @@ struct GSTestSuite
solver
.
preprocess
();
solver
.
preprocess
();
solver
.
solve
();
solver
.
solve
();
passed
=
passed
and
analyser
.
analyse
(
u_copy
,
name
);
return
u_copy
;
};
auto
analyse
=
[
&
](
const
Vector
&
v
,
std
::
string
testCase
,
double
tolerance
)
{
const
auto
normDiff
=
p
.
energyNorm
.
diff
(
p
.
u_ex
,
v
);
const
std
::
string
s
=
Dune
::
formatString
(
"%*s"
,
-
60
,
testCase
.
c_str
());
std
::
cout
<<
"error for solver
\"
"
<<
s
<<
"
\"
: "
<<
normDiff
<<
std
::
endl
;
if
(
normDiff
>
tolerance
)
{
std
::
cerr
<<
"Error too large for solver
\"
"
<<
testCase
<<
"
\"
."
<<
std
::
endl
;
return
false
;
}
return
true
;
};
auto
test
=
[
&
](
Step
*
step
,
std
::
string
name
)
{
auto
result
=
solve
(
step
,
1e-12
,
2000
);
passed
=
passed
and
analyse
(
result
,
name
,
1e-7
);
};
};
{
{
...
@@ -98,14 +78,34 @@ struct GSTestSuite
...
@@ -98,14 +78,34 @@ struct GSTestSuite
test
(
&
gsStep
,
"BlockGS"
);
test
(
&
gsStep
,
"BlockGS"
);
}
}
// test regularizable block GS
for
(
auto
reg
:
{
false
,
true
})
{
for
(
auto
type
:
{
"Direct"
,
"LDLt"
,
"CG"
})
{
Dune
::
ParameterTree
config
;
config
[
"type"
]
=
type
;
config
[
"regularize_diagonal"
]
=
reg
?
"1"
:
"0"
;
// for SemiDefiniteBlockGS
config
[
"regularize_diag"
]
=
reg
?
"1e-10"
:
"0.0"
;
// for Dune::Solvers::*BlockGS
config
[
"maxIter"
]
=
"100"
;
// for Dune::Solvers::CGBlockGS
config
[
"tol"
]
=
"1e-10"
;
// for Dune::Solvers::CGBlockGS
{
SemiDefiniteBlockGSStep
<
Matrix
,
Vector
>
gsStep
(
config
);
test
(
&
gsStep
,
Dune
::
formatString
(
"SemiDefiniteBlockGS %s %s"
,
type
,
reg
?
"regularized"
:
""
));
}
}
}
// test projected block GS
{
{
size_t
size
=
p
.
u
.
size
();
size_t
size
=
p
.
u
.
size
();
using
GSStep
=
ProjectedBlockGSStep
<
Matrix
,
Vector
>
;
using
GSStep
=
ProjectedBlockGSStep
<
Matrix
,
Vector
>
;
ProjectedBlockGSStep
<
Matrix
,
Vector
>
gsStep
;
typename
GSStep
::
HasObstacle
hasObstacle
(
size
,
false
);
typename
GSStep
::
HasObstacle
hasObstacle
(
size
,
false
);
gsStep
.
hasObstacle_
=
&
hasObstacle
;
{
test
(
&
gsStep
,
"ProjectedBlockGS w/o obstacle"
);
ProjectedBlockGSStep
<
Matrix
,
Vector
>
gsStep
;
gsStep
.
hasObstacle_
=
&
hasObstacle
;
test
(
&
gsStep
,
"ProjectedBlockGS free"
);
}
hasObstacle
.
setAll
();
hasObstacle
.
setAll
();
std
::
vector
<
typename
GSStep
::
Obstacle
>
obstacles
(
size
);
std
::
vector
<
typename
GSStep
::
Obstacle
>
obstacles
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
...
@@ -115,19 +115,11 @@ struct GSTestSuite
...
@@ -115,19 +115,11 @@ struct GSTestSuite
obstacles
[
i
].
upper
(
j
)
=
j
+
1
;
obstacles
[
i
].
upper
(
j
)
=
j
+
1
;
}
}
}
}
gsStep
.
obstacles_
=
&
obstacles
;
{
test
(
&
gsStep
,
"ProjectedBlockGS w obstacle"
);
ProjectedBlockGSStep
<
Matrix
,
Vector
>
gsStep
;
}
gsStep
.
hasObstacle_
=
&
hasObstacle
;
gsStep
.
obstacles_
=
&
obstacles
;
for
(
auto
reg
:
{
false
,
true
})
{
test
(
&
gsStep
,
"ProjectedBlockGS obstacle"
);
for
(
auto
type
:
{
"direct"
,
"ldlt"
,
"cg"
})
{
Dune
::
ParameterTree
config
;
config
[
"type"
]
=
type
;
config
[
"regularize_diagonal"
]
=
reg
?
"1"
:
"0"
;
SemiDefiniteBlockGSStep
<
Matrix
,
Vector
>
gsStep
(
config
);
test
(
&
gsStep
,
Dune
::
formatString
(
"SemiDefiniteBlockGS %s %s"
,
type
,
reg
?
"regularized"
:
""
));
}
}
}
}
...
...
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