### How to define vector Expression with complicated piecewise behavior?

104

views

0

I'm trying to define a vector source term. Physically, this could be the body force in elasticity. I have a complicated piecewise definition that I want to use. That is, I need to use a bunch of if-elif statements.

For simple expressions, I am able to use the usual Expression syntax. My piecewise expression seems too complicated for the "conditional" option. I found this approach:

https://fenicsproject.org/qa/3397/define-a-piecewise-constant-source/

but I have 2 problems with that.

1) I can get it to work, I don't understand how and why. I'd like to understand better before using it. Can anyone explain or point me to the right place in the documentation.

2) the link describes the scalar case. I tried and failed to do the vector case. I would appreciate help with that. Maybe the answer to my first question will also help me to generalize it myself.

For simple expressions, I am able to use the usual Expression syntax. My piecewise expression seems too complicated for the "conditional" option. I found this approach:

https://fenicsproject.org/qa/3397/define-a-piecewise-constant-source/

but I have 2 problems with that.

1) I can get it to work, I don't understand how and why. I'd like to understand better before using it. Can anyone explain or point me to the right place in the documentation.

2) the link describes the scalar case. I tried and failed to do the vector case. I would appreciate help with that. Maybe the answer to my first question will also help me to generalize it myself.

Community: FEniCS Project

### 1 Answer

2

I was able to figure out my answer at this page:

https://fenicsproject.org/olddocs/dolfin/1.5.0/python/programmers-reference/functions/expression/Expression.html

See the first example in Section 3. I had not changed the `return (1,)`

to `return (2,)`

in the example at the link in the original question.

Please login to add an answer/comment or follow this question.