Pore-scale simulation and upscaling of flow, transport and wetting in porous media