Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hysop
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
particle_methods
hysop
Commits
4c5faf36
Commit
4c5faf36
authored
5 years ago
by
EXT Jean-Matthieu Etancelin
Browse files
Options
Downloads
Patches
Plain Diff
update some tests (for ctest)
parent
67e1108f
No related branches found
No related tags found
1 merge request
!16
MPI operators
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hysop/operator/tests/test_spectral_curl.py
+99
-86
99 additions, 86 deletions
hysop/operator/tests/test_spectral_curl.py
hysop/operator/tests/test_spectral_derivative.py
+10
-0
10 additions, 0 deletions
hysop/operator/tests/test_spectral_derivative.py
with
109 additions
and
86 deletions
hysop/operator/tests/test_spectral_curl.py
+
99
−
86
View file @
4c5faf36
import
random
,
primefac
import
random
import
primefac
from
hysop.deps
import
it
,
sm
,
random
from
hysop.deps
import
it
,
sm
,
random
from
hysop.constants
import
HYSOP_REAL
,
BoxBoundaryCondition
from
hysop.constants
import
HYSOP_REAL
,
BoxBoundaryCondition
from
hysop.defaults
import
VelocityField
,
VorticityField
from
hysop.defaults
import
VelocityField
,
VorticityField
...
@@ -11,18 +12,19 @@ from hysop.tools.io_utils import IO
...
@@ -11,18 +12,19 @@ from hysop.tools.io_utils import IO
from
hysop.tools.numpywrappers
import
npw
from
hysop.tools.numpywrappers
import
npw
from
hysop.tools.sympy_utils
import
truncate_expr
,
round_expr
from
hysop.tools.sympy_utils
import
truncate_expr
,
round_expr
from
hysop.tools.spectral_utils
import
make_multivariate_trigonometric_polynomial
,
\
from
hysop.tools.spectral_utils
import
make_multivariate_trigonometric_polynomial
,
\
make_multivariate_polynomial
make_multivariate_polynomial
from
hysop.operator.curl
import
SpectralCurl
,
Implementation
from
hysop.operator.curl
import
SpectralCurl
,
Implementation
from
hysop.defaults
import
VorticityField
,
VelocityField
from
hysop.defaults
import
VorticityField
,
VelocityField
from
hysop
import
Field
,
Box
from
hysop
import
Field
,
Box
class
TestSpectralCurl
(
object
):
class
TestSpectralCurl
(
object
):
@classmethod
@classmethod
def
setup_class
(
cls
,
def
setup_class
(
cls
,
enable_extra_tests
=
__ENABLE_LONG_TESTS__
,
enable_extra_tests
=
__ENABLE_LONG_TESTS__
,
enable_debug_mode
=
False
):
enable_debug_mode
=
False
):
IO
.
set_default_path
(
'
/tmp/hysop_tests/test_spectral_curl
'
)
IO
.
set_default_path
(
'
/tmp/hysop_tests/test_spectral_curl
'
)
...
@@ -30,53 +32,52 @@ class TestSpectralCurl(object):
...
@@ -30,53 +32,52 @@ class TestSpectralCurl(object):
cls
.
size_max
=
16
cls
.
size_max
=
16
cls
.
enable_extra_tests
=
enable_extra_tests
cls
.
enable_extra_tests
=
enable_extra_tests
cls
.
enable_debug_mode
=
enable_debug_mode
cls
.
enable_debug_mode
=
enable_debug_mode
from
hysop.tools.sympy_utils
import
enable_pretty_printing
from
hysop.tools.sympy_utils
import
enable_pretty_printing
enable_pretty_printing
()
enable_pretty_printing
()
@classmethod
@classmethod
def
teardown_class
(
cls
):
def
teardown_class
(
cls
):
pass
pass
@classmethod
@classmethod
def
build_analytic_solutions
(
cls
,
polynomial
,
def
build_analytic_solutions
(
cls
,
polynomial
,
dim
,
nb_components
,
dim
,
nb_components
,
lboundaries
,
rboundaries
,
lboundaries
,
rboundaries
,
origin
,
end
):
origin
,
end
):
from
hysop.symbolic.base
import
TensorBase
from
hysop.symbolic.base
import
TensorBase
from
hysop.symbolic.frame
import
SymbolicFrame
from
hysop.symbolic.frame
import
SymbolicFrame
from
hysop.symbolic.field
import
laplacian
,
curl
from
hysop.symbolic.field
import
laplacian
,
curl
assert
len
(
lboundaries
)
==
nb_components
assert
len
(
lboundaries
)
==
nb_components
assert
len
(
rboundaries
)
==
nb_components
assert
len
(
rboundaries
)
==
nb_components
frame
=
SymbolicFrame
(
dim
=
dim
)
frame
=
SymbolicFrame
(
dim
=
dim
)
coords
=
frame
.
coords
coords
=
frame
.
coords
def
gen_Fin
():
def
gen_Fin
():
Fins
=
()
Fins
=
()
for
i
in
xrange
(
nb_components
):
for
i
in
xrange
(
nb_components
):
if
polynomial
:
if
polynomial
:
fin
,
y
=
make_multivariate_polynomial
(
origin
,
end
,
fin
,
y
=
make_multivariate_polynomial
(
origin
,
end
,
lboundaries
[
i
],
rboundaries
[
i
],
lboundaries
[
i
],
rboundaries
[
i
],
10
,
4
)
10
,
4
)
else
:
else
:
fin
,
y
=
make_multivariate_trigonometric_polynomial
(
origin
,
end
,
fin
,
y
=
make_multivariate_trigonometric_polynomial
(
origin
,
end
,
lboundaries
[
i
],
rboundaries
[
i
],
2
)
lboundaries
[
i
],
rboundaries
[
i
],
2
)
fin
=
fin
.
xreplace
({
yi
:
xi
for
(
yi
,
xi
)
in
zip
(
y
,
coords
)})
fin
=
fin
.
xreplace
({
yi
:
xi
for
(
yi
,
xi
)
in
zip
(
y
,
coords
)})
Fins
+=
(
fin
,)
Fins
+=
(
fin
,)
return
npw
.
asarray
(
Fins
).
view
(
TensorBase
)
return
npw
.
asarray
(
Fins
).
view
(
TensorBase
)
Fins
=
gen_Fin
()
Fins
=
gen_Fin
()
Fouts
=
npw
.
atleast_1d
(
curl
(
Fins
,
frame
))
Fouts
=
npw
.
atleast_1d
(
curl
(
Fins
,
frame
))
fFins
=
tuple
(
sm
.
lambdify
(
coords
,
Fin
)
for
Fin
in
Fins
)
fFins
=
tuple
(
sm
.
lambdify
(
coords
,
Fin
)
for
Fin
in
Fins
)
fFouts
=
tuple
(
sm
.
lambdify
(
coords
,
Fout
)
for
Fout
in
Fouts
)
fFouts
=
tuple
(
sm
.
lambdify
(
coords
,
Fout
)
for
Fout
in
Fouts
)
analytic_expressions
=
{
'
Fin
'
:
Fins
,
'
Fout
'
:
Fouts
}
analytic_expressions
=
{
'
Fin
'
:
Fins
,
'
Fout
'
:
Fouts
}
analytic_functions
=
{
'
Fin
'
:
fFins
,
'
Fout
'
:
fFouts
}
analytic_functions
=
{
'
Fin
'
:
fFins
,
'
Fout
'
:
fFouts
}
return
(
analytic_expressions
,
analytic_functions
)
return
(
analytic_expressions
,
analytic_functions
)
@staticmethod
@staticmethod
...
@@ -93,20 +94,20 @@ class TestSpectralCurl(object):
...
@@ -93,20 +94,20 @@ class TestSpectralCurl(object):
data
[...]
=
npw
.
asarray
(
fn
(
*
coords
)).
astype
(
dtype
)
data
[...]
=
npw
.
asarray
(
fn
(
*
coords
)).
astype
(
dtype
)
def
_test
(
self
,
dim
,
dtype
,
nb_components
,
max_runs
=
5
,
def
_test
(
self
,
dim
,
dtype
,
nb_components
,
max_runs
=
5
,
polynomial
=
False
,
size_min
=
None
,
size_max
=
None
):
polynomial
=
False
,
size_min
=
None
,
size_max
=
None
):
enable_extra_tests
=
self
.
enable_extra_tests
enable_extra_tests
=
self
.
enable_extra_tests
size_min
=
first_not_None
(
size_min
,
self
.
size_min
)
size_min
=
first_not_None
(
size_min
,
self
.
size_min
)
size_max
=
first_not_None
(
size_max
,
self
.
size_max
)
size_max
=
first_not_None
(
size_max
,
self
.
size_max
)
valid_factors
=
{
2
,
3
,
5
,
7
,
11
,
13
}
valid_factors
=
{
2
,
3
,
5
,
7
,
11
,
13
}
factors
=
{
1
}
factors
=
{
1
}
while
(
factors
-
valid_factors
):
while
(
factors
-
valid_factors
):
factors
.
clear
()
factors
.
clear
()
shape
=
tuple
(
npw
.
random
.
randint
(
low
=
size_min
,
high
=
size_max
+
1
,
size
=
dim
).
tolist
())
shape
=
tuple
(
npw
.
random
.
randint
(
low
=
size_min
,
high
=
size_max
+
1
,
size
=
dim
).
tolist
())
for
Si
in
shape
:
for
Si
in
shape
:
factors
.
update
(
set
(
primefac
.
primefac
(
int
(
Si
)))
)
factors
.
update
(
set
(
primefac
.
primefac
(
int
(
Si
))))
domain_boundaries
=
list
(
domain_boundary_iterator
(
dim
=
dim
))
domain_boundaries
=
list
(
domain_boundary_iterator
(
dim
=
dim
))
periodic
=
domain_boundaries
[
0
]
periodic
=
domain_boundaries
[
0
]
domain_boundaries
=
domain_boundaries
[
1
:]
domain_boundaries
=
domain_boundaries
[
1
:]
...
@@ -114,51 +115,53 @@ class TestSpectralCurl(object):
...
@@ -114,51 +115,53 @@ class TestSpectralCurl(object):
domain_boundaries
.
insert
(
0
,
periodic
)
domain_boundaries
.
insert
(
0
,
periodic
)
for
i
,
(
lboundaries
,
rboundaries
)
in
enumerate
(
domain_boundaries
,
1
):
for
i
,
(
lboundaries
,
rboundaries
)
in
enumerate
(
domain_boundaries
,
1
):
domain
=
Box
(
origin
=
(
npw
.
random
.
rand
(
dim
)
-
0.5
),
domain
=
Box
(
origin
=
(
npw
.
random
.
rand
(
dim
)
-
0.5
),
length
=
(
0.5
+
npw
.
random
.
rand
(
dim
)
*
2
*
npw
.
pi
),
length
=
(
0.5
+
npw
.
random
.
rand
(
dim
)
*
2
*
npw
.
pi
),
lboundaries
=
lboundaries
,
lboundaries
=
lboundaries
,
rboundaries
=
rboundaries
)
rboundaries
=
rboundaries
)
if
(
dim
==
nb_components
):
if
(
dim
==
nb_components
):
Fin
=
VelocityField
(
name
=
'
Fin
'
,
domain
=
domain
)
Fin
=
VelocityField
(
name
=
'
Fin
'
,
domain
=
domain
)
Fout
=
VorticityField
(
name
=
'
Fout
'
,
velocity
=
Fin
)
Fout
=
VorticityField
(
name
=
'
Fout
'
,
velocity
=
Fin
)
else
:
else
:
Fin
=
Field
(
name
=
'
Fin
'
,
domain
=
domain
,
dtype
=
dtype
,
nb_components
=
nb_components
)
Fin
=
Field
(
name
=
'
Fin
'
,
domain
=
domain
,
dtype
=
dtype
,
nb_components
=
nb_components
)
Fout
=
Fin
.
curl
(
name
=
'
Fout
'
)
Fout
=
Fin
.
curl
(
name
=
'
Fout
'
)
self
.
_test_one
(
shape
=
shape
,
dim
=
dim
,
dtype
=
dtype
,
self
.
_test_one
(
shape
=
shape
,
dim
=
dim
,
dtype
=
dtype
,
domain
=
domain
,
Fin
=
Fin
,
Fout
=
Fout
,
polynomial
=
polynomial
)
domain
=
domain
,
Fin
=
Fin
,
Fout
=
Fout
,
polynomial
=
polynomial
)
if
(
max_runs
is
not
None
)
and
(
i
==
max_runs
):
if
(
max_runs
is
not
None
)
and
(
i
==
max_runs
):
missing
=
((
4
**
(
dim
+
1
)
-
1
)
/
3
)
-
i
missing
=
((
4
**
(
dim
+
1
)
-
1
)
/
3
)
-
i
print
print
print
'
>> MAX RUNS ACHIEVED FOR {}D DOMAINS -- SKIPING {} OTHER BOUNDARY CONDITIONS <<
'
.
format
(
dim
,
missing
)
print
'
>> MAX RUNS ACHIEVED FOR {}D DOMAINS -- SKIPING {} OTHER BOUNDARY CONDITIONS <<
'
.
format
(
dim
,
missing
)
print
print
print
print
break
break
else
:
else
:
assert
(
i
==
(
4
**
(
dim
+
1
)
-
1
)
/
3
),
(
i
+
1
,
(
4
**
(
dim
+
1
)
-
1
)
/
3
)
assert
(
i
==
(
4
**
(
dim
+
1
)
-
1
)
/
3
),
(
i
+
1
,
(
4
**
(
dim
+
1
)
-
1
)
/
3
)
print
print
print
'
>> TESTED ALL {}D BOUNDARY CONDITIONS <<
'
.
format
(
dim
)
print
'
>> TESTED ALL {}D BOUNDARY CONDITIONS <<
'
.
format
(
dim
)
print
print
print
print
def
_test_one
(
self
,
shape
,
dim
,
dtype
,
def
_test_one
(
self
,
shape
,
dim
,
dtype
,
domain
,
Fout
,
Fin
,
polynomial
):
domain
,
Fout
,
Fin
,
polynomial
):
(
analytic_expressions
,
analytic_functions
)
=
\
(
analytic_expressions
,
analytic_functions
)
=
\
self
.
build_analytic_solutions
(
self
.
build_analytic_solutions
(
dim
=
dim
,
nb_components
=
Fin
.
nb_components
,
polynomial
=
polynomial
,
dim
=
dim
,
nb_components
=
Fin
.
nb_components
,
polynomial
=
polynomial
,
lboundaries
=
[
fin
.
lboundaries
[::
-
1
]
for
fin
in
Fin
.
fields
],
# => boundaries in variable order x0,...,xn
lboundaries
=
[
fin
.
lboundaries
[::
-
1
]
for
fin
in
Fin
.
fields
],
# => boundaries in variable order x0,...,xn
rboundaries
=
[
fin
.
rboundaries
[::
-
1
]
for
fin
in
Fin
.
fields
],
rboundaries
=
[
fin
.
rboundaries
[::
-
1
]
for
fin
in
Fin
.
fields
],
origin
=
domain
.
origin
[::
-
1
],
origin
=
domain
.
origin
[::
-
1
],
end
=
domain
.
end
[::
-
1
])
end
=
domain
.
end
[::
-
1
])
def
format_expr
(
e
):
def
format_expr
(
e
):
return
truncate_expr
(
round_expr
(
e
,
3
),
80
)
return
truncate_expr
(
round_expr
(
e
,
3
),
80
)
msg
=
'
\n
Testing {}D Curl: dtype={} shape={} polynomial={}, bc=[{}]
'
.
format
(
msg
=
'
\n
Testing {}D Curl: dtype={} shape={} polynomial={}, bc=[{}]
'
.
format
(
dim
,
dtype
.
__name__
,
shape
,
polynomial
,
domain
.
format_boundaries
())
dim
,
dtype
.
__name__
,
shape
,
polynomial
,
domain
.
format_boundaries
())
print
msg
print
msg
print
'
>Input analytic field is (truncated):
'
print
'
>Input analytic field is (truncated):
'
for
(
fin
,
fins
)
in
zip
(
Fin
.
fields
,
analytic_expressions
[
'
Fin
'
]):
for
(
fin
,
fins
)
in
zip
(
Fin
.
fields
,
analytic_expressions
[
'
Fin
'
]):
...
@@ -169,55 +172,55 @@ class TestSpectralCurl(object):
...
@@ -169,55 +172,55 @@ class TestSpectralCurl(object):
print
'
>Testing all implementations:
'
print
'
>Testing all implementations:
'
implementations
=
SpectralCurl
.
implementations
().
keys
()
implementations
=
SpectralCurl
.
implementations
().
keys
()
variables
=
{
Fout
:
shape
,
Fin
:
shape
}
variables
=
{
Fout
:
shape
,
Fin
:
shape
}
def
iter_impl
(
impl
):
def
iter_impl
(
impl
):
base_kwds
=
dict
(
Fin
=
Fin
,
Fout
=
Fout
,
variables
=
variables
,
base_kwds
=
dict
(
Fin
=
Fin
,
Fout
=
Fout
,
variables
=
variables
,
implementation
=
impl
,
implementation
=
impl
,
name
=
'
curl_{}
'
.
format
(
str
(
impl
).
lower
()))
name
=
'
curl_{}
'
.
format
(
str
(
impl
).
lower
()))
if
impl
is
Implementation
.
PYTHON
:
if
impl
is
Implementation
.
PYTHON
:
msg
=
'
*Python FFTW:
'
msg
=
'
*Python FFTW:
'
print
msg
,
print
msg
,
yield
SpectralCurl
(
**
base_kwds
)
yield
SpectralCurl
(
**
base_kwds
)
elif
impl
is
Implementation
.
OPENCL
:
elif
impl
is
Implementation
.
OPENCL
:
msg
=
'
*OpenCl CLFFT:
'
msg
=
'
*OpenCl CLFFT:
'
print
msg
print
msg
for
cl_env
in
iter_clenv
():
for
cl_env
in
iter_clenv
():
msg
=
'
|platform {}, device {}
'
.
format
(
cl_env
.
platform
.
name
.
strip
(),
msg
=
'
|platform {}, device {}
'
.
format
(
cl_env
.
platform
.
name
.
strip
(),
cl_env
.
device
.
name
.
strip
())
cl_env
.
device
.
name
.
strip
())
print
msg
,
print
msg
,
yield
SpectralCurl
(
cl_env
=
cl_env
,
**
base_kwds
)
yield
SpectralCurl
(
cl_env
=
cl_env
,
**
base_kwds
)
else
:
else
:
msg
=
'
Unknown implementation to test {}.
'
.
format
(
impl
)
msg
=
'
Unknown implementation to test {}.
'
.
format
(
impl
)
raise
NotImplementedError
(
msg
)
raise
NotImplementedError
(
msg
)
# Compare to analytic solution
# Compare to analytic solution
Fout_ref
=
None
Fout_ref
=
None
Fin_ref
=
None
Fin_ref
=
None
for
impl
in
implementations
:
for
impl
in
implementations
:
for
(
i
,
op
)
in
enumerate
(
iter_impl
(
impl
)):
for
(
i
,
op
)
in
enumerate
(
iter_impl
(
impl
)):
from
hysop.tools.debug_dumper
import
DebugDumper
from
hysop.tools.debug_dumper
import
DebugDumper
name
=
'
{}_{}
'
.
format
(
impl
,
i
)
name
=
'
{}_{}
'
.
format
(
impl
,
i
)
op
=
op
.
build
()
op
=
op
.
build
()
dFin
=
op
.
get_input_discrete_field
(
Fin
).
as_contiguous_dfield
()
dFin
=
op
.
get_input_discrete_field
(
Fin
).
as_contiguous_dfield
()
dFout
=
op
.
get_output_discrete_field
(
Fout
).
as_contiguous_dfield
()
dFout
=
op
.
get_output_discrete_field
(
Fout
).
as_contiguous_dfield
()
dFin
.
initialize
(
self
.
__analytic_init
,
dtype
=
dtype
,
dFin
.
initialize
(
self
.
__analytic_init
,
dtype
=
dtype
,
fns
=
analytic_functions
[
'
Fin
'
])
fns
=
analytic_functions
[
'
Fin
'
])
if
(
Fout_ref
is
None
):
if
(
Fout_ref
is
None
):
dFout
.
initialize
(
self
.
__analytic_init
,
dtype
=
dtype
,
dFout
.
initialize
(
self
.
__analytic_init
,
dtype
=
dtype
,
fns
=
analytic_functions
[
'
Fout
'
])
fns
=
analytic_functions
[
'
Fout
'
])
Fin_ref
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFin
.
data
)
Fin_ref
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFin
.
data
)
Fout_ref
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFout
.
data
)
Fout_ref
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFout
.
data
)
dFout
.
initialize
(
self
.
__random_init
,
dtype
=
dtype
)
dFout
.
initialize
(
self
.
__random_init
,
dtype
=
dtype
)
op
.
apply
(
simulation
=
None
)
op
.
apply
(
simulation
=
None
)
Wout
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFin
.
data
)
Wout
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFin
.
data
)
Uout
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFout
.
data
)
Uout
=
tuple
(
data
.
get
().
handle
.
copy
()
for
data
in
dFout
.
data
)
self
.
_check_output
(
impl
,
op
,
Fin_ref
,
Fout_ref
,
Wout
,
Uout
)
self
.
_check_output
(
impl
,
op
,
Fin_ref
,
Fout_ref
,
Wout
,
Uout
)
print
print
...
@@ -229,9 +232,9 @@ class TestSpectralCurl(object):
...
@@ -229,9 +232,9 @@ class TestSpectralCurl(object):
check_instance
(
Uout
,
tuple
,
values
=
npw
.
ndarray
,
size
=
len
(
Fout_ref
))
check_instance
(
Uout
,
tuple
,
values
=
npw
.
ndarray
,
size
=
len
(
Fout_ref
))
msg0
=
'
Reference field {} is not finite.
'
msg0
=
'
Reference field {} is not finite.
'
for
(
fields
,
name
)
in
zip
((
Fin_ref
,
Fout_ref
),(
'
Fin_ref
'
,
'
Fout_ref
'
)):
for
(
fields
,
name
)
in
zip
((
Fin_ref
,
Fout_ref
),
(
'
Fin_ref
'
,
'
Fout_ref
'
)):
for
(
i
,
field
)
in
enumerate
(
fields
):
for
(
i
,
field
)
in
enumerate
(
fields
):
iname
=
'
{}{}
'
.
format
(
name
,
i
)
iname
=
'
{}{}
'
.
format
(
name
,
i
)
mask
=
npw
.
isfinite
(
field
)
mask
=
npw
.
isfinite
(
field
)
if
not
mask
.
all
():
if
not
mask
.
all
():
print
print
...
@@ -243,8 +246,8 @@ class TestSpectralCurl(object):
...
@@ -243,8 +246,8 @@ class TestSpectralCurl(object):
raise
ValueError
(
msg
)
raise
ValueError
(
msg
)
for
(
out_buffers
,
ref_buffers
,
name
)
in
zip
((
Wout
,
Uout
),
(
Fin_ref
,
Fout_ref
),
(
'
Fin
'
,
'
Fout
'
)):
for
(
out_buffers
,
ref_buffers
,
name
)
in
zip
((
Wout
,
Uout
),
(
Fin_ref
,
Fout_ref
),
(
'
Fin
'
,
'
Fout
'
)):
for
i
,
(
fout
,
fref
)
in
enumerate
(
zip
(
out_buffers
,
ref_buffers
)):
for
i
,
(
fout
,
fref
)
in
enumerate
(
zip
(
out_buffers
,
ref_buffers
)):
iname
=
'
{}{}
'
.
format
(
name
,
i
)
iname
=
'
{}{}
'
.
format
(
name
,
i
)
assert
fout
.
dtype
==
fref
.
dtype
,
iname
assert
fout
.
dtype
==
fref
.
dtype
,
iname
assert
fout
.
shape
==
fref
.
shape
,
iname
assert
fout
.
shape
==
fref
.
shape
,
iname
assert
not
npw
.
any
(
npw
.
isnan
(
fref
))
assert
not
npw
.
any
(
npw
.
isnan
(
fref
))
...
@@ -257,7 +260,7 @@ class TestSpectralCurl(object):
...
@@ -257,7 +260,7 @@ class TestSpectralCurl(object):
elif
has_inf
:
elif
has_inf
:
deps
=
'
inf
'
deps
=
'
inf
'
else
:
else
:
eps
=
npw
.
finfo
(
fout
.
dtype
).
eps
eps
=
npw
.
finfo
(
fout
.
dtype
).
eps
dist
=
npw
.
abs
(
fout
-
fref
)
dist
=
npw
.
abs
(
fout
-
fref
)
dinf
=
npw
.
max
(
dist
)
dinf
=
npw
.
max
(
dist
)
try
:
try
:
...
@@ -277,26 +280,26 @@ class TestSpectralCurl(object):
...
@@ -277,26 +280,26 @@ class TestSpectralCurl(object):
print
print
if
cls
.
enable_debug_mode
:
if
cls
.
enable_debug_mode
:
print
'
REFERENCE INPUTS:
'
print
'
REFERENCE INPUTS:
'
for
(
i
,
w
)
in
enumerate
(
Fin_ref
):
for
(
i
,
w
)
in
enumerate
(
Fin_ref
):
print
'
Fin{}
'
.
format
(
i
)
print
'
Fin{}
'
.
format
(
i
)
print
w
print
w
print
print
if
(
name
==
'
Fout
'
):
if
(
name
==
'
Fout
'
):
print
'
REFERENCE OUTPUT:
'
print
'
REFERENCE OUTPUT:
'
for
(
i
,
u
)
in
enumerate
(
Fout_ref
):
for
(
i
,
u
)
in
enumerate
(
Fout_ref
):
print
'
Fout{}
'
.
format
(
i
)
print
'
Fout{}
'
.
format
(
i
)
print
u
print
u
print
print
print
print
print
'
OPERATOR {} OUTPUT:
'
.
format
(
op
.
name
.
upper
())
print
'
OPERATOR {} OUTPUT:
'
.
format
(
op
.
name
.
upper
())
print
print
for
(
i
,
u
)
in
enumerate
(
Uout
):
for
(
i
,
u
)
in
enumerate
(
Uout
):
print
'
Fout{}
'
.
format
(
i
)
print
'
Fout{}
'
.
format
(
i
)
print
u
print
u
print
print
else
:
else
:
print
'
MODIFIED INPUTS:
'
print
'
MODIFIED INPUTS:
'
for
(
i
,
w
)
in
enumerate
(
Wout
):
for
(
i
,
w
)
in
enumerate
(
Wout
):
print
'
Fin{}
'
.
format
(
i
)
print
'
Fin{}
'
.
format
(
i
)
print
w
print
w
print
print
...
@@ -306,34 +309,44 @@ class TestSpectralCurl(object):
...
@@ -306,34 +309,44 @@ class TestSpectralCurl(object):
msg
=
msg
.
format
(
name
,
i
,
impl
)
msg
=
msg
.
format
(
name
,
i
,
impl
)
raise
RuntimeError
(
msg
)
raise
RuntimeError
(
msg
)
def
test_2d_float32__1
(
self
,
**
kwds
):
def
test_2d_float32__1
(
self
,
**
kwds
):
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
nb_components
=
1
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float32
:
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
nb_components
=
1
,
**
kwds
)
def
test_2d_float32__2
(
self
,
**
kwds
):
def
test_2d_float32__2
(
self
,
**
kwds
):
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
nb_components
=
2
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float32
:
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
nb_components
=
2
,
**
kwds
)
def
test_3d_float32
(
self
,
**
kwds
):
def
test_3d_float32
(
self
,
**
kwds
):
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
nb_components
=
3
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float32
:
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
nb_components
=
3
,
**
kwds
)
def
test_2d_float64__1
(
self
,
**
kwds
):
def
test_2d_float64__1
(
self
,
**
kwds
):
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
nb_components
=
1
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float64
:
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
nb_components
=
1
,
**
kwds
)
def
test_2d_float64__2
(
self
,
**
kwds
):
def
test_2d_float64__2
(
self
,
**
kwds
):
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
nb_components
=
2
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float64
:
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
nb_components
=
2
,
**
kwds
)
def
test_3d_float64
(
self
,
**
kwds
):
def
test_3d_float64
(
self
,
**
kwds
):
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float64
,
nb_components
=
3
,
**
kwds
)
if
HYSOP_REAL
==
npw
.
float64
:
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float64
,
nb_components
=
3
,
**
kwds
)
def
perform_tests
(
self
):
def
perform_tests
(
self
):
max_2d_runs
=
None
if
__ENABLE_LONG_TESTS__
else
2
max_2d_runs
=
None
if
__ENABLE_LONG_TESTS__
else
2
max_3d_runs
=
None
if
__ENABLE_LONG_TESTS__
else
2
max_3d_runs
=
None
if
__ENABLE_LONG_TESTS__
else
2
if
__ENABLE_LONG_TESTS__
or
(
HYSOP_REAL
==
npw
.
float32
):
if
__ENABLE_LONG_TESTS__
or
(
HYSOP_REAL
==
npw
.
float32
):
self
.
test_2d_float32__1
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float32__1
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float32__2
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float32__2
(
max_runs
=
max_2d_runs
)
self
.
test_3d_float32
(
max_runs
=
max_3d_runs
)
self
.
test_3d_float32
(
max_runs
=
max_3d_runs
)
if
__ENABLE_LONG_TESTS__
or
(
HYSOP_REAL
==
npw
.
float64
):
if
__ENABLE_LONG_TESTS__
or
(
HYSOP_REAL
==
npw
.
float64
):
self
.
test_2d_float64__1
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float64__1
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float64__2
(
max_runs
=
max_2d_runs
)
self
.
test_2d_float64__2
(
max_runs
=
max_2d_runs
)
self
.
test_3d_float64
(
max_runs
=
max_3d_runs
)
self
.
test_3d_float64
(
max_runs
=
max_3d_runs
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
TestSpectralCurl
.
setup_class
(
enable_extra_tests
=
False
,
TestSpectralCurl
.
setup_class
(
enable_extra_tests
=
False
,
enable_debug_mode
=
False
)
enable_debug_mode
=
False
)
...
...
This diff is collapsed.
Click to expand it.
hysop/operator/tests/test_spectral_derivative.py
+
10
−
0
View file @
4c5faf36
...
@@ -322,22 +322,28 @@ class TestSpectralDerivative(object):
...
@@ -322,22 +322,28 @@ class TestSpectralDerivative(object):
raise
RuntimeError
(
msg
)
raise
RuntimeError
(
msg
)
def
test_1d_trigonometric_float32
(
self
,
**
kwds
):
def
test_1d_trigonometric_float32
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
3
})
self
.
_test
(
dim
=
1
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
1
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
def
test_2d_trigonometric_float32
(
self
,
**
kwds
):
def
test_2d_trigonometric_float32
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
1
,
'
max_runs
'
:
None
})
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
def
test_3d_trigonometric_float32
(
self
,
**
kwds
):
def
test_3d_trigonometric_float32
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
1
,
'
max_runs
'
:
5
})
if
__ENABLE_LONG_TESTS__
:
if
__ENABLE_LONG_TESTS__
:
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
polynomial
=
False
,
**
kwds
)
def
test_1d_trigonometric_float64
(
self
,
**
kwds
):
def
test_1d_trigonometric_float64
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
3
})
self
.
_test
(
dim
=
1
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
1
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
def
test_2d_trigonometric_float64
(
self
,
**
kwds
):
def
test_2d_trigonometric_float64
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
1
,
'
max_runs
'
:
None
})
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
def
test_3d_trigonometric_float64
(
self
,
**
kwds
):
def
test_3d_trigonometric_float64
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
1
,
'
max_runs
'
:
5
})
if
__ENABLE_LONG_TESTS__
:
if
__ENABLE_LONG_TESTS__
:
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float64
,
polynomial
=
False
,
**
kwds
)
...
@@ -348,6 +354,7 @@ class TestSpectralDerivative(object):
...
@@ -348,6 +354,7 @@ class TestSpectralDerivative(object):
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
polynomial
=
True
,
**
kwds
)
self
.
_test
(
dim
=
2
,
dtype
=
npw
.
float32
,
polynomial
=
True
,
**
kwds
)
def
test_3d_polynomial_float32
(
self
,
**
kwds
):
def
test_3d_polynomial_float32
(
self
,
**
kwds
):
kwds
.
update
({
'
max_derivative
'
:
1
})
if
__ENABLE_LONG_TESTS__
:
if
__ENABLE_LONG_TESTS__
:
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
polynomial
=
True
,
**
kwds
)
self
.
_test
(
dim
=
3
,
dtype
=
npw
.
float32
,
polynomial
=
True
,
**
kwds
)
...
@@ -355,6 +362,9 @@ class TestSpectralDerivative(object):
...
@@ -355,6 +362,9 @@ class TestSpectralDerivative(object):
self
.
test_1d_trigonometric_float32
(
max_derivative
=
3
)
self
.
test_1d_trigonometric_float32
(
max_derivative
=
3
)
self
.
test_2d_trigonometric_float32
(
max_derivative
=
1
,
max_runs
=
None
)
self
.
test_2d_trigonometric_float32
(
max_derivative
=
1
,
max_runs
=
None
)
self
.
test_3d_trigonometric_float32
(
max_derivative
=
1
,
max_runs
=
5
)
self
.
test_3d_trigonometric_float32
(
max_derivative
=
1
,
max_runs
=
5
)
self
.
test_1d_trigonometric_float64
(
max_derivative
=
3
)
self
.
test_2d_trigonometric_float64
(
max_derivative
=
1
,
max_runs
=
None
)
self
.
test_3d_trigonometric_float64
(
max_derivative
=
1
,
max_runs
=
5
)
if
__ENABLE_LONG_TESTS__
:
if
__ENABLE_LONG_TESTS__
:
# self.test_1d_trigonometric_float64(max_derivative=3)
# self.test_1d_trigonometric_float64(max_derivative=3)
...
...
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