*SET,a,NODE(lx,ly,lz)                            ! Get the corner node ref. number for displacement
*GET,element_1,ELEM,,NUM,MIN                      ! Read the number of the first selected element
*GET,element_n,ELEM,,NUM,MAX                     ! Read the number of the last selected element
*GET,starttime,ACTIVE,0,TIME,WALL     ! Start time for benchmarking

/SOLU                                                ! Solution mode
EQSLV,JCG,1E-6                                             ! Select JCG solver, with 1e-6 tolerance (faster)


*DO,icon,1,con_no,1
            /SOLU
            SOLVE
            /POST1
            SET,1
            *GET,elem_1,ELEM,0,NUM,MIN
            *GET,elem_no,ELEM,0,NUM,MAX
	    *GET,mat_no,MAT,0,NUM,MAX
            vf_air_post = 0
            vf_poled_post = 0
            vf_unpoled_post = 0
            elem_mat = 0
            AVPRIN,0, , 
            ETABLE,TZZ,S,Z 
            !*  
            AVPRIN,0, , 
            ETABLE,SZZ,EPTO,Z   
            !*  
            AVPRIN,0, , 
            ETABLE,EZZ,EF,Z 
            !*  
            AVPRIN,0, , 
            ETABLE,DZZ,D,Z  
            !*  
	    AVPRIN,0, , 
	    ETABLE, ,S,EQV  
	    !*  
	    AVPRIN,0, , 
	    ETABLE, ,EPTO,EQV   
	    !*  
            SMULT,MECH,TZZ,SZZ,1,1, 
            SMULT,ELEC,EZZ,DZZ,1,1, 
            SADD,ENERGY,MECH,ELEC,1,1, ,
            /PREP7
		
            *DO,m,elem_1,elem_no,1         
                        *GET,POLE,ELEM,m,ETAB,ENERGY
                        *GET,elem_mat,ELEM,m,ATTR,MAT
		        *IF,elem_mat,LT,mesh_size**3+2,THEN
                        *IF,elem_mat,NE,1,THEN
		           *IF,POLE,GE,W,THEN ! Eur. J. Mech. A/Solids 25 (2006) 950-964
                             MPCHG,elem_mat+mesh_size**3+1,m
                           *ENDIF
                        *ENDIF
                        *ENDIF
            *ENDDO

  	    ESEL,S,MAT,,2,max_elem+1
            *GET,elem_unpoled_post,ELEM,0,COUNT
            ESEL,S,MAT,,n+1,meshdivs**3+n
            *GET,elem_poled_post,ELEM,0,COUNT
            ESEL,S,MAT,,1
            *GET,elem_air_post,ELEM,0,COUNT
            ALLSEL,ALL
            vf_air_post = elem_air_post
            vf_poled_post = elem_poled_post
            vf_unpoled_post = elem_unpoled_post
            con_res(icon,1) = vf_air_post
            con_res(icon,2) = vf_poled_post
            con_res(icon,3) = vf_unpoled_post
            *IF,icon,GE,2,THEN
            ic = icon - 1
            *VOPER,con_res(icon,4),con_res(ic,2),DIV,con_res(icon,2)
            *IF,con_res(icon,4),GT,0.95,AND,con_res(icon,4),LT,1.05,EXIT
            *IF,con_res(icon,4),EQ,1,EXIT
            *ENDIF
*ENDDO
