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

How to write vector-valued and area-specific Expressions?

+1 vote

Quick, short question.
Consider the function

$\mathbf{f}(\mathbf {x}) = c \mathbf {e}_{x_2} * \chi_{\mathbf{x} \in A }( \mathbf{x})$

with $x \in \mathbb{R}^2$, where $c > 0$, $A$ is an area, $\mathbf {e}_{x_2}$ is the unit vector in y-direction and $\chi$ is the characteristic function.
Problem: this function is vector-valued. If it wasn't, I would simply use

f = Expression("condition ? a : b")

but I can't really figure out how to do this vector-valued. Any ideas?

asked Nov 16, 2016 by freistil FEniCS Novice (260 points)

1 Answer

+1 vote

To answer my own question, if someone stumbles across the same problem:
My 2D-solution looks like this:

class source(Expression):
def eval(self, value, x):
    value[0] = 0.0
    if (x[0] < 0.15) & (abs(x[1]-0.7) < 0.1):
        value[1] = 1.0
    else:
        value[1] = 0.0

def value_shape(self):
    return (2,)

f = source()

Might not be the nicest, so if someone has a shorter approach, let me know, but this compiles

answered Nov 16, 2016 by freistil FEniCS Novice (260 points)
...