  We introduce the method and the implementation of a cosmological simulation
of a class of metric-variation f(R) models that accelerate the cosmological
expansion without a cosmological constant and evade solar-system bounds of
small-field deviations to general relativity. Such simulations are shown to
reduce to solving a non-linear Poisson equation for the scalar degree of
freedom introduced by the f(R) modifications. We detail the method to
efficiently solve the non-linear Poisson equation by using a
Newton-Gauss-Seidel relaxation scheme coupled with multigrid method to
accelerate the convergence. The simulations are shown to satisfy tests
comparing the simulated outcome to analytical solutions for simple situations,
and the dynamics of the simulations are tested with orbital and Zeldovich
collapse tests. Finally, we present several static and dynamical simulations
using realistic cosmological parameters to highlight the differences between
standard physics and f(R) physics. In general, we find that the f(R)
modifications result in stronger gravitational attraction that enhances the
dark matter power spectrum by ~20% for large but observationally allowed f(R)
modifications. More detailed study of the non-linear f(R) effects on the power
spectrum are presented in a companion paper.
