Discrete element methods are an alternative to finite element approach to modelise thebehaviour of granular materials. This work is devoted to the study of a granular matter submittedto cyclic loadings : the ballast of the railway track submitted to repeated train passing. We choosethe NonSmooth Contact Dynamics approach for the resolution method, and we present all technicalaspects for the two-dimensional and three-dimensional cases : contact detection algorithmbetween convex polygons and convex polyhedra, the kinematic parametrization, the resolution ofthe contact and friction problem. We investigate the best parameters for numerical computation ofcyclic loadings. In the following we present some results in order to show the ability of discreteelement methods to describe the behaviour of granular matter under cyclic loading. A comparisonbetween experiment and numericals computations underline the special behaviour of this kind ofsystem. We focuse on the thin granular layer behaviour with a specific mechanical reponse dueto the creation of special structures. The three-dimensional model has been used as an exampleto study well known behaviour of masonery structure. We present a numerical study of lateralresistance of railway track based on an experiment with digitised ballast grains.