Nematic solver in two and three dimensions