In multigrid, the coarse operator is given by $$A^{2h}=RA^hP$$
where $R$ is a restriction and $P$ is a interpolation. In 1D case, I can implement it easily with or without making explicitly matrix $A^{2h}$. For the 2D case of Poisson equation, I can actually implement it without constructing matrix $A^{2h}$. But I don't know how to implement for other problems.
It looks like that $A^{2h}$ is very large matrix. In general, how to make $A^{2h}$?
In algebraic multigrid, the standard procedure is to build and store the restriction and interpolation operators on each level, and use them to construct and store the coarse level operator on each level. The work of constructing these operators is usually done in a setup phase prior to the actual multigrid iterations.
In geometric multigrid, which is the flavor of multigrid to which I assume you are referring, there are two standard ways to construct the coarse grid operator. One way is to build $A^{2h}$ via the discrete equations on the coarse grid. The other, is to define $A^{2h}$ as the Galerkin operator $RA^hP$. Depending on $R$ and $P$ it may be possible to hard-code the construction of $A^{2h}$ into your solver, or it may be necessary to construct $R$ and $P$ and compute the matrix product. Naturally, the work of building $R$, $P$, and $A^{2h}$ can be done in a setup phase prior to iterating. I highly recommend the book "Multigrid" by Trottenberg for more information.