0

我用第一个子域中的斯托克斯方程和第二个子域中的混合泊松方程(达西)创建了一个划分域。我使用 UnitSquare,子域 1 应该是从 0 到 0,5 的区间,子域 2 应该是从 0,5 到 1 的区间。

但现在我收到以下错误:

解决线性变分问题。与调用 numeric 相关的 UMFPACK 问题 * 警告:UMFPACK 报告正在求解的矩阵是奇异的。与调用求解有关的 UMFPACK 问题 *警告:UMFPACK 报告正在求解的矩阵是奇异的。断言 vmax>=vmin, "空范围,请指定 vmin 和/或 vmax" 断言错误:空范围,请指定 vmin 和/或 vmax

任何人都可以帮忙吗?谢谢!

这是代码:

enter code here


#-*- coding: utf-8 -*-

from dolfin import *

import numpy as np

# Define mesh
mesh = UnitSquare(32,32)

#Subdomain 1
# Gitter übergeben
subdomains = CellFunction("uint", mesh)

# Klasse des Teilgebiets
class Domain_1(SubDomain):
   def inside(self, x, on_boundary):
       return between(x[0], (0, 0.5)) # Koordinatenangabe des Teilgebiets

# Objekt der Klasse erstellen
sub_domain1 = Domain_1()
sub_domain1.mark(subdomains,0)

# Definition Funktionenräume
U = FunctionSpace(mesh, "CG", 2)
V = FunctionSpace(mesh, "CG", 1)
W = U*V

# Definition Trial- und Testfunktion
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)

# boundary condition
p_in = 1
p_out = 0
noslip = DirichletBC(W.sub(0), (0),

                      "on_boundary && \

                      (x[1] <= DOLFIN_EPS | x[1] >= 0.5-DOLFIN_EPS)")

inflow = DirichletBC(W.sub(1), p_in, "x[0] <= 0.0 + DOLFIN_EPS*1000")
outflow = DirichletBC(W.sub(1), p_out, "x[0] >= 0.5 - DOLFIN_EPS*1000")

bcp = [noslip,inflow, outflow]

# Definition f
f = Expression("0")

# Variationsformulierung
a = inner(grad(u), grad(v))*dx + div(v)*p*dx(0) + q*div(u)*dx(0)
L = inner(f,v)*dx(0)

# Lösung berechnen
w = Function(W)
problem = LinearVariationalProblem(a, L, w, bcp)
solver = LinearVariationalSolver(problem)
solver.solve()
(u, p) = w.split()

# Subdomain 2
# Gitter übergeben
subdomains = CellFunction("uint", mesh)

# Klasse des Teilgebiets
class Domain_2(SubDomain):
   def inside(self,x,on_boundary):
       return between(x[0], (0.5,1.0)) # Koordinatenangabe des Teilgebiets

# Objekt der Klasse erstellen
sub_domain2 = Domain_2()
sub_domain2.mark(subdomains,1)

# Define function spaces and mixed (product) space
BDM = FunctionSpace(mesh, "BDM", 1)
DG = FunctionSpace(mesh, "DG", 0)
CG = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([BDM, DG, CG])

# Define trial and test functions
(sigma, u, p) = TrialFunctions(W)
(tau, v, q) = TestFunctions(W)

#Define pressure boundary condition
p_in = 1
p_out = 0
noslip = DirichletBC(W.sub(1), (0),
                      "on_boundary && \
                      (x[1] <= 0.5 + DOLFIN_EPS | x[1] >= 1.0-DOLFIN_EPS)")

inflow = DirichletBC(W.sub(2), p_in, "x[0] <= 0.5 + DOLFIN_EPS*1000")
outflow = DirichletBC(W.sub(2), p_out, "x[0] >= 1.0 - DOLFIN_EPS*1000")
bcp = [noslip,inflow, outflow]

# Define f
#f = Expression("0")
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")

# Define variational form
a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx(1) + inner(p,q)*dx(1) + u*q*dx(1)
L = f*v*dx(1)

# Compute solution
w = Function(W)
problem = LinearVariationalProblem(a, L, w, bcp)
solver = LinearVariationalSolver(problem)
solver.solve()
(sigma, u, p) = w.split()

# plot

plot(u, axes = True, interactive=True, title = "u")
plot(p, axes = True, interactive=True, title = "p")

我忘记了这个术语中的 dx(0)。但这不是问题所在。

在代码的第一部分(Stokes)中,我尝试用以下方式编写无滑移条件:

# Randbedingungen

def top_bottom(x, on_boundary):
    return x[1] > 1.0 - DOLFIN_EPS or x[1] < DOLFIN_EPS

noslip = Constant((0.0,0.0))  

bc0 = DirichletBC(W.sub(0), noslip, top_bottom)

p_in = 1
p_out = 0

inflow = DirichletBC(W.sub(1), p_in, "x[0] <= 0.0 + DOLFIN_EPS*1000")
outflow = DirichletBC(W.sub(1), p_out, "x[0] >= 0.5 - DOLFIN_EPS*1000")

bcp = [bc0, inflow, outflow]

# Definition f

f = Expression("(0.0, 0.0)")

# Variationsformulierung Stokes
a = inner(grad(u), grad(v))*dx(0) + div(v)*p*dx(0) + q*div(u)*dx(0)
L = inner(f,v)*dx(0)

但现在我收到以下错误:

Shape mismatch: line 56, in <module> L = inner(f,v)*dx(0

任何人都可以帮忙吗?谢谢!

4

1 回答 1

0

我认为这里有几个错误。在代码的第一部分,我认为您正在使用 Taylor-Hood 元素来求解斯托克斯方程。如果我们是这种情况,那么 U 应该是:

U = VectorFunctionSpace(网格,“CG”,2)

同样在这部分代码中:

a = 内部(grad(u), grad(v))*dx + div(v)*p*dx(0) + q*div(u)*dx(0)

L = 内部(f,v)*dx(0)

我不知道你为什么不使用 dx(0) 第一个学期。我鼓励您查看以下演示: http: //fenicsproject.org/documentation/dolfin/dev/python/demo/index.html 您可能会得到更多提示。

于 2013-10-11T11:44:07.433 回答