def _do_inner_iteration_stage(self, guess, **kwargs):
        r"""
        This inner loop updates the source terms based on the new values of
        the quantity, then modifies A and b matrices, solves AX = b and
        returns the result.
        """
        # Updating the source terms
        s1 = sp.zeros(self._coeff_dimension)
        s2 = sp.zeros(self._coeff_dimension)
        for label in self.labels():
            if 'pore.source_' in label:
                source_name = label.replace('pore.source_', '')
                if 'pore.source_nonlinear_s1_' + source_name in self.props():
                    arr = self.pores('source_'+source_name)
                    tol = min(sp.unique(self['pore.source_tol'][arr]))
                    maxiter = max(sp.unique(self['pore.source_maxiter'][arr]))
                    self.set_source_term(source_name=source_name,
                                         pores=self.pores(label), x0=guess,
                                         tol=tol, maxiter=maxiter,
                                         mode='update')
                    prop1 = 'pore.source_nonlinear_s1_' + source_name
                    mask1 = ~sp.isnan(self[prop1])
                    s1[~sp.isnan(self[prop1])] = s1[mask1] + self[prop1][mask1]
                    prop2 = 'pore.source_nonlinear_s2_' + source_name
                    mask2 = ~sp.isnan(self[prop2])
                    s2[~sp.isnan(self[prop2])] = s2[mask2] + self[prop2][mask2]
        self.s1 = s1
        self.s2 = s2
        # Modifying A and b
        pores = self.pores('source_*')
        S1 = s1[pores]
        S2 = s2[pores]
        A = self._build_coefficient_matrix(modified_diag_pores=pores,
                                           diag_added_data=S1,
                                           mode='modify_diagonal')
        b = self._build_RHS_matrix(modified_RHS_pores=pores,
                                   RHS_added_data=-S2, mode='modify_RHS')
        # Solving AX = b
        X = self._do_one_inner_iteration(A=A, b=b, **kwargs)
        # Calculates absolute error
        t = sp.amax(sp.absolute(guess - X))
        return X, t, A, b
dataset/ETHPy150Open PMEAL/OpenPNM/OpenPNM/Algorithms/__GenericLinearTransport__.py/GenericLinearTransport._do_inner_iteration_stage/original