On Sat, 14 Nov 2015 22:45:41 +0800 zheng li <[email protected]> wrote: > Hi Blechta, > > Thanks for your reply and I had resolved my boundary problem. > But now, I meet another problem. There is a item (y, z) in my weak > form, where y and z are 2 order tensor. When code runs, error “shape > mismatch” appears. I gauss this error caused by define function space > Vy in a wrong way. I look through all demos and don’t find answer to > this error. I want to know how to define function space for tensor > variable. Could you tell me how to do it or give me some hints? > Thanks. > > > # Define function spaces > Vy = VectorFunctionSpace(mesh, "CG", 1) > Vr = FunctionSpace(mesh, "CG", 2) > Vp = FunctionSpace(mesh, "CG", 1) > Vu = FunctionSpace(mesh, "CG", 2) > Vqp = VectorFunctionSpace(mesh, "CG", 2) > W = MixedFunctionSpace([Vqp, Vu, Vp, Vr, Vy]) > > # Define boundary conditions > u0 = Constant((0.0,0.0)) > u1 = Constant(0.0) > bc0 = DirichletBC(W.sub(0), u0, "on_boundary") > bc1 = DirichletBC(W.sub(1), u1, "on_boundary") > > # Collect boundary conditions > bcs = [bc0, bc1] > > # Define variational problem > (p1,u, p, r, y) = TrialFunctions(W) > (eta, v, q, s, z) = TestFunctions(W) > f = Constant(0.0) > a = (inner(y, z) - inner(grad(p1),z) - inner(grad(s), grad(u)) > +inner(grad(s), p1)+ q*rot(p1)-inner(grad(r), grad(v)) > -inner(y, grad(eta))+inner(grad(r), eta)+ p*rot(eta))*dx
Just put every term on a single line and UFL will tell you where's the problem. In particular lines inner(grad(p1),z) inner(y, grad(eta)) will raise ufl.log.UFLException: Shape mismatch. because the terms have no good meaning. As a sidenote, this kind of questions (getting helped with FEniCS usage) are better asked on QA, see http://fenicsproject.org/support/ Jan > L = f*v*dx > > > > > > On Nov 9, 2015, at 8:50 PM, Jan Blechta > > <[email protected]> wrote: > > > > On Sat, 7 Nov 2015 15:02:06 +0800 > > zheng li <[email protected]> wrote: > > > >> Dear developer, > >> > >> I am using FEniCS to do mixed finite element case. There > >> are five element spaces in my case and the boundary conditions for > >> space Vqp and Vu are homogeneous Dirichlet condition. I define the > >> BCs in my code like following way: > >> > >> # Define function spaces > >> Vqp = VectorFunctionSpace(mesh, "CG", 2) > >> Vu = FunctionSpace(mesh, "CG", 2) > >> Vp = VectorFunctionSpace(mesh, "CG", 1) > >> Vr = FunctionSpace(mesh, "CG", 2) > >> Vy = VectorFunctionSpace(mesh, "CG", 1) > >> > >> W = Vqp * Vu * Vp * Vr * Vy > > > > Here's the problem. In Python FunctionSpace.__mul__ operator cannot > > be flattened so W is not what you expect but > > > > W = (((( Vqp * Vu ) * Vp ) * Vr ) * Vy ) > > > > You should do rather > > > > W = MixedFunctionSpace([Vqp, Vu, Vp, Vr, Vy]) > > > > This will work with DOLFIN <= 1.6. But MixedFunctionSpace is > > deprecated from future release of DOLFIN 1.7.0, see > > http://fenicsproject.org/documentation/dolfin/dev/python/demo/documented/stokes-iterative/python/documentation.html > > for a correct solution. > > > > Jan > > > >> > >> # Define boundary conditions > >> u0 = Constant((0.0,0.0)) > >> u1 = Constant(0.0) > >> bc0 = DirichletBC(W.sub(0), u0, "on_boundary") > >> bc1 = DirichletBC(W.sub(1), u1, "on_boundary") > >> > >> # Collect boundary conditions > >> bcs = [bc0, bc1] > >> > >> However, error occurred when my code is running. The detail error > >> infos are > >> > >> Traceback (most recent call last): > >> File "demo_stokes-taylorhood.py", line 49, in <module> > >> bc0 = DirichletBC(W.sub(0), u0, "on_boundary") > >> File > >> "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/fem/bcs.py", > >> line 128, in __init__ cpp.DirichletBC.__init__(self, *args) File > >> "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/fem.py", > >> line 1140, in __init__ > >> _fem.DirichletBC_swiginit(self,_fem.new_DirichletBC(*args)) > >> 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 *** *** [email protected] > >> *** > >> *** Remember to include the error message listed below and, if > >> possible, *** include a *minimal* running example to reproduce the > >> error. *** > >> *** > >> ------------------------------------------------------------------------- > >> *** Error: Unable to create Dirichlet boundary condition. *** > >> Reason: Illegal value dimension (2), expecting (6). *** Where: > >> This error was encountered inside DirichletBC.cpp. *** Process: > >> unknown > >> > >> I don’t know what caused this. Is there any wrong with my > >> definition of BCs? Looking forward to your reply. Thanks a lot. > >> > >> > >> Best wishes, > >> > >> > >> —Zheng > >> > >> > >> > > > _______________________________________________ fenics mailing list [email protected] http://fenicsproject.org/mailman/listinfo/fenics
