nonlocal displacement averaging copied from ibvpy to start modifications