We need .value to access the value of dolfinx.fem.Constant. However, to log it correctly, we also need to make it a list by .tolist(). Otherwise the returned number is always the current number.
Incorrect log:
test_mesh = dolfinx.mesh.create_rectangle(
comm=mpi4py.MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 1.0)),
n=(32, 16),
cell_type=dolfinx.mesh.CellType.triangle,
)
test_num = dolfinx.fem.Constant(test_mesh, petsc4py.PETSc.ScalarType(0.))
test_list = []
for i in range(10):
test_num.value = i
test_list.append(test_num.value)
print(test_list)
Correct log:
test_mesh = dolfinx.mesh.create_rectangle(
comm=mpi4py.MPI.COMM_WORLD,
points=((0.0, 0.0), (2.0, 1.0)),
n=(32, 16),
cell_type=dolfinx.mesh.CellType.triangle,
)
test_num = dolfinx.fem.Constant(test_mesh, petsc4py.PETSc.ScalarType(0.))
test_list = []
for i in range(10):
test_num.value = i
test_list.append(test_num.value.tolist())
print(test_list)