33from itertools import chain
44from finat .physically_mapped import DirectlyDefinedElement , PhysicallyMappedElement
55
6- from numpy import asarray
7-
86import ufl
97from ufl .algorithms import extract_arguments , extract_coefficients
108from ufl .algorithms .analysis import has_type
119from ufl .classes import Form , GeometricQuantity
1210from ufl .log import GREEN
13- from ufl .utils .sequences import max_degree
1411
1512import gem
1613import gem .impero_utils as impero_utils
1714
18- from FIAT .reference_element import TensorProductCell
19-
2015import finat
21- from finat .quadrature import AbstractQuadratureRule , make_quadrature
2216
2317from tsfc import fem , ufl_utils
24- from tsfc .finatinterface import as_fiat_cell
2518from tsfc .logging import logger
2619from tsfc .parameters import default_parameters , is_complex
2720from tsfc .ufl_utils import apply_mapping
@@ -105,7 +98,6 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
10598 :returns: a kernel constructed by the kernel interface
10699 """
107100 parameters = preprocess_parameters (parameters )
108-
109101 if interface is None :
110102 if coffee :
111103 import tsfc .kernel_interface .firedrake as firedrake_interface_coffee
@@ -118,14 +110,12 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
118110 scalar_type = parameters ["scalar_type_c" ]
119111 else :
120112 scalar_type = parameters ["scalar_type" ]
121-
122113 integral_type = integral_data .integral_type
123114 mesh = integral_data .domain
124115 arguments = form_data .preprocessed_form .arguments ()
125116 kernel_name = "%s_%s_integral_%s" % (prefix , integral_type , integral_data .subdomain_id )
126117 # Handle negative subdomain_id
127118 kernel_name = kernel_name .replace ("-" , "_" )
128-
129119 # Dict mapping domains to index in original_form.ufl_domains()
130120 domain_numbering = form_data .original_form .domain_numbering ()
131121 domain_number = domain_numbering [integral_data .domain ]
@@ -145,22 +135,17 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
145135 scalar_type ,
146136 parameters ["scalar_type" ],
147137 diagonal = diagonal )
148-
149138 builder .set_coordinates (mesh )
150139 builder .set_cell_sizes (mesh )
151-
152140 builder .set_coefficients (integral_data , form_data )
153-
154141 ctx = builder .create_context ()
155142 for integral in integral_data .integrals :
156143 params = parameters .copy ()
157144 params .update (integral .metadata ()) # integral metadata overrides
158-
159145 integrand = ufl .replace (integral .integrand (), form_data .function_replace_map )
160146 integrand_exprs = builder .compile_ufl (integrand , params , ctx )
161147 integral_exprs = builder .construct_integrals (integrand_exprs , params )
162148 builder .stash_integrals (integral_exprs , params , ctx )
163-
164149 return builder .construct_kernel (kernel_name , ctx )
165150
166151
@@ -342,107 +327,3 @@ def __call__(self, ps):
342327 assert set (gem_expr .free_indices ) <= set (chain (ps .indices , * argument_multiindices ))
343328
344329 return gem_expr
345-
346-
347- def set_quad_rule (params , cell , integral_type , functions ):
348- # Check if the integral has a quad degree attached, otherwise use
349- # the estimated polynomial degree attached by compute_form_data
350- try :
351- quadrature_degree = params ["quadrature_degree" ]
352- except KeyError :
353- quadrature_degree = params ["estimated_polynomial_degree" ]
354- function_degrees = [f .ufl_function_space ().ufl_element ().degree () for f in functions ]
355- if all ((asarray (quadrature_degree ) > 10 * asarray (degree )).all ()
356- for degree in function_degrees ):
357- logger .warning ("Estimated quadrature degree %s more "
358- "than tenfold greater than any "
359- "argument/coefficient degree (max %s)" ,
360- quadrature_degree , max_degree (function_degrees ))
361- if params .get ("quadrature_rule" ) == "default" :
362- del params ["quadrature_rule" ]
363- try :
364- quad_rule = params ["quadrature_rule" ]
365- except KeyError :
366- fiat_cell = as_fiat_cell (cell )
367- integration_dim , _ = lower_integral_type (fiat_cell , integral_type )
368- integration_cell = fiat_cell .construct_subelement (integration_dim )
369- quad_rule = make_quadrature (integration_cell , quadrature_degree )
370- params ["quadrature_rule" ] = quad_rule
371-
372- if not isinstance (quad_rule , AbstractQuadratureRule ):
373- raise ValueError ("Expected to find a QuadratureRule object, not a %s" %
374- type (quad_rule ))
375-
376-
377- def get_index_ordering (quadrature_indices , return_variables ):
378- split_argument_indices = tuple (chain (* [var .index_ordering ()
379- for var in return_variables ]))
380- return tuple (quadrature_indices ) + split_argument_indices
381-
382-
383- def lower_integral_type (fiat_cell , integral_type ):
384- """Lower integral type into the dimension of the integration
385- subentity and a list of entity numbers for that dimension.
386-
387- :arg fiat_cell: FIAT reference cell
388- :arg integral_type: integral type (string)
389- """
390- vert_facet_types = ['exterior_facet_vert' , 'interior_facet_vert' ]
391- horiz_facet_types = ['exterior_facet_bottom' , 'exterior_facet_top' , 'interior_facet_horiz' ]
392-
393- dim = fiat_cell .get_dimension ()
394- if integral_type == 'cell' :
395- integration_dim = dim
396- elif integral_type in ['exterior_facet' , 'interior_facet' ]:
397- if isinstance (fiat_cell , TensorProductCell ):
398- raise ValueError ("{} integral cannot be used with a TensorProductCell; need to distinguish between vertical and horizontal contributions." .format (integral_type ))
399- integration_dim = dim - 1
400- elif integral_type == 'vertex' :
401- integration_dim = 0
402- elif integral_type in vert_facet_types + horiz_facet_types :
403- # Extrusion case
404- if not isinstance (fiat_cell , TensorProductCell ):
405- raise ValueError ("{} integral requires a TensorProductCell." .format (integral_type ))
406- basedim , extrdim = dim
407- assert extrdim == 1
408-
409- if integral_type in vert_facet_types :
410- integration_dim = (basedim - 1 , 1 )
411- elif integral_type in horiz_facet_types :
412- integration_dim = (basedim , 0 )
413- else :
414- raise NotImplementedError ("integral type %s not supported" % integral_type )
415-
416- if integral_type == 'exterior_facet_bottom' :
417- entity_ids = [0 ]
418- elif integral_type == 'exterior_facet_top' :
419- entity_ids = [1 ]
420- else :
421- entity_ids = list (range (len (fiat_cell .get_topology ()[integration_dim ])))
422-
423- return integration_dim , entity_ids
424-
425-
426- def pick_mode (mode ):
427- "Return one of the specialized optimisation modules from a mode string."
428- try :
429- from firedrake_citations import Citations
430- cites = {"vanilla" : ("Homolya2017" , ),
431- "coffee" : ("Luporini2016" , "Homolya2017" , ),
432- "spectral" : ("Luporini2016" , "Homolya2017" , "Homolya2017a" ),
433- "tensor" : ("Kirby2006" , "Homolya2017" , )}
434- for c in cites [mode ]:
435- Citations ().register (c )
436- except ImportError :
437- pass
438- if mode == "vanilla" :
439- import tsfc .vanilla as m
440- elif mode == "coffee" :
441- import tsfc .coffee_mode as m
442- elif mode == "spectral" :
443- import tsfc .spectral as m
444- elif mode == "tensor" :
445- import tsfc .tensor as m
446- else :
447- raise ValueError ("Unknown mode: {}" .format (mode ))
448- return m
0 commit comments