Edit values inside AssignedVectorFunction



I have two AssignedVectorFunctions, one is velocity field w_u and the other is b_f, which is a function of the velocity field. I want to edit the values of b_f so that on every node that has a higher value than that node in w_u, the value is set to the value of w_u. Or, in other words, every node in b_f has to satisfy:

b_f(i) <= w_u(i), with i being the current node.

Does anybody know how to achieve this?

Thanks in advance

Edit values of a dolfin::Function at certain co-ordinates (C++)

Hi, consider adapting the following

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, 'CG', 1)
f = interpolate(Expression('x[0]', degree=1), V)
g = interpolate(Expression('x[1]', degree=1), V)

f_arr, g_arr = f.vector().get_local(), g.vector().get_local()
f.vector().set_local(np.where(f_arr < g_arr, g_arr, f_arr))

true = Expression('x[0] < x[1] ? x[1] : x[0]', degree=1)

print sqrt(abs(assemble(inner(f-true, f-true)*dx)))
1 Like

Hi MiroK,

Thank you for your answer, but I don’t see completely how this is going to solve my problem. My problem is that I have two Functions, both having x and y component of the velocity for each node. I want to replace the value of vector b_f (so sqrt(b_f(x)^2 + b_f(y)^2)) on the nodes in which the bf vector is bigger than the w_u vector.

In your example you give two scalar functions, in stead of vector functions. I understand your script, but dont think this will work the same for vector functions, or am I mistaking?

Thanks in advance