Structural and magnetic properties of CaFe2As2and BaFe2As2from first-principles density functional theory