python中的数值延续

pacop的Python项目详细描述


压缩

CircleCIcodecovCode style: blackDocumentation StatusPyPi VersionGitHub stars

pacopy为python中的pde提供了各种numerical parameter continuation算法。

pacopy是后端不可知论者,所以你的问题是否由 SciPyFEniCSpyfvm,或任何其他python包。唯一的事 用户必须提供一个具有一些简单方法的类,例如函数求值 f(u, lmbda),雅可比矩阵a解算器jacobian_solver(u, lmbda, rhs)等。

有些pacopy文档是可用的here

示例

布拉图

经典的Bratu problem 一维dirichlet边界条件。要再现情节,你首先必须 指定问题;这是经典的有限差分近似:

classBratu1d(object):def__init__(self):self.n=51h=1.0/(self.n-1)self.H=numpy.full(self.n,h)self.H[0]=h/2self.H[-1]=h/2self.A=(scipy.sparse.diags([-1.0,2.0,-1.0],[-1,0,1],shape=(self.n,self.n))/h**2)returndefinner(self,a,b):"""The inner product of the problem. Can be numpy.dot(a, b), but factoring in        the mesh width stays true to the PDE.        """returnnumpy.dot(a,self.H*b)defnorm2_r(self,a):"""The norm in the range space; used to determine if a solution has been found.        """returnnumpy.dot(a,a)deff(self,u,lmbda):"""The evaluation of the function to be solved        """out=self.A.dot(u)-lmbda*numpy.exp(u)out[0]=u[0]out[-1]=u[-1]returnoutdefdf_dlmbda(self,u,lmbda):"""The function's derivative with respect to the parameter. Used in Euler-Newton        continuation.        """out=-numpy.exp(u)out[0]=0.0out[-1]=0.0returnoutdefjacobian_solver(self,u,lmbda,rhs):"""A solver for the Jacobian problem.        """M=self.A.copy()d=M.diagonal().copy()d-=lmbda*numpy.exp(u)M.setdiag(d)# Dirichlet conditionsM.data[0][self.n-2]=0.0M.data[1][0]=1.0M.data[1][self.n-1]=1.0M.data[2][1]=0.0returnscipy.sparse.linalg.spsolve(M.tocsr(),rhs)

然后将对象传递到Pacopy的任何方法,例如Euler-Newton(ArcLength) 续:

problem=Bratu1d()# Initial guessu0=numpy.zeros(problem.n)# Initial parameter valuelmbda0=0.0lmbda_list=[]values_list=[]defcallback(k,lmbda,sol):# Use the callback for plotting, writing data to files etc.fig=plt.figure()ax1=fig.add_subplot(111)ax1.set_xlabel("$\\lambda$")ax1.set_ylabel("$||u||_2$")ax1.grid()lmbda_list.append(lmbda)values_list.append(numpy.sqrt(problem.inner(sol,sol)))ax1.plot(lmbda_list,values_list,"-x",color="#1f77f4")ax1.set_xlim(0.0,4.0)ax1.set_ylim(0.0,6.0)return# Natural parameter continuation# pacopy.natural(problem, u0, lmbda0, callback, max_steps=100)pacopy.euler_newton(problem,u0,lmbda0,callback,max_steps=500,newton_tol=1.0e-10)

金茨堡-兰道

ginzburg-landau

Ginzburg-Landau equations模型 极端ii型超导体在磁场下的行为。上面的例子 (详细内容见 here中) 显示磁场强度的参数连续性。上的情节 右侧显示了使用 cplot

安装

pacopy是available from the Python Package Index,所以只需键入

pip install -U pacopy

安装或升级。

测试

要运行pacopy单元测试,请签出此存储库并键入

pytest

分布

创建新版本

  1. __version__号撞一下,

  2. 发布到pypi和github:

    make publish
    

许可证

pacopy在MIT license下发布。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何获得要渲染的纹理   java如何动态确定对象类型的文本的实际类型   java如何用方括号解析参数数组?   java与ECC公钥的长度混淆   JavaLWJGL包括GUI类吗?   java如何打印所有收件箱电子邮件   java在片段中使用RecyclerView而不是活动会导致E/RecyclerView:没有连接适配器;跳过布局错误   为位于系统托盘中的Java程序创建键盘挂钩   使用java将三个json对象合并为一个   java获取范围(x,y)内的随机整数?   java定制primaryStage标题:以图标为中心   命令行无法使用运行java应用程序。jar依赖性“错误:无法找到或加载主类”   java LuaJava编译错误“未解析的外部符号”   如何修复java函数   java文件。Listfile()强制关闭(NullPointerException)   java调试模式在IDEA和Kotlin中停止工作   当使用命名空间STD的C++头文件上运行Sigg时,java丢失分号错误   java如何在使用DBUnit时防止数据删除   找不到java类org/apache/zookeeper/server/NIOServerCnxn$工厂   java无法在上启动jbpmhttp://localhost:8080/businesscentral