Very Intersting Question

Hi all, quick question - and a continuation from my last post here (yes, Fenicsx is able to handle “virtual” nodes with gmsh “crack” plugin to create fictitious dof).


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.

import dolfinx
from import gmshio
import ufl
from mpi4py import MPI
import numpy as np
import gmsh

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

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)

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

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