I think I'd personally refactor this block along the lines of
```C++
std::string dimkw;
if (newParserDeck_->hasKeyword("DIMENS")) { dimkw = "DIMENS"; }
else if (newParserDeck_->hasKeyword("SPECGRID") { dimkw = "SPECGRID"; }
else { OPM_THROW(...); }
{
    std::vector<std::string> N = { "NX", "NY", "NZ" };
    DeckRecordConstPtr dimRecord =
        newParserDeck_->getKeyword(dimkw)->getRecord(0);
    for (std::size_t i = 0; i < 3; ++i) {
        logical_grid_size_[i] = dimRecord->getItem(N[i])->getInt(0);
    }
}
```
to reduce the amount of repetition.