Hi, I am a novice here so please let me know if someone already asked this question before and had it solved. I am trying to define initial conditions using mesh coordinates. The program runs but does not generate desired result. Please have a look:
from dolfin import *
import numpy as np
mesh = UnitSquareMesh(16,8)
V = FunctionSpace(mesh,'CG',1)
C1 = Function(V)
C1_array = C1.vector().array()
meshco = mesh.coordinates()
for i in range(mesh.num_vertices()):
if meshco[i][0]<=0.5+DOLFIN_EPS:
C1_array[i]=1.0
else:
C1_array[i]=0.0
C1.vector()[:]=C1_array
plot(C1, mode='color', elevate=0.0, range_max=1.0, range_min=0.0)
plot(mesh, interactive=True)
I checked the array in C1_array and the mesh coordinates are correct for what I wanted. The issue might arise when I imported C1_array back to C1.vector()[:]. This code results in a semi-random patterns of 0 and 1 across the unit square. I don't know how to embed the plot in here so if you could get a quick run on your computer to see what I meant.
Thank you in advance.