Praise be to Allah.
Your father’s wife is a mahram to you, whether she bore children or not.
If he only did the marriage contract with her, and did not consummate the marriage with her, then she is still a mahram to you, because Allah, may He be exalted, said (interpretation of the meaning): “And marry not women whom your fathers married” [an-Nisa’ 4:22]. The wives of fathers and grandfathers become mahrams (to sons and grandsons) as soon as the marriage contract is done. Even if your grandfather or father did not consummate the marriage with her, she is still a mahram to you. If he did consummate the marriage with her and lived with her, then it is more definite that she is a mahram to you, even if she did not bear children.
To sum up: the wives of fathers and grandfathers are mahrams (to sons and grandsons) regardless of whether they bore children to your father and grandfathers or not. And Allah knows best.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allah have mercy on him).