# BCs in mixed space vector+scalar+scalar

I want to solve for a vector and two scalars, and I have specified the FunctionSpace W intuitively correctly,

but the BC complains that my dimension is incorrect (for the vector). What am I doing wrong?

mesh=UnitSquare

V=VectorFunctio

Q=FunctionSpace

R=FunctionSpace

W=V+Q+R

def bound0(x):

x[0]<DOLFIN_EPS

v0=Constant(

bc=DirichletBC(

bc=

File "/usr/lib/

cpp.

File "/usr/lib/

_cpp.

RuntimeError: *** Error: Unable to create boundary condition. Reason: Illegal value 2 for value dimension, should be 3.

## Question information

- Language:
- English Edit question

- Status:
- Solved

- For:
- DOLFIN Edit question

- Assignee:
- No assignee Edit question

- Solved by:
- Chris Richardson

- Solved:
- 2010-03-15

- Last query:
- 2010-03-15

- Last reply:
- 2010-03-15

Johan Hake (johan-hake) said : | #1 |

Hello Chris!

When defining MixedFunction spaces with more than one component you should

use:

W = MixedFunctionSp

The add operator in FunctionSpace returns a MixedFunctionSpace of its two

components, so

V+Q+R

would result in:

W = MixedFunctionSp

Johan

On Monday 15 March 2010 14:13:12 Chris Richardson wrote:

> New question #104471 on DOLFIN:

> https:/

>

> I want to solve for a vector and two scalars, and I have specified the

> FunctionSpace W intuitively correctly, but the BC complains that my

> dimension is incorrect (for the vector). What am I doing wrong?

>

> mesh=UnitSquare

>

> V=VectorFunctio

> Q=FunctionSpace

> R=FunctionSpace

> W=V+Q+R

>

> def bound0(x):

> x[0]<DOLFIN_EPS

>

> v0=Constant(

>

> bc=DirichletBC(

>

>

> bc=DirichletBC(

> File "/usr/lib/

> __init__ cpp.DirichletBC

> File "/usr/lib/

> __init__ _cpp.DirichletB

> RuntimeError: *** Error: Unable to create boundary condition. Reason:

> Illegal value 2 for value dimension, should be 3.

>

Chris Richardson (chris-bpi) said : | #2 |

OK, that solves my problem. Thank you, Johan!

It would be better, perhaps, if the default behaviour could be:

W=V+Q+R

is equivalent to

W=MixedFunction

and

W=(V+Q)+R

could be MixedFunctionSp

or maybe the W=V+Q style syntax should be deprecated...

Anders Logg (logg) said : | #3 |

On Mon, Mar 15, 2010 at 09:33:27PM -0000, Chris Richardson wrote:

> Question #104471 on DOLFIN changed:

> https:/

>

> Status: Answered => Solved

>

> Chris Richardson confirmed that the question is solved:

> OK, that solves my problem. Thank you, Johan!

>

> It would be better, perhaps, if the default behaviour could be:

>

> W=V+Q+R

> is equivalent to

> W=MixedFunction

>

> and

> W=(V+Q)+R

> could be MixedFunctionSp

>

> or maybe the W=V+Q style syntax should be deprecated...

Yes, that would be good but I don't know how to fix that.

The problem is if you write

x + y + z

then Python will interpret that as (x + y) + z.

So x + y will be a mixed function space, and then that will again be

mixed with z.

This question comes up again and again so it would be good to find a

way around this.

--

Anders

Johan Hake (johan-hake) said : | #4 |

On Monday 15 March 2010 14:33:27 Chris Richardson wrote:

> Question #104471 on DOLFIN changed:

> https:/

>

> Status: Answered => Solved

>

> Chris Richardson confirmed that the question is solved:

> OK, that solves my problem. Thank you, Johan!

>

> It would be better, perhaps, if the default behaviour could be:

>

> W=V+Q+R

> is equivalent to

> W=MixedFunction

This is unfortunately not possible in Python (please prove me wrong!).

> and

> W=(V+Q)+R

> could be MixedFunctionSp

> needed...

>

> or maybe the W=V+Q style syntax should be deprecated...

I tend to agree with you, as this is the number one question new users of

FEniCS have.

However it is nice to define a MixedFunctionSpace using the add operator, so

we like to think of it as a feature and not a bug. :)

Johan