code: def _submarine_2d_nonsmooth(space):
      
  
      def ellipse(x):
          """Characteristic function of an ellipse.
  
          If ``space.domain`` is a rectangle ``[0, 1] x [0, 1]``,
          the ellipse is centered at ``(0.6, 0.3)`` and has half-axes
          ``(0.4, 0.14)``. For other domains, the values are scaled
          accordingly.
          """
          halfaxes = np.array([0.4, 0.14]) * space.domain.extent
          center = np.array([0.6, 0.3]) * space.domain.extent
          center += space.domain.min()
  
          sq_ndist = np.zeros_like(x[0])
          for xi, rad, cen in zip(x, halfaxes, center):
              sq_ndist = sq_ndist + ((xi - cen) / rad) ** 2
  
          return np.where(sq_ndist <= 1, 1, 0)
  
      def rect(x):
          """Characteristic function of a rectangle.
  
          If ``space.domain`` is a rectangle ``[0, 1] x [0, 1]``,
          the rect has lower left ``(0.56, 0.4)`` and upper right
          ``(0.76, 0.6)``. For other domains, the values are scaled
          accordingly.
          """
          xlower = np.array([0.56, 0.4]) * space.domain.extent
          xlower += space.domain.min()
          xupper = np.array([0.76, 0.6]) * space.domain.extent
          xupper += space.domain.min()
  
          out = np.ones_like(x[0])
          for xi, low, upp in zip(x, xlower, xupper):
              out = out * ((xi >= low) & (xi <= upp))
          return out
  
      out = space.element(ellipse)
      out += space.element(rect)
      return out.ufuncs.minimum(1, out=out)
docs: Return a 2d nonsmooth 'submarine' phantom.