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
- How to use ‘x’ instead of ‘x_space’ to define ‘init_cond’?
- 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}")