mass density calculation logic