diff --git a/python/dune/perftool/options.py b/python/dune/perftool/options.py index 9d4ccb3f5da38ac1d83bd5d7b63f7c7a1059c99d..25fd514582a9873eb26cf59f50897b1dbe59cdc9 100644 --- a/python/dune/perftool/options.py +++ b/python/dune/perftool/options.py @@ -54,6 +54,7 @@ class PerftoolGlobalOptionsArray(ImmutableRecord): operators = PerftoolOption(default="r", helpstr="A comma separated list of operators, each name will be interpreted as a subsection name within the formcompiler section") target_name = PerftoolOption(default=None, helpstr="The target name from CMake") operator_to_build = PerftoolOption(default=None, helpstr="The operators from the list that is about to be build now. CMake sets this one!!!") + debug_interpolate_input = PerftoolOption(default=False, helpstr="Should the input for printresidual and printmatix be interpolated (instead of random input).") # Arguments that are mainly to be set by logic depending on other options max_vector_width = PerftoolOption(default=256, helpstr=None) diff --git a/python/dune/perftool/pdelab/driver/solve.py b/python/dune/perftool/pdelab/driver/solve.py index 0648df399d809fd84d30624711dfc2fb02bbc631..4603905e947beefa970b61e3a3300a46a903b521 100644 --- a/python/dune/perftool/pdelab/driver/solve.py +++ b/python/dune/perftool/pdelab/driver/solve.py @@ -9,6 +9,7 @@ from dune.perftool.pdelab.driver import (get_form_ident, name_initree, ) from dune.perftool.pdelab.driver.gridfunctionspace import (name_trial_gfs, + name_leafview, type_domainfield, type_trial_gfs, ) @@ -19,7 +20,7 @@ from dune.perftool.pdelab.driver.gridoperator import (name_gridoperator, type_gridoperator, ) from dune.perftool.pdelab.driver.interpolate import interpolate_dirichlet_data - +from dune.perftool.pdelab.geometry import world_dimension @preamble(section="solver") def dune_solve(): @@ -204,6 +205,31 @@ def name_stationarynonlinearproblemsolver(go_type, go): return name +def random_input(v): + return [" // Setup random input", + " std::size_t seed = 0;", + " auto rng = std::mt19937_64(seed);", + " auto dist = std::uniform_real_distribution<>(-1., 1.);", + " for (auto& v : {})".format(v), + " v = dist(rng);"] + + +def interpolate_input(v): + dim = world_dimension(); + gv = name_leafview() + gfs = name_trial_gfs() + expr = [] + for i in range(dim): + expr.append("x[{}]*x[{}]".format(i, i)) + expr = "+".join(expr) + return [" // Interpolate input", + " auto interpolate_lambda = [] (const auto& x){", + " return std::exp({});".format(expr), + " };", + " auto interpolate = Dune::PDELab::makeGridFunctionFromCallable({}, interpolate_lambda);".format(gv), + " Dune::PDELab::interpolate(interpolate,{},{});".format(gfs, v), + ] + @preamble(section="printing") def print_residual(): ini = name_initree() @@ -212,16 +238,15 @@ def print_residual(): t_v = type_vector(get_form_ident()) include_file("random", system=True, filetag="driver") + if get_option("debug_interpolate_input"): + input = interpolate_input(v) + else: + input = random_input(v) + return ["if ({}.get<bool>(\"printresidual\", false)) {{".format(ini), " using Dune::PDELab::Backend::native;", - " {} r({});".format(t_v, v), - " // Setup random input", - " std::size_t seed = 0;", - " auto rng = std::mt19937_64(seed);", - " auto dist = std::uniform_real_distribution<>(-1., 1.);", - " for (auto& v : {})".format(v), - " v = dist(rng);", - " r=0.0;", + " {} r({});".format(t_v, v)] + input + \ + [" r=0.0;", " {}.residual({}, r);".format(n_go, v), " Dune::printvector(std::cout, native(r), \"residual vector\", \"row\");", "}"] @@ -235,14 +260,15 @@ def print_matrix(): v = name_vector(get_form_ident()) t_v = type_vector(get_form_ident()) + if get_option("debug_interpolate_input"): + input = interpolate_input(v) + else: + input = random_input(v) + return ["if ({}.get<bool>(\"printmatrix\", false)) {{".format(ini), - " // Setup random input", - " std::size_t seed = 0;", - " auto rng = std::mt19937_64(seed);", - " auto dist = std::uniform_real_distribution<>(1., 10.);", - " for (auto& v : {})".format(v), - " v = dist(rng);", - " using M = typename {}::Traits::Jacobian;".format(t_go), + " using Dune::PDELab::Backend::native;", + " {} r({});".format(t_v, v)] + input + \ + [" using M = typename {}::Traits::Jacobian;".format(t_go), " M m({});".format(n_go), " {}.jacobian({},m);".format(n_go, v), " using Dune::PDELab::Backend::native;", diff --git a/test/sumfact/poisson/poisson_2d_unstructured.mini b/test/sumfact/poisson/poisson_2d_unstructured.mini index b797809b2f626a3d8e9a0aa546df4e549f12e3fe..bca80233015f166dbad795b48de6a3f87256f74f 100644 --- a/test/sumfact/poisson/poisson_2d_unstructured.mini +++ b/test/sumfact/poisson/poisson_2d_unstructured.mini @@ -23,6 +23,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 5e-5, 5e-7 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_3d_unstructured.mini b/test/sumfact/poisson/poisson_3d_unstructured.mini index 05f9a1d10e7068c6bb7f8c3c1742ed97f9ee86ab..5e9eae243b8d608ad1dbe01ea73fd76f03777f56 100644 --- a/test/sumfact/poisson/poisson_3d_unstructured.mini +++ b/test/sumfact/poisson/poisson_3d_unstructured.mini @@ -23,6 +23,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 1e-4, 1e-8 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_dg_2d_gmsh.mini b/test/sumfact/poisson/poisson_dg_2d_gmsh.mini index 970da4de6dd24e42891191e83ee10227899fa49e..79df9ea4e0ce87805ea9220e3be9b05262beb596 100644 --- a/test/sumfact/poisson/poisson_dg_2d_gmsh.mini +++ b/test/sumfact/poisson/poisson_dg_2d_gmsh.mini @@ -21,6 +21,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 5e-5, 5e-7 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_dg_2d_unstructured.mini b/test/sumfact/poisson/poisson_dg_2d_unstructured.mini index 639b96da2988d7f50f4fbb4b1569f46997d21d31..fec1c93d095eb90dcbfc1a40e11f01af58ecced0 100644 --- a/test/sumfact/poisson/poisson_dg_2d_unstructured.mini +++ b/test/sumfact/poisson/poisson_dg_2d_unstructured.mini @@ -23,6 +23,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 5e-5, 5e-5 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_dg_3d_gmsh.mini b/test/sumfact/poisson/poisson_dg_3d_gmsh.mini index 23f7ebc020396f071fc661ee0fe6a44cf9ee28a1..eb320a2d90f99e9c2abd40470f160370677ebe81 100644 --- a/test/sumfact/poisson/poisson_dg_3d_gmsh.mini +++ b/test/sumfact/poisson/poisson_dg_3d_gmsh.mini @@ -23,6 +23,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 1e-4, 5e-6 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_dg_3d_unstructured.mini b/test/sumfact/poisson/poisson_dg_3d_unstructured.mini index 5c833f28f3dc61bb28fb163d43a4d09eb1243315..271b1f54d533db26bf7a205ff0df772ae0254b0c 100644 --- a/test/sumfact/poisson/poisson_dg_3d_unstructured.mini +++ b/test/sumfact/poisson/poisson_dg_3d_unstructured.mini @@ -23,6 +23,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 1e-4, 5e-6 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 1, 0 | expand num diff --git a/test/sumfact/poisson/poisson_fastdg_3d_gmsh.mini b/test/sumfact/poisson/poisson_fastdg_3d_gmsh.mini index 380cef481215099d4c9b7ce028e4f03cae34e337..52de26ab8457740a0ff15c6e2ce3a3969328ff0b 100644 --- a/test/sumfact/poisson/poisson_fastdg_3d_gmsh.mini +++ b/test/sumfact/poisson/poisson_fastdg_3d_gmsh.mini @@ -21,6 +21,7 @@ extension = vtu [formcompiler] compare_l2errorsquared = 1e-4, 5e-6 | expand deg grid_unstructured = 1 +debug_interpolate_input = 1 [formcompiler.r] numerical_jacobian = 0