How to assign different values to different elements and How to extract values of a variable defined as a function of the solution u?

Hello, I wonder how to assign different values to different elements of a 1D domain? How to extract values of a variable that is defined as a function of the solution u? Thanks a lot!

Here is the simplified script. Specifically, my questions are

  1. How to use ‘x’ instead of ‘x_space’ to define ‘init_cond’?
  2. How to extract values of ‘testf’?

##################
import numpy as np
import ufl
from mpi4py import MPI
import dolfinx
from dolfinx.fem import *

domain = dolfinx.mesh.create_interval(MPI.COMM_WORLD, 10, (0.0, 1.0))
element = ufl.FiniteElement(“CG”, domain.ufl_cell(), degree=1)
element1 = ufl.FiniteElement(“CG”, domain.ufl_cell(), degree=1)
mixedElem = ufl.MixedElement([element, element1])
V = FunctionSpace(domain, mixedElem)
V0, V0toV = V.sub(0).collapse()
u0 = Function(V0)

u1u2 = Function(V)
u1, u2 = ufl.split(u1u2)

x = ufl.SpatialCoordinate(domain)

x_space = np.linspace(0, 1.0, 11)
init_cond = 7 * np.exp(-((x_space - x_space[5]) / 0.03) ** 2)
print(f’–> init_cond: {init_cond}')

u0.vector.array[:] = init_cond
print(f’–> u0: {list(u0.vector.array)}')

four = Constant(domain, 4.0)
testf = four * u1 # Just an example; testf is more complex in my case.
print(f"–> testf: {testf}“)
print(f”–> testf_: {testf.vector.array}")

I can assign different values to different elements based on Equivalent for Expression in dolfinx
Yet, I don’t know how to extract values of a variable defined as a function of the solution u? Here is a MRE that can be easily copied compared to the one shown in the previous post:

import numpy as np
import ufl
from mpi4py import MPI
import dolfinx
from dolfinx.fem import *

L = 1.0
domain = dolfinx.mesh.create_interval(MPI.COMM_WORLD, 10, (0.0, L))
V = FunctionSpace(domain, ('CG', 1))

u = Function(V)
u0 = Function(V)

x_space = np.linspace(0, 1.0, 11)
init_cond = x_space * 50.0

u0.vector.array[:] = init_cond
print(f'--> u0: {u0.vector.array}')

u.vector.array[:] = u0.vector.array
print("u: ", u.vector.array)

testf = 5.0 * u  #Just a simple example; 'testf' is much more complex in my case.
print(f"--> testf: {testf}")
#print(f'--> testf: {testf.vector.array}')
u0.interpolate(testf)
print(f'--> testf: {u0.vector.array}')