How to Use Discrete Data to Calculate

Hello all,
Just like the simple Poisson equation demo, the function f mentioned has a clear expression, but I wonder if that is possible to access the discrete f, for example, input a m*n matrix(m,n is the size of mesh), to solve the Poisson equation.

Consider the following example

import dolfinx.fem
import dolfinx.mesh
import mpi4py.MPI
import numpy as np

mesh = dolfinx.mesh.create_unit_square(mpi4py.MPI.COMM_WORLD, 1, 1)

V = dolfinx.fem.functionspace(mesh, ("CG", 1))

pressure_data = np.array([0.1, 0.3, 0.4, 0.8])
pressure_coordinates = np.array([[1., 1.], [0, 0], [0., 1.], [1., 0]])
ind2 = np.lexsort((pressure_coordinates[:, 1], pressure_coordinates[:, 0]))

p = dolfinx.fem.Function(V)
dof_coords = V.tabulate_dof_coordinates()
ind = np.lexsort((dof_coords[:, 1], dof_coords[:, 0]))

for (in_index, p_index) in zip(ind2, ind):
    p.vector[p_index] = pressure_data[in_index]

print({tuple(c): d for (c, d) in zip(pressure_coordinates, pressure_data)})
print({tuple(c): d for (c, d) in zip(dof_coords, p.vector.array)})

adapted from How to impose a pressure distribution from a data file as a boundary condition (loading)? - #5 by dokken by @dokken.

1 Like