This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Inputting a random permeability dataset from a text file into FEniCS

0 votes

I have a text file containing a list of (cell-wise) permeabilities for a given mesh (e.g., the SPE10 benchmark). Is there a simple way for FEniCS to input this data into a MeshFunction? I am assuming here that the cell ordering for the random permeability data is consistent with that of my input unstructured mesh file (e.g., GMSH in my case).

asked May 5, 2015 by jychang48 FEniCS Novice (510 points)

1 Answer

+1 vote
 
Best answer

You can load it as a numpy array and set the array of the meshfunction directly:

mf = CellFunction("double", mesh)
mf.array()[:] = my_array

To reuse it in parallel (or in cases where your assumtion no longer holds), you can save it to file and re-read it later:

f = File("my_meshfunction.xml.gz")
f << mf

And re-read it as

mf = MeshFunction("double", mesh, "my_meshfunction.xml.gz")
answered May 6, 2015 by Øyvind Evju FEniCS Expert (17,700 points)
selected May 10, 2015 by jychang48
...