📄 demo.py
字号:
# This demo demonstrates how to compute functionals (or forms# in general) over subsets of the mesh. The two functionals# lift and drag are computed for the pressure field around# a dolphin. Here, we use the pressure field obtained from# solving the Stokes equations (see demo program in the# sub directory src/demo/pde/stokes/taylor-hood).## Original implementation: ../cpp/main.cpp by Anders Logg#__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"__date__ = "2007-11-14 -- 2007-11-28"__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"__license__ = "GNU LGPL Version 2.1"from dolfin import *# FIXME: Not working, see notice belowimport sysprint "This demo is not working, please fix me"sys.exit(1)# Create elementelement = FiniteElement("Lagrange", "triangle", 1)# Read velocity field from file and get the meshp = Function(element, "../pressure.xml.gz")mesh = p.mesh()# Define sub domain for the dolphinclass Fish(SubDomain): def inside(self, x, on_boundary): return bool(x[0] > DOLFIN_EPS and x[0] < (1.0 - DOLFIN_EPS) and x[1] > DOLFIN_EPS and x[1] < (1.0 - DOLFIN_EPS) and on_boundary)n = FacetNormal("triangle", mesh)# Functionals for drag and liftD = -p*n[0]*dsL = p*n[1]*ds# Assemble functionals over sub domainfish = Fish()# FIXME: Need to assemble over subdomain, but not yet supported in Pythondrag = assemble(D, mesh, fish)lift = assemble(L, mesh, fish)print "Lift: %f" %liftprint "Drag: %f" %drag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -