Coupling of gravity to matter, spectral action and cosmic topology