Emerging spin transfer torque magnetoresistive random access memories (STT MRAM) are nonvolatile and offer high speed and endurance. MRAM cells include a fixed reference magnetic layer and a free-to-switch ferromagnetic layer (FL), separated by a tunnel barrier. The FL usually consists of several sub-layers separated by nonmagnetic buffer layers. The magnetization dynamics is governed by the Landau-Lifshitz-Gilbert (LLG) equation supplemented with the corresponding torques. To accurately design MRAM cells it is necessary to evaluate the torques in composite magnetic layers, which depend on nonequilibrium spin accumulation generated by an electric current. Spin accumulation and current also depend on the magnetization. Therefore, the LLG and the spin-charge transport equations must be solved simultaneously. We apply the finite element method (FEM) to numerically solve this coupled system of partial differential equations. We follow a modular approach and use well-developed C++ FEM libraries. For the computation of the torques acting in a magnetic tunnel junction (MTJ), a magnetization-dependent resistivity of the tunnel barrier is introduced. A fully three-dimensional solution of the equations is performed to accurately model the torques acting on the magnetization. The use of a unique set of equations for the whole memory cell is an ultimate advantage of our approach.