⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.py

📁 利用C
💻 PY
字号:
# This demo solves the time-dependent convection-diffusion equation by# a least-squares stabilized cG(1)cG(1) method. The velocity field used# in the simulation is the output from the Stokes (Taylor-Hood) demo.# The sub domains for the different boundary conditions are computed# by the demo program in src/demo/subdomains.## Modified by Anders Logg, 2008__author__ = "Kristian B. Oelgaard (k.b.oelgaard@tudelft.nl)"__date__ = "2007-11-14 -- 2008-01-04"__copyright__ = "Copyright (C) 2007 Kristian B. Oelgaard"__license__  = "GNU LGPL Version 2.1"from dolfin import *# Load mesh and create finite elementsmesh = Mesh("../../../../data/meshes/dolfin-2.xml.gz")scalar = FiniteElement("Lagrange", "triangle", 1)vector = VectorElement("Lagrange", "triangle", 2)# Load subdomains and velocitysub_domains = MeshFunction("uint", mesh, "../subdomains.xml.gz");velocity = Function(vector, "../velocity.xml.gz");# Initialise source function and previous solution functionf = Function(scalar, mesh, 0.0)u0 = Function(scalar, mesh, 0.0)# ParametersT = 5.0k = 0.1t = kc = 0.005# Test and trial functionsv = TestFunction(scalar)u = TrialFunction(scalar)# Functionsx0 = Vector()x1 = Vector()u0 = Function(scalar, mesh, x0)u1 = Function(scalar, mesh, x1)# Variational problema = v*u*dx + 0.5*k*(v*dot(velocity, grad(u))*dx + c*dot(grad(v), grad(u))*dx)L = v*u0*dx - 0.5*k*(v*dot(velocity, grad(u0))*dx + c*dot(grad(v), grad(u0))*dx) + k*v*f*dx# Set up boundary conditiong = Function(mesh, 1.0)bc = DirichletBC(g, sub_domains, 1)# Assemble matrixA = assemble(a, mesh)# Output fileout_file = File("temperature.pvd")# Time-steppingwhile t < T:    # Copy solution from previous interval    u0.assign(u1)    # Assemble vector and apply boundary conditions    b = assemble(L, mesh)    bc.apply(A, b, a)        # Solve the linear system    solve(A, x1, b)        # Plot solution    plot(u1)    # Save the solution to file    out_file << u1    # Move to next interval    t += k# Hold plotinteractive()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -