This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Error in form of advection type equation

–1 vote

I am trying to solve the following set of equations:

$$\frac{\partial P_x}{\partial t} + \frac{\partial D}{\partial x} = 0$$

$$\frac{\partial P_y}{\partial t} + \frac{\partial D}{\partial y} = 0$$

For P with some boundary conditions, where D is known.

The form I use with backward Euler is:

F3 = (1.0/dt)*dot(grad(p_)-grad(p_n), v)*dx + dot(grad(D), v)*dx
a3 = lhs(F3)
L3 = rhs(F3)

And then to apply the boundary conditions for P I use:

A3 = assemble(a3)
bcp.apply(A3)

When I try running this I get and error in the bcp line:

TypeError: in method 'DirichletBC_apply', argument 2 of type 'dolfin::GenericVector &'

What does the error mean? How could I apply the boundary conditions properly?

asked May 15, 2017 by alexmm FEniCS User (4,240 points)
edited May 15, 2017 by alexmm

1 Answer

+1 vote

Can you please provide a complete code?

I guess you need to add the rhs to bcp.apply:

b3 = assemble(L3)
bcp.apply(A3,b3) 
answered May 15, 2017 by caterinabig FEniCS User (1,460 points)

I'm still getting the same error after including the rhs of the form

Difficult to say without a running code.

Here's the code:

from fenics import *

dt = 0.01 # time step size
nElems = 32

# Create mesh and define function spaces
mesh = UnitSquareMesh(nElems, nElems)

V = VectorFunctionSpace(mesh, 'P', 2)
Q = FunctionSpace(mesh, 'P', 1)


# Define boundary conditions
bcp = DirichletBC(Q, Constant(0.0), PPoint, 'pointwise')

# Define trial and test functions
v = TestFunction(V)


# Define functions for solutions at previous and current time steps
p_n = Function(Q)
p_  = Function(Q)
D   = Function(Q)

# Define expressions used in variational forms
k   = Constant(dt)


F3 = (1.0/dt)*dot(grad(p_)-grad(p_n), v)*dx + dot(grad(D), v)*dx
a3 = lhs(F3)
L3 = rhs(F3)

A3 = assemble(a3)
bcp.apply(A3)

b3 = assemble(L3)

solve(A3, p_.vector(), b3)

I don't know what's wrong but I already have two questions:

  • Shouldn't you prescribe some initial conditions? shouldn't you have a time loop?
  • Why you you choose the pointwise method and what is PPoint?

Maybe they help...

Hi, PPoint is a point in the mesh:

PPoint  = 'near(x[0], 0.0) && near(x[1], 0.0)'

Hence the use of 'pointwise' when declaring the boundary conditions:

bcp = DirichletBC(Q, Constant(0.0), PPoint, 'pointwise')

And yes this is part of a larger program with a time loop but I wanted to show a simpler case that has the same error

OK understood.

What is the element family 'P'? I don't find in the documentation https://fenicsproject.org/olddocs/dolfin/1.3.0/python/programmers-reference/functions/functionspace/FunctionSpace.html

However, I've never worked with trial functions (p_) and test functions (v) in difference spaces (scalar space Q vs. vector space V). Maybe this is the problem?

...