Efficient cohomology computation for electromagnetic modeling