A physics-based compact model for thermoelectric devices