From clean energy and research to advocacy, nonprofit groups are struggling as federal dollars dry up. Foundations say they won’t be able to fill funding gaps.