RuntimeError с использованием FEniCS - PullRequest
0 голосов
/ 07 апреля 2020

Я пытаюсь решить проблему механики сплошных сред с помощью FEniCS. Я хочу вычислить поле смещения u в определенном случае.

Вот мой код:

from dolfin import *
from fenics import * 
import matplotlib.pyplot as plt
mesh = RectangleMesh(Point(-1., 0.0),Point(1., 10.), 10, 10)
plot(mesh, title="Rectangle")

P1 = FiniteElement('P', triangle,1)
element = P1*P1

V = FunctionSpace(mesh,element)
v_1, v_3 = TestFunction(V)
u = Function(V)
u_1, u_3 = split(u)

def boundaryDC(x):
    return abs(x[1])<tol
u_D = as_vector((Expression('0.', degree = 0),Expression('0.', degree = 0)))
bc = DirichletBC(V,u_D,boundaryDC)


g11 = Expression('x[0]>(1.-pow(10,-14)) ? 1 : 0', degree = 0)
g12 = Expression('x[0]<(-1.+pow(10,-14)) ? 1 : 0', degree = 0)
g32 = Expression('x[1]>(10.-pow(10,-14)) ? 1 : 0', degree = 0)

a = -(dot(grad(u_1),grad(v_1))+dot(grad(u_3),grad(v_3))+(Dx(u_1,0)+Dx(u_3,0))*(Dx(v_1,0)+Dx(v_3,0)))*dx + ((-2)*Dx(u_1,0)*v_1-v_3*Dx(u_1,1))*(g11+g12)*ds + ((-2)*Dx(u_3,1)*v_3-v_1*Dx(u_3,0))*g32*ds

L = -(7.2*10**(-5))*(v_1*(g11-g12)+v_3*g32)*ds+(0.018)*v_3*g32*ds

solve(a==L, u, bc)

Когда я его запускаю, я получаю эту ошибку:

RuntimeError                              Traceback (most recent call last)
<ipython-input-50-766317262156> in <module>
     28 L = -(7.2*10**(-5))*(v_1*(g11-g12)+v_3*g32)*ds+(0.018)*v_3*g32*ds
     29 
---> 30 solve(a==L, u, bc)

/usr/lib/python3/dist-packages/dolfin/fem/solving.py in solve(*args, **kwargs)
    218     # tolerance)
    219     elif isinstance(args[0], ufl.classes.Equation):
--> 220         _solve_varproblem(*args, **kwargs)
    221 
    222     # Default case, just call the wrapped C++ solve function

/usr/lib/python3/dist-packages/dolfin/fem/solving.py in _solve_varproblem(*args, **kwargs)
    240         # Create problem
    241         problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
--> 242                                            form_compiler_parameters=form_compiler_parameters)
    243 
    244         # Create solver and call solve

/usr/lib/python3/dist-packages/dolfin/fem/problem.py in __init__(self, a, L, u, bcs, form_compiler_parameters)
     57 
     58         # Initialize C++ base class
---> 59         cpp.fem.LinearVariationalProblem.__init__(self, a, L, u._cpp_object, bcs)
     60 
     61 

RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to define linear variational problem a(u, v) == L(v) for all v.
*** Reason:  Expecting the left-hand side to be a bilinear form (not rank 1).
*** Where:   This error was encountered inside LinearVariationalProblem.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** Git changeset:  unknown


'

Ты знаешь как это исправить?

...