Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
dumux-repositories
dumux
Commits
92fc1411
Commit
92fc1411
authored
5 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[test] Add test computing l2 error of projection
parent
343b3c1a
No related branches found
No related tags found
1 merge request
!1636
Feature/l2 norm
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/common/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/common/CMakeLists.txt
test/common/functions/CMakeLists.txt
+3
-0
3 additions, 0 deletions
test/common/functions/CMakeLists.txt
test/common/functions/test_function_l2norm.cc
+80
-0
80 additions, 0 deletions
test/common/functions/test_function_l2norm.cc
with
84 additions
and
0 deletions
test/common/CMakeLists.txt
+
1
−
0
View file @
92fc1411
add_subdirectory
(
boundingboxtree
)
add_subdirectory
(
functions
)
add_subdirectory
(
geometry
)
add_subdirectory
(
math
)
add_subdirectory
(
parameters
)
...
...
This diff is collapsed.
Click to expand it.
test/common/functions/CMakeLists.txt
0 → 100644
+
3
−
0
View file @
92fc1411
dune_add_test
(
SOURCES test_function_l2norm.cc
CMAKE_GUARD dune-functions_FOUND
LABELS unit
)
This diff is collapsed.
Click to expand it.
test/common/functions/test_function_l2norm.cc
0 → 100644
+
80
−
0
View file @
92fc1411
#include
<config.h>
#include
<dune/common/fvector.hh>
#include
<dune/istl/bvector.hh>
#include
<dune/functions/functionspacebases/interpolate.hh>
#include
<dune/functions/functionspacebases/lagrangebasis.hh>
#include
<dune/functions/gridfunctions/analyticgridviewfunction.hh>
#include
<dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
#include
<dumux/common/parameters.hh>
#include
<dumux/common/integrate.hh>
#include
<dumux/multidomain/glue.hh>
#include
<dumux/discretization/projection/projector.hh>
#include
<dumux/discretization/fem/fegridgeometry.hh>
#include
<dumux/io/grid/gridmanager_yasp.hh>
int
main
(
int
argc
,
char
*
argv
[])
try
{
// maybe initialize mpi
Dune
::
MPIHelper
::
instance
(
argc
,
argv
);
// initialize parameters
Dumux
::
Parameters
::
init
([](
auto
&
p
){
p
[
"Grid.UpperRight"
]
=
"1 1"
;
p
[
"Coarse.Grid.Cells"
]
=
"10 10"
;
p
[
"Fine.Grid.Cells"
]
=
"33 33"
;
});
// initialize a grid
using
Grid
=
Dune
::
YaspGrid
<
2
>
;
Dumux
::
GridManager
<
Grid
>
gridManagerCoarse
,
gridManagerFine
;
gridManagerCoarse
.
init
(
"Coarse"
);
gridManagerFine
.
init
(
"Fine"
);
const
auto
gvFine
=
gridManagerFine
.
grid
().
leafGridView
();
const
auto
gvCoarse
=
gridManagerCoarse
.
grid
().
leafGridView
();
// a quadratic function on the grid
auto
f
=
[](
const
auto
&
pos
){
return
pos
.
two_norm2
();
};
// make discrete functions
using
R
=
Dune
::
FieldVector
<
double
,
1
>
;
using
SolutionVector
=
Dune
::
BlockVector
<
R
>
;
using
GridView
=
Grid
::
LeafGridView
;
using
namespace
Dune
::
Functions
;
using
P2
=
LagrangeBasis
<
GridView
,
2
>
;
auto
basisCoarse
=
std
::
make_shared
<
P2
>
(
gvCoarse
),
basisFine
=
std
::
make_shared
<
P2
>
(
gvFine
);
SolutionVector
solCoarse
,
solFine
;
interpolate
(
*
basisCoarse
,
solCoarse
,
f
);
interpolate
(
*
basisFine
,
solFine
,
f
);
auto
gfCoarse
=
makeDiscreteGlobalBasisFunction
<
R
>
(
*
basisCoarse
,
solCoarse
);
auto
gfFine
=
makeDiscreteGlobalBasisFunction
<
R
>
(
*
basisFine
,
solFine
);
// project fine discrete function onto coarse grid
Dumux
::
FEGridGeometry
<
P2
>
ggCoarse
(
basisCoarse
),
ggFine
(
basisFine
);
const
auto
projector
=
Dumux
::
makeProjector
(
*
basisFine
,
*
basisCoarse
,
makeGlue
(
ggFine
,
ggCoarse
));
SolutionVector
solCoarse2
;
projector
.
project
(
solFine
,
solCoarse2
);
auto
gfCoarse2
=
makeDiscreteGlobalBasisFunction
<
R
>
(
*
basisCoarse
,
solCoarse
);
// check that these functions are identical and that they exactly represent the analytical function
auto
l2norm
=
Dumux
::
integrateL2Error
(
gvCoarse
,
gfCoarse
,
gfCoarse2
,
3
);
if
(
l2norm
>
1e-14
)
DUNE_THROW
(
Dune
::
MathError
,
"L2 norm of projection and interpolation is non-zero!"
);
l2norm
=
Dumux
::
integrateL2Error
(
gvCoarse
,
makeAnalyticGridViewFunction
(
f
,
gvCoarse
),
gfCoarse2
,
3
);
if
(
l2norm
>
1e-14
)
DUNE_THROW
(
Dune
::
MathError
,
"L2 norm of analytical solution and interpolation is non-zero!"
);
std
::
cout
<<
"All tests passed!"
<<
std
::
endl
;
return
0
;
}
// //////////////////////////////////
// Error handler
// /////////////////////////////////
catch
(
const
Dune
::
Exception
&
e
)
{
std
::
cout
<<
e
<<
std
::
endl
;
return
1
;
}
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