It is acknowledged that the injection of high power proton beams into synchrotrons must be done using stripping injection of $H^{-}$ beams which are accelerated by an injector, as done in many facilities worldwide such as ISIS, JPARC, SNS and CERN. However, this technique is not necessarily the only way of accumulation and in some cases might not represent the best choice. For example in the case of the ESS$\nu$SB Accumulator Ring, injecting the protons into the ring could represent savings in capital cost, reduced risk of losses in the linac and transfer lines and simplification to the overall project. This work presents the development of a method allowing to optimize the 4D Liouvillian accumulation of high-power proton and heavy ion beams.