ReactionSystem.py 文件源码

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

项目:Chemical-Reaction-System-Simulator 作者: axlevisu 项目源码 文件源码
def run_till(self,delta_time=0.001,eps = 10**-12,every=10, stop=100000):
        """
        Runs till the gradients are less than eps
        returns time taken with array of concentrations
        default values of time_step and eps are 10**-3 and 10**-12 
        """
        y = self.concentrations
        output = [y]
        t=0
        t_index = np.linspace(0,every,int(every/(delta_time)))
        if every>10*delta_time:
             while True:
                gy = odes(y,t,self.reactions,self.rates)
                if (np.abs(gy) <eps).all():
                    break
                o = odeint(odes, y, t_index, args= (self.reactions,self.rates))
                y = o[-1,:]
                t+=every
                output = output + o[1:]
                if t>stop:
                    break 
        else:
            while True:
                gy = odes(y,t,self.reactions,self.rates)
                if (np.abs(gy) <eps).all():
                    break
                y+= gy*delta_time
                t+=delta_time
                output.append(y)
                if t>stop:
                    break

        output = np.array(output)
        self.concentrations =y
        return output,t
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号