Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dune-mmdg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hörl, Maximilian
dune-mmdg
Commits
b8ab3fdf
Commit
b8ab3fdf
authored
Mar 19, 2020
by
Hörl, Maximilian
Browse files
Options
Downloads
Patches
Plain Diff
add method to compute L2 error, bugfix for boundary terms
parent
ce573fe9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/mmdg/dg.hh
+55
-14
55 additions, 14 deletions
dune/mmdg/dg.hh
with
55 additions
and
14 deletions
dune/mmdg/dg.hh
+
55
−
14
View file @
b8ab3fdf
...
@@ -19,12 +19,13 @@
...
@@ -19,12 +19,13 @@
template
<
class
Grid
,
class
GridView
,
class
Mapper
,
class
Problem
>
template
<
class
Grid
,
class
GridView
,
class
Mapper
,
class
Problem
>
class
DG
class
DG
{
//TODO: Ordnung (private / public)
{
public:
public:
//using GridView = typename Grid::LeafGridView;
//using Mapper = typename Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
using
Scalar
=
typename
GridView
::
ctype
;
static
constexpr
int
dim
=
GridView
::
dimension
;
static
constexpr
int
dim
=
GridView
::
dimension
;
static
constexpr
auto
simplex
=
Dune
::
GeometryTypes
::
simplex
(
dim
);
static
constexpr
auto
edge
=
Dune
::
GeometryTypes
::
simplex
(
dim
-
1
);
using
Scalar
=
typename
GridView
::
ctype
;
using
Matrix
=
Dune
::
BCRSMatrix
<
Dune
::
FieldMatrix
<
Scalar
,
1
,
1
>>
;
using
Matrix
=
Dune
::
BCRSMatrix
<
Dune
::
FieldMatrix
<
Scalar
,
1
,
1
>>
;
using
Vector
=
Dune
::
BlockVector
<
Dune
::
FieldVector
<
Scalar
,
1
>>
;
using
Vector
=
Dune
::
BlockVector
<
Dune
::
FieldVector
<
Scalar
,
1
>>
;
using
VTKFunction
=
Dune
::
VTKFunction
<
GridView
>
;
using
VTKFunction
=
Dune
::
VTKFunction
<
GridView
>
;
...
@@ -34,8 +35,6 @@ public:
...
@@ -34,8 +35,6 @@ public:
using
QRulesElem
=
Dune
::
QuadratureRules
<
Scalar
,
dim
>
;
using
QRulesElem
=
Dune
::
QuadratureRules
<
Scalar
,
dim
>
;
using
QRuleEdge
=
Dune
::
QuadratureRule
<
Scalar
,
dim
-
1
>
;
using
QRuleEdge
=
Dune
::
QuadratureRule
<
Scalar
,
dim
-
1
>
;
using
QRulesEdge
=
Dune
::
QuadratureRules
<
Scalar
,
dim
-
1
>
;
using
QRulesEdge
=
Dune
::
QuadratureRules
<
Scalar
,
dim
-
1
>
;
static
constexpr
auto
simplex
=
Dune
::
GeometryTypes
::
simplex
(
dim
);
static
constexpr
auto
edge
=
Dune
::
GeometryTypes
::
simplex
(
dim
-
1
);
//constructor
//constructor
DG
(
const
Grid
&
grid
,
const
GridView
&
gridView
,
const
Mapper
&
mapper
,
const
Problem
&
problem
)
:
DG
(
const
Grid
&
grid
,
const
GridView
&
gridView
,
const
Mapper
&
mapper
,
const
Problem
&
problem
)
:
...
@@ -50,7 +49,7 @@ public:
...
@@ -50,7 +49,7 @@ public:
d
=
Vector
(
dof_
);
d
=
Vector
(
dof_
);
}
}
const
void
operator
()
(
const
Scalar
mu
)
void
operator
()
(
const
Scalar
mu
)
{
{
//assemble stiffness matrix A and load vector b
//assemble stiffness matrix A and load vector b
assembleSLE
(
mu
);
assembleSLE
(
mu
);
...
@@ -64,6 +63,48 @@ public:
...
@@ -64,6 +63,48 @@ public:
writeVTKoutput
();
writeVTKoutput
();
}
}
Scalar
computeL2error
(
const
int
quadratureOrder
=
5
)
const
{
if
(
!
problem_
.
hasExactSolution
())
{
DUNE_THROW
(
Dune
::
Exception
,
"ERROR: Problem has no exact solution or "
"exact solution is not implemented"
);
}
Scalar
error
(
0.0
);
for
(
const
auto
&
elem
:
elements
(
gridView_
))
{
const
int
elemIdxSLE
=
(
dim
+
1
)
*
mapper_
.
index
(
elem
);
const
auto
&
geo
=
elem
.
geometry
();
const
QRuleElem
&
qrule
=
QRulesElem
::
rule
(
simplex
,
quadratureOrder
);
//determine L2-error on element elem using a quadrature rule
for
(
const
auto
&
ip
:
qrule
)
{
const
auto
&
qpLocal
=
ip
.
position
();
const
auto
&
qpGlobal
=
geo
.
global
(
qpLocal
);
const
Scalar
quadratureFactor
=
ip
.
weight
()
*
geo
.
integrationElement
(
qpLocal
);
Scalar
numericalSolutionAtQP
=
d
[
elemIdxSLE
];
for
(
int
i
=
0
;
i
<
dim
;
i
++
)
{
numericalSolutionAtQP
+=
d
[
elemIdxSLE
+
i
+
1
]
*
qpGlobal
[
i
];
}
const
Scalar
errorEvaluation
=
numericalSolutionAtQP
-
problem_
.
exactSolution
(
qpGlobal
);
error
+=
quadratureFactor
*
errorEvaluation
*
errorEvaluation
;
}
}
return
std
::
sqrt
(
error
);
}
const
Grid
&
grid_
;
const
Grid
&
grid_
;
const
GridView
&
gridView_
;
const
GridView
&
gridView_
;
const
Mapper
&
mapper_
;
//element mapper for gridView_
const
Mapper
&
mapper_
;
//element mapper for gridView_
...
@@ -388,15 +429,15 @@ protected:
...
@@ -388,15 +429,15 @@ protected:
const
auto
&
qpLocal
=
ip
.
position
();
const
auto
&
qpLocal
=
ip
.
position
();
const
auto
&
qpGlobal
=
intersctGeo
.
global
(
qpLocal
);
const
auto
&
qpGlobal
=
intersctGeo
.
global
(
qpLocal
);
const
Scalar
weight
(
ip
.
weight
());
const
Scalar
quadratureFactor
=
const
S
cal
ar
ip
.
weight
()
*
intersctGeo
.
integrationElement
(
qpLo
cal
);
integrationElem
(
intersctGeo
.
integrationElement
(
qpLocal
));
const
Scalar
boundaryEvaluation
(
problem_
.
boundary
(
qpGlobal
));
const
Scalar
boundaryEvaluation
(
problem_
.
boundary
(
qpGlobal
));
const
Dune
::
FieldMatrix
<
Scalar
,
dim
,
dim
>
KEvaluation
=
const
Dune
::
FieldMatrix
<
Scalar
,
dim
,
dim
>
KEvaluation
=
problem_
.
K
(
qpGlobal
);
problem_
.
K
(
qpGlobal
);
//quadrature for int_intersct mu * g * phi_elem,0 ds
//quadrature for int_intersct mu * g * phi_elem,0 ds
b
[
elemIdxSLE
]
+=
weight
*
integrationElem
*
mu
*
boundaryEvaluation
;
b
[
elemIdxSLE
]
+=
quadratureFactor
*
mu
*
boundaryEvaluation
;
//quadrature for
//quadrature for
// int_intersct (mu * phi_elem,i - K[:,i] * normal) * g ds
// int_intersct (mu * phi_elem,i - K[:,i] * normal) * g ds
...
@@ -404,7 +445,7 @@ protected:
...
@@ -404,7 +445,7 @@ protected:
for
(
int
i
=
0
;
i
<
dim
;
i
++
)
for
(
int
i
=
0
;
i
<
dim
;
i
++
)
{
{
b
[
elemIdxSLE
+
i
+
1
]
+=
b
[
elemIdxSLE
+
i
+
1
]
+=
weight
*
integrationElem
*
(
mu
*
qpGlobal
[
i
]
-
quadratureFactor
*
(
mu
*
qpGlobal
[
i
]
-
(
KEvaluation
[
i
]
*
normal
))
*
boundaryEvaluation
;
(
KEvaluation
[
i
]
*
normal
))
*
boundaryEvaluation
;
}
}
}
}
...
@@ -417,7 +458,7 @@ protected:
...
@@ -417,7 +458,7 @@ protected:
// int_intersct phi_elem,0 * K*grad(phi_elem,i) * normal ds
// int_intersct phi_elem,0 * K*grad(phi_elem,i) * normal ds
//with K*grad(phi_elem,i) = K[:,i]
//with K*grad(phi_elem,i) = K[:,i]
A
->
entry
(
elemIdxSLE
+
i
+
1
,
elemIdxSLE
)
+=
A
->
entry
(
elemIdxSLE
+
i
+
1
,
elemIdxSLE
)
+=
mu
*
linearIntegrals
[
i
]
-
0.5
*
KIntegrals
[
i
];
mu
*
linearIntegrals
[
i
]
-
KIntegrals
[
i
];
for
(
int
j
=
0
;
j
<=
i
;
j
++
)
for
(
int
j
=
0
;
j
<=
i
;
j
++
)
{
{
...
@@ -429,7 +470,7 @@ protected:
...
@@ -429,7 +470,7 @@ protected:
//with K*grad(phi_elem,i) = K[:,i]
//with K*grad(phi_elem,i) = K[:,i]
A
->
entry
(
elemIdxSLE
+
i
+
1
,
elemIdxSLE
+
j
+
1
)
+=
A
->
entry
(
elemIdxSLE
+
i
+
1
,
elemIdxSLE
+
j
+
1
)
+=
mu
*
quadraticIntregrals
[
i
][
j
]
mu
*
quadraticIntregrals
[
i
][
j
]
-
0.5
*
(
KIntegralsX
[
i
][
j
]
+
KIntegralsX
[
j
][
i
]
);
-
(
KIntegralsX
[
i
][
j
]
+
KIntegralsX
[
j
][
i
]
);
}
}
}
}
}
}
...
...
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