Hello,
Using dolfin_adjoint, is it possible to have, as control variables, some specific DOF of a function?
I know that we can have all of the DOF as control variables but what if I want to keep some of them fixed and only use the free ones as control variables?
Here is a minimal example showing what I would like to do:
from dolfin import *
from dolfin_adjoint import *
import numpy as np
mesh = UnitSquareMesh(50,50)
V = FunctionSpace(mesh, "CG", 2)
n = V.dim()
d = mesh.geometry().dim()
# Recover the coordinates of the dof
dof_V_coordinates = V.tabulate_dof_coordinates()
dof_V_coordinates.resize((n, d))
dof_V_x = dof_V_coordinates[:, 0]
dof_V_y = dof_V_coordinates[:, 1]
# Some function as initialization
initial = Expression("sin(pi*x[0])*cos(pi*x[1])",degree=3)
u = interpolate(initial, V)
# find some indexes of the free and fixed dof
fixed_indexes = np.where(dof_V_x >= 0.5)[0]
free_indexes = np.where(dof_V_x < 0.5)[0]
fixed_value = 0.4
u.vector()[fixed_indexes] = fixed_value
# Working example:
m = Control(u) #Control variables (all the dofs of the Function u)
J = assemble(inner(grad(u), grad(u)) * dx) # Some Functional
Jhat = ReducedFunctional(J, m)
dJdm = Jhat.derivative()
# Non-working example:
m_1 = Control(u.vector()[free_indexes]) # Control variables (some dofs of the Function u)
Jhat_1 = ReducedFunctional(J, m_1)
dJdm_1 = Jhat_1.derivative()
I get: AttributeError: ânumpy.ndarrayâ object has no attribute âblock_variableâ at the line where m_1 is declared. Does it mean that I cannot achieve this without using Custom functions? And if yes what are your suggestions?
To have it working, just comment the last three lines that are just there to better explain what I am trying to achieve.
Thank you for your time.