A unified simulation of the filling and postfilling stages in injection molding. Part I: Formulation