Hello I have a 2D mesh and I want to define a tangent vector along the mesh boundary.
- The normal vector is a ufl function:
n_i = ufl.FacetNormal(mesh)
. - For a 2D mesh, the natural way to define the tangent vector is
t_i = ufl.as_vector([-n_i[1], n_i[0]])
.
They are orthogonal to each other and the tangent vector is automatically normalized since the normal vector is normalized. But as I checked dolfinx.fem.assemble_scalar(dolfinx.fem.form(t_i[i] * t_i[i] * ufl_ds))
, this is not equal to dolfinx.fem.assemble_scalar(dolfinx.fem.form(dolfinx.fem.Constant(mesh, ScalarType(1)) * ufl_ds))
. Can you tell me how this is possible?
I could just normalize this vector by myself. But this solution makes me worry that this is indeed not the real tangent vector for some mysterious reasons, as I don’t know how to exam the values of these vectors and their inner product one by one. That’s the reason I choose to integrate them. Is there a way to examine them?
Thank you!
import basix.ufl
import dolfinx.fem
import dolfinx.fem.petsc
import dolfinx.io
import dolfinx.nls.petsc
import dolfinx.log
import gmsh
import mpi4py.MPI
import numpy as np
import petsc4py.PETSc
import ufl
import multiphenicsx.fem
import multiphenicsx.fem.petsc
import viskex
from petsc4py.PETSc import ScalarType
import matplotlib.pyplot as plt
a = 6.
beta = 2.
q = 1.
alpha = 1.0 - q/6.
nu_p = 0.5
tau = 0.3
R_0 = 10.0
Y = 1.
lcar = .5
# circular mesh
gmsh.initialize()
gmsh.model.add("mesh")
p0 = gmsh.model.geo.addPoint(0.0, 0.0, 0.0, lcar)
p1 = gmsh.model.geo.addPoint(0.0, a, 0.0, lcar)
p2 = gmsh.model.geo.addPoint(0.0, -a, 0.0, lcar)
c0 = gmsh.model.geo.addCircleArc(p1, p0, p2)
c1 = gmsh.model.geo.addCircleArc(p2, p0, p1)
boundary = gmsh.model.geo.addCurveLoop([c0, c1])
domain = gmsh.model.geo.addPlaneSurface([boundary])
p_center = gmsh.model.geo.addPoint(0, 0, 0, lcar)
gmsh.model.geo.synchronize()
gmsh.model.addPhysicalGroup(1, [c0, c1], 1)
gmsh.model.addPhysicalGroup(0, [p_center], 2)
gmsh.model.addPhysicalGroup(2, [boundary], 0)
gmsh.model.mesh.embed(0, [p_center], 2, domain)
gmsh.model.mesh.generate(2)
mesh, subdomains, boundaries = dolfinx.io.gmshio.model_to_mesh(gmsh.model, comm=mpi4py.MPI.COMM_WORLD, rank=0, gdim=2)
gmsh.finalize()
boundary_facet = boundaries.indices[boundaries.values == 1]
ufl_ds = ufl.Measure("ds", mesh)
n_i = ufl.FacetNormal(mesh)
t_i = ufl.as_vector([-n_i[1], n_i[0]])
i,j,k,l = ufl.indices(4)
dolfinx.fem.assemble_scalar(dolfinx.fem.form(dolfinx.fem.Constant(mesh, ScalarType(1)) * ufl_ds))
dolfinx.fem.assemble_scalar(dolfinx.fem.form(n_i[i] * n_i[i] * ufl_ds))
dolfinx.fem.assemble_scalar(dolfinx.fem.form(t_i[i] * t_i[i] * ufl_ds))
dolfinx.fem.assemble_scalar(dolfinx.fem.form(n_i[i] * t_i[i] * ufl_ds))