Neumann condition as a circle

Hello,
How can I create a Neumann boundary condition for a circle area?
I have created a mesh that looks like this. At the edges there is a Dirichlet boundary condition =0. In the centre around the circle there should be a Neumann boundary condition with dA/dn = B.

Mesh:
A

I have found this:
https://jorgensd.github.io/dolfinx-tutorial/chapter3/neumann_dirichlet_code.html

But how do I implement the Neumann condition as a circle?

There is nothing specific with the inner boundary being circular. You use integration by parts to add the boundary condition to your variational form (as usual)

Can you show me an example of how this is done?

None of the formulations in Setting multiple Dirichlet, Neumann, and Robin conditions — FEniCSx tutorial rely on the fact that the boundary is a straight segment.

Thank you, I have seen the tutorial, but I don´t know how to integrate into Fenicsx.

The tutorial is FEniCSx.
You only need to create a MeshTags object, marking the circular boundary with some value (say 2)

Then, you use this tag as subdomain_data in a ds=ufl.Measure("ds", subdomain_data=facet_tags, subdomain_id=2).
You can then add this to an integral in your variational form

Thank you. How do I create a facet_tags?

rectangle = gmsh.model.occ.addRectangle(0,0,0, L, H, tag=1)
obstacle = gmsh.model.occ.addDisk(c_x, c_y, 0, r, r)

Mesh_domain = gmsh.model.occ.cut([(gdim, rectangle)], [(gdim, obstacle)])
    gmsh.model.occ.synchronize()

Mesh_domain_marker = 1

volumes = gmsh.model.getEntities(dim=gdim)
gmsh.model.addPhysicalGroup(volumes[0][0], [volumes[0][1]], Mesh_domain_marker)
gmsh.model.setPhysicalName(volumes[0][0], Mesh_domain_marker, "Mesh_domain")

ufl_domain = ufl_mesh_from_gmsh(cell_id, gdim)
gmsh_cell_perm = cell_perm_gmsh(to_type(str(ufl_domain.ufl_cell())), num_nodes)
cells = cells[:, gmsh_cell_perm]
mesh = create_mesh(MPI.COMM_WORLD, cells, x[:, :gdim], ufl_domain)
tdim = mesh.topology.dim
fdim = tdim - 1

facet_type = cell_entity_type(to_type(str(ufl_domain.ufl_cell())), fdim, 0)
gmsh_facet_perm = cell_perm_gmsh(facet_type, num_facet_nodes)
marked_facets = np.asarray(marked_facets[:, gmsh_facet_perm], dtype=np.int64)

local_entities, local_values = distribute_entity_data(mesh, fdim, marked_facets, facet_values)
mesh.topology.create_connectivity(fdim, tdim)
adj = create_adjacencylist(local_entities)

ft = meshtags_from_entities(mesh, fdim, adj, np.int32(local_values))
ft.name = "Facet tags"

s_cg1 = FiniteElement("CG", mesh.ufl_cell(), 1)
V = FunctionSpace(mesh, s_cg1)
V_E= fem.VectorFunctionSpace(mesh, ("DG", 0))
fdim = mesh.topology.dim - 1

obstacle_facets = ft.indices[ft.values == obstacle_marker]

u1 = ufl.TrialFunction(V) 
v1 = ufl.TestFunction(V)
k = Constant(mesh, PETSc.ScalarType(0))
f = k/epsilon_0
ds=ufl.Measure("ds", subdomain_data=???, subdomain_id=2)

a = ufl.inner(ufl.grad(u1), ufl.grad(v1)) * ufl.dx
x = SpatialCoordinate(mesh)
L = ufl.inner(f , v1) * ufl.dx + ufl.inner(E_c, v1) * ds   
u1 = fem.Function(V)

problem1 = fem.petsc.LinearProblem(a, L, bcu1, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
phi = problem1.solve()

See for instance: Test problem 2: Flow past a cylinder (DFG 2D-3 benchmark) — FEniCSx tutorial

This example was perfect! Thank you so much!

I have a supplementary question about the link. The mesh consists of 5948 nodes 6119 elements. Is it possible to increase this with a function?

I assume you’re using gmsh. See their documentation and tutorials.