資源簡介
python有限元框架FENICS教程及例子,擁有12個例子文件

代碼片段和文件信息
“““
FEniCS?tutorial?demo?program:?Poisson?equation?with?Dirichlet?conditions.
Test?problem?is?chosen?to?give?an?exact?solution?at?all?nodes?of?the?mesh.
??-Laplace(u)?=?f????in?the?unit?square
????????????u?=?u_D??on?the?boundary
??u_D?=?1?+?x^2?+?2y^2
????f?=?-6
“““
from?__future__?import?print_function
from?fenics?import?*
#?Create?mesh?and?define?function?space
mesh?=?UnitSquareMesh(8?8)
V?=?FunctionSpace(mesh?‘P‘?1)
#?Define?boundary?condition
u_D?=?expression(‘1?+?x[0]*x[0]?+?2*x[1]*x[1]‘?degree=2)
def?boundary(x?on_boundary):
????return?on_boundary
bc?=?DirichletBC(V?u_D?boundary)
#?Define?variational?problem
u?=?TrialFunction(V)
v?=?TestFunction(V)
f?=?Constant(-6.0)
a?=?dot(grad(u)?grad(v))*dx
L?=?f*v*dx
#?Compute?solution
u?=?Function(V)
solve(a?==?L?u?bc)
#?Plot?solution?and?mesh
plot(u)
plot(mesh)
#?Save?solution?to?file?in?VTK?format
vtkfile?=?File(‘poisson/solution.pvd‘)
vtkfile?<
#?Compute?error?in?L2?norm
error_L2?=?errornorm(u_D?u?‘L2‘)
#?Compute?maximum?error?at?vertices
vertex_values_u_D?=?u_D.compute_vertex_values(mesh)
vertex_values_u?=?u.compute_vertex_values(mesh)
import?numpy?as?np
error_max?=?np.max(np.abs(vertex_values_u_D?-?vertex_values_u))
#?Print?errors
print(‘error_L2??=‘?error_L2)
print(‘error_max?=‘?error_max)
#?Hold?plot
interactive()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????8639837??2019-04-16?00:09??fenics-tutorial-vol1.pdf
?????文件????????1380??2018-10-11?16:54??ft01_poisson.py
?????文件????????1869??2018-10-11?16:54??ft02_poisson_membrane.py
?????文件????????1733??2018-10-11?16:54??ft03_heat.py
?????文件????????1468??2018-10-11?16:54??ft04_heat_gaussian.py
?????文件????????1617??2018-10-11?16:54??ft05_poisson_nonlinear.py
?????文件????????2010??2018-10-11?16:54??ft06_elasticity.py
?????文件????????3296??2018-10-11?16:54??ft07_navier_stokes_channel.py
?????文件????????4400??2018-10-11?16:54??ft08_navier_stokes_cylinder.py
?????文件????????3105??2018-10-11?16:54??ft09_reaction_system.py
?????文件???????27206??2018-10-11?16:54??ft10_poisson_extended.py
?????文件????????2989??2018-10-11?16:54??ft11_magnetostatics.py
?????文件????????2732??2018-10-11?16:54??ft12_poisson_solver.py
?????文件??????????88??2018-10-11?16:54??README.md
評論
共有 條評論