code: def _set_BC(self, pores, bctype, bcvalues=None, mode='merge'):
          r
          # First check that given pores do not have source terms already set
          for item in self.settings['sources']:
              if np.any(self[item][pores]):
                  raise Exception('Source term already present in given ' +
                                  'pores, cannot also assign boundary ' +
                                  'conditions')
          # Then call parent class function if above check passes
          super()._set_BC(pores=pores, bctype=bctype, bcvalues=bcvalues,
                          mode=mode)
docs: r"""
          Apply boundary conditions to specified pores if no source terms are
          already assigned to these pores. Otherwise, raise an error.
  
          Parameters
          ----------
          pores : array_like
              The pores where the boundary conditions should be applied
  
          bctype : string
              Specifies the type or the name of boundary condition to apply. The
              types can be one one of the following:
  
              - *'value'* : Specify the value of the quantity in each location
              - *'rate'* : Specify the flow rate into each location
  
          bcvalues : int or array_like
              The boundary value to apply, such as concentration or rate.  If
              a single value is given, it's assumed to apply to all locations.
              Different values can be applied to all pores in the form of an
              array of the same length as ``pores``.
  
          mode : string, optional
              Controls how the conditions are applied.  Options are:
  
              *'merge'*: (Default) Adds supplied boundary conditions to already
              existing conditions.
  
              *'overwrite'*: Deletes all boundary condition on object then add
              the given ones
  
          Notes
          -----
          It is not possible to have multiple boundary conditions for a
          specified location in one algorithm. Use ``remove_BCs`` to
          clear existing BCs before applying new ones or ``mode='overwrite'``
          which removes all existing BC's before applying the new ones.