How to set initial field value by every point's position

Dear all,

I am trying to do a thermo-fluid-solidification-solid problem. The thermo-fluid-solidification problem has been solved by other software, and the temperature with every point in the solid formed by solidification has been gotten. Now i extract the solid shape to gmsh, reconstruct a finite element mesh, and import it into Fenics for thermal stress analysis, but i don’t know how to set the same initial temperature value of the solid in the Fenics. Could anyone give me some advice?

Thanks in advance!

Your question is very general, and would depend on the structure of the data from the other software.

In general, you can

  1. Create a relation between the location of each degree of freedom and its physical coordinate in space by using FunctionSpace.tabulate_dof_coordinates()
  2. You can then directly assign data to the underlying vector in 'Function.vector()`

See for instance

Thank you! I will learn and have a try using this method.