Esempio n. 1
0
    def UpdateSolution(self, r, x):

        self.V.appendleft(deepcopy(r))
        self.W.appendleft(deepcopy(x))
        row = len(r)
        col = len(self.V) - 1
        k = col
        if k == 0:
            ## For the first iteration, do relaxation only
            if self.echo_level > 3:
                classprint(
                    self._ClassName(),
                    "Doing relaxation in the first iteration with factor = ",
                    "{0:.1g}".format(self.alpha))
            return self.alpha * r
        else:
            self.F = np.empty(shape=(col, row))  # will be transposed later
            self.X = np.empty(shape=(col, row))  # will be transposed later
            for i in range(0, col):
                self.F[i] = self.V[i] - self.V[i + 1]
                self.X[i] = self.W[i] - self.W[i + 1]
            self.F = self.F.T
            self.X = self.X.T

            #compute Moore-Penrose inverse of F^T F
            A = np.linalg.pinv(self.F.T @ self.F)

            switch = (self.iteration_counter + 1) / self.p

            classprint(magenta(self.iteration_counter))

            if switch.is_integer() == True:
                B = self.beta * np.identity(row) - (
                    self.X + self.beta * self.F) @ A @ self.F.T
                if self.echo_level > 3:
                    classprint(self._ClassName(),
                               blue("Compute B with Anderson"))
            else:
                B = self.alpha * np.identity(row)
                if self.echo_level > 3:
                    classprint(self._ClassName(),
                               red("Constant underrelaxtion"))

            delta_x = B @ r

            self.iteration_counter += 1

            return delta_x
Esempio n. 2
0
 def UpdateSolution(self, r, x):
     if self.echo_level > 3:
         classprint(self._ClassName(), "Doing relaxation with factor = ",
                    "{0:.1g}".format(self.alpha))
     delta_x = self.alpha * r
     return delta_x