From 7f666045947341ddbf0dee6c62cf6e0f84645170 Mon Sep 17 00:00:00 2001 From: Marcel Koch <marcel.koch@uni-muenster.de> Date: Thu, 18 Oct 2018 11:39:00 +0200 Subject: [PATCH] adds option `generate_jacobian_apply` This options enables to generate jacobian apply methods regardless of the `matrix_free` option. If `matrix_free` is set to true, `generate_jacobian_apply` is also set to true. This option replaces `matrix_free` in all contexts except in the selection of the solver. --- python/dune/perftool/options.py | 7 ++++++- python/dune/perftool/pdelab/driver/__init__.py | 2 +- python/dune/perftool/pdelab/driver/solve.py | 5 +++-- python/dune/perftool/pdelab/localoperator.py | 10 +++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/python/dune/perftool/options.py b/python/dune/perftool/options.py index 9d4ccb3f..504aba44 100644 --- a/python/dune/perftool/options.py +++ b/python/dune/perftool/options.py @@ -93,6 +93,7 @@ class PerftoolFormOptionsArray(ImmutableRecord): vectorization_target = PerftoolOption(_type=float, helpstr="The cost function target for the 'target' cost model. Only needed to verify the cost model itself, do not use light-heartedly!!!") simplify = PerftoolOption(default=False, helpstr="Whether to simplify expressions using sympy") generate_jacobians = PerftoolOption(default=True, helpstr="Whether jacobian_* methods should be generated. This is set to false automatically, when numerical_jacobian is set to true.") + generate_jacobian_apply = PerftoolOption(default=False, helpstr="Wether jacobian_allpy_* methods should be generated.") generate_residuals = PerftoolOption(default=True, helpstr="Whether alpha_* methods should be generated.") unroll_dimension_loops = PerftoolOption(default=False, helpstr="whether loops over the geometric dimension should be unrolled") precompute_quadrature_info = PerftoolOption(default=True, helpstr="compute quadrature points and weights in the constructor of the local operator") @@ -171,7 +172,7 @@ def process_form_options(opt, form): opt = opt.copy(unroll_dimension_loops=True) if opt.numerical_jacobian: - opt = opt.copy(generate_jacobians=False) + opt = opt.copy(generate_jacobians=False, generate_jacobian_apply=False) if opt.form is None: opt = opt.copy(form=form) @@ -188,6 +189,10 @@ def process_form_options(opt, form): generate_jacobians=False, matrix_free=True, ) + + if opt.matrix_free: + opt = opt.copy(generate_jacobian_apply=True) + return opt diff --git a/python/dune/perftool/pdelab/driver/__init__.py b/python/dune/perftool/pdelab/driver/__init__.py index 3877165c..591c022d 100644 --- a/python/dune/perftool/pdelab/driver/__init__.py +++ b/python/dune/perftool/pdelab/driver/__init__.py @@ -253,7 +253,7 @@ def generate_driver(): from dune.perftool.loopy.target import type_floatingpoint pre_include("#define HP_TIMER_OPCOUNTER {}".format(type_floatingpoint()), filetag="driver") evaluate_residual_timer() - if get_form_option("matrix_free"): + if get_form_option("generate_jacobian_apply"): apply_jacobian_timer() elif is_stationary(): from dune.perftool.pdelab.driver.solve import dune_solve diff --git a/python/dune/perftool/pdelab/driver/solve.py b/python/dune/perftool/pdelab/driver/solve.py index 061a1439..e0a90cae 100644 --- a/python/dune/perftool/pdelab/driver/solve.py +++ b/python/dune/perftool/pdelab/driver/solve.py @@ -50,8 +50,9 @@ def dune_solve(): snp = name_stationarynonlinearproblemsolver(go_type, go) solve = "{}.apply();".format(snp) - print_residual() - if not matrix_free: + if get_form_option("generate_residuals"): + print_residual() + if get_form_option("generate_jacobians"): print_matrix() if get_option('instrumentation_level') >= 2: diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py index 3f12af75..0a3636cc 100644 --- a/python/dune/perftool/pdelab/localoperator.py +++ b/python/dune/perftool/pdelab/localoperator.py @@ -783,7 +783,7 @@ def generate_residual_kernels(form, original_form): ) # In the case of matrix free operator evaluation we need jacobian apply methods - if get_form_option("matrix_free"): + if get_form_option("generate_jacobian_apply"): from dune.perftool.pdelab.driver import is_linear if is_linear(original_form): # Numeical jacobian apply base class @@ -826,10 +826,7 @@ def generate_jacobian_kernels(form, original_form): jacform = offdiagonal_block_jacobian(jacform) operator_kernels = {} - # Decide if the jacobian apply or jacobian method is needed - if get_form_option("matrix_free"): - # Matrix-free computations need the jacobian apply method - + if get_form_option("generate_jacobian_apply"): # The apply vector has reserved index 1 so we directly use Coefficient class from ufl from ufl import Coefficient apply_coefficient = Coefficient(form.coefficients()[0].ufl_element(), 1) @@ -856,8 +853,7 @@ def generate_jacobian_kernels(form, original_form): with global_context(integral_type=it): from dune.perftool.pdelab.signatures import assembly_routine_signature operator_kernels[(it, 'jacobian_apply')] = [LoopyKernelMethod(assembly_routine_signature(), kernel=None)] - else: - # Non matrix-free computations need the jacobian method + if get_form_option("generate_jacobians"): with global_context(form_type="jacobian"): if get_form_option("generate_jacobians"): if get_form_option("sumfact"): -- GitLab