Hi all,
I have a question about how do we manage to update a function using a gradient descent step. Here, I consider updating a function “mtrue” by a standard unit vector “mtilde” that has one at t = 6 and zero for others.
import fenics as dl
import numpy as np
import matplotlib.pyplot as pltT = 10 # [hours]
N_t = 100 # the number of tempral intervals
mesh_m = dl.IntervalMesh(N_t, 0, T)
Vm = dl.FunctionSpace(mesh_m, ‘Lagrange’, 1)m_true = dl.Expression(‘2.0 * sin((x[0] + 1.0)*pi/T)’, T = T, degree = 5)
mtrue = dl.interpolate(m_true, Vm)x = np.zeros(Vm.dim())
x[60] = 0.1 # 60 corresponds to t = 6
mtilde = dl.Function(Vm)
mtilde.vector().set_local(x)
mtrue.vector().axpy(1.0, mtilde.vector())
I obtained an updated funciton below, which is not a desired result (the spike should be t = 6), because the orders of the corrdinate of a vector and DOLFIN function space are different.
What would be the best way to manage this situation? I have an update of the function as a PETSc vector and want to update the function, which will be input to DOLFIN form in the next step.