Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
7d282888
Commit
7d282888
authored
Aug 19, 2021
by
Dennis Gläser
Committed by
Martin Schneider
Sep 07, 2021
Browse files
[tests][md][ffpm][conv] improve script
parent
d74c3f21
Changes
2
Hide whitespace changes
Inline
Side-by-side
test/multidomain/boundary/stokesdarcy/1p_1p/convergencetest/CMakeLists.txt
View file @
7d282888
...
...
@@ -13,9 +13,10 @@ dune_add_test(NAME test_md_boundary_darcy1ptpfa_stokes1p_convtest
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1ptpfa_freeflow1p_convtest params.input
-Problem.TestCase ShiueExampleTwo
-Darcy.SpatialParams.Permeability 1.0
)
CMD_ARGS -e test_md_boundary_darcy1ptpfa_freeflow1p_convtest
-i params.input
-c ShiueExampleTwo
-Darcy.SpatialParams.Permeability 1.0
)
dune_add_test
(
NAME test_md_boundary_darcy1ptpfa_navierstokes1p_convtest
TARGET test_md_boundary_darcy1ptpfa_freeflow1p_convtest
...
...
@@ -23,10 +24,11 @@ dune_add_test(NAME test_md_boundary_darcy1ptpfa_navierstokes1p_convtest
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1ptpfa_freeflow1p_convtest params.input
-Problem.TestCase Schneider
-FreeFlow.Problem.EnableInertiaTerms true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForBeaversJoseph true
)
CMD_ARGS -e test_md_boundary_darcy1ptpfa_freeflow1p_convtest
-i params.input
-c Schneider
-FreeFlow.Problem.EnableInertiaTerms true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForBeaversJoseph true
)
dune_add_test
(
NAME test_md_boundary_darcy1pbox_stokes1p_convtest
TARGET test_md_boundary_darcy1pbox_freeflow1p_convtest
...
...
@@ -34,9 +36,10 @@ dune_add_test(NAME test_md_boundary_darcy1pbox_stokes1p_convtest
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1pbox_freeflow1p_convtest params.input
-Problem.TestCase ShiueExampleTwo
-Darcy.SpatialParams.Permeability 1.0
)
CMD_ARGS -e test_md_boundary_darcy1pbox_freeflow1p_convtest
-i params.input
-c ShiueExampleTwo
-Darcy.SpatialParams.Permeability 1.0
)
dune_add_test
(
NAME test_md_boundary_darcy1pbox_navierstokes1p_convtest
TARGET test_md_boundary_darcy1pbox_freeflow1p_convtest
...
...
@@ -44,10 +47,11 @@ dune_add_test(NAME test_md_boundary_darcy1pbox_navierstokes1p_convtest
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1pbox_freeflow1p_convtest params.input
-Problem.TestCase Schneider
-FreeFlow.Problem.EnableInertiaTerms true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForBeaversJoseph true
)
CMD_ARGS -e test_md_boundary_darcy1pbox_freeflow1p_convtest
-i params.input
-c Schneider
-FreeFlow.Problem.EnableInertiaTerms true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForBeaversJoseph true
)
dune_add_test
(
NAME test_md_boundary_darcy1pbox_stokes1p_convtest_bj
TARGET test_md_boundary_darcy1pbox_freeflow1p_convtest
...
...
@@ -55,12 +59,13 @@ dune_add_test(NAME test_md_boundary_darcy1pbox_stokes1p_convtest_bj
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1pbox_freeflow1p_convtest params.input
-Problem.TestCase Cao
-Problem.SlipCondition BJ
-Darcy.SpatialParams.AlphaBeaversJoseph -1
-Darcy.SpatialParams.Porosity 1.0
-Darcy.SpatialParams.Permeability
"1.0 1.0 0.0"
)
CMD_ARGS -e test_md_boundary_darcy1pbox_freeflow1p_convtest
-i params.input
-c Cao
-Problem.SlipCondition BJ
-Darcy.SpatialParams.Permeability
"1.0 1.0 0.0"
-Darcy.SpatialParams.AlphaBeaversJoseph -1
-Darcy.SpatialParams.Porosity 1.0
)
dune_add_test
(
NAME test_md_boundary_darcy1p_stokes1p_newic
TARGET test_md_boundary_darcy1pbox_freeflow1p_convtest
...
...
@@ -68,16 +73,17 @@ dune_add_test(NAME test_md_boundary_darcy1p_stokes1p_newic
TIMEOUT 1000
CMAKE_GUARD HAVE_UMFPACK
COMMAND ./convergencetest.py
CMD_ARGS test_md_boundary_darcy1pbox_freeflow1p_convtest params.input
-Problem.TestCase NewICNonSymmetrized
-Problem.SlipCondition ER
-Problem.NewIc true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForIC true
-FreeFlow.EnableUnsymmetrizedVelocityGradient true
-Darcy.InterfaceParams.EpsInterface 1.0
-Darcy.InterfaceParams.N_s_bl 0.5
-Darcy.InterfaceParams.N_1_bl -3.0
-Darcy.InterfaceParams.M_bl
"1.0 1.0"
-Darcy.SpatialParams.Porosity 1.0
-Darcy.SpatialParams.Permeability
"1.0 1.0 0.0"
-Component.LiquidKinematicViscosity 2.0
)
\ No newline at end of file
CMD_ARGS -e test_md_boundary_darcy1pbox_freeflow1p_convtest
-i params.input
-c NewICNonSymmetrized
-Problem.SlipCondition ER
-Problem.NewIc true
-FreeFlow.EnableUnsymmetrizedVelocityGradientForIC true
-FreeFlow.EnableUnsymmetrizedVelocityGradient true
-Darcy.SpatialParams.Permeability
"1.0 1.0 0.0"
-Darcy.InterfaceParams.EpsInterface 1.0
-Darcy.InterfaceParams.N_s_bl 0.5
-Darcy.InterfaceParams.N_1_bl -3.0
-Darcy.InterfaceParams.M_bl
"1.0 1.0"
-Darcy.SpatialParams.Porosity 1.0
-Component.LiquidKinematicViscosity 2.0
)
test/multidomain/boundary/stokesdarcy/1p_1p/convergencetest/convergencetest.py
View file @
7d282888
#!/usr/bin/env python3
from
math
import
*
from
statistics
import
mean
from
math
import
log
,
isnan
,
isinf
from
argparse
import
ArgumentParser
import
subprocess
import
sys
if
len
(
sys
.
argv
)
<
2
:
sys
.
stderr
.
write
(
'Please provide a single argument <testname> to the script
\n
'
)
sys
.
exit
(
1
)
executableName
=
str
(
sys
.
argv
[
1
])
testargs
=
[
str
(
i
)
for
i
in
sys
.
argv
][
2
:]
testname
=
testargs
[
testargs
.
index
(
'-Problem.TestCase'
)
+
1
]
# remove the old log files
subprocess
.
call
([
'rm'
,
testname
+
'_freeFlow.log'
])
print
(
"Removed old log file ({})!"
.
format
(
testname
+
'_freeFlow.log'
))
subprocess
.
call
([
'rm'
,
testname
+
'_darcy.log'
])
print
(
"Removed old log file ({})!"
.
format
(
testname
+
'_darcy.log'
))
# do the runs with different refinement
for
i
in
[
0
,
1
,
2
]:
subprocess
.
call
([
'./'
+
executableName
]
+
testargs
+
[
'-Grid.Refinement'
,
str
(
i
)])
def
checkRatesFreeFlow
():
# check the rates and append them to the log file
logfile
=
open
(
testname
+
'_freeFlow.log'
,
"r+"
)
errorP
=
[]
errorVx
=
[]
errorVy
=
[]
for
line
in
logfile
:
line
=
line
.
strip
(
"
\n
"
)
line
=
line
.
strip
(
"\[ConvergenceTest\]"
)
line
=
line
.
split
()
errorP
.
append
(
float
(
line
[
2
]))
errorVx
.
append
(
float
(
line
[
5
]))
errorVy
.
append
(
float
(
line
[
8
]))
resultsP
=
[]
resultsVx
=
[]
resultsVy
=
[]
logfile
.
truncate
(
0
)
logfile
.
write
(
"n
\t
errorP
\t\t
rateP
\t\t
errorVx
\t\t
rateVx
\t\t
errorVy
\t\t
rateVy
\n
"
)
logfile
.
write
(
"-"
*
50
+
"
\n
"
)
for
i
in
range
(
len
(
errorP
)
-
1
):
if
isnan
(
errorP
[
i
])
or
isinf
(
errorP
[
i
]):
continue
if
not
((
errorP
[
i
]
<
1e-12
or
errorP
[
i
+
1
]
<
1e-12
)
and
(
errorVx
[
i
]
<
1e-12
or
errorVx
[
i
+
1
]
<
1e-12
)
and
(
errorVy
[
i
]
<
1e-12
or
errorVy
[
i
+
1
]
<
1e-12
)):
rateP
=
(
log
(
errorP
[
i
])
-
log
(
errorP
[
i
+
1
]))
/
log
(
2
)
rateVx
=
(
log
(
errorVx
[
i
])
-
log
(
errorVx
[
i
+
1
]))
/
log
(
2
)
rateVy
=
(
log
(
errorVy
[
i
])
-
log
(
errorVy
[
i
+
1
]))
/
log
(
2
)
message
=
"{}
\t
{:0.4e}
\t
{:0.4e}
\t
{:0.4e}
\t
{:0.4e}
\t
{:0.4e}
\t
{:0.4e}
\n
"
.
format
(
i
,
errorP
[
i
],
rateP
,
errorVx
[
i
],
rateVx
,
errorVy
[
i
],
rateVy
)
logfile
.
write
(
message
)
resultsP
.
append
(
rateP
)
resultsVx
.
append
(
rateVx
)
resultsVy
.
append
(
rateVy
)
else
:
logfile
.
write
(
"error: exact solution!?"
)
i
=
len
(
errorP
)
-
1
message
=
"{}
\t
{:0.4e}
\t\t
{}
\t
{:0.4e}
\t\t
{}
\t
{:0.4e}
\t\t
{}
\n
"
.
format
(
i
,
errorP
[
i
],
""
,
errorVx
[
i
],
""
,
errorVy
[
i
],
""
)
logfile
.
write
(
message
)
logfile
.
close
()
print
(
"
\n
Computed the following convergence rates for {}:
\n
"
.
format
(
testname
))
subprocess
.
call
([
'cat'
,
testname
+
'_freeFlow.log'
])
return
{
"p"
:
resultsP
,
"v_x"
:
resultsVx
,
"v_y"
:
resultsVy
}
def
checkRatesDarcy
():
# check the rates and append them to the log file
logfile
=
open
(
testname
+
'_darcy.log'
,
"r+"
)
errorP
=
[]
for
line
in
logfile
:
line
=
line
.
strip
(
"
\n
"
)
line
=
line
.
strip
(
"\[ConvergenceTest\]"
)
line
=
line
.
split
()
errorP
.
append
(
float
(
line
[
2
]))
resultsP
=
[]
logfile
.
truncate
(
0
)
logfile
.
write
(
"n
\t
errorP
\t\t
rateP
\n
"
)
logfile
.
write
(
"-"
*
50
+
"
\n
"
)
for
i
in
range
(
len
(
errorP
)
-
1
):
if
isnan
(
errorP
[
i
])
or
isinf
(
errorP
[
i
]):
continue
if
not
((
errorP
[
i
]
<
1e-12
or
errorP
[
i
+
1
]
<
1e-12
)):
rateP
=
(
log
(
errorP
[
i
])
-
log
(
errorP
[
i
+
1
]))
/
log
(
2
)
message
=
"{}
\t
{:0.4e}
\t
{:0.4e}
\n
"
.
format
(
i
,
errorP
[
i
],
rateP
)
logfile
.
write
(
message
)
resultsP
.
append
(
rateP
)
else
:
logfile
.
write
(
"error: exact solution!?"
)
i
=
len
(
errorP
)
-
1
message
=
"{}
\t
{:0.4e}
\n
"
.
format
(
i
,
errorP
[
i
],
""
)
logfile
.
write
(
message
)
logfile
.
close
()
print
(
"
\n
Computed the following convergence rates for {}:
\n
"
.
format
(
testname
))
subprocess
.
call
([
'cat'
,
testname
+
'_darcy.log'
])
return
{
"p"
:
resultsP
}
def
checkRatesFreeFlowAndDarcy
():
resultsFreeFlow
=
checkRatesFreeFlow
()
resultsDarcy
=
checkRatesDarcy
()
def
mean
(
numbers
):
return
float
(
sum
(
numbers
))
/
len
(
numbers
)
# check the rates, we expect rates around 2
if
mean
(
resultsFreeFlow
[
"p"
])
<
2.05
and
mean
(
resultsFreeFlow
[
"p"
])
<
1.84
:
sys
.
stderr
.
write
(
"*"
*
70
+
"
\n
"
+
"The convergence rates for pressure were not close enough to 2! Test failed.
\n
"
+
"*"
*
70
+
"
\n
"
)
sys
.
exit
(
1
)
if
mean
(
resultsFreeFlow
[
"v_x"
])
<
2.05
and
mean
(
resultsFreeFlow
[
"v_x"
])
<
1.95
:
sys
.
stderr
.
write
(
"*"
*
70
+
"
\n
"
+
"The convergence rates for x-velocity were not close enough to 2! Test failed.
\n
"
+
"*"
*
70
+
"
\n
"
)
sys
.
exit
(
1
)
if
mean
(
resultsFreeFlow
[
"v_y"
])
<
2.05
and
mean
(
resultsFreeFlow
[
"v_y"
])
<
1.95
:
sys
.
stderr
.
write
(
"*"
*
70
+
"
\n
"
+
"The convergence rates for y-velocity were not close enough to 2! Test failed.
\n
"
+
"*"
*
70
+
"
\n
"
)
sys
.
exit
(
1
)
if
mean
(
resultsDarcy
[
"p"
])
<
2.05
and
mean
(
resultsDarcy
[
"p"
])
<
1.95
:
sys
.
stderr
.
write
(
"*"
*
70
+
"
\n
"
+
"The convergence rates for pressure were not close enough to 2! Test failed.
\n
"
+
"*"
*
70
+
"
\n
"
)
sys
.
exit
(
1
)
checkRatesFreeFlowAndDarcy
()
class
Test
:
def
__init__
(
self
,
args
):
self
.
args
=
args
self
.
darcySuffix
=
'darcy'
self
.
freeFlowSuffix
=
'freeFlow'
self
.
numRefinements
=
2
def
run
(
self
):
self
.
_removeLogFile
(
self
.
darcySuffix
)
self
.
_removeLogFile
(
self
.
freeFlowSuffix
)
self
.
_compile
()
for
i
in
range
(
0
,
self
.
numRefinements
+
1
):
self
.
_runDumux
(
i
)
darcyLog
=
self
.
_getLogFileName
(
self
.
darcySuffix
)
freeFlowLog
=
self
.
_getLogFileName
(
self
.
freeFlowSuffix
)
errorsDarcy
=
self
.
_collectErrors
(
darcyLog
)
ratesDarcy
=
self
.
_collectRates
(
errorsDarcy
)
errorsFreeFlow
=
self
.
_collectErrors
(
freeFlowLog
)
ratesFreeFlow
=
self
.
_collectRates
(
errorsFreeFlow
)
self
.
_checkMeanRates
(
ratesDarcy
,
ratesFreeFlow
)
def
_checkMeanRates
(
self
,
ratesDarcy
,
ratesFreeFlow
):
def
checkRate
(
rates
,
key
,
expected
):
m
=
mean
(
rates
[
key
])
if
m
<
expected
:
raise
Exception
(
'Rate {} is below expected value {}: {}'
.
format
(
key
,
expected
,
m
))
else
:
print
(
'Test for "{}" successful: '
'computed vs expected rate {:.3f}/{:.3f}'
.
format
(
key
,
m
,
expected
)
)
expectedP
=
float
(
self
.
args
[
'expectedpressurerate'
])
expectedV
=
float
(
self
.
args
[
'expectedvelocityrate'
])
checkRate
(
ratesDarcy
,
'p_rate'
,
expectedP
)
checkRate
(
ratesFreeFlow
,
'p_rate'
,
expectedP
)
checkRate
(
ratesFreeFlow
,
'vx_rate'
,
expectedV
)
checkRate
(
ratesFreeFlow
,
'vy_rate'
,
expectedV
)
def
_compile
(
self
):
subprocess
.
run
([
'make'
,
self
.
args
[
'exe'
]],
check
=
True
)
def
_runDumux
(
self
,
refIdx
):
command
=
[
'./{}'
.
format
(
self
.
args
[
'exe'
]),
self
.
args
[
'inputfile'
],
'-Problem.TestCase'
,
self
.
args
[
'case'
],
'-Grid.Refinement'
,
str
(
refIdx
)
]
if
args
[
'dumux_args'
]:
command
.
extend
(
args
[
'dumux_args'
])
subprocess
.
run
(
command
,
check
=
True
)
def
_getLogFileName
(
self
,
suffix
):
return
self
.
args
[
'case'
]
+
'_'
+
suffix
+
'.log'
def
_removeLogFile
(
self
,
suffix
):
logFileName
=
self
.
_getLogFileName
(
suffix
)
subprocess
.
run
([
'rm'
,
'-f'
,
logFileName
],
check
=
True
)
print
(
"Removed old log file ({})!"
.
format
(
logFileName
))
def
_collectErrors
(
self
,
logFileName
):
result
=
{}
with
open
(
logFileName
,
'r'
)
as
logFile
:
for
line
in
logFile
:
line
=
line
.
strip
(
r
'[ConvergenceTest]'
)
errors
=
line
.
split
(
'L2('
)
errors
=
filter
(
lambda
e
:
'='
in
e
,
errors
)
errors
=
[
err
.
split
(
'='
)
for
err
in
errors
]
for
name
,
val
in
errors
:
name
=
name
.
strip
().
strip
(
')'
)
val
=
val
.
strip
()
if
name
not
in
result
:
result
[
name
]
=
[]
result
[
name
].
append
(
float
(
val
))
return
result
def
_collectRates
(
self
,
errors
):
rates
=
{}
for
name
,
errValues
in
errors
.
items
():
for
i
in
range
(
len
(
errValues
)
-
1
):
if
isnan
(
errValues
[
i
])
or
isinf
(
errValues
[
i
]):
continue
if
not
(
(
errValues
[
i
]
<
1e-12
or
errValues
[
i
+
1
]
<
1e-12
)
and
(
errValues
[
i
]
<
1e-12
or
errValues
[
i
+
1
]
<
1e-12
)
and
(
errValues
[
i
]
<
1e-12
or
errValues
[
i
+
1
]
<
1e-12
)
):
rate
=
(
log
(
errValues
[
i
])
-
log
(
errValues
[
i
+
1
]))
/
log
(
2
)
key
=
name
+
'_rate'
if
key
not
in
rates
:
rates
[
key
]
=
[]
rates
[
key
].
append
(
rate
)
else
:
raise
Exception
(
"Error: exact solution!?"
)
return
rates
if
__name__
==
'__main__'
:
parser
=
ArgumentParser
()
parser
.
add_argument
(
'-e'
,
'--exe'
,
required
=
True
)
parser
.
add_argument
(
'-c'
,
'--case'
,
required
=
True
)
parser
.
add_argument
(
'-rp'
,
'--expectedpressurerate'
,
default
=
'1.75'
)
parser
.
add_argument
(
'-rv'
,
'--expectedvelocityrate'
,
default
=
'1.75'
)
parser
.
add_argument
(
'-i'
,
'--inputfile'
,
default
=
'params.input'
)
args
,
unknown
=
parser
.
parse_known_args
()
args
=
vars
(
args
)
args
[
'dumux_args'
]
=
unknown
Test
(
args
).
run
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment