CoupledNavierStokesSolver.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:FenicsSolver 作者: qingfengxia 项目源码 文件源码
def solve_static(self, F, up_, Dirichlet_bcs_up):
        # Solve stationary Navier-Stokes problem with Picard method
        # other methods may be more acurate and faster

        iter_ = 0
        max_iter = 50
        eps = 1.0
        tol = 1E-3
        under_relax_ratio = 0.7
        up_temp = Function(self.function_space)  # a temporal to save value in the Picard loop

        timer_solver = Timer("TimerSolveStatic")
        timer_solver.start()
        while (iter_ < max_iter and eps > tol):
            # solve the linear stokes flow to avoid up_s = 0

            up_temp.assign(up_)
            # other solving methods
            up_ = self.solve_linear_problem(F, up_, Dirichlet_bcs_up)
            #up_s = self.solve_amg(F, Dirichlet_bcs_up, up_s)  #  AMG is not working with mixed function space

            diff_up = up_.vector().array() - up_temp.vector().array()
            eps = np.linalg.norm(diff_up, ord=np.Inf)

            print("iter = {:d}; eps_up = {:e}; time elapsed = {}\n".format(iter_, eps, timer_solver.elapsed()))

            ## underreleax should be defined here, Courant number, 
            up_.vector()[:] = up_temp.vector().array() + diff_up * under_relax_ratio

            iter_ += 1
        ## end of Picard loop
        timer_solver.stop()
        print("*" * 10 + " end of Navier-Stokes equation iteration" + "*" * 10)

        return up_
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号