Nonisothermal multiphase flow of brine and gas through saline media