diff --git a/WENO.F90 b/WENO.F90 index 712b8b773cbce21fb5f00be9b3fc365330225ebb..8013b2cbf01c89fa816dd332602dc813f5154ada 100644 --- a/WENO.F90 +++ b/WENO.F90 @@ -982,18 +982,18 @@ end subroutine ! prg = lp.parse_fortran(lp.c_preprocess(SOURCE), FILENAME) ! prg = lp.fix_parameters(prg, ndim=3, nvars=5, _remove=False) ! -! cfd = prg["compute_flux_derivatives"] +! knl = prg["compute_flux_derivatives"] ! -! cfd = lp.assume(cfd, "nx > 0 and ny > 0 and nz > 0") +! knl = lp.assume(knl, "nx > 0 and ny > 0 and nz > 0") ! -! cfd = lp.set_temporary_scope(cfd, "flux_derivatives_generalized", +! knl = lp.set_temporary_scope(knl, "flux_derivatives_generalized", ! lp.AddressSpace.GLOBAL) -! cfd = lp.set_temporary_scope(cfd, "generalized_fluxes", +! knl = lp.set_temporary_scope(knl, "generalized_fluxes", ! lp.AddressSpace.GLOBAL) -! cfd = lp.set_temporary_scope(cfd, "weno_flux_tmp", +! knl = lp.set_temporary_scope(knl, "weno_flux_tmp", ! lp.AddressSpace.GLOBAL) ! -! prg = prg.with_kernel(cfd) +! prg = prg.with_kernel(knl) ! ! RESULT = prg ! diff --git a/build-and-test-py-project.sh b/build-and-test-py-project.sh index 8bfbc06940aa87368d22708756076e22b9e615a8..22bf66974d1b41338b9a8eb336cb91142cf9a1ea 100644 --- a/build-and-test-py-project.sh +++ b/build-and-test-py-project.sh @@ -85,6 +85,6 @@ if test -f $REQUIREMENTS_TXT; then $PIP install -r $REQUIREMENTS_TXT fi -${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow test.py +${PY_EXE} -m pytest -rw --durations=10 --tb=native --junitxml=pytest.xml -rxsw --runslow test # vim: foldmethod=marker diff --git a/data_for_test.py b/data_for_test.py deleted file mode 100644 index bde2cd974fb711349107e23ebf51e308b3c05316..0000000000000000000000000000000000000000 --- a/data_for_test.py +++ /dev/null @@ -1,938 +0,0 @@ -import pytest -import utilities as u - - -# {{{ FluxDataSingle - -class FluxDataSingle: - nvars = 5 - ndim = 3 - dirs = {"x": 1, "y": 2, "z": 3} - - def __init__(self, states_str, fluxes_str, - lam_str, R_str, R_inv_str, wavespeeds_str, - char_fluxes_pos_str, char_fluxes_neg_str, - oscillation_pos_str, oscillation_neg_str, - weno_weights_pos_str, weno_weights_neg_str, - consistent_str, dissipation_pos_str, dissipation_neg_str, - weno_flux_str, direction): - - self.direction = self.dirs[direction] - - self.state_pair = self.swap_array_rows( - u.transposed_array_from_string(states_str), self.direction) - self.states = u.expand_to_6(self.state_pair) - - self.flux_pair = self.swap_array_rows( - u.transposed_array_from_string(fluxes_str), self.direction) - self.fluxes = u.expand_to_6(self.flux_pair) - - self.lam_pointwise = u.expand_to_6( - u.transposed_array_from_string(lam_str)) - - self.R = self.swap_array_rows( - u.array_from_string(R_str), self.direction) - self.R_inv = self.swap_array_cols( - u.array_from_string(R_inv_str), self.direction) - self.wavespeeds = u.array_from_string(wavespeeds_str) - - self.char_fluxes_pos = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_pos_str)) - self.char_fluxes_neg = u.expand_to_6( - u.transposed_array_from_string(char_fluxes_neg_str)) - - self.oscillation_pos = u.transposed_array_from_string(oscillation_pos_str) - self.oscillation_neg = u.transposed_array_from_string(oscillation_neg_str) - - self.weno_weights_pos = u.transposed_array_from_string(weno_weights_pos_str) - self.weno_weights_neg = u.transposed_array_from_string(weno_weights_neg_str) - - self.consistent = self.swap_array( - u.array_from_string(consistent_str), self.direction) - self.dissipation_pos = self.swap_array( - u.array_from_string(dissipation_pos_str), self.direction) - self.dissipation_neg = self.swap_array( - u.array_from_string(dissipation_neg_str), self.direction) - - self.weno_flux = self.swap_array( - u.array_from_string(weno_flux_str), self.direction) - - def swap_array(self, arr, d): - p = self.permutation(d) - arr[p] = arr[[1, 2, 3]] - return arr - - def swap_array_rows(self, arr, d): - p = self.permutation(d) - arr[p, :] = arr[[1, 2, 3], :] - return arr - - def swap_array_cols(self, arr, d): - p = self.permutation(d) - arr[:, p] = arr[:, [1, 2, 3]] - return arr - - def permutation(self, d): - return [(d-1+i) % 3 + 1 for i in range(3)] - -# }}} - - -single_data = {} - -# {{{ Input data: "flat" case - -single_data["Case flat:x"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="x") -single_data["Case flat:y"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="y") -single_data["Case flat:z"] = FluxDataSingle( - states_str="1 1 1 1 5.5,1 1 1 1 5.5", - fluxes_str="1 2.6 1 1 7.1,1 2.6 1 1 7.1", - lam_str=("1. 1. 1. 2.4966629547095764 -0.49666295470957644," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.3340765523905305 0.3340765523905305," - "1 0 0 0.8340765523905306 -0.1659234476094695," - "1 1 0 0.3340765523905305 0.3340765523905305," - "1 0 1 0.3340765523905305 0.3340765523905305," - "1.5000000000000009 1 1 2.8719435219727663 1.8719435219727667"), - R_inv_str=("0.7321428571428572 0.1785714285714286 0.1785714285714286 " - "0.1785714285714286 -0.1785714285714286," - "-1. 0 1. 0 0," - "-1. 0 0 1. 0," - "-0.5991081371313636 0.7327387580875756 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244," - "1.4008918628686364 -1.2672612419124245 -0.2672612419124244 " - "-0.2672612419124244 0.2672612419124244"), - wavespeeds_str="1.1 1.1 1.1 2.7463292501805343 0.5463292501805341", - char_fluxes_pos_str=( - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326," - "0.30000000000000004 0. 0. 2.8024972160321826 0.026547751617514326"), - char_fluxes_neg_str=( - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178," - "-0.014285714285714235 0. 0. -0.13345224838248493 -0.5575027839678178"), - oscillation_pos_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - oscillation_neg_str=("0 0 0 0 0,0 0 0 0 0,0 0 0 0 0"), - weno_weights_pos_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - weno_weights_neg_str=("0.1 0.1 0.1 0.1 0.1," - "0.6 0.6 0.6 0.6 0.6,0.3 0.3 0.3 0.3 0.3"), - consistent_str="1 2.6 1 1 7.1", - dissipation_pos_str=("0 0 0 0 0"), - dissipation_neg_str=("0 0 0 0 0"), - weno_flux_str=("1 2.6 1 1 7.1"), - direction="z") - -# }}} - -# {{{ Input data: Case (a) - -single_data["Case a:x"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="x") -single_data["Case a:y"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="y") -single_data["Case a:z"] = FluxDataSingle( - states_str="2 4 4 4 20,1 1 1 1 5.5", - fluxes_str="4 11.2 8 8 46.4,1 2.6 1 1 7.1", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "1.5857864376269053 0 0 1.4330995704840366 0.018886008110941373," - "1.5857864376269053 1.4142135623730951 0 0.7259927892974889 " - "0.7259927892974889," - "1.5857864376269053 0 1.4142135623730951 0.7259927892974889 " - "0.7259927892974889," - "3.7720779386421466 2.2426406871192857 2.2426406871192857 " - "5.578600290173388 3.335959603054103"), - R_inv_str=("0.36752136386566203 0.265894835574803 0.265894835574803 " - "0.265894835574803 -0.16767379847989416," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "-0.43055863210991147 0.41670966546755195 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456," - "1.8120820550093746 -0.9975038969055432 -0.2903971157189956 " - "-0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 7.523052586013577 0.23295627081394965," - "0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 1.4795302623674356 0.3125273038443238"), - char_fluxes_neg_str=("-0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 -0.7274934638648571 -0.30602629876675014," - "-0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 -0.10725061063772967 -0.37456222716537935"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "48.69888276854567 0.00844206573002786," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "121.7472069213642 0.02110516432506965"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.5129349293057707 0.006262897975282706," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "1.2823373232644266 0.015657244938206753"), - weno_weights_pos_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999999999997268 0.9999909282503908," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 2.5299566294114733e-13 8.39888391917283e-6," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 2.0239658022589593e-14 6.728656898188601e-7"), - weno_weights_neg_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999999975371708 0.9999835300215946," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 2.2803933579018906e-9 0.000015247816238787948," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.824357365679662e-10 1.2221621667041045e-6"), - consistent_str="2.5 6.9 4.5 4.5 26.75", - dissipation_pos_str=("1.6768551393982627 4.8239743723334865 " - "3.997611768980551 3.997611768980551 22.145196359962693"), - dissipation_neg_str=("0.1768550804014161 0.523974175351619 " - "0.4976116690805634 0.4976116690805634 2.495196349669178"), - weno_flux_str=("4.353710219799678 12.247948547685105 8.995223438061114 " - "8.995223438061114 51.39039270963187"), - direction="z") - -# }}} - -# {{{ Input data: Case (b) - -single_data["Case b:x"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="x") -single_data["Case b:y"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="y") -single_data["Case b:z"] = FluxDataSingle( - states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", - fluxes_str="-1 2.6 1 1 -7.1,-4 11.2 8 8 -46.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.45781245952886396 0.45781245952886396," - "-1.5857864376269053 0 0 -0.018886008110941373 " - "-1.4330995704840366," - "-1.5857864376269053 1.4142135623730951 0 -0.7259927892974889 " - "-0.7259927892974889," - "-1.5857864376269053 0 1.4142135623730951 -0.7259927892974889 " - "-0.7259927892974889," - "3.7720779386421466 -2.2426406871192857 -2.2426406871192857 " - "3.335959603054103 5.578600290173388"), - R_inv_str=("0.36752136386566203 -0.265894835574803 -0.265894835574803 " - "-0.265894835574803 -0.16767379847989416," - "1.1213203435596428 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "1.8120820550093746 0.9975038969055432 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456," - "-0.43055863210991147 -0.41670966546755195 0.2903971157189956 " - "0.2903971157189956 0.1831249838115456"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.06722315769446469 0.24852813742385726 " - "0.24852813742385726 0.37456222716537935 0.10725061063772967," - "0.16835489671908455 -0.05857864376269045 " - "-0.05857864376269045 0.30602629876675014 0.7274934638648571"), - char_fluxes_neg_str=("-0.4673767959969717 -0.6627416997969526 " - "-0.6627416997969526 -0.3125273038443238 -1.4795302623674356," - "-1.0907156303492833 1.2301515190164993 " - "1.2301515190164993 -0.23295627081394965 -7.523052586013577"), - oscillation_pos_str=("0. 0. 0. 0. 0.," - "0.01363683818419176 0.12575276673434946 0.12575276673434946 " - "0.006262897975282706 0.5129349293057707," - "0.0340920954604794 0.31438191683587363 0.31438191683587363 " - "0.015657244938206753 1.2823373232644266"), - oscillation_neg_str=("0. 0. 0. 0. 0.," - "0.5180684032155981 4.777392983773268 4.777392983773268 " - "0.00844206573002786 48.69888276854567," - "1.2951710080389953 11.94348245943317 11.94348245943317 " - "0.02110516432506965 121.7472069213642"), - weno_weights_pos_str=("0.9999965203327451 0.999999959029252 " - "0.999999959029252 0.9999835300215946 0.9999999975371708," - "3.2217041402391125e-6 3.793560951911702e-8 " - "3.793560951911702e-8 0.000015247816238787948 2.2803933579018906e-9," - "2.579631146567429e-7 3.0351383606886035e-9 " - "3.0351383606886035e-9 1.2221621667041045e-6 1.824357365679662e-10"), - weno_weights_neg_str=("0.999999997585736 0.9999999999716082 " - "0.9999999999716082 0.9999909282503908 0.9999999999997268," - "2.2354258683870077e-9 2.6288602366075745e-11 " - "2.6288602366075745e-11 8.39888391917283e-6 2.5299566294114733e-13," - "1.788382117901561e-10 2.1030934718853924e-12 " - "2.1030934718853924e-12 6.728656898188601e-7 2.0239658022589593e-14"), - consistent_str="-2.5 6.899999999999999 4.5 4.5 -26.75", - dissipation_pos_str=("-0.17685508040141606 0.523974175351619 " - "0.49761166908056337 0.49761166908056337 -2.495196349669178"), - dissipation_neg_str=("-1.6768551393982627 4.823974372333487 " - "3.9976117689805504 3.9976117689805504 -22.145196359962693"), - weno_flux_str=("-4.353710219799678 12.247948547685105 " - "8.995223438061114 8.995223438061114 -51.390392709631875"), - direction="z") - -# }}} - -# {{{ Input data: Case (c) - -single_data["Case c:x"] = FluxDataSingle( - states_str="2 4 8 12 64,1 1 2 3 11", - fluxes_str="4 11.2 16 24 134.4,1 2.6 2 3 12.6", - lam_str=("2. 2. 2. 3.4966629547095764 0.5033370452904236," - "1. 1. 1. 2.4966629547095764 -0.49666295470957644"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "1.5857864376269053 0 0 1.363377989567262 -0.05083557280583326," - "3.1715728752538106 1.4142135623730951 0 1.3125424167614286 " - "1.3125424167614286," - "4.757359312880716 0 1.4142135623730951 1.968813625142143 " - "1.968813625142143," - "17.60303038033002 4.485281374238571 6.727922061357858 " - "11.42671019719969 9.184069510080404"), - R_inv_str=("-1.4118746341171051 0.21727611674823194 0.4345522334964639 " - "0.6518283502446959 -0.13701474018997217," - "-2.2426406871192857 0 0.7071067811865475 0 0," - "-3.3639610306789285 0 0 0.7071067811865475 0," - "1.7926564050747988 0.4445982978342618 -0.5250169667045714 " - "-0.7875254500568571 0.16553835820737872," - "4.035297092194084 -0.9696152645388333 -0.5250169667045714 " - "-0.7875254500568571 0.16553835820737872"), - wavespeeds_str="2.2 2.2 2.2 3.8463292501805344 0.553670749819466", - char_fluxes_pos_str=("1.1162114029572359 2.4603030380329987 " - "3.690454557049497 7.986924884679773 0.4290108979594782," - "0.26073527447612554 -1.3254833995939053 " - "-1.9882250993908572 2.052422890589809 0.5017887559695788"), - char_fluxes_neg_str=("-0.1482823715615963 -0.1171572875253809 " - "-0.1757359312880714 -0.8893252542028551 -0.20004041758408686," - "-0.009488213714461069 0.49705627484771453 " - "0.7455844122715716 -0.4306378813126712 -0.31431832174320373"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.9757858752013722 " - "19.109571935093072 42.996536853959384 46.95775189047701 " - "0.007062155488717821,2.4394646880034303 47.77392983773268 " - "107.49134213489849 117.39437972619254 0.017655388721794552"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.025685091003327314 " - "0.5030110669373978 1.1317749006091449 0.28052547473186484 " - "0.017412585838667068,0.06421272750831829 1.2575276673434945 " - "2.8294372515228616 0.7013136868296621 0.04353146459666767"), - weno_weights_pos_str=("0.999999999319454 0.9999999999982254 " - "0.9999999999996494 0.9999999999997061 0.9999870425235151," - "6.301345524776077e-10 1.6430428067143077e-12 " - "3.245518542322869e-13 2.721049684463335e-13 0.000011996153712066484," - "5.041138413805998e-11 1.3144350707803127e-13 " - "2.5964155584975223e-14 2.1768403038595738e-14 9.613227729623656e-7"), - weno_weights_neg_str=("0.9999990185022956 0.9999999974390363 " - "0.9999999994941201 0.9999999917661908 0.9999978651320311," - "9.08762722250494e-7 2.3712585027633853e-9 " - "4.684070887233427e-10 7.62387333908512e-9 1.976628702372801e-6," - "7.27349821618269e-8 1.897052057748541e-10 " - "3.747296441221644e-11 6.099359570650648e-10 1.5823926647977797e-7"), - consistent_str="2.5 6.9 9. 13.5 73.5", - dissipation_pos_str=("1.6406634409601506 4.725635754575325 " - "7.88043892893644 11.820658393408754 68.69422377699841"), - dissipation_neg_str=("0.14066328824586258 0.4256356884430299 " - "0.8804384437989111 1.3206576666570364 7.7942206041633595"), - weno_flux_str=("4.281326729206013 12.051271443018354 " - "17.76087737273535 26.64131606006579 149.98844438116177"), - direction="x") -single_data["Case c:y"] = FluxDataSingle( - states_str="2 8 12 4 64,1 2 3 1 11", - fluxes_str="8 35.2 48 16 268.8,2 5.6 6 2 25.2", - lam_str=("4. 4. 4. 5.496662954709576 2.5033370452904236," - "2. 2. 2. 3.4966629547095764 0.5033370452904236"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "3.1715728752538106 0 0 2.019649197947976 0.605435635574881," - "4.757359312880716 1.4142135623730951 0 1.968813625142143 " - "1.968813625142143," - "1.5857864376269053 0 1.4142135623730951 0.6562712083807143 " - "0.6562712083807143," - "17.60303038033002 6.727922061357858 2.2426406871192857 " - "12.548030540759331 8.062749166520762"), - R_inv_str=("-1.4118746341171051 0.4345522334964639 0.6518283502446959 " - "0.21727611674823194 -0.13701474018997217," - "-3.3639610306789285 0 0.7071067811865475 0 0," - "-1.1213203435596428 0 0 0.7071067811865475 0," - "0.671336061515156 0.18208981448197611 -0.7875254500568571 " - "-0.2625084833522857 0.16553835820737872," - "5.156617435753728 -1.2321237478911191 -0.7875254500568571 " - "-0.2625084833522857 0.16553835820737872"), - wavespeeds_str="4.4 4.4 4.4 6.046329250180534 2.753670749819466", - char_fluxes_pos_str=("2.2324228059144673 7.380909114098994 " - "2.4603030380329987 15.885347333048884 0.9465242322295992," - "0.5214705489522515 -3.9764501987817145 " - "-1.3254833995939053 1.3413036144786457 3.767119678640133"), - char_fluxes_neg_str=("-0.2965647431231918 -0.3514718625761428 " - "-0.1171572875253809 -1.6097440213843948 -0.5689873221894901," - "-0.018976427428922138 1.4911688245431431 " - "0.49705627484771453 -0.05753157056903602 -1.432380835542713"), - oscillation_pos_str=("0. 0. 0. 0. 0.,3.9031435008054665 " - "171.98614741583754 19.109571935093072 282.0389435835765 " - "10.607678229749117,9.757858752013666 429.96536853959395 " - "47.77392983773268 705.0973589589414 26.519195574372795"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.10274036401330869 " - "4.5270996024365795 0.5030110669373978 3.21248465662163 " - "0.9939311452005626,0.25685091003327176 11.317749006091447 " - "1.2575276673434945 8.031211641554076 2.484827863001407"), - weno_weights_pos_str=("0.9999999999574652 0.999999999999978 " - "0.9999999999982254 0.9999999999999919 0.9999999999942413," - "3.9384014966385437e-11 2.0284497966079935e-14 " - "1.6430428067143077e-12 7.542808138536806e-15 5.332240836330361e-12," - "3.1507308840273685e-12 1.622759950511315e-15 " - "1.3144350707803127e-13 6.034246767570432e-16 4.265797494767529e-13"), - weno_weights_neg_str=("0.9999999386221037 0.9999999999683822 " - "0.9999999974390363 0.9999999999372101 0.9999999993440752," - "5.68308936788955e-8 2.9275831062158654e-11 " - "2.3712585027633853e-9 5.8138848037057226e-11 6.073372407373299e-10," - "4.547002513715645e-9 2.3420726930957915e-12 " - "1.897052057748541e-10 4.6511252168302e-12 4.8587565862160355e-11"), - consistent_str="5. 20.4 27. 9. 147.", - dissipation_pos_str=("3.281326602835503 16.54629350160538 " - "23.641315459112736 7.8804384863675505 137.3884413587739"), - dissipation_neg_str=("0.2813265968286516 1.7462934823903076 " - "2.641315430506613 0.8804384760489334 15.588441251607525"), - weno_flux_str=("8.562653199664155 38.69258698399568 " - "53.28263088961935 17.760876962416482 299.9768826103814"), - direction="y") -single_data["Case c:z"] = FluxDataSingle( - states_str="2 12 4 8 64,1 3 1 2 11", - fluxes_str="12 75.2 24 48 403.2,3 10.6 3 6 37.8", - lam_str=("6. 6. 6. 7.496662954709576 4.503337045290424," - "3. 3. 3. 4.496662954709576 1.5033370452904236"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "4.757359312880716 0 0 2.6759204063286903 1.2617068439555954," - "1.5857864376269053 1.4142135623730951 0 0.6562712083807143 " - "0.6562712083807143," - "3.1715728752538106 0 1.4142135623730951 1.3125424167614286 " - "1.3125424167614286," - "17.60303038033002 2.2426406871192857 4.485281374238571 " - "13.669350884318975 6.941428822961119"), - R_inv_str=("-1.4118746341171051 0.6518283502446959 " - "0.21727611674823194 0.4345522334964639 -0.13701474018997217," - "-1.1213203435596428 0 0.7071067811865475 0 0," - "-2.2426406871192857 0 0 0.7071067811865475 0," - "-0.4499842820444868 -0.08041866887030964 -0.2625084833522857 " - "-0.5250169667045714 0.16553835820737872," - "6.27793777931337 -1.4946322312434048 -0.2625084833522857 " - "-0.5250169667045714 0.16553835820737872"), - wavespeeds_str="6.6 6.6 6.6 8.246329250180533 4.953670749819467", - char_fluxes_pos_str=("3.348634208871708 3.690454557049497 " - "7.380909114098994 26.24407281945101 -0.9962654715332988," - "0.7822058234283737 -1.9882250993908581 " - "-3.9764501987817162 -0.6952990612264269 8.357934000904585"), - char_fluxes_neg_str=("-0.44484711468478866 -0.1757359312880714 " - "-0.3514718625761428 -2.447320076091316 -0.8207769392695052," - "-0.02846464114338254 0.7455844122715716 " - "1.4911688245431431 0.8126310150223119 -3.0474996241899346"), - oscillation_pos_str=("0. 0. 0. 0. 0.,8.782072876812371 " - "42.9965368539594 171.9861474158376 967.6396764339121 " - "116.6680636935429,21.955182192030932 107.49134213489847 " - "429.9653685395939 2419.099191084781 291.67015923385725"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.23116581902994632 " - "1.1317749006091449 4.5270996024365795 14.169708155270577 " - "6.6110585540523275,0.5779145475748658 2.8294372515228616 " - "11.317749006091447 35.42427038817644 16.527646385130815"), - weno_weights_pos_str=("0.999999999991598 0.9999999999996494 " - "0.999999999999978 0.9999999999999993 0.9999999999999524," - "7.779580658268568e-12 3.2455185423228674e-13 " - "2.028449796607992e-14 6.408020704124379e-16 4.408056940300416e-14," - "6.223673030753551e-13 2.596415558497523e-14 " - "1.6227599505113154e-15 5.126416626873783e-17 3.526445914956101e-15"), - weno_weights_neg_str=("0.9999999878747177 0.9999999994941201 " - "0.9999999999683822 0.9999999999967727 0.9999999999851737," - "1.1227070122726888e-8 4.684070887233427e-10 " - "2.9275831062158654e-11 2.988331869942141e-12 1.372802081812638e-11," - "8.982122341016933e-10 3.747296441221644e-11 " - "2.3420726930957915e-12 2.390667520553204e-13 1.0982436589127136e-12"), - consistent_str="7.5 42.9 13.5 27. 220.5", - dissipation_pos_str=("4.921989904281101 36.24738971766925 " - "11.82065772959958 23.641315459201046 206.08266203865145"), - dissipation_neg_str=("0.4219899024845117 3.9473897091113366 " - "1.3206577265155963 2.6413154534736667 23.382662006532225"), - weno_flux_str=("12.843979806765613 83.09477942678058 " - "26.641315456115176 53.28263091267471 449.9653240451837"), - direction="z") - -# }}} - -# {{{ Input data: Case (d) - -single_data["Case d:x"] = FluxDataSingle( - states_str="1 -1 -2 -3 11,2 -4 -8 -12 64", - fluxes_str="-1 2.6 2 3 -12.6,-4 11.2 16 24 -134.4", - lam_str=("-1. -1. -1. 0.49666295470957644 -2.4966629547095764," - "-2. -2. -2. -0.5033370452904236 -3.4966629547095764"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-1.5857864376269053 0 0 0.05083557280583326 -1.363377989567262," - "-3.1715728752538106 1.4142135623730951 0 -1.3125424167614286 " - "-1.3125424167614286," - "-4.757359312880716 0 1.4142135623730951 -1.968813625142143 " - "-1.968813625142143," - "17.60303038033002 -4.485281374238571 -6.727922061357858 " - "9.184069510080404 11.42671019719969"), - R_inv_str=("-1.4118746341171051 -0.21727611674823194 " - "-0.4345522334964639 -0.6518283502446959 -0.13701474018997217," - "2.2426406871192857 0 0.7071067811865475 0 0," - "3.3639610306789285 0 0 0.7071067811865475 0," - "4.035297092194084 0.9696152645388333 0.5250169667045714 " - "0.7875254500568571 0.16553835820737872," - "1.7926564050747988 -0.4445982978342618 0.5250169667045714 " - "0.7875254500568571 0.16553835820737872"), - wavespeeds_str="2.2 2.2 2.2 0.553670749819466 3.8463292501805344", - char_fluxes_pos_str=("0.009488213714461069 0.49705627484771453 " - "0.7455844122715716 0.31431832174320373 0.4306378813126712," - "0.1482823715615963 -0.1171572875253809 " - "-0.1757359312880714 0.20004041758408686 0.8893252542028551"), - char_fluxes_neg_str=("-0.26073527447612554 -1.3254833995939053 " - "-1.9882250993908572 -0.5017887559695788 -2.052422890589809," - "-1.1162114029572359 2.4603030380329987 " - "3.690454557049497 -0.4290108979594782 -7.986924884679773"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.025685091003327314 " - "0.5030110669373978 1.1317749006091449 0.017412585838667068 " - "0.28052547473186484,0.06421272750831829 1.2575276673434945 " - "2.8294372515228616 0.04353146459666767 0.7013136868296621"), - oscillation_neg_str=("0. 0. 0. 0. 0.,0.9757858752013722 " - "19.109571935093072 42.996536853959384 0.007062155488717821 " - "46.95775189047701,2.4394646880034303 47.77392983773268 " - "107.49134213489849 0.017655388721794552 117.39437972619254"), - weno_weights_pos_str=("0.9999990185022956 0.9999999974390363 " - "0.9999999994941201 0.9999978651320311 0.9999999917661908," - "9.08762722250494e-7 2.3712585027633853e-9 " - "4.684070887233427e-10 1.976628702372801e-6 7.62387333908512e-9," - "7.27349821618269e-8 1.897052057748541e-10 " - "3.747296441221644e-11 1.5823926647977797e-7 6.099359570650648e-10"), - weno_weights_neg_str=("0.999999999319454 0.9999999999982254 " - "0.9999999999996494 0.9999870425235151 0.9999999999997061," - "6.301345524776077e-10 1.6430428067143077e-12 " - "3.245518542322869e-13 0.000011996153712066484 2.721049684463335e-13," - "5.041138413805998e-11 1.3144350707803127e-13 " - "2.5964155584975223e-14 9.613227729623656e-7 2.1768403038595738e-14"), - consistent_str="-2.5 6.9 9. 13.5 -73.5", - dissipation_pos_str=("-0.14066328824586258 0.42563568844302985 " - "0.8804384437989112 1.3206576666570364 -7.7942206041633595"), - dissipation_neg_str=("-1.6406634409601506 4.725635754575325 " - "7.88043892893644 11.820658393408754 -68.69422377699841"), - weno_flux_str=("-4.281326729206013 12.051271443018354 " - "17.76087737273535 26.641316060065794 -149.98844438116177"), - direction="x") -single_data["Case d:y"] = FluxDataSingle( - states_str="1 -2 -3 -1 11,2 -8 -12 -4 64", - fluxes_str="-2 5.6 6 2 -25.2,-8 35.2 48 16 -268.8", - lam_str=("-2. -2. -2. -0.5033370452904236 -3.4966629547095764," - "-4. -4. -4. -2.5033370452904236 -5.496662954709576"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-3.1715728752538106 0 0 -0.605435635574881 -2.019649197947976," - "-4.757359312880716 1.4142135623730951 0 -1.968813625142143 " - "-1.968813625142143," - "-1.5857864376269053 0 1.4142135623730951 -0.6562712083807143 " - "-0.6562712083807143," - "17.60303038033002 -6.727922061357858 -2.2426406871192857 " - "8.062749166520762 12.548030540759331"), - R_inv_str=("-1.4118746341171051 -0.4345522334964639 " - "-0.6518283502446959 -0.21727611674823194 -0.13701474018997217," - "3.3639610306789285 0 0.7071067811865475 0 0," - "1.1213203435596428 0 0 0.7071067811865475 0," - "5.156617435753728 1.2321237478911191 0.7875254500568571 " - "0.2625084833522857 0.16553835820737872," - "0.671336061515156 -0.18208981448197611 0.7875254500568571 " - "0.2625084833522857 0.16553835820737872"), - wavespeeds_str="4.4 4.4 4.4 2.753670749819466 6.046329250180534", - char_fluxes_pos_str=("0.018976427428922138 1.4911688245431431 " - "0.49705627484771453 1.432380835542713 0.05753157056903602," - "0.2965647431231918 -0.3514718625761428 " - "-0.1171572875253809 0.5689873221894901 1.6097440213843948"), - char_fluxes_neg_str=("-0.5214705489522515 -3.9764501987817145 " - "-1.3254833995939053 -3.767119678640133 -1.3413036144786457," - "-2.2324228059144673 7.380909114098994 " - "2.4603030380329987 -0.9465242322295992 -15.885347333048884"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.10274036401330869 " - "4.5270996024365795 0.5030110669373978 0.9939311452005626 " - "3.21248465662163,0.25685091003327176 11.317749006091447 " - "1.2575276673434945 2.484827863001407 8.031211641554076"), - oscillation_neg_str=("0. 0. 0. 0. 0.,3.9031435008054665 " - "171.98614741583754 19.109571935093072 10.607678229749117 " - "282.0389435835765,9.757858752013666 429.96536853959395 " - "47.77392983773268 26.519195574372795 705.0973589589414"), - weno_weights_pos_str=("0.9999999386221037 0.9999999999683822 " - "0.9999999974390363 0.9999999993440752 0.9999999999372101," - "5.68308936788955e-8 2.9275831062158654e-11 " - "2.3712585027633853e-9 6.073372407373299e-10 5.8138848037057226e-11," - "4.547002513715645e-9 2.3420726930957915e-12 " - "1.897052057748541e-10 4.8587565862160355e-11 4.6511252168302e-12"), - weno_weights_neg_str=("0.9999999999574652 0.999999999999978 " - "0.9999999999982254 0.9999999999942413 0.9999999999999919," - "3.9384014966385437e-11 2.0284497966079935e-14 " - "1.6430428067143077e-12 5.332240836330361e-12 7.542808138536806e-15," - "3.1507308840273685e-12 1.622759950511315e-15 " - "1.3144350707803127e-13 4.265797494767529e-13 6.034246767570432e-16"), - consistent_str="-5. 20.4 27. 9. -147.", - dissipation_pos_str=("-0.2813265968286516 1.7462934823903074 " - "2.641315430506612 0.8804384760489334 -15.588441251607525"), - dissipation_neg_str=("-3.281326602835503 16.54629350160538 " - "23.641315459112736 7.880438486367551 -137.3884413587739"), - weno_flux_str=("-8.562653199664155 38.69258698399569 " - "53.28263088961934 17.760876962416486 -299.97688261038144"), - direction="y") -single_data["Case d:z"] = FluxDataSingle( - states_str="1 -3 -1 -2 11,2 -12 -4 -8 64", - fluxes_str="-3 10.6 3 6 -37.8,-12 75.2 24 48 -403.2", - lam_str=("-3. -3. -3. -1.5033370452904236 -4.496662954709576," - "-6. -6. -6. -4.503337045290424 -7.496662954709576"), - R_str=("1 0 0 0.41384589551844686 0.41384589551844686," - "-4.757359312880716 0 0 -1.2617068439555954 -2.6759204063286903," - "-1.5857864376269053 1.4142135623730951 0 -0.6562712083807143 " - "-0.6562712083807143," - "-3.1715728752538106 0 1.4142135623730951 -1.3125424167614286 " - "-1.3125424167614286," - "17.60303038033002 -2.2426406871192857 -4.485281374238571 " - "6.941428822961119 13.669350884318975"), - R_inv_str=("-1.4118746341171051 -0.6518283502446959 " - "-0.21727611674823194 -0.4345522334964639 -0.13701474018997217," - "1.1213203435596428 0 0.7071067811865475 0 0," - "2.2426406871192857 0 0 0.7071067811865475 0," - "6.27793777931337 1.4946322312434048 0.2625084833522857 " - "0.5250169667045714 0.16553835820737872," - "-0.4499842820444868 0.08041866887030964 0.2625084833522857 " - "0.5250169667045714 0.16553835820737872"), - wavespeeds_str="6.6 6.6 6.6 4.953670749819467 8.246329250180533", - char_fluxes_pos_str=("0.02846464114338254 0.7455844122715716 " - "1.4911688245431431 3.0474996241899346 -0.8126310150223119," - "0.44484711468478866 -0.1757359312880714 " - "-0.3514718625761428 0.8207769392695052 2.447320076091316"), - char_fluxes_neg_str=("-0.7822058234283737 -1.9882250993908581 " - "-3.9764501987817162 -8.357934000904585 0.6952990612264269," - "-3.348634208871708 3.690454557049497 " - "7.380909114098994 0.9962654715332988 -26.24407281945101"), - oscillation_pos_str=("0. 0. 0. 0. 0.,0.23116581902994632 " - "1.1317749006091449 4.5270996024365795 6.6110585540523275 " - "14.169708155270577,0.5779145475748658 2.8294372515228616 " - "11.317749006091447 16.527646385130815 35.42427038817644"), - oscillation_neg_str=("0. 0. 0. 0. 0.,8.782072876812371 " - "42.9965368539594 171.9861474158376 116.6680636935429 " - "967.6396764339121,21.955182192030932 107.49134213489847 " - "429.9653685395939 291.67015923385725 2419.099191084781"), - weno_weights_pos_str=("0.9999999878747177 0.9999999994941201 " - "0.9999999999683822 0.9999999999851737 0.9999999999967727," - "1.1227070122726888e-8 4.684070887233427e-10 " - "2.9275831062158654e-11 1.372802081812638e-11 2.988331869942141e-12," - "8.982122341016933e-10 3.747296441221644e-11 " - "2.3420726930957915e-12 1.0982436589127136e-12 2.390667520553204e-13"), - weno_weights_neg_str=("0.999999999991598 0.9999999999996494 " - "0.999999999999978 0.9999999999999524 0.9999999999999993," - "7.779580658268568e-12 3.2455185423228674e-13 " - "2.028449796607992e-14 4.408056940300416e-14 6.408020704124379e-16," - "6.223673030753551e-13 2.596415558497523e-14 " - "1.6227599505113154e-15 3.526445914956101e-15 5.126416626873783e-17"), - consistent_str="-7.5 42.9 13.5 27. -220.5", - dissipation_pos_str=("-0.42198990248451174 3.947389709111337 " - "1.3206577265155963 2.6413154534736667 -23.382662006532225"), - dissipation_neg_str=("-4.9219899042811 36.247389717669265 " - "11.820657729599578 23.641315459201046 -206.08266203865145"), - weno_flux_str=("-12.843979806765612 83.09477942678059 " - "26.641315456115173 53.28263091267471 -449.9653240451837"), - direction="z") - -# }}} - - -@pytest.fixture(scope="session", params=[ - "Case flat:x", "Case flat:y", "Case flat:z", - "Case a:x", "Case a:y", "Case a:z", - "Case b:x", "Case b:y", "Case b:z", - "Case c:x", "Case c:y", "Case c:z", - "Case d:x", "Case d:y", "Case d:z"]) -def flux_test_data_fixture(request): - return single_data[request.param] - - -# vim: foldmethod=marker diff --git a/benchmark.py b/test/benchmark.py similarity index 100% rename from benchmark.py rename to test/benchmark.py diff --git a/conftest.py b/test/conftest.py similarity index 100% rename from conftest.py rename to test/conftest.py diff --git a/test/data_for_test.py b/test/data_for_test.py new file mode 100644 index 0000000000000000000000000000000000000000..ccea4b9b1e984e1291ab9bfe7a7b3cfea7c64459 --- /dev/null +++ b/test/data_for_test.py @@ -0,0 +1,127 @@ +import numpy as np +import pytest +import utilities as u +import weno_reference_implementation as ref + + +# {{{ FluxDataSingle + +class FluxDataSingle: + nvars = 5 + ndim = 3 + dirs = {"x": 1, "y": 2, "z": 3} + + def __init__(self, states_str, direction): + + self.direction = self.dirs[direction] + self.dir_internal = self.direction-1 + + self.metrics = np.array([np.identity(self.ndim) for i in range(6)], + dtype=np.float64, order="F") + self.jacobians = np.repeat(1.0, 6) + + # FIXME: should be computed directly from the metrics and jacobians + self.frozen_metrics = np.mean(self.metrics[2:4], axis=0) + self.frozen_jacobian = np.mean(self.jacobians[2:4], axis=0) + self.combined_frozen_metrics = 1.0 + + self.state_pair = self.swap_array_rows( + u.transposed_array_from_string(states_str), self.dir_internal) + self.states = u.expand_to_6(self.state_pair) + + # FIXME: these should be generalized fluxes + # FIXME: make a clear distinction between fluxes in physical and + # generalized coordinates + self.flux_pair = ref.pointwise_fluxes( + self.state_pair)[:,:,self.dir_internal].T.copy(order="F") + self.fluxes = ref.pointwise_fluxes( + self.states)[:,:,self.dir_internal].T.copy(order="F") + + self.lam_pointwise = ref.lambda_pointwise( + self.states, self.metrics, self.dir_internal) + self.R, self.R_inv, self.lam_roe = ref.roe_eigensystem( + self.state_pair, self.frozen_metrics, self.direction) + self.wavespeeds = ref.wavespeeds(self.lam_pointwise, self.lam_roe) + + self.char_fluxes_pos, self.char_fluxes_neg = ref.split_char_fluxes( + self.states, self.wavespeeds, + self.frozen_metrics[self.dir_internal], self.frozen_jacobian, + self.R_inv) + + self.oscillation_pos = ref.oscillation(self.char_fluxes_pos) + self.oscillation_neg = ref.oscillation(self.char_fluxes_neg[:,::-1]) + + self.weno_weights_pos = ref.weno_weights( + self.oscillation_pos, self.combined_frozen_metrics) + self.weno_weights_neg = ref.weno_weights( + self.oscillation_neg, self.combined_frozen_metrics) + + self.consistent = ref.consistent_part(self.fluxes) + self.dissipation_pos = ref.dissipation_part( + self.R, self.char_fluxes_pos, self.weno_weights_pos, 1) + self.dissipation_neg = ref.dissipation_part( + self.R, self.char_fluxes_neg, self.weno_weights_neg, -1) + + self.weno_flux = ref.weno_flux( + self.consistent, self.dissipation_pos, self.dissipation_neg) + + def swap_array_rows(self, arr, d): + p = self.permutation(d) + arr[p, :] = arr[[1, 2, 3], :] + return arr + + def permutation(self, d): + return [(d+i) % 3 + 1 for i in range(3)] + +# }}} + + +single_data = {} + +single_data["Case flat:x"] = FluxDataSingle( + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="x") +single_data["Case flat:y"] = FluxDataSingle( + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="y") +single_data["Case flat:z"] = FluxDataSingle( + states_str="1 1 1 1 5.5,1 1 1 1 5.5", direction="z") + +single_data["Case a:x"] = FluxDataSingle( + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="x") +single_data["Case a:y"] = FluxDataSingle( + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="y") +single_data["Case a:z"] = FluxDataSingle( + states_str="2 4 4 4 20,1 1 1 1 5.5", direction="z") + +single_data["Case b:x"] = FluxDataSingle( + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="x") +single_data["Case b:y"] = FluxDataSingle( + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="y") +single_data["Case b:z"] = FluxDataSingle( + states_str="1 -1 -1 -1 5.5,2 -4 -4 -4 20", direction="z") + +single_data["Case c:x"] = FluxDataSingle( + states_str="2 4 8 12 64,1 1 2 3 11", direction="x") +single_data["Case c:y"] = FluxDataSingle( + states_str="2 8 12 4 64,1 2 3 1 11", direction="y") +single_data["Case c:z"] = FluxDataSingle( + states_str="2 12 4 8 64,1 3 1 2 11", direction="z") + +single_data["Case d:x"] = FluxDataSingle( + states_str="1 -1 -2 -3 11,2 -4 -8 -12 64", direction="x") +single_data["Case d:y"] = FluxDataSingle( + states_str="1 -2 -3 -1 11,2 -8 -12 -4 64", direction="y") +single_data["Case d:z"] = FluxDataSingle( + states_str="1 -3 -1 -2 11,2 -12 -4 -8 64", direction="z") + + +@pytest.fixture(scope="session", params=[ + "Case flat:x", "Case flat:y", "Case flat:z", + "Case a:x", "Case a:y", "Case a:z", + "Case b:x", "Case b:y", "Case b:z", + "Case c:x", "Case c:y", "Case c:z", + "Case d:x", "Case d:y", "Case d:z"]) +def flux_test_data_fixture(request): + return single_data[request.param] + + +# vim: foldmethod=marker diff --git a/test/ideal_gas.py b/test/ideal_gas.py new file mode 100644 index 0000000000000000000000000000000000000000..12b8c0011fd7ebb961e60e9d7666dbaccf9a1848 --- /dev/null +++ b/test/ideal_gas.py @@ -0,0 +1,54 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + + +ndim = 3 +nvars = 3 +gamma = 1.4 + + +def rho(state): + return state[0] + + +def velocity(state): + return state[1:ndim+1]/rho(state) + + +def energy(state): + return state[ndim+1] + + +def kinetic_energy(state): + vel = velocity(state) + return 0.5*rho(state)*np.dot(vel, vel) + + +def internal_energy(state): + return energy(state) - kinetic_energy(state) + + +def pressure(state): + return (gamma - 1)*internal_energy(state) + + +def sound_speed(state): + return np.sqrt(gamma*pressure(state)/rho(state)) + + +def flux(state): + vel = velocity(state) + p = pressure(state) + + result = np.outer(state, vel) + + for i in range(ndim): + result[i+1,i] += p + result[ndim+1,i] += vel[i]*p + + return result diff --git a/pytest.ini b/test/pytest.ini similarity index 100% rename from pytest.ini rename to test/pytest.ini diff --git a/test/test_eigensystem.py b/test/test_eigensystem.py new file mode 100644 index 0000000000000000000000000000000000000000..4b0a7a6b14af212778076242e3e0fbef81e7f2e7 --- /dev/null +++ b/test/test_eigensystem.py @@ -0,0 +1,117 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + +import sys +import logging + +import pytest +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl + as pytest_generate_tests) + +import utilities as u +from data_for_test import ( # noqa: F401 + flux_test_data_fixture, + single_data as sd + ) + + +def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") + queue = u.get_queue(ctx_factory) + + lam_dev = u.empty_array_on_device(queue, data.nvars, 6) + + prg(queue, nvars=data.nvars, d=data.direction, + states=data.states, lambda_pointwise=lam_dev) + + u.compare_arrays(lam_dev.get(), data.lam_pointwise) + + +def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture + + def check_roe_identity(states, R, R_inv): + d_state = states[:, 1] - states[:, 0] + u.compare_arrays(R@(R_inv@d_state), d_state) + + def check_roe_property(states, fluxes, R, R_inv, lam): + d_state = states[:, 1] - states[:, 0] + d_flux = fluxes[:, 1] - fluxes[:, 0] + + temp = R_inv@d_state + temp = np.multiply(lam, temp) + u.compare_arrays(R@temp, d_flux) + + prg = u.get_weno_program_with_root_kernel("roe_eigensystem") + queue = u.get_queue(ctx_factory) + + R_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) + R_inv_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) + lam_dev = u.empty_array_on_device(queue, data.nvars) + + prg(queue, nvars=data.nvars, ndim=data.ndim, d=data.direction, + states=data.state_pair, metrics_frozen=data.frozen_metrics, + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) + + R = R_dev.get() + R_inv = R_inv_dev.get() + lam = lam_dev.get() + + check_roe_identity(data.state_pair, R, R_inv) + check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) + + +@pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ + ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), + ("1 2 3 4 5,-2 -4 -6 -8 -10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), + ("1 2 3 4 5,-2 -4 -6 -8 -10", "3 6 9 12 15", "3.3 6.6 9.9 13.2 16.5"), + ("1 2 3 4 5,2 4 6 8 10", "-3 -6 -9 -12 -15", "3.3 6.6 9.9 13.2 16.5"), + ("3 2 9 4 5,2 6 6 12 10", "-1 -4 -3 -8 -15", "3.3 6.6 9.9 13.2 16.5") + ]) +def test_lax_wavespeeds( + ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): + prg = u.get_weno_program_with_root_kernel("lax_wavespeeds") + queue = u.get_queue(ctx_factory) + + nvars = 5 + + lam_pointwise = u.expand_to_6(u.transposed_array_from_string(lam_pointwise_str)) + lam_roe = u.array_from_string(lam_roe_str) + lam_dev = u.empty_array_on_device(queue, nvars) + + prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, + lambda_roe=lam_roe, wavespeeds=lam_dev) + + lam_expected = u.array_from_string(lam_expected_str) + u.compare_arrays(lam_dev.get(), lam_expected) + + +def test_matvec(ctx_factory): + prg = u.get_weno_program_with_root_kernel("mult_mat_vec") + queue = u.get_queue(ctx_factory) + + a = u.random_array_on_device(queue, 10, 10) + b = u.random_array_on_device(queue, 10) + + c = u.empty_array_on_device(queue, 10) + + prg(queue, alpha=1.0, a=a, b=b, c=c) + + u.compare_arrays(a.get()@b.get(), c.get()) + + +# This lets you run 'python test.py test_case(cl._csc)' without pytest. +if __name__ == "__main__": + if len(sys.argv) > 1: + logging.basicConfig(level="INFO") + exec(sys.argv[1]) + else: + pytest.main([__file__]) diff --git a/test/test_flux_derivatives.py b/test/test_flux_derivatives.py new file mode 100644 index 0000000000000000000000000000000000000000..aaa0e43471a62a771cd6a908f8c20324e3e01ac1 --- /dev/null +++ b/test/test_flux_derivatives.py @@ -0,0 +1,53 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + +import sys +import logging + +import pytest +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl + as pytest_generate_tests) + +import utilities as u + + +@pytest.mark.slow +def test_compute_flux_derivatives(ctx_factory): + prg = u.get_weno_program() + + queue = u.get_queue(ctx_factory) + prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) + + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=0, + parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) + + +@pytest.mark.slow +def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): + prg = u.get_weno_program() + prg = u.transform_weno_for_gpu(prg) + + queue = u.get_queue(ctx_factory) + prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) + prg = lp.set_options(prg, no_numpy=True) + + if write_code: + u.write_target_device_code(prg) + + lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=0, + parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) + + +# This lets you run 'python test.py test_case(cl._csc)' without pytest. +if __name__ == "__main__": + if len(sys.argv) > 1: + logging.basicConfig(level="INFO") + exec(sys.argv[1]) + else: + pytest.main([__file__]) diff --git a/test.py b/test/test_weno_flux.py similarity index 56% rename from test.py rename to test/test_weno_flux.py index 671b7fe606f27d44b93dfd6f761ad7ab6a5878c6..76976cd4a19965cfb72528fa01d369383b5a1d9f 100644 --- a/test.py +++ b/test/test_weno_flux.py @@ -17,7 +17,7 @@ from pyopencl.tools import ( # noqa import utilities as u from data_for_test import ( # noqa: F401 flux_test_data_fixture, - single_data as std # "single_test_data", sorry + single_data as sd ) @@ -33,7 +33,7 @@ def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): generalized_fluxes=data.fluxes, characteristic_fluxes_pos=data.char_fluxes_pos, characteristic_fluxes_neg=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, flux=flux_dev) @@ -65,7 +65,7 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, dissipation_pos=dissipation_dev) @@ -82,7 +82,7 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, R=data.R, dissipation_neg=dissipation_dev) @@ -99,7 +99,7 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_pos, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) @@ -118,7 +118,7 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): prg(queue, nvars=data.nvars, characteristic_fluxes=data.char_fluxes_neg, - combined_frozen_metrics=1.0, + combined_frozen_metrics=data.combined_frozen_metrics, w=weights_dev) sum_weights = np.sum(weights_dev.get(), axis=1) @@ -178,125 +178,6 @@ def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) -def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") - queue = u.get_queue(ctx_factory) - - lam_dev = u.empty_array_on_device(queue, data.nvars, 6) - - prg(queue, nvars=data.nvars, d=data.direction, - states=data.states, lambda_pointwise=lam_dev) - - u.compare_arrays(lam_dev.get(), data.lam_pointwise) - - -def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): - data = flux_test_data_fixture - - def identity_matrix(n): - return np.identity(n).astype(np.float64).copy(order="F") - - def check_roe_identity(states, R, R_inv): - d_state = states[:, 1] - states[:, 0] - u.compare_arrays(R@(R_inv@d_state), d_state) - - def check_roe_property(states, fluxes, R, R_inv, lam): - d_state = states[:, 1] - states[:, 0] - d_flux = fluxes[:, 1] - fluxes[:, 0] - - temp = R_inv@d_state - temp = np.multiply(lam, temp) - u.compare_arrays(R@temp, d_flux) - - prg = u.get_weno_program_with_root_kernel("roe_eigensystem") - queue = u.get_queue(ctx_factory) - - metrics_frozen = identity_matrix(data.ndim) - - R_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) - R_inv_dev = u.empty_array_on_device(queue, data.nvars, data.nvars) - lam_dev = u.empty_array_on_device(queue, data.nvars) - - prg(queue, nvars=data.nvars, ndim=data.ndim, d=data.direction, - states=data.state_pair, metrics_frozen=metrics_frozen, - R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) - - R = R_dev.get() - R_inv = R_inv_dev.get() - lam = lam_dev.get() - - check_roe_identity(data.state_pair, R, R_inv) - check_roe_property(data.state_pair, data.flux_pair, R, R_inv, lam) - - -@pytest.mark.parametrize("lam_pointwise_str,lam_roe_str,lam_expected_str", [ - ("1 2 3 4 5,2 4 6 8 10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), - ("1 2 3 4 5,-2 -4 -6 -8 -10", "1.5 3 4.5 6 7.5", "2.2 4.4 6.6 8.8 11"), - ("1 2 3 4 5,-2 -4 -6 -8 -10", "3 6 9 12 15", "3.3 6.6 9.9 13.2 16.5"), - ("1 2 3 4 5,2 4 6 8 10", "-3 -6 -9 -12 -15", "3.3 6.6 9.9 13.2 16.5"), - ("3 2 9 4 5,2 6 6 12 10", "-1 -4 -3 -8 -15", "3.3 6.6 9.9 13.2 16.5") - ]) -def test_lax_wavespeeds( - ctx_factory, lam_pointwise_str, lam_roe_str, lam_expected_str): - prg = u.get_weno_program_with_root_kernel("lax_wavespeeds") - queue = u.get_queue(ctx_factory) - - nvars = 5 - - lam_pointwise = u.expand_to_6(u.transposed_array_from_string(lam_pointwise_str)) - lam_roe = u.array_from_string(lam_roe_str) - lam_dev = u.empty_array_on_device(queue, nvars) - - prg(queue, nvars=nvars, lambda_pointwise=lam_pointwise, - lambda_roe=lam_roe, wavespeeds=lam_dev) - - lam_expected = u.array_from_string(lam_expected_str) - u.compare_arrays(lam_dev.get(), lam_expected) - - -def test_matvec(ctx_factory): - prg = u.get_weno_program_with_root_kernel("mult_mat_vec") - queue = u.get_queue(ctx_factory) - - a = u.random_array_on_device(queue, 10, 10) - b = u.random_array_on_device(queue, 10) - - c = u.empty_array_on_device(queue, 10) - - prg(queue, alpha=1.0, a=a, b=b, c=c) - - u.compare_arrays(a.get()@b.get(), c.get()) - - -@pytest.mark.slow -def test_compute_flux_derivatives(ctx_factory): - prg = u.get_weno_program() - - queue = u.get_queue(ctx_factory) - prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) - - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, - parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) - - -@pytest.mark.slow -def test_compute_flux_derivatives_gpu(ctx_factory, write_code=False): - prg = u.get_weno_program() - prg = u.transform_weno_for_gpu(prg) - - queue = u.get_queue(ctx_factory) - prg = prg.copy(target=lp.PyOpenCLTarget(queue.device)) - prg = lp.set_options(prg, no_numpy=True) - - if write_code: - u.write_target_device_code(prg) - - lp.auto_test_vs_ref(prg, ctx_factory(), warmup_rounds=1, - parameters=dict(ndim=3, nvars=5, nx=16, ny=16, nz=16)) - - # This lets you run 'python test.py test_case(cl._csc)' without pytest. if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/utilities.py b/test/utilities.py similarity index 81% rename from utilities.py rename to test/utilities.py index c8bde8a3b7baf9e034541188c01b6e73e3bfc00e..35ea205de6bcec427579a775a3126d9108fe2fc2 100644 --- a/utilities.py +++ b/test/utilities.py @@ -7,23 +7,29 @@ import pyopencl.clrandom # noqa import loopy as lp # noqa from pytest import approx +import os.path + # {{{ arrays def compare_arrays(a, b): - assert a == approx(b, rel=1e-5, abs=2e-5) + assert a == approx(b, rel=1e-12, abs=1e-14) -def random_array_on_device(queue, *shape): - ary = empty_array_on_device(queue, *shape) - cl.clrandom.fill_rand(ary) - return ary +def transposed_array(a): + return np.array(a).T.copy(order="F") def empty_array_on_device(queue, *shape): return cl.array.empty(queue, shape, dtype=np.float64, order="F") +def random_array_on_device(queue, *shape): + ary = empty_array_on_device(queue, *shape) + cl.clrandom.fill_rand(ary) + return ary + + def arrays_from_string(string_arrays): return split_map_to_list(string_arrays, array_from_string, ":") @@ -87,9 +93,11 @@ def get_queue(ctx_factory): _WENO_PRG = {} +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + def parse_weno(): - fn = "WENO.F90" + fn = os.path.join(project_root, "WENO.F90") with open(fn, "r") as infile: infile_content = infile.read() @@ -129,26 +137,26 @@ def get_weno_program_with_root_kernel(knl): def transform_weno_for_gpu(prg, print_kernel=False): - cfd = prg["compute_flux_derivatives"] + knl = prg["compute_flux_derivatives"] for suffix in ["", "_1", "_2", "_3", "_4", "_5", "_6", "_7"]: - cfd = lp.split_iname(cfd, "i"+suffix, 16, + knl = lp.split_iname(knl, "i"+suffix, 16, outer_tag="g.0", inner_tag="l.0") - cfd = lp.split_iname(cfd, "j"+suffix, 16, + knl = lp.split_iname(knl, "j"+suffix, 16, outer_tag="g.1", inner_tag="l.1") for var_name in ["delta_xi", "delta_eta", "delta_zeta"]: - cfd = lp.assignment_to_subst(cfd, var_name) + knl = lp.assignment_to_subst(knl, var_name) - cfd = lp.add_barrier(cfd, "tag:to_generalized", "tag:flux_x_compute") - cfd = lp.add_barrier(cfd, "tag:flux_x_compute", "tag:flux_x_diff") - cfd = lp.add_barrier(cfd, "tag:flux_x_diff", "tag:flux_y_compute") - cfd = lp.add_barrier(cfd, "tag:flux_y_compute", "tag:flux_y_diff") - cfd = lp.add_barrier(cfd, "tag:flux_y_diff", "tag:flux_z_compute") - cfd = lp.add_barrier(cfd, "tag:flux_z_compute", "tag:flux_z_diff") - cfd = lp.add_barrier(cfd, "tag:flux_z_diff", "tag:from_generalized") + knl = lp.add_barrier(knl, "tag:to_generalized", "tag:flux_x_compute") + knl = lp.add_barrier(knl, "tag:flux_x_compute", "tag:flux_x_diff") + knl = lp.add_barrier(knl, "tag:flux_x_diff", "tag:flux_y_compute") + knl = lp.add_barrier(knl, "tag:flux_y_compute", "tag:flux_y_diff") + knl = lp.add_barrier(knl, "tag:flux_y_diff", "tag:flux_z_compute") + knl = lp.add_barrier(knl, "tag:flux_z_compute", "tag:flux_z_diff") + knl = lp.add_barrier(knl, "tag:flux_z_diff", "tag:from_generalized") - prg = prg.with_kernel(cfd) + prg = prg.with_kernel(knl) # FIXME: These should work, but don't # FIXME: Undo the hand-inlining in WENO.F90 diff --git a/test/weno_reference_implementation.py b/test/weno_reference_implementation.py new file mode 100644 index 0000000000000000000000000000000000000000..2b18fd70c2fe7f7eef6eecd3a0abb48b5a867a0d --- /dev/null +++ b/test/weno_reference_implementation.py @@ -0,0 +1,130 @@ +import numpy as np +import numpy.linalg as la # noqa: F401 +import pyopencl as cl # noqa: F401 +import pyopencl.array # noqa +import pyopencl.tools # noqa +import pyopencl.clrandom # noqa +import loopy as lp # noqa + +import utilities as u +import ideal_gas as gas + + +def pointwise_fluxes(states): + return np.array([gas.flux(s) for s in states.T]) + + +def roe_eigensystem(state_pair, frozen_metrics, direction): + # FIXME: startup for test suite is pretty slow due to this routine + # -- can we speed this up? + + nvars = state_pair.shape[0] + ndim = frozen_metrics.shape[0] + + prg = u.get_weno_program_with_root_kernel("roe_eigensystem") + queue = u.get_queue(cl._csc) + + R_dev = u.empty_array_on_device(queue, nvars, nvars) + R_inv_dev = u.empty_array_on_device(queue, nvars, nvars) + lam_dev = u.empty_array_on_device(queue, nvars) + + prg(queue, nvars=nvars, ndim=ndim, d=direction, + states=state_pair, metrics_frozen=frozen_metrics, + R=R_dev, R_inv=R_inv_dev, lambda_roe=lam_dev) + + return R_dev.get(), R_inv_dev.get(), lam_dev.get() + + +def lambda_pointwise(states, metrics, direction): + def lam(state, metric_norm): + c = gas.sound_speed(state) + c_norm = c*metric_norm[direction] + vel = gas.velocity(state)[direction] + + result = np.repeat(vel, state.size) + result[-2] += c_norm + result[-1] -= c_norm + + return result + + metric_norm = np.sqrt((metrics**2).sum(axis=1)) + + return u.transposed_array([lam(s, m) for s, m in zip(states.T, metric_norm)]) + + +def wavespeeds(pointwise, roe): + lam = np.c_[pointwise, roe] + return 1.1*np.max(np.abs(lam), axis=1) + + +def split_char_fluxes(states, wavespeeds, frozen_metrics, frozen_jacobian, R_inv): + def split(flux, state): + generalized_fluxes = np.dot(flux, frozen_metrics) + weighted_states = np.outer(wavespeeds, state/frozen_jacobian) + + return (0.5*np.sum(R_inv*(generalized_fluxes + weighted_states), axis=1), + 0.5*np.sum(R_inv*(generalized_fluxes - weighted_states), axis=1)) + + fluxes = pointwise_fluxes(states) + + char_fluxes_pos, char_fluxes_neg = zip( + *[split(f, s) for f, s in zip(fluxes, states.T)]) + + return (u.transposed_array(char_fluxes_pos), + u.transposed_array(char_fluxes_neg)) + + +def oscillation(fluxes): + coeffs1 = np.array([[1, -4, 3], [-1, 0, 1], [-3, 4, -1]]) + coeffs2 = np.array([1, -2, 1]) + + indices = np.arange(3)[None,:] + np.arange(3)[:,None] + + sum1 = u.transposed_array( + [np.dot(c, f) for c, f in zip(coeffs1, fluxes.T[indices])]) + sum2 = u.transposed_array([np.dot(coeffs2, f) for f in fluxes.T[indices]]) + + return (1.0/4)*(sum1**2) + (13.0/12)*(sum2**2) + + +def weno_weights(oscillation, frozen_metric): + linear = np.array([0.1, 0.6, 0.3]) + eps = 1e-6*frozen_metric + + raw_weights = linear[None,:]/(oscillation + eps)**2 + + return raw_weights/raw_weights.sum(axis=1)[:,None] + + +def flux_differences(fluxes): + w = np.array([-1, 3, -3, 1]) + indices = np.arange(3)[:,None] + np.arange(4)[None,:] + + return u.transposed_array([np.dot(w, f) for f in fluxes.T[indices]]) + + +def combination_weighting(w): + return np.array( + [20*w[:,0] - 1, -10*(w[:,0] + w[:,1]) + 5, np.ones(w.shape[0])] + ).T + + +def combine_fluxes(w, f): + cw = combination_weighting(w) + return np.sum(cw*f, axis=1) + + +def dissipation_part(R, char_fluxes, w, sign): + flux_diff = flux_differences(char_fluxes)[:,::sign] + flux_comb = combine_fluxes(w, flux_diff) + + return -sign*R@flux_comb/60 + + +def consistent_part(fluxes): + w = np.array([1.0, -8.0, 37.0, 37.0, -8.0, 1.0])/60.0 + return np.dot(fluxes, w) + + +def weno_flux(consistent, dissipation_pos, dissipation_neg): + return consistent + dissipation_pos + dissipation_neg