22import sys
33from itertools import chain
44
5- from numpy import asarray
6-
75import ufl
86from ufl .algorithms import extract_arguments , extract_coefficients
97from ufl .algorithms .analysis import has_type
108from ufl .classes import Form , GeometricQuantity
119from ufl .log import GREEN
12- from ufl .utils .sequences import max_degree
1310
1411import gem
1512import gem .impero_utils as impero_utils
1613
17- from FIAT .reference_element import TensorProductCell
18-
1914import finat
20- from finat .quadrature import AbstractQuadratureRule , make_quadrature
2115
2216from tsfc import fem , ufl_utils
23- from tsfc .finatinterface import as_fiat_cell
2417from tsfc .logging import logger
2518from tsfc .parameters import default_parameters , is_complex
2619from tsfc .ufl_utils import apply_mapping
@@ -104,7 +97,6 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
10497 :returns: a kernel constructed by the kernel interface
10598 """
10699 parameters = preprocess_parameters (parameters )
107-
108100 if interface is None :
109101 if coffee :
110102 import tsfc .kernel_interface .firedrake as firedrake_interface_coffee
@@ -117,14 +109,12 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
117109 scalar_type = parameters ["scalar_type_c" ]
118110 else :
119111 scalar_type = parameters ["scalar_type" ]
120-
121112 integral_type = integral_data .integral_type
122113 mesh = integral_data .domain
123114 arguments = form_data .preprocessed_form .arguments ()
124115 kernel_name = "%s_%s_integral_%s" % (prefix , integral_type , integral_data .subdomain_id )
125116 # Handle negative subdomain_id
126117 kernel_name = kernel_name .replace ("-" , "_" )
127-
128118 # Dict mapping domains to index in original_form.ufl_domains()
129119 domain_numbering = form_data .original_form .domain_numbering ()
130120 domain_number = domain_numbering [integral_data .domain ]
@@ -144,22 +134,17 @@ def compile_integral(integral_data, form_data, prefix, parameters, interface, co
144134 scalar_type ,
145135 parameters ["scalar_type" ],
146136 diagonal = diagonal )
147-
148137 builder .set_coordinates (mesh )
149138 builder .set_cell_sizes (mesh )
150-
151139 builder .set_coefficients (integral_data , form_data )
152-
153140 ctx = builder .create_context ()
154141 for integral in integral_data .integrals :
155142 params = parameters .copy ()
156143 params .update (integral .metadata ()) # integral metadata overrides
157-
158144 integrand = ufl .replace (integral .integrand (), form_data .function_replace_map )
159145 integrand_exprs = builder .compile_ufl (integrand , params , ctx )
160146 integral_exprs = builder .construct_integrals (integrand_exprs , params )
161147 builder .stash_integrals (integral_exprs , params , ctx )
162-
163148 return builder .construct_kernel (kernel_name , ctx )
164149
165150
@@ -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