def ufl_domains(self): """Returns the integration domains of the integrals associated with the tensor. """ collected_domains = [obj.ufl_domains() for obj in self.operands + self.actee] return join_domains(chain(*collected_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 _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 par_loop(kernel, measure, args, **kwargs): """A :func:`par_loop` is a user-defined operation which reads and writes :class:`.Function`\s by looping over the mesh cells or facets and accessing the degrees of freedom on adjacent entities. :arg kernel: is a string containing the C code to be executed. :arg measure: is a UFL :class:`~ufl.measure.Measure` which determines the manner in which the iteration over the mesh is to occur. Alternatively, you can pass :data:`direct` to designate a direct loop. :arg args: is a dictionary mapping variable names in the kernel to :class:`.Function`\s or components of mixed :class:`.Function`\s and indicates how these :class:`.Function`\s are to be accessed. :arg kwargs: additional keyword arguments are passed to the :class:`~pyop2.op2.Kernel` constructor **Example** Assume that `A` is a :class:`.Function` in CG1 and `B` is a :class:`.Function` in DG0. Then the following code sets each DoF in `A` to the maximum value that `B` attains in the cells adjacent to that DoF:: A.assign(numpy.finfo(0.).min) par_loop('for (int i=0; i<A.dofs; i++) A[i][0] = fmax(A[i][0], B[0][0]);', dx, {'A' : (A, RW), 'B': (B, READ)}) **Argument definitions** Each item in the `args` dictionary maps a string to a tuple containing a :class:`.Function` or :class:`.Constant` and an argument intent. The string is the c language variable name by which this function will be accessed in the kernel. The argument intent indicates how the kernel will access this variable: `READ` The variable will be read but not written to. `WRITE` The variable will be written to but not read. If multiple kernel invocations write to the same DoF, then the order of these writes is undefined. `RW` The variable will be both read and written to. If multiple kernel invocations access the same DoF, then the order of these accesses is undefined, but it is guaranteed that no race will occur. `INC` The variable will be added into using +=. As before, the order in which the kernel invocations increment the variable is undefined, but there is a guarantee that no races will occur. .. note:: Only `READ` intents are valid for :class:`.Constant` coefficients, and an error will be raised in other cases. **The measure** The measure determines the mesh entities over which the iteration will occur, and the size of the kernel stencil. The iteration will occur over the same mesh entities as if the measure had been used to define an integral, and the stencil will likewise be the same as the integral case. That is to say, if the measure is a volume measure, the kernel will be called once per cell and the DoFs accessible to the kernel will be those associated with the cell, its facets, edges and vertices. If the measure is a facet measure then the iteration will occur over the corresponding class of facets and the accessible DoFs will be those on the cell(s) adjacent to the facet, and on the facets, edges and vertices adjacent to those facets. For volume measures the DoFs are guaranteed to be in the FIAT local DoFs order. For facet measures, the DoFs will be in sorted first by the cell to which they are adjacent. Within each cell, they will be in FIAT order. Note that if a continuous :class:`.Function` is accessed via an internal facet measure, the DoFs on the interface between the two facets will be accessible twice: once via each cell. The orientation of the cell(s) relative to the current facet is currently arbitrary. A direct loop over nodes without any indirections can be specified by passing :data:`direct` as the measure. In this case, all of the arguments must be :class:`.Function`\s in the same :class:`.FunctionSpace`. **The kernel code** The kernel code is plain C in which the variables specified in the `args` dictionary are available to be read or written in according to the argument intent specified. Most basic C operations are permitted. However there are some restrictions: * Only functions from `math.h <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/math.h.html>`_ may be called. * Pointer operations other than dereferencing arrays are prohibited. Indirect free variables referencing :class:`.Function`\s are all of type `double**` in which the first index is the local node number, while the second index is the vector (or tensor) component. The latter only applies to :class:`.Function`\s over a :class:`.FunctionSpace` with :attr:`.FunctionSpace.rank` greater than zero (spaces with a VectorElement or TensorElement). In the case of scalar :class:`FunctionSpace`\s, the second index is always 0. In a direct :func:`par_loop`, the variables will all be of type `double*` with the single index being the vector component. :class:`.Constant`\s are always of type `double*`, both for indirect and direct :func:`par_loop` calls. """ _map = _maps[measure.integral_type()] # Ensure that the dict args passed in are consistently ordered # (sorted by the string key). sorted_args = collections.OrderedDict() for k in sorted(args.iterkeys()): sorted_args[k] = args[k] args = sorted_args if measure is direct: mesh = None for (func, intent) in args.itervalues(): if isinstance(func, Indexed): c, i = func.ufl_operands idx = i._indices[0]._value if mesh and c.node_set[idx] is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = c.node_set[idx] else: try: if mesh and func.node_set is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = func.node_set except AttributeError: # Argument was a Global. pass if not mesh: raise TypeError("No Functions passed to direct par_loop") else: domains = [] for func, _ in args.itervalues(): domains.extend(func.ufl_domains()) domains = join_domains(domains) # Assume only one domain domain, = domains mesh = domain op2args = [_form_kernel(kernel, measure, args, **kwargs)] op2args.append(_map['itspace'](mesh, measure)) def mkarg(f, intent): if isinstance(func, Indexed): c, i = func.ufl_operands idx = i._indices[0]._value m = _map['nodes'](c) return c.dat[idx](intent, m.split[idx] if m else None) return f.dat(intent, _map['nodes'](f)) op2args += [mkarg(func, intent) for (func, intent) in args.itervalues()] return pyop2.par_loop(*op2args)
def par_loop(kernel, measure, args, **kwargs): """A :func:`par_loop` is a user-defined operation which reads and writes :class:`.Function`\s by looping over the mesh cells or facets and accessing the degrees of freedom on adjacent entities. :arg kernel: is a string containing the C code to be executed. :arg measure: is a UFL :class:`~ufl.measure.Measure` which determines the manner in which the iteration over the mesh is to occur. Alternatively, you can pass :data:`direct` to designate a direct loop. :arg args: is a dictionary mapping variable names in the kernel to :class:`.Function`\s or components of mixed :class:`.Function`\s and indicates how these :class:`.Function`\s are to be accessed. :arg kwargs: additional keyword arguments are passed to the :class:`~pyop2.op2.Kernel` constructor **Example** Assume that `A` is a :class:`.Function` in CG1 and `B` is a :class:`.Function` in DG0. Then the following code sets each DoF in `A` to the maximum value that `B` attains in the cells adjacent to that DoF:: A.assign(numpy.finfo(0.).min) par_loop('for (int i=0; i<A.dofs; i++) A[i][0] = fmax(A[i][0], B[0][0]);', dx, {'A' : (A, RW), 'B': (B, READ)}) **Argument definitions** Each item in the `args` dictionary maps a string to a tuple containing a :class:`.Function` or :class:`.Constant` and an argument intent. The string is the c language variable name by which this function will be accessed in the kernel. The argument intent indicates how the kernel will access this variable: `READ` The variable will be read but not written to. `WRITE` The variable will be written to but not read. If multiple kernel invocations write to the same DoF, then the order of these writes is undefined. `RW` The variable will be both read and written to. If multiple kernel invocations access the same DoF, then the order of these accesses is undefined, but it is guaranteed that no race will occur. `INC` The variable will be added into using +=. As before, the order in which the kernel invocations increment the variable is undefined, but there is a guarantee that no races will occur. .. note:: Only `READ` intents are valid for :class:`.Constant` coefficients, and an error will be raised in other cases. **The measure** The measure determines the mesh entities over which the iteration will occur, and the size of the kernel stencil. The iteration will occur over the same mesh entities as if the measure had been used to define an integral, and the stencil will likewise be the same as the integral case. That is to say, if the measure is a volume measure, the kernel will be called once per cell and the DoFs accessible to the kernel will be those associated with the cell, its facets, edges and vertices. If the measure is a facet measure then the iteration will occur over the corresponding class of facets and the accessible DoFs will be those on the cell(s) adjacent to the facet, and on the facets, edges and vertices adjacent to those facets. For volume measures the DoFs are guaranteed to be in the FInAT local DoFs order. For facet measures, the DoFs will be in sorted first by the cell to which they are adjacent. Within each cell, they will be in FInAT order. Note that if a continuous :class:`.Function` is accessed via an internal facet measure, the DoFs on the interface between the two facets will be accessible twice: once via each cell. The orientation of the cell(s) relative to the current facet is currently arbitrary. A direct loop over nodes without any indirections can be specified by passing :data:`direct` as the measure. In this case, all of the arguments must be :class:`.Function`\s in the same :class:`.FunctionSpace`. **The kernel code** The kernel code is plain C in which the variables specified in the `args` dictionary are available to be read or written in according to the argument intent specified. Most basic C operations are permitted. However there are some restrictions: * Only functions from `math.h <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/math.h.html>`_ may be called. * Pointer operations other than dereferencing arrays are prohibited. Indirect free variables referencing :class:`.Function`\s are all of type `double**` in which the first index is the local node number, while the second index is the vector (or tensor) component. The latter only applies to :class:`.Function`\s over a :class:`.FunctionSpace` with :attr:`.FunctionSpace.rank` greater than zero (spaces with a VectorElement or TensorElement). In the case of scalar :class:`FunctionSpace`\s, the second index is always 0. In a direct :func:`par_loop`, the variables will all be of type `double*` with the single index being the vector component. :class:`.Constant`\s are always of type `double*`, both for indirect and direct :func:`par_loop` calls. """ _map = _maps[measure.integral_type()] # Ensure that the dict args passed in are consistently ordered # (sorted by the string key). sorted_args = collections.OrderedDict() for k in sorted(args.iterkeys()): sorted_args[k] = args[k] args = sorted_args if measure is direct: mesh = None for (func, intent) in args.itervalues(): if isinstance(func, Indexed): c, i = func.ufl_operands idx = i._indices[0]._value if mesh and c.node_set[idx] is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = c.node_set[idx] else: try: if mesh and func.node_set is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = func.node_set except AttributeError: # Argument was a Global. pass if not mesh: raise TypeError("No Functions passed to direct par_loop") else: domains = [] for func, _ in args.itervalues(): domains.extend(func.ufl_domains()) domains = join_domains(domains) # Assume only one domain domain, = domains mesh = domain op2args = [_form_kernel(kernel, measure, args, **kwargs)] op2args.append(_map['itspace'](mesh, measure)) def mkarg(f, intent): if isinstance(func, Indexed): c, i = func.ufl_operands idx = i._indices[0]._value m = _map['nodes'](c) return c.dat[idx](intent, m.split[idx] if m else None) return f.dat(intent, _map['nodes'](f)) op2args += [mkarg(func, intent) for (func, intent) in args.itervalues()] return pyop2.par_loop(*op2args)
def par_loop(kernel, measure, args, kernel_kwargs=None, is_loopy_kernel=False, **kwargs): r"""A :func:`par_loop` is a user-defined operation which reads and writes :class:`.Function`\s by looping over the mesh cells or facets and accessing the degrees of freedom on adjacent entities. :arg kernel: a string containing the C code to be executed. Or a 2-tuple of (domains, instructions) to create a loopy kernel (must also set ``is_loopy_kernel=True``). If loopy syntax is used, the domains and instructions should be specified in loopy kernel syntax. See the `loopy tutorial <https://documen.tician.de/loopy/tutorial.html>`_ for details. :arg measure: is a UFL :class:`~ufl.measure.Measure` which determines the manner in which the iteration over the mesh is to occur. Alternatively, you can pass :data:`direct` to designate a direct loop. :arg args: is a dictionary mapping variable names in the kernel to :class:`.Function`\s or components of mixed :class:`.Function`\s and indicates how these :class:`.Function`\s are to be accessed. :arg kernel_kwargs: keyword arguments to be passed to the :class:`~pyop2.op2.Kernel` constructor :arg kwargs: additional keyword arguments are passed to the underlying :class:`~pyop2.par_loop` :kwarg iterate: Optionally specify which region of an :class:`ExtrudedSet` to iterate over. Valid values are the following objects from pyop2: - ``ON_BOTTOM``: iterate over the bottom layer of cells. - ``ON_TOP`` iterate over the top layer of cells. - ``ALL`` iterate over all cells (the default if unspecified) - ``ON_INTERIOR_FACETS`` iterate over all the layers except the top layer, accessing data two adjacent (in the extruded direction) cells at a time. **Example** Assume that `A` is a :class:`.Function` in CG1 and `B` is a :class:`.Function` in DG0. Then the following code sets each DoF in `A` to the maximum value that `B` attains in the cells adjacent to that DoF:: A.assign(numpy.finfo(0.).min) par_loop('for (int i=0; i<A.dofs; i++) A[i] = fmax(A[i], B[0]);', dx, {'A' : (A, RW), 'B': (B, READ)}) The equivalent using loopy kernel syntax is:: domain = '{[i]: 0 <= i < A.dofs}' instructions = ''' for i A[i] = max(A[i], B[0]) end ''' par_loop((domain, instructions), dx, {'A' : (A, RW), 'B': (B, READ)}, is_loopy_kernel=True) **Argument definitions** Each item in the `args` dictionary maps a string to a tuple containing a :class:`.Function` or :class:`.Constant` and an argument intent. The string is the c language variable name by which this function will be accessed in the kernel. The argument intent indicates how the kernel will access this variable: `READ` The variable will be read but not written to. `WRITE` The variable will be written to but not read. If multiple kernel invocations write to the same DoF, then the order of these writes is undefined. `RW` The variable will be both read and written to. If multiple kernel invocations access the same DoF, then the order of these accesses is undefined, but it is guaranteed that no race will occur. `INC` The variable will be added into using +=. As before, the order in which the kernel invocations increment the variable is undefined, but there is a guarantee that no races will occur. .. note:: Only `READ` intents are valid for :class:`.Constant` coefficients, and an error will be raised in other cases. **The measure** The measure determines the mesh entities over which the iteration will occur, and the size of the kernel stencil. The iteration will occur over the same mesh entities as if the measure had been used to define an integral, and the stencil will likewise be the same as the integral case. That is to say, if the measure is a volume measure, the kernel will be called once per cell and the DoFs accessible to the kernel will be those associated with the cell, its facets, edges and vertices. If the measure is a facet measure then the iteration will occur over the corresponding class of facets and the accessible DoFs will be those on the cell(s) adjacent to the facet, and on the facets, edges and vertices adjacent to those facets. For volume measures the DoFs are guaranteed to be in the FInAT local DoFs order. For facet measures, the DoFs will be in sorted first by the cell to which they are adjacent. Within each cell, they will be in FInAT order. Note that if a continuous :class:`.Function` is accessed via an internal facet measure, the DoFs on the interface between the two facets will be accessible twice: once via each cell. The orientation of the cell(s) relative to the current facet is currently arbitrary. A direct loop over nodes without any indirections can be specified by passing :data:`direct` as the measure. In this case, all of the arguments must be :class:`.Function`\s in the same :class:`.FunctionSpace`. **The kernel code** The kernel code is plain C in which the variables specified in the `args` dictionary are available to be read or written in according to the argument intent specified. Most basic C operations are permitted. However there are some restrictions: * Only functions from `math.h <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/math.h.html>`_ may be called. * Pointer operations other than dereferencing arrays are prohibited. Indirect free variables referencing :class:`.Function`\s are all of type `double*`. For spaces with rank greater than zero (Vector or TensorElement), the data are laid out XYZ... XYZ... XYZ.... With the vector/tensor component moving fastest. In loopy syntax, these may be addressed using 2D indexing:: A[i, j] Where ``i`` runs over nodes, and ``j`` runs over components. In a direct :func:`par_loop`, the variables will all be of type `double*` with the single index being the vector component. :class:`.Constant`\s are always of type `double*`, both for indirect and direct :func:`par_loop` calls. """ if kernel_kwargs is None: kernel_kwargs = {} _map = _maps[measure.integral_type()] # Ensure that the dict args passed in are consistently ordered # (sorted by the string key). sorted_args = collections.OrderedDict() for k in sorted(args.keys()): sorted_args[k] = args[k] args = sorted_args if measure is direct: mesh = None for (func, intent) in args.values(): if isinstance(func, Indexed): c, i = func.ufl_operands idx = i._indices[0]._value if mesh and c.node_set[idx] is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = c.node_set[idx] else: try: if mesh and func.node_set is not mesh: raise ValueError("Cannot mix sets in direct loop.") mesh = func.node_set except AttributeError: # Argument was a Global. pass if not mesh: raise TypeError("No Functions passed to direct par_loop") else: domains = [] for func, _ in args.values(): domains.extend(func.ufl_domains()) domains = join_domains(domains) # Assume only one domain domain, = domains mesh = domain if is_loopy_kernel: kernel_domains, instructions = kernel op2args = [_form_loopy_kernel(kernel_domains, instructions, measure, args, **kernel_kwargs)] else: op2args = [_form_string_kernel(kernel, measure, args, **kernel_kwargs)] op2args.append(_map['itspace'](mesh, measure)) def mkarg(f, intent): if isinstance(f, Indexed): c, i = f.ufl_operands idx = i._indices[0]._value m = _map['nodes'](c) return c.dat[idx](intent, m.split[idx] if m else None) return f.dat(intent, _map['nodes'](f)) op2args += [mkarg(func, intent) for (func, intent) in args.values()] return pyop2.par_loop(*op2args, **kwargs)
def ufl_domains(self): """Returns the integration domains of the integrals associated with the tensor. """ A, B = self.tensors return join_domains(A.ufl_domains() + B.ufl_domains())
def ufl_domains(self): "Return ufl domains." domainlist = [] for s in self._ufl_function_spaces: domainlist.extend(s.ufl_domains()) return join_domains(domainlist)
def ufl_domains(self): """Returns the integration domains of the integrals associated with the tensor. """ collected_domains = [op.ufl_domains() for op in self.operands] return join_domains(chain(*collected_domains))
def test_join_domains(): from ufl.domain import join_domains mesh7 = MockMesh(7) mesh8 = MockMesh(8) triangle3 = Cell("triangle", geometric_dimension=3) xa = VectorElement("CG", triangle, 1) xb = VectorElement("CG", triangle, 1) # Equal domains are joined assert 1 == len(join_domains([Mesh(triangle, ufl_id=7), Mesh(triangle, ufl_id=7)])) assert 1 == len(join_domains([Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle, ufl_id=7, cargo=mesh7)])) assert 1 == len(join_domains([Mesh(xa, ufl_id=3), Mesh(xa, ufl_id=3)])) # Different domains are not joined assert 2 == len(join_domains([Mesh(triangle), Mesh(triangle)])) assert 2 == len(join_domains([Mesh(triangle, ufl_id=7), Mesh(triangle, ufl_id=8)])) assert 2 == len(join_domains([Mesh(triangle, ufl_id=7), Mesh(quadrilateral, ufl_id=8)])) assert 2 == len(join_domains([Mesh(xa, ufl_id=7), Mesh(xa, ufl_id=8)])) assert 2 == len(join_domains([Mesh(xa), Mesh(xb)])) # Incompatible cells require labeling # self.assertRaises(UFLException, lambda: join_domains([Mesh(triangle), Mesh(triangle3)])) # FIXME: Figure out # self.assertRaises(UFLException, lambda: join_domains([Mesh(triangle), # Mesh(quadrilateral)])) # FIXME: Figure out # Incompatible coordinates require labeling xc = Coefficient(FunctionSpace(Mesh(triangle), VectorElement("CG", triangle, 1))) xd = Coefficient(FunctionSpace(Mesh(triangle), VectorElement("CG", triangle, 1))) with pytest.raises(UFLException): join_domains([Mesh(xc), Mesh(xd)]) # Incompatible data is checked if and only if the domains are the same assert 2 == len(join_domains([Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle, ufl_id=8, cargo=mesh8)])) assert 2 == len(join_domains([Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(quadrilateral, ufl_id=8, cargo=mesh8)])) # Geometric dimensions must match with pytest.raises(UFLException): join_domains([Mesh(triangle), Mesh(triangle3)]) with pytest.raises(UFLException): join_domains([Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle3, ufl_id=8, cargo=mesh8)]) # Cargo and mesh ids must match with pytest.raises(UFLException): Mesh(triangle, ufl_id=7, cargo=mesh8) # Nones are removed assert 2 == len(join_domains([None, Mesh(triangle, ufl_id=3), None, Mesh(triangle, ufl_id=3), None, Mesh(triangle, ufl_id=4)])) assert 2 == len(join_domains([Mesh(triangle, ufl_id=7), None, Mesh(quadrilateral, ufl_id=8)])) assert None not in join_domains([Mesh(triangle3, ufl_id=7), None, Mesh(tetrahedron, ufl_id=8)])
def test_join_domains(): from ufl.domain import join_domains mesh7 = MockMesh(7) mesh8 = MockMesh(8) triangle3 = Cell("triangle", geometric_dimension=3) xa = VectorElement("CG", triangle, 1) xb = VectorElement("CG", triangle, 1) # Equal domains are joined assert 1 == len( join_domains([Mesh(triangle, ufl_id=7), Mesh(triangle, ufl_id=7)])) assert 1 == len( join_domains([ Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle, ufl_id=7, cargo=mesh7) ])) assert 1 == len(join_domains([Mesh(xa, ufl_id=3), Mesh(xa, ufl_id=3)])) # Different domains are not joined assert 2 == len(join_domains([Mesh(triangle), Mesh(triangle)])) assert 2 == len( join_domains([Mesh(triangle, ufl_id=7), Mesh(triangle, ufl_id=8)])) assert 2 == len( join_domains([Mesh(triangle, ufl_id=7), Mesh(quadrilateral, ufl_id=8)])) assert 2 == len(join_domains([Mesh(xa, ufl_id=7), Mesh(xa, ufl_id=8)])) assert 2 == len(join_domains([Mesh(xa), Mesh(xb)])) # Incompatible cells require labeling # self.assertRaises(UFLException, lambda: join_domains([Mesh(triangle), Mesh(triangle3)])) # FIXME: Figure out # self.assertRaises(UFLException, lambda: join_domains([Mesh(triangle), # Mesh(quadrilateral)])) # FIXME: Figure out # Incompatible coordinates require labeling xc = Coefficient( FunctionSpace(Mesh(triangle), VectorElement("CG", triangle, 1))) xd = Coefficient( FunctionSpace(Mesh(triangle), VectorElement("CG", triangle, 1))) with pytest.raises(UFLException): join_domains([Mesh(xc), Mesh(xd)]) # Incompatible data is checked if and only if the domains are the same assert 2 == len( join_domains([ Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle, ufl_id=8, cargo=mesh8) ])) assert 2 == len( join_domains([ Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(quadrilateral, ufl_id=8, cargo=mesh8) ])) # Geometric dimensions must match with pytest.raises(UFLException): join_domains([Mesh(triangle), Mesh(triangle3)]) with pytest.raises(UFLException): join_domains([ Mesh(triangle, ufl_id=7, cargo=mesh7), Mesh(triangle3, ufl_id=8, cargo=mesh8) ]) # Cargo and mesh ids must match with pytest.raises(UFLException): Mesh(triangle, ufl_id=7, cargo=mesh8) # Nones are removed assert 2 == len( join_domains([ None, Mesh(triangle, ufl_id=3), None, Mesh(triangle, ufl_id=3), None, Mesh(triangle, ufl_id=4) ])) assert 2 == len( join_domains( [Mesh(triangle, ufl_id=7), None, Mesh(quadrilateral, ufl_id=8)])) assert None not in join_domains( [Mesh(triangle3, ufl_id=7), None, Mesh(tetrahedron, ufl_id=8)])