Skip to content

Instantly share code, notes, and snippets.

@wence-
Created June 2, 2015 12:12
Show Gist options
  • Select an option

  • Save wence-/6dd3b2a6c5519d044921 to your computer and use it in GitHub Desktop.

Select an option

Save wence-/6dd3b2a6c5519d044921 to your computer and use it in GitHub Desktop.
from firedrake import *
import numpy as np
Dx = 0.1; Nx = 10
mesh = IntervalMesh(Nx, Nx*Dx)
V = FunctionSpace(mesh, "DG", 0)
def coord2idx(x, coords):
for i, cell in enumerate(coords.cell_node_map().values):
a, b = coords.dat.data_ro_with_halos[cell]
a, b = (a, b) if a < b else (b, a)
if a <= x < b:
return i
return None
print "Rank " + str(op2.MPI.comm.rank)
point = 0.5
idx = coord2idx(point, mesh.coordinates)
print idx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment