Import functions from the.txt/.csv file

~~~~~ I have one file contains node coordinates and displacement field/temperature field data and would like to import function in Dolfinx as boundary conditions. I wonder how this works in the Dolfinx version?
~~~~~ I tried with reference to Impose Velocity Profile on Inlet Face using Array - #6 by dokken , but some of the code under dolfinx may not apply.

# read mesh and meshtags
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, 'mesh.xdmf', 'r') as xdmf:
    mesh = xdmf.read_mesh(name="Grid")  
    subdomains = xdmf.read_meshtags(mesh, name="Grid")  
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim-1)  
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, 'mt.xdmf', 'r') as xdmf:
    boundaries = xdmf.read_meshtags(mesh, name="Grid")

# Define Function
V = dolfinx.fem.FunctionSpace(mesh, ("CG", 1))
u_p = dolfinx.fem.Function(V)  
dof_coords = V.tabulate_dof_coordinates()  

# from .txt import data
dofs = np.array([[x0,y0,z0],...,[xn,yn,zn]])
u_x = np.array([u_x])
u_y = np.array([])
u_z = np.array([])

# Function degrees of freedom are assigned through /.txt X/Y/Z value data
u_p.vector.setValueLocal(dof_index, values[u_x]/values[u_y]/values[u_z])

# Apply the dirichlet boundary to S0 surface of meshtag
bcl = DirichletBC(V, u_p, S0)

I would suggest to make a minimal example that either produces an error, or produces a wrong result, as shown in: Impose Velocity Profile on Inlet Face using Array - #2 by dokken

I think I might have a better description of the problem.I want to import the pressure distribution (.txt) known on the surface of the solid structure as boundary conditions. I found examples that define boundary conditions:Elasto-plastic analysis of a 2D von Mises material — Numerical tours of continuum mechanics using FEniCS master documentation (comet-fenics.readthedocs.io)


But here it has a constant pressure “q”, and if the pressure is a spatial distribution q(x,y,z), how do I define it in variational form? I now have to import pressure to dolfinx.fem.functionspace definition of function, but the test-function “v” is dolfinx.fem.VectorFunctionSpace defined.

Is the pressure distribution an explicit function of the coordinates? i.e. p=p(x,y,z) or is it only defined at certain nodes?

Pressure distribution is the form data from [x, y, z, pvalue] stored in .csv interpolation to the function defined in dolfinx.fem.functionspace.

Perhaps you may find the discussion in this topic usefull

I also wanted to feed my own values to the boundary conditions and the discussion in this topic helped me.

~~~~~ Yes, I also got a lot of help from this topic before. However, the difference between my current problem and this is that the distribution I imported is not as DirichletBC, it appears in the linear term as Neumann boundary. image
~~~~~ At this time, the p is defined in dolfinx.fem.functionspace and the test-function “v” is defined in dolfinx.fem.VectorFunctionSpace. p[pressure] is just one column of degrees of freedom, and V is three columns of degrees[v_x,v_y,v_z] of freedom, I don’t know how do they multiply. Profile - RokyC - FEniCS Project, In the above example, the problem is avoided because p is a constant in space.

The pressure p cannot be a scalar value, as there is a dot product between p and v, meaning that they are of the same dimension.
I guess you are assuming that the pressure p(x,y,z) is working in the normal direction?

~~~ Yes, the pressure is air pressure, it is working in the normal direction of solid surface. In this case, how do I implement it?

As stated above, you create a scalar space, as in:

and then your variational form is
inner(p*n,v)*ds were n is the facetnormal