Skip to content
Snippets Groups Projects
Commit deb684d1 authored by Marcel Koch's avatar Marcel Koch
Browse files

only generate jacobian method if the computation is not matrix free

parent 467f2a3e
No related branches found
No related tags found
No related merge requests found
......@@ -826,35 +826,10 @@ def generate_jacobian_kernels(form, original_form):
jacform = offdiagonal_block_jacobian(jacform)
operator_kernels = {}
with global_context(form_type="jacobian"):
if get_form_option("generate_jacobians"):
if get_form_option("sumfact"):
was_sumfact = True
if get_form_option("sumfact_regular_jacobians"):
set_form_option("sumfact", False)
for measure in set(i.integral_type() for i in jacform.integrals()):
logger.info("generate_jacobian_kernels: measure {}".format(measure))
with global_context(integral_type=measure):
from dune.perftool.pdelab.signatures import assembler_routine_name
with global_context(kernel=assembler_routine_name()):
kernel = [k for k in get_backend(interface="generate_kernels_per_integral")(jacform.integrals_by_type(measure))]
operator_kernels[(measure, 'jacobian')] = kernel
# Generate dummy functions for those kernels, that vanished in the differentiation process
# We *could* solve this problem by using lambda_* terms but we do not really want that, so
# we use empty jacobian assembly methods instead
alpha_measures = set(i.integral_type() for i in form.integrals())
jacobian_measures = set(i.integral_type() for i in jacform.integrals())
for it in alpha_measures - jacobian_measures:
with global_context(integral_type=it):
from dune.perftool.pdelab.signatures import assembly_routine_signature
operator_kernels[(it, 'jacobian')] = [LoopyKernelMethod(assembly_routine_signature(), kernel=None)]
if get_form_option("sumfact_regular_jacobians"):
if was_sumfact:
set_form_option("sumfact", True)
# Jacobian apply methods for matrix-free computations
# Decide if the jacobian apply or jacobian method is needed
if get_form_option("matrix_free"):
# Matrix-free computations need the jacobian apply method
# 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)
......@@ -881,6 +856,34 @@ 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
with global_context(form_type="jacobian"):
if get_form_option("generate_jacobians"):
if get_form_option("sumfact"):
was_sumfact = True
if get_form_option("sumfact_regular_jacobians"):
set_form_option("sumfact", False)
for measure in set(i.integral_type() for i in jacform.integrals()):
logger.info("generate_jacobian_kernels: measure {}".format(measure))
with global_context(integral_type=measure):
from dune.perftool.pdelab.signatures import assembler_routine_name
with global_context(kernel=assembler_routine_name()):
kernel = [k for k in get_backend(interface="generate_kernels_per_integral")(jacform.integrals_by_type(measure))]
operator_kernels[(measure, 'jacobian')] = kernel
# Generate dummy functions for those kernels, that vanished in the differentiation process
# We *could* solve this problem by using lambda_* terms but we do not really want that, so
# we use empty jacobian assembly methods instead
alpha_measures = set(i.integral_type() for i in form.integrals())
jacobian_measures = set(i.integral_type() for i in jacform.integrals())
for it in alpha_measures - jacobian_measures:
with global_context(integral_type=it):
from dune.perftool.pdelab.signatures import assembly_routine_signature
operator_kernels[(it, 'jacobian')] = [LoopyKernelMethod(assembly_routine_signature(), kernel=None)]
if get_form_option("sumfact_regular_jacobians"):
if was_sumfact:
set_form_option("sumfact", True)
return operator_kernels
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment