### Minimize difference for single point

62
views
0
4 weeks ago by

Most examples I've found concerning dolfin adjoint minimizing a function go something like:

j = 0.5*float(dt)*assemble((u_0 - d)**2*dx)

But what if rather than minimizing the difference between an entire function and a function representing a set of experimental data, I just wanted to minimize the difference between a single data point and a point from the fenics function. Something like:

j = (Fenics_function_Point - experimental_data_point)

How would I go about setting a J Function like this, if possible?

I've seen a previous post (Is it possible to compute the gradient of a Functional only at a specific point with dolfin-adjoint?) that was close to what I was looking for, but not exactly.

If more details would be helpful, just let me know.

Thanks,

Community: FEniCS Project
1
Depending on the details, you might be able to get away with using a vertex measure.  (In particular, the point of interest needs to be a vertex of the mesh, which creates a meshing restriction and also means that point evaluations of the solution gradient won't be well-defined.)  I have never tried using this in conjunction with dolfin-adjoint, but the following test code for solving the Poisson problem with a point source (but using a vertex measure instead of altering the RHS vector directly with a PointSource) may or may not be useful:

from dolfin import *

# Mesh, function space.  Must have even number of elements in each direction,
# to ensure that there is a vertex at (0.5,0.5).
N = 100
mesh = UnitSquareMesh(2*N,2*N)
V = FunctionSpace(mesh,"Lagrange",1)

# Set up vertex measure that corresponds to a Dirac mass at (0.5,0.5).  There
# must be a mesh vertex at the desired location of the Dirac mass.
point_function = MeshFunction("size_t", mesh, 0, 0)
point_subdomain = CompiledSubDomain("near(x[0], 0.5) and near(x[1], 0.5)")
point_subdomain.mark(point_function, 1)
dP = Measure('vertex',subdomain_data=point_function)

# Set up variational problem; RHS is point evaluation of the
# integrand at the vertex (0.5,0.5).  One could also extract values of
# UFL objects at that vertex using assemble((...)*dP(1)).
# (Unfortunately, though, vertices are not great places to evaluate gradients.)
u = TrialFunction(V)
v = TestFunction(V)

# Solve problem with Dirichlet BCs on boundary
class Bdry(SubDomain):
def inside(self,x,on_boundary):
return on_boundary
bc = DirichletBC(V,Constant(0.0),Bdry())
u = Function(V,name="u")
solve(eqn,u,bcs=[bc,])
File("u.pvd") << u​
written 4 weeks ago by David Kamensky