# What's the best way to define source terms from datasets in dolfinx?

**URL:** <https://fenicsproject.discourse.group/t/whats-the-best-way-to-define-source-terms-from-datasets-in-dolfinx/12588>\
**Category:** General\
**Created:** [October 29, 2023, 5:16am UTC](https://fenicsproject.discourse.group/t/whats-the-best-way-to-define-source-terms-from-datasets-in-dolfinx/12588 "2023-10-29T05:16:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcgomeza](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rcgomeza/32/5771_2.png) [@rcgomeza](https://fenicsproject.discourse.group/u/rcgomeza)\
**Post date:** [October 29, 2023, 5:16am UTC](https://fenicsproject.discourse.group/t/whats-the-best-way-to-define-source-terms-from-datasets-in-dolfinx/12588/1 "2023-10-29T05:16:48Z")

</div>

I’m solving the heat transport equation. I have a source term of the form:

```auto
f = alpha*Io*ufl.exp(-(alpha+beta)*(0.01-x[1])) #W/m3

```

It seems to work properly. However, I’m trying to define a source wich could be interpolated from x,y data resulting from experimental data or another solver. I tested if I could make f as a function

```auto
coords= V.tabulate_dof_coordinates()
f = Function(V)
f.x.array[:] = alpha.x.array[:]*Io*np.exp(-(alpha.x.array[:]+beta.x.array[:])*(0.01-coords[:,1])

```

However, although the function is the same, I get different results. I tried to define f as a Function to have the freedom to evaluate numpy or scipy interpolants with the dofs coordinates. The idea was something like

```auto
f.x.array[:] = alpha.x.array[:]*Io*MC.MC(0.01-coords[:,1])

```

Being MC the interpolation module wich recieves dofs coordinates and returns any data interpolated from a dataset

This is my variational problem. It’s axisymmetrical.

```auto
a = ((rho*cp*u*v*x[0]
      + dt*k*inner(grad(u), grad(v))*x[0])*dx #laplacian
      + dt*h*u*v*x[0]* ds(14) #Convection bundary
      + dt*u*cp_b*rho_b*w_b*v*x[0]*dx #Blood perfusion
      )
L = (rho*cp*u_n*v*x[0]*dx
    + dt*inner(f, v)*x[0]* dx(10) #Laser
    + dt*h*Tref*v*x[0]*ds(14) #Convection bundary
    + dt*T_b*cp_b*rho_b*w_b*v*x[0]*dx#Blood perfusion
    + dt*Qm*v*x[0]*dx #Metabolic heat
    )

```

Any help will be greatly appreciated.  
Thanks.
