def _sorted_integrals(integrals): """Sort integrals by domain id, integral type, subdomain id for a more stable signature computation.""" # Group integrals in multilevel dict by keys # [domain][integral_type][subdomain_id] integrals_dict = defaultdict(lambda: defaultdict(lambda: defaultdict(list))) for integral in integrals: d = integral.ufl_domain() if d is None: error("Each integral in a form must have a uniquely defined integration domain.") it = integral.integral_type() si = integral.subdomain_id() integrals_dict[d][it][si] += [integral] all_integrals = [] # Order integrals canonically to increase signature stability for d in sort_domains(integrals_dict): for it in sorted(integrals_dict[d]): # str is sortable for si in sorted(integrals_dict[d][it], key=lambda x: (type(x).__name__, x)): # int/str are sortable unsorted_integrals = integrals_dict[d][it][si] # TODO: At this point we could order integrals by # metadata and integrand, or even add the # integrands with the same metadata. This is # done in # accumulate_integrands_with_same_metadata in # algorithms/domain_analysis.py and would # further increase the signature stability. all_integrals.extend(unsorted_integrals) # integrals_dict[d][it][si] = unsorted_integrals return tuple(all_integrals) # integrals_dict
def _analyze_domains(self): from ufl.domain import join_domains, sort_domains # Collect unique integration domains integration_domains = join_domains([itg.ufl_domain() for itg in self._integrals]) # Make canonically ordered list of the domains self._integration_domains = sort_domains(integration_domains) # TODO: Not including domains from coefficients and arguments # here, may need that later self._domain_numbering = dict((d, i) for i, d in enumerate(self._integration_domains))
def _analyze_domains(self): from ufl.domain import join_domains, sort_domains # Collect unique integration domains integration_domains = join_domains( [itg.ufl_domain() for itg in self._integrals]) # Make canonically ordered list of the domains self._integration_domains = sort_domains(integration_domains) # TODO: Not including domains from coefficients and arguments # here, may need that later self._domain_numbering = dict( (d, i) for i, d in enumerate(self._integration_domains))
def _sorted_integrals(integrals): """Sort integrals by domain id, integral type, subdomain id for a more stable signature computation.""" # Group integrals in multilevel dict by keys # [domain][integral_type][subdomain_id] integrals_dict = defaultdict( lambda: defaultdict(lambda: defaultdict(list))) for integral in integrals: d = integral.ufl_domain() if d is None: error( "Each integral in a form must have a uniquely defined integration domain." ) it = integral.integral_type() si = integral.subdomain_id() integrals_dict[d][it][si] += [integral] all_integrals = [] # Order integrals canonically to increase signature stability for d in sort_domains(integrals_dict): for it in sorted(integrals_dict[d]): # str is sortable for si in sorted(integrals_dict[d][it], key=lambda x: (type(x).__name__, x)): # int/str are sortable unsorted_integrals = integrals_dict[d][it][si] # TODO: At this point we could order integrals by # metadata and integrand, or even add the # integrands with the same metadata. This is # done in # accumulate_integrands_with_same_metadata in # algorithms/domain_analysis.py and would # further increase the signature stability. all_integrals.extend(unsorted_integrals) # integrals_dict[d][it][si] = unsorted_integrals return tuple(all_integrals) # integrals_dict