Try to write a consistent test to modify the porosity values ...
IF(INPOLY(XX1,YY1,XSOM,YSOM,NSOM)) THEN
IF(XX1.GE.-10.D0.AND.XX1.LE.10.D0) THEN
POROS%R(IELEM) = POR
ELSEIF(XX1.LT.-10.D0) THEN
POROS%R(IELEM) = POR - (1.D0-POR) * (XX1+10.D0) / 10.D0
ELSEIF(XX1.GT.10.D0) THEN
POROS%R(IELEM) = POR + (1.D0-POR) * (XX1-10.D0) / 10.D0
ENDIF
ENDIF
When element XX1, YY1 is in your polygon, the following conditions are probably not satisfied except maybe the last one ...
Then you probably have porosity = 0 in some elements...