Hi Justin, On 20/01/17 20:38, Justin Chang wrote:
Hi all,
I am trying to run a density driven flow problem where the computational domain has some initial perturbation in the concentration field. I have a unit cube domain and I want the concentrations at z >= 0.9 to be randomly perturbed by some random values.
So I have a text file 'initialfield.txt' containing these perturbations which looks something like this:
<xcoord> <ycoord> <zcoord> <value1> <xcoord> <ycoord> <zcoord> <value 2> ...
Which is for a specific coarse grid resolution, say h-size = 1/20. How would I best go about projecting this data into a Firedrake/UFL Function? Does the initialfield.txt data set have to have the same connectivity/mapping as the Mesh function? Also, if I wanted to project this data onto a finer grid, like h-size = 1/40 or 1/60, would I create two meshes, one coarse mesh for the initialfield.txt data and one fine grid that the data shall be projected onto?
Any guidelines or tips on how to best do this appreciated, thanks!
One way to do this is as follows. Load the (regularly gridded) data into a numpy array. Now you can use scipy interpolation to get the values at arbitrary points. Let's say you want to represent this field in a P2 FunctionSpace. You can do something like: V = FunctionSpace(mesh, "CG", 2) Vv = VectorFunctionSpace(mesh, "CG", 2) coords = Function(Vv) # Get coordinates of the interpolation points of the P2 field. coords.interpolate(SpatialCoordinate(mesh)) from scipy.interpolate import griddata value_coords, values = read("initial_field") f = Function(V) f.dat.data[:] = griddata(value_coords, values, coords.dat.data_ro, method="linear") Cheers, Lawrence