python fipy_Python学习点滴

安装gmsh,并设置环境变量

Delaunay使用

import numpy as np

from scipy.spatial import Delaunay

points = np.random.rand(30, 2) # 30 points in 2-d

tri = Delaunay(points)

# Make a list of line segments:

# edge_points = [ ((x1_1, y1_1), (x2_1, y2_1)),

# ((x1_2, y1_2), (x2_2, y2_2)),

# ... ]

edge_points = []

edges = set()

def add_edge(i, j):

"""Add a line between the i-th and j-th points, if not in the list already"""

if (i, j) in edges or (j, i) in edges:

# already added

return

edges.add( (i, j) )

edge_points.append(points[ [i, j] ])

# loop over triangles:

# ia, ib, ic = indices of corner points of the triangle

for ia, ib, ic in tri.vertices:

add_edge(ia, ib)

add_edge(ib, ic)

add_edge(ic, ia)

# plot it: the LineCollection is just a (maybe) faster way to plot lots of

# lines at once

import matplotlib.pyplot as plt

from matplotlib.collections import LineCollection

lines = LineCollection(edge_points)

plt.figure()

plt.title('Delaunay triangulation')

plt.gca().add_collection(lines)

plt.plot(points[:,0], points[:,1], 'o', hold=1)

plt.xlim(-1, 2)

plt.ylim(-1, 2)

# -- the same stuff for the convex hull

edges = set()

edge_points = []

for ia, ib in tri.convex_hull:

add_edge(ia, ib)

lines = LineCollection(edge_points)

plt.figure()

plt.title('Convex hull')

plt.gca().add_collection(lines)

plt.plot(points[:,0], points[:,1], 'o', hold=1)

plt.xlim(-1, 2)

plt.ylim(-1, 2)

plt.show()

python程序打包Install PyInstaller from PyPI:

pip install pyinstaller

Go to your program’s directory and run:

pyinstaller yourprogram.py

This will generate the bundle in a subdirectory called dist. For a more detailed walkthrough, see the安装jupyter lab

清除cache C:\Users\Administrator\AppData\Local\pip\cache

安装jupyter lab:

conda install -c conda-forge jupyterlab安装sublime的anaconda插件

管理员权限启动sublime 3,continuesfepy demo测试

安装运行时需要的库

conda install mayavi wxpython

conda install traits traitsui

vtk

运行库mayavi安装不顺利:

(C:\Anaconda2) C:\wxPython-master>conda install mayavi

Fetching package metadata ...........

Solving package specifications: .

UnsatisfiableError: The following specifications were found to be in conflict:

- mayavi

- sfepy

Use "conda info " to see the dependencies for each package.

(C:\Anaconda2) C:\wxPython-master>conda install -c menpo mayavi=4.5.0

Fetching package metadata .............

Solving package specifications: .

Package plan for installation in environment C:\Anaconda2:

The following NEW packages will be INSTALLED:

apptools: 4.4.0-py27_0 menpo

envisage: 4.5.1-py27_0 menpo

mayavi: 4.5.0-py27_0 menpo

The following packages will be UPDATED:

vtk: 5.10.1-py27_0 --> 7.0.0-py27_0 menpo

Proceed ([y]/n)? y

vtk-7.0.0-py27 100% |###############################| Time: 0:00:31 787.75 kB/s

apptools-4.4.0 100% |###############################| Time: 0:00:05 72.23 kB/s

envisage-4.5.1 100% |###############################| Time: 0:00:02 117.34 kB/s

mayavi-4.5.0-p 100% |###############################| Time: 0:00:14 882.55 kB/s

PowerShell计算命令行:

PSC:\sfepy> python simple.py examples/diffusion/poisson_short_syntax.py

sfepy: left over: ['verbose', '__builtins__', 'absolute_import', '__file__', '__doc__', '__name__', 'data_dir', '__package__', '_filename']

sfepy: reading mesh [line2, tri3, quad4, tetra4, hexa8] (C:\Anaconda2\lib\site-packages\sfepy\meshes\3d\cylinder.mesh)...

sfepy: ...done in 0.11 s

sfepy: creating regions...

sfepy: Gamma_Right

sfepy: Omega

sfepy: Gamma_Left

sfepy: ...done in 0.09 s

sfepy: equation "Temperature":

sfepy: dw_laplace.i.Omega( coef.val, s, t ) = 0

sfepy: using solvers:

ts: no ts

nls: newton

ls: lssfepy: updating variables...

sfepy: ...done

sfepy: setting up dof connectivities...

sfepy: ...done in 0.00 s

sfepy: matrix shape: (300, 300)

sfepy: assembling matrix graph...

sfepy: ...done in 0.00 s

sfepy: matrix structural nonzeros: 3538 (3.93e-02% fill)

sfepy: updating materials...

sfepy: coef

sfepy: ...done in 0.05 s

sfepy: nls: iter: 0, residual: 1.176265e-01 (rel: 1.000000e+00)

sfepy: rezidual: 0.05 [s]

sfepy: solve: 0.09 [s]

sfepy: matrix: 0.00 [s]

sfepy: nls: iter: 1, residual: 1.784271e-16 (rel: 1.516895e-15)

PSC:\sfepy> python postproc.py cylinder.vtk

anaconda默认安装pyQt5,需要强制安装pyQt4:

conda install -c anaconda pyqt=4.11.4

安装pandas

conda install pandas安装Fipy

1升级pip

python -m pip install --upgrade pip

2 安装Fipy

pip install fipy

conda install fipy #error

3 Test:

from fipy import Variable, FaceVariable, CellVariable, Grid1D, ExplicitDiffusionTerm, TransientTerm, DiffusionTerm, Viewer

from fipy.tools import numerix

%matplotlib inline

nx = 50

dx = 1.

mesh = Grid1D(nx=nx, dx=dx)

D = 1.

valueLeft = 1

valueRight = 0

phi = CellVariable(name="solution variable",mesh=mesh,value=0.)

phi.constrain(valueRight, mesh.facesRight)

phi.constrain(valueLeft, mesh.facesLeft)

eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D)

timeStepDuration = 0.9 * dx**2 / (2 * D)

steps = 100

for step in range(steps):

eqX.solve(var=phi,dt=timeStepDuration)

viewer = Viewer(vars=phi,datamin=0., datamax=1.)

viewer.plot()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值