Optimization of adaptive metal foam arrangement in a heat storage tank