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

📄 demo.py

📁 利用C
💻 PY
字号:
# This demo program computes the value of the functional##     M(v) = int v^2 + (grad v)^2 dx## on the unit square for v = sin(x) + cos(y). The exact# value of the functional is M(v) = 2 + 2*sin(1)*(1-cos(1))## The functional M corresponds to the energy norm for a# simple reaction-diffusion equation.## 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 *# Create mesh and finite elementmesh = UnitSquare(16, 16)element = FiniteElement("Lagrange", "triangle", 2)# The function vclass MyFunction(Function):    def __init__(self, element, mesh):        Function.__init__(self, element, mesh)        def eval(self, values, x):        values[0] = sin(x[0]) + cos(x[1])# Define variational problem# Test and trial functionsv = MyFunction(element, mesh)M = (v*v + dot(grad(v), grad(v)))*dxvalue = assemble(M, mesh)# Compute exact valueexact_value = 2.0 + 2.0*sin(1.0)*(1.0 - cos(1.0))print "The energy norm of v is %.15g (should be %.15g)." %(value, exact_value)

⌨️ 快捷键说明

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