Thermodynamics of pyroelectricity and piezoelectricity in polymers