示例#1
0
    def Solve(self,
              rhs: BaseVector,
              sol: Optional[BaseVector] = None,
              initialize: bool = True) -> None:
        old_status = _GetStatus()
        _PushStatus("CG Solve")
        _SetThreadPercentage(0)
        self.sol = sol if sol is not None else self.mat.CreateRowVector()
        d, w, s = self._tmp_vecs
        u, mat, pre, conjugate, tol, maxsteps, callback = self.sol, self.mat, self.pre, self.conjugate, \
            self.tol, self.maxsteps, self.callback
        if initialize:
            u[:] = 0
        d.data = rhs - mat * u
        w.data = pre * d if pre else d
        s.data = w
        wdn = w.InnerProduct(d, conjugate=conjugate)
        err0 = sqrt(abs(wdn))

        self.errors = [err0]
        if wdn == err0:
            return u
        lwstart = log(err0)
        errstop = err0 * tol
        if self.abstol is not None:
            errstop = max(errstop, self.abstol)
        logerrstop = log(errstop)

        for it in range(maxsteps):
            self.iterations = it + 1
            w.data = mat * s
            wd = wdn
            as_s = s.InnerProduct(w, conjugate=conjugate)
            alpha = wd / as_s
            u.data += alpha * s
            d.data += (-alpha) * w

            w.data = pre * d if pre else d

            wdn = w.InnerProduct(d, conjugate=conjugate)
            beta = wdn / wd

            s *= beta
            s.data += w

            err = sqrt(abs(wd))
            self.errors.append(err)
            self.logger.info("iteration " + str(it) + " error = " + str(err))
            if callback is not None:
                callback(it, err)
            _SetThreadPercentage(
                100. * max(it / maxsteps,
                           (log(err) - lwstart) / (logerrstop - lwstart)))
            if err < errstop: break
        else:
            self.logger.warning("CG did not converge to tol")
        if old_status[0] != "idle":
            _PushStatus(old_status[0])
            _SetThreadPercentage(old_status[1])
示例#2
0
 def Solve(self,
           rhs: BaseVector,
           sol: Optional[BaseVector] = None,
           initialize: bool = True) -> BaseVector:
     old_status = _GetStatus()
     _PushStatus(self.name + " Solve")
     _SetThreadPercentage(0)
     if sol is None:
         sol = rhs.CreateVector()
         initialize = True
     if initialize:
         sol[:] = 0
     self.sol = sol
     self._SolveImpl(rhs=rhs, sol=sol)
     if old_status[0] != "idle":
         _PushStatus(old_status[0])
         _SetThreadPercentage(old_status[1])
     return sol
示例#3
0
 def update(self):
     cpuPercent = psutil.cpu_percent()
     mem = psutil.virtual_memory()
     memPercent = mem.used/mem.total * 100
     self.history[:-1] = self.history[1:]
     self.history[-1] = cpuPercent
     self.line.set_ydata(self.history)
     self.figure.canvas.draw()
     self.figure.canvas.flush_events()
     self.historyMem[:-1] = self.historyMem[1:]
     self.historyMem[-1] = memPercent
     self.lineMem.set_ydata(self.historyMem)
     self.figureMem.canvas.draw()
     self.figureMem.canvas.flush_events()
     cpu_text = str(int(cpuPercent))+"%"
     mem_text = str(int(memPercent))+"%"
     self.cpu_label.setText(cpu_text)
     self.mem_label.setText(mem_text)
     import netgen.libngpy._meshing as msh
     status, percent = msh._GetStatus()
     self.progress_bar_label.setText(status)
     self.progress_bar.setValue(percent)