Delta function in fenicsx

Hi everyone!
I’m trying to define the delta function in FEniCSx. My code:

import dolfinx
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
import math
from ufl import (FacetNormal, FiniteElement, Identity, Measure, TestFunction, TrialFunction, VectorElement,
                 as_vector, div, dot, ds, dx, inner, lhs, grad, nabla_grad, rhs, sym)

s_cg1 = FiniteElement("CG", mesh.ufl_cell(), 1)
Q = dolfinx.fem.FunctionSpace(domain, s_cg1)

# Create delta function
a=0.1
rpi = math.sqrt(math.pi)
deno = (rpi*a)**3
a3 = a**3
x_upstream = 0.02
x_downstream = 0.3
x_throat = 0.2

delta_up = Function(Q)
delta_up.name = "d_u"
delta_up.interpolate(lambda x : (1/deno)*np.exp(-((x[0]-x_upstream)**2+(x[1])**2+ (x[2])**2)/a3))

with dolfinx.io.XDMFFile(domain.comm, "Plot/delta.xdmf", "w") as file:
    file.write_mesh(domain)
    file.write_function(delta_up)

when I try to save to visualize, I get the next error:

RuntimeError: Newton method failed to converge for non-affine geometry

I don’t know if is a problem of the definition of delta function…
Does anyone have a suggestion?
Thank you so much

1 Like

You haven’t defined your mesh here.
This error message usually happens when the mesh is broken (i.e. a cell is inverted/degenerated).

sorry, I forgot it.

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "venturi_coarse.xdmf", "r") as xdmf:
    domain = xdmf.read_mesh(name="Grid")

and the mesh is in

I reinstalled FeniCSx and works!