Direct-substitution method for studying second harmonic generation in arbitrary optical superlattices