refactored grid class and distributed_matrix class

encapsulted the members of `grid` and `distributed_matrix`.

removed the inheritance and the template parameter of `grid` class.