def __init__(self, form, name, parameters, number_map): """A wrapper object for one or more TSFC kernels compiled from a given :class:`~ufl.classes.Form`. :arg form: the :class:`~ufl.classes.Form` from which to compile the kernels. :arg name: a prefix to be applied to the compiled kernel names. This is primarily useful for debugging. :arg parameters: a dict of parameters to pass to the form compiler. :arg number_map: a map from local coefficient numbers to global ones (useful for split forms). """ if self._initialized: return tree = tsfc_compile_form(form, prefix=name, parameters=parameters) kernels = [] for kernel in tree: # Set optimization options opts = default_parameters["coffee"] ast = kernel.ast ast = ast if not parameters.get("assemble_inverse", False) else _inverse(ast) # Unwind coefficient numbering numbers = tuple(number_map[c] for c in kernel.coefficient_numbers) kernels.append( KernelInfo(kernel=Kernel(ast, ast.name, opts=opts), integral_type=kernel.integral_type, oriented=kernel.oriented, subdomain_id=kernel.subdomain_id, domain_number=kernel.domain_number, coefficient_map=numbers, needs_cell_facets=False, pass_layer_arg=False, needs_cell_sizes=kernel.needs_cell_sizes)) self.kernels = tuple(kernels) self._initialized = True
def __init__(self, form, name, parameters, number_map, interface, coffee=False, diagonal=False): """A wrapper object for one or more TSFC kernels compiled from a given :class:`~ufl.classes.Form`. :arg form: the :class:`~ufl.classes.Form` from which to compile the kernels. :arg name: a prefix to be applied to the compiled kernel names. This is primarily useful for debugging. :arg parameters: a dict of parameters to pass to the form compiler. :arg number_map: a map from local coefficient numbers to the split global coefficient numbers. :arg interface: the KernelBuilder interface for TSFC (may be None) """ if self._initialized: return tree = tsfc_compile_form(form, prefix=name, parameters=parameters, interface=interface, coffee=coffee, diagonal=diagonal) kernels = [] for kernel in tree: # Set optimization options opts = default_parameters["coffee"] ast = kernel.ast # Unwind coefficient numbering numbers = tuple(number_map[c] for c in kernel.coefficient_numbers) kernels.append(KernelInfo(kernel=Kernel(ast, kernel.name, opts=opts, requires_zeroed_output_arguments=True, flop_count=kernel.flop_count), integral_type=kernel.integral_type, oriented=kernel.oriented, subdomain_id=kernel.subdomain_id, domain_number=kernel.domain_number, coefficient_map=numbers, needs_cell_facets=False, pass_layer_arg=False, needs_cell_sizes=kernel.needs_cell_sizes)) self.kernels = tuple(kernels) self._initialized = True
def __init__(self, form, name, parameters): """A wrapper object for one or more FFC kernels compiled from a given :class:`~ufl.classes.Form`. :arg form: the :class:`~ufl.classes.Form` from which to compile the kernels. :arg name: a prefix to be applied to the compiled kernel names. This is primarily useful for debugging. :arg parameters: a dict of parameters to pass to the form compiler. """ if self._initialized: return incl = [PreprocessNode('#include "firedrake_geometry.h"\n')] inc = [path.dirname(__file__)] try: ffc_tree = ffc_compile_form(form, prefix=name, parameters=parameters) if len(ffc_tree) == 0: raise EmptyIntegrandError kernels = [] # need compute_form_data here to get preproc form integrals fd = compute_form_data(form) elements = fd.unique_elements needs_orientations = self._needs_orientations(elements) for it, kernel in zip(fd.preprocessed_form.integrals(), ffc_tree): # Set optimization options opts = default_parameters["coffee"] _kernel = kernel if not parameters.get( "assemble_inverse", False) else _inverse(kernel) kernels.append((Kernel( Root(incl + [_kernel]), '%s_%s_integral_0_%s' % (name, it.integral_type(), it.subdomain_id()), opts, inc), needs_orientations)) self.kernels = tuple(kernels) self._empty = False except EmptyIntegrandError: # FFC noticed that the integrand was zero and simplified # it, catch this here and set a flag telling us to ignore # the kernel when returning it in compile_form self._empty = True self._initialized = True
f = 0.5f*(vol1* q1[1] + p1*dy + vol2* qinf[1] + p2*dy) + mu*(q1[1]-qinf[1]); res1[1] += f; f = 0.5f*(vol1* q1[2] - p1*dx + vol2* qinf[2] - p2*dx) + mu*(q1[2]-qinf[2]); res1[2] += f; f = 0.5f*(vol1*(q1[3]+p1) + vol2*(qinf[3]+p2) ) + mu*(q1[3]-qinf[3]); res1[3] += f; } } """ update_code = """ void update(double *qold, double *q, double *res, double *adt, double *rms){ double del, adti; adti = 1.0f/(*adt); for (int n=0; n<4; n++) { del = adti*res[n]; q[n] = qold[n] - del; res[n] = 0.0f; *rms += del*del; } } """ save_soln = Kernel(save_soln_code, "save_soln") adt_calc = Kernel(adt_calc_code, "adt_calc") res_calc = Kernel(res_calc_code, "res_calc") bres_calc = Kernel(bres_calc_code, "bres_calc") update = Kernel(update_code, "update")
*rms += (*u)*(*u); }""" updateP_code = """ void updateP(double *r, double *p, const double *beta){ *p = (*beta)*(*p)+(*r); }""" updateUR_code = """ void updateUR(double *u, double *r, double *p, double *v, const double *alpha){ *u += (*alpha)*(*p); *r -= (*alpha)*(*v); *v = 0.0f; }""" dirichlet = Kernel(dirichlet_code, 'dirichlet') dotPV = Kernel(dotPV_code, 'dotPV') dotR = Kernel(dotR_code, 'dotR') init_cg = Kernel(init_cg_code, 'init_cg') res_calc = Kernel(res_calc_code, 'res_calc') spMV = Kernel(spMV_code, 'spMV') update = Kernel(update_code, 'update') updateP = Kernel(updateP_code, 'updateP')