# Very Intersting Question

**URL:** <https://fenicsproject.discourse.group/t/very-intersting-question/10276>\
**Category:** variational formulation\
**Created:** [January 27, 2023, 11:43pm UTC](https://fenicsproject.discourse.group/t/very-intersting-question/10276 "2023-01-27T23:43:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattMcLean](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@MattMcLean](https://fenicsproject.discourse.group/u/MattMcLean)\
**Post date:** [January 27, 2023, 11:43pm UTC](https://fenicsproject.discourse.group/t/very-intersting-question/10276/1 "2023-01-27T23:43:32Z")

</div>

Hi all, quick question - and a continuation from my last post [here](https://fenicsproject.discourse.group/t/virtual-element-method-in-fenicsx/10155) (yes, Fenicsx is able to handle “virtual” nodes with gmsh “crack” plugin to create fictitious dof).

Question:

Are you able to directly use the value at a dof in the variational form? For example, say you are interested in tracking the relative difference between master/slave nodes. See the MWE below.

```auto
import dolfinx
from dolfinx.io import gmshio
import ufl
from mpi4py import MPI
import numpy as np
import gmsh

gmsh.initialize()
square = gmsh.model.occ.addRectangle(0,0,0,1,1,tag=-1)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(1, [1], 1)
gmsh.model.addPhysicalGroup(1, [3], 2)
gmsh.model.addPhysicalGroup(2, [1], 10)
gmsh.model.mesh.generate(2)

mesh, subdomains, facets = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
dx = ufl.Measure("dx", domain=mesh, subdomain_data=subdomains)
ds = ufl.Measure("ds", domain=mesh, subdomain_data=facets)

def base(x):
    return np.isclose(x[1], 0.0)

def top(x):
    return np.isclose(x[1], 1.0)

dof_base = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, base)
dof_top = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, top)

V = dolfinx.fem.FunctionSpace(mesh, ufl.FiniteElement("CG",mesh.ufl_cell(),2))
u = dolfinx.fem.Function(V)
v = ufl.TestFunction(V)

cst = dolfinx.fem.Constant(mesh,1.0)

# How to implement this?
gap = u[dof_base]-u[dof_top]
F = ufl.inner(cst,gap)*ds(1)

```

---

<div class="post-metadata">

**Author:** ![MattMcLean](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@MattMcLean](https://fenicsproject.discourse.group/u/MattMcLean)\
**Post date:** [January 30, 2023, 7:02pm UTC](https://fenicsproject.discourse.group/t/very-intersting-question/10276/2 "2023-01-30T19:02:07Z")

</div>

This pretty much sums up the above issue into one line of code.

```auto
F = ufl.inner(cst,u*ds(1)-u*ds(2))*ds(1)

```
