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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hörl, Maximilian
dune-mmdg
Commits
3d89cd18
Commit
3d89cd18
authored
5 years ago
by
Hörl, Maximilian
Browse files
Options
Downloads
Patches
Plain Diff
add python script for convergence test
parent
a279a843
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/CMakeLists.txt
+2
-1
2 additions, 1 deletion
src/CMakeLists.txt
src/convergenceTest.py
+111
-0
111 additions, 0 deletions
src/convergenceTest.py
src/dg.cc
+19
-2
19 additions, 2 deletions
src/dg.cc
src/mmdg.cc
+5
-0
5 additions, 0 deletions
src/mmdg.cc
with
137 additions
and
3 deletions
src/CMakeLists.txt
+
2
−
1
View file @
3d89cd18
...
@@ -14,4 +14,5 @@ add_executable("mmdg-2d" mmdg.cc)
...
@@ -14,4 +14,5 @@ add_executable("mmdg-2d" mmdg.cc)
target_compile_definitions
(
"mmdg-2d"
PRIVATE GRIDDIM=2
)
target_compile_definitions
(
"mmdg-2d"
PRIVATE GRIDDIM=2
)
target_link_dune_default_libraries
(
"mmdg-2d"
)
target_link_dune_default_libraries
(
"mmdg-2d"
)
dune_symlink_to_source_files
(
FILES grids parameterMMDG.ini parameterDG.ini
)
dune_symlink_to_source_files
(
FILES grids parameterMMDG.ini parameterDG.ini
convergenceTest.py
)
This diff is collapsed.
Click to expand it.
src/convergenceTest.py
0 → 100644
+
111
−
0
View file @
3d89cd18
import
numpy
as
np
from
os.path
import
join
,
exists
from
subprocess
import
call
from
math
import
log
# writes a dgf file for a grid with N elements per directions and dimension dim
def
writeDGF
(
N
,
dim
):
# open dgf file
file
=
open
(
join
(
"
grids
"
,
"
cube
"
+
str
(
dim
)
+
"
d.dgf
"
),
"
w
"
)
file
.
write
(
"
DGF
\n\n
Interval
\n
"
)
# write lower left corner
for
i
in
range
(
0
,
dim
):
file
.
write
(
str
(
0
)
+
"
\t
"
)
file
.
write
(
"
\n
"
)
# write upper right corner
for
i
in
range
(
0
,
dim
):
file
.
write
(
str
(
1
)
+
"
\t
"
)
file
.
write
(
"
\n
"
)
# write number of grid elements
for
i
in
range
(
0
,
dim
):
file
.
write
(
str
(
N
)
+
"
\t
"
)
file
.
write
(
"
\n
#
\n\n
Simplex
\n
#
"
)
# close dgf file
file
.
close
()
# reads error, run time and number of elements, i.e. the output from the
# excuted discontinuous Galerkin scheme
def
readData
():
file
=
open
(
"
convergenceData
"
,
"
r
"
)
# read data
error
=
float
(
file
.
readline
())
timeTotal
=
float
(
file
.
readline
())
numberOfElements
=
float
(
file
.
readline
())
file
.
close
()
# return data
return
np
.
array
([
error
,
timeTotal
,
numberOfElements
])
# === main ===
# create directory for the plots if necessary
if
not
exists
(
"
plots
"
):
os
.
mkdir
(
"
plots
"
)
# number of runs from which the run times are taken as mean value
numberOfMeans
=
3
# numbers of grid elements per direction
numElemsPerDir
=
[
1
,
5
,
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
,
90
,
100
]
dimensions
=
[
1
,
2
]
for
dim
in
dimensions
:
# storage for errors, run times and largestEdgeLength
# column 0: error
# column 1: total run time
# column 2: largest edge length
# different rows correspond to different numbers of grid elements
data
=
np
.
zeros
((
len
(
numElemsPerDir
),
3
))
for
i
in
range
(
len
(
numElemsPerDir
)):
# write dgf file
writeDGF
(
numElemsPerDir
[
i
],
dim
)
# take mean value over numberOfMeans runs
for
j
in
range
(
numberOfMeans
):
# run executable
call
(
join
(
"
.
"
,
"
dg-
"
+
str
(
dim
)
+
"
d
"
))
# store data
data
[
i
,
:]
+=
readData
()
# end for j
# end for i
# divide by numberOfMeans
data
/=
numberOfMeans
# determine experimental order of convergence (EOC)
EOC
=
np
.
empty
(
len
(
numElemsPerDir
)
-
1
)
for
i
in
range
(
len
(
numElemsPerDir
)
-
1
):
if
data
[
i
,
0
]
!=
0
:
EOC
[
i
]
=
log
(
data
[
i
,
0
]
/
data
[
i
+
1
,
0
])
/
\
log
(
data
[
i
+
1
,
2
]
/
data
[
i
,
2
])
else
:
EOC
[
i
]
=
-
1.0
*
float
(
'
inf
'
)
# end for i
print
(
"
\n\n
-------------------------------------------------------------
\n
"
)
# print EOCs
print
(
"
EOCs (
"
+
str
(
dim
)
+
"
d):
\t
"
)
print
(
EOC
)
print
(
"
\n\n
"
)
# write data to file
np
.
savetxt
(
join
(
"
plots
"
,
"
dgAnalysis_
"
+
str
(
dim
)
+
"
d
"
),
data
)
np
.
savetxt
(
join
(
"
plots
"
,
"
dgEOC_
"
+
str
(
dim
)
+
"
d
"
),
EOC
)
# end for dim
# remove output files
os
.
remove
(
"
convergenceData
"
)
This diff is collapsed.
Click to expand it.
src/dg.cc
+
19
−
2
View file @
3d89cd18
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include
<sys/stat.h>
#include
<sys/stat.h>
#include
<sys/types.h>
#include
<sys/types.h>
#include
<type_traits>
#include
<type_traits>
#include
<iostream>
#include
<dune/common/exceptions.hh>
#include
<dune/common/exceptions.hh>
#include
<dune/common/parametertree.hh>
#include
<dune/common/parametertree.hh>
...
@@ -87,10 +88,26 @@ int main(int argc, char** argv)
...
@@ -87,10 +88,26 @@ int main(int argc, char** argv)
dg
(
mu
);
dg
(
mu
);
//print total run time
//error and total run time
const
double
error
=
dg
.
computeL2error
();
const
double
timeTotal
=
ClockHelper
::
elapsedRuntime
(
timeInitial
);
const
double
timeTotal
=
ClockHelper
::
elapsedRuntime
(
timeInitial
);
//write error, runtime and number of grid elements to file
std
::
ofstream
errorFile
(
"convergenceData"
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
if
(
errorFile
.
is_open
())
{
errorFile
<<
error
<<
"
\n
"
<<
timeTotal
<<
"
\n
"
<<
gridView
.
size
(
0
);
errorFile
.
close
();
}
else
{
std
::
cout
<<
"Unable to write error data to file.
\n
"
;
}
//print total run time and error
std
::
cout
<<
"Finished with a total run time of "
<<
timeTotal
<<
std
::
cout
<<
"Finished with a total run time of "
<<
timeTotal
<<
" Seconds.
\n
L2-error: "
<<
dg
.
computeL2
error
()
<<
".
\n
"
;
" Seconds.
\n
L2-error: "
<<
error
<<
".
\n
"
;
return
0
;
return
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/mmdg.cc
+
5
−
0
View file @
3d89cd18
...
@@ -76,6 +76,11 @@ int main(int argc, char** argv)
...
@@ -76,6 +76,11 @@ int main(int argc, char** argv)
"parameterDG.ini (use 'mmdg2' or TODO)"
);
"parameterDG.ini (use 'mmdg2' or TODO)"
);
}
}
if
(
pt
.
hasKey
(
"gridfile"
))
//non-default grid type
{
gridType
=
pt
[
"gridfile"
];
}
//create a grid from .dgf file
//create a grid from .dgf file
GridFactory
gridFactory
(
"grids/"
+
gridType
+
".msh"
);
GridFactory
gridFactory
(
"grids/"
+
gridType
+
".msh"
);
const
Grid
&
grid
=
*
gridFactory
.
grid
();
const
Grid
&
grid
=
*
gridFactory
.
grid
();
...
...
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