Offshore nuclear small reactor is a promising research direction during recent years. In order to carry out system simulation and safety analysis under accident conditions for marine reactors, the classic thermal-hydraulic system analysis code RELAP5 is modified by taking heaving, inclining and rolling motion into consideration in this paper. Additional forces are added to the momentum equation for heaving and rolling, and control volume coordination are transformed for inclining and rolling. Then, a simplified small reactor with two loops is simulated by the modified code and the effect of ocean motion is investigated. Generally, heaving leads to the periodic fluctuation of mass flow rate, inclining would cause the decrease of total mass flow through the core, and the effect of rolling is more complex. Simulation analysis is also performed on two design basis accident LOCA and LOFA in this study. Safety related conclusions are obtained about the impacts of various ocean motion.