VM294 Input Listing


/COM,ANSYS MEDIA REL. 2024R2 (05/10/2024) REF. VERIF. MANUAL: REL. 2024R2
/VERIFY,vm294
/TITLE,VM294, FOURIER SERIES ANALYSIS OF A DIODE RECTIFIED CIRCUIT
/COM, REF: SEDRA/SMITH "MICROELECTRONIC CIRCUITS 4TH ED." SEC. 3.7
/COM,
/COM   FIRST PART: NO CAPACITANCE
/COM
PI = 4*ATAN(1)
R1=2500                         ! RESISTOR VALUE
OMEGA=2*PI*60
IFINAL=3                        ! NUMBER OF MODES ( 3 -> A0,A1,B1)
IFIN=IFINAL+20			! WE MUST COMPUTE MORE COEFF THAN WE NEED
U=135

! FOR THE SECOND PART
*DIM,CAPA,ARRAY,2
CAPA(1)=1E-6,10E-6		! CAPACITOR VALUES
EPS=1E-09                       ! ERROR CRITERIA FOR TO1

!FOR RESULTS
*DIM,RESUL,ARRAY,IFINAL,(IFINAL+1)*3
*DIM,COEFFOU,CHAR,IFINAL
*DIM,TAUARR,ARRAY,1,IFINAL+1
COEFFOU(1)='A0/2= ','A1= ','B1= '
TAUARR(1,1)=CAPA(1)*R1
TAUARR(1,2)=CAPA(2)*R1

/PREP7
R,1,,U,OMEGA/2/PI,              !SET UP SINUSOIDAL VOLTAGE SOURCE
N,1,-0.85,0.4,0
N,2,-0.85,0.25,0
RMOD,1,15,0,1
ET,1,CIRCU124,4,1
TYPE,1
REAL,1
MAT,1
!
N,3,-0.85,0.325,0
E,1,2,3                       !CREATE IND. SINUSOIDAL VOLT SOURCE
R,2,R1,                       !SET UP 2500 OHM RESISTOR
N,4,-0.75,0.4,0
N,5,-0.75,0.25,0
RMOD,2,15,0,2
ET,2,CIRCU124,0,0
TYPE,2
REAL,2
MAT,1
E,4,5                         !CREATE 2500 OHM RESISTOR
!
! THE FOLLOWING COMMANDS ARE USED TO SET UP THE IDEAL DIODE
!
ET,3,125
R,3,,,,1.e-6,,1.e+8
TYPE,3
REAL,3
E,1,4
!
! APPLY GROUND TO CIRCUIT
!
D,2,VOLT,0
D,5,VOLT,0
SAVE
ALLS
EPLOT
FINISH
!
! SOLVE NON-LINEAR CIRCUIT WITH T = 0 TO 0.025
! USING A TIME STEP OF 0.001 FOR EACH ITERATION
!
/SOLU
ANTYPE,TRANS
OUTRES,ALL,ALL,
TIME,0.025
AUTOTS,-1
DELTIM,0.0001, , ,1
CNVTOL,VOLT,,0.0001,2,1.0E-6    !CONVERGANCE CRITERIA
CNVTOL,AMPS,1,1.E-2   		!CONVERGANCE CRITERIA
/OUT,SCRATCH
SOLVE
/OUT
FINISH


/POST26
NSOL,2,4,VOLT,,

/COLOR,CURVE,BLUE,1
/TITLE,VM294, LOAD VOLTAGE WAVEFORM WITH NO CAPACITANCE
/AXLAB,Y,OUTPUT POTENTIAL (VOLT)
PLVAR,2,
/TITLE,VM294, FOURIER SERIES ANALYSIS OF A DIODE RECTIFIED CIRCUIT
!
! SET UP TABLE ARRAYS TO DISPLAY OUTPUT RESULTS
!
*DIM,VOLTG,TABLE,251
*DIM,TARGET,ARRAY,251
*DO,INC,1,251,1
  T = INC*0.0001
  !TIME(INC) = T
  *GET,V,VARI,2,RTIME,T
  VOLTG(INC,1) = V
  VOLTG(INC,0) = T
  ANAL = U*SIN(OMEGA*T)
  *IF,ANAL,LT,0,THEN            !SET TARGET TO ZERO IF ANALYTICAL SOLUTION
    TARGET(INC) = 0             ! IS NEGATIVE
  *ELSE
    TARGET(INC) = ANAL
  *ENDIF
*ENDDO
FINISH
*DIM,COEFF,,IFIN
*DIM,MODE,TABLE,IFIN
*DIM,ISYM,TABLE,IFIN
*DIM,THETA,TABLE,121
*DIM,CURVEI,TABLE,121                  ! CURVE INPUT TO PROGRAM
*DIM,CURVEO,TABLE,121

*VFILL,THETA(1),RAMP,0,3               ! THETA VALUES INCREMENT 3 DEGREES
*DO,INC,1,121,1
T=(INC-1)*3/360*2*PI/OMEGA
CURVEI(INC)=VOLTG(T,1)
*ENDDO
!     CALCULATE FOURIER COEFFICIENT
MODE(1)=0
ISYM(1)=1
ISTART=2
/COM
/COM *** *DO          *********************************************************
/COM
*DO,I,ISTART,IFIN,2
        MODE(I)=I/2                        ! FILL EVEN INDICIES OF {MODE}
        ISYM(I)=1
*ENDDO
/COM
/COM *** *ENDDO   WAS LAST COMMAND USED   *************************************
/COM
!                                       ! FILL ODD INDICIES OF {MODE}
ISTART=3
*DO,I,ISTART,IFIN,2
        MODE(I)=(I/2)-.5
        ISYM(I)=-1
*ENDDO
*MFOURI,FIT, COEFF(1),MODE(1),ISYM(1),THETA(1),CURVEI(1)
!
! CURVE WHICH WILL BE DEVELOPED FROM GENERATED COEFFICIENTS
!
*MFOURI,EVAL,COEFF(1),MODE(1),ISYM(1),THETA(1),CURVEO(1)


! PLOT CURVE
/TRIAD,OFF
/PLOPTS,LOGO,0
/PLOPTS,INFO,2
/PLOPTS,WP,0
/COLOR,CURVE,CBLU
/XRANGE,0,370
/YRANGE,0,140
/TSPEC,15
/TLAB,1,0.75,CAPACITANCE = 0
/TSPEC,4
/TLAB,1,0.7,BLUE->ANSYS
/TSPEC,1
/TLAB,1,0.65,RED->FOURIER
*VPLOT,THETA(1),CURVEI(1)            ! PLOT INPUT CURVE VERSUS THETA
/USER
/NOERASE
/COM OVERLAY THE OUTPUT CURVE ON THE INPUT CURVE
/COLOR,CURVE,RED
/COLOR,AXLAB,BLAC
/AXLAB,X,ANGLE IN DEGREE
/AXLAB,Y,VOLT
*VPLOT,THETA(1),CURVEO(1)    ! PLOT OUTPUT CURVE VERSUS THETA
/ERASE
!     ANALYTICAL FOURIER COEFFICIENT
RESUL(1,2)=2*U/PI/2             ! FIRST FOURIER COEFFICIENT = A0/2
ISTART=4
*DO,I,ISTART,IFINAL,4
RESUL(I,2)=-2*U/(PI*((I/2)**2-1))
*ENDDO
*DO,I,2,IFINAL,4
RESUL(I,2)=0
*ENDDO
RESUL(3,2)=U/2
ISTART=5
*DO,I,ISTART,IFINAL,2
RESUL(I,2)=0
*ENDDO
*DO,I,1,IFINAL
RESUL(I,1)=COEFF(I)
RESUL(I,3)=RESUL(I,2)/RESUL(I,1)
*ENDDO
*DO,CAP,1,2			! START DO LOOP ON CAPACITANCE
PARSAV,ALL
/CLEAR,NOSTART
/COM    SECOND PART: CAPACITANCE VALUE
/COM
/PREP7
RESUME
PARRES,CHANGE
C1=CAPA(CAP)
TAU=TAUARR(1,CAP)
N,6,-0.65,0.4,0

ET,4,CIRCU124,2
R,4,C1
TYPE,4
REAL,4
E,4,6
!
! APPLY GROUND TO CIRCUIT
!
D,6,VOLT,0
ALLS
EPLOT
FINISH
!
! SOLVE NON-LINEAR CIRCUIT WITH T = 0 TO 0.025
! USING A TIME STEP OF 0.0001 FOR EACH ITERATION
!
/SOLU
ANTYPE,TRANS
OUTRES,ALL,ALL,
TIME,0.025
AUTOTS,-1
DELTIM,0.0001, , ,1
CNVTOL,VOLT,,0.0001,2,1.0E-6    !CONVERGANCE CRITERIA
CNVTOL,AMPS,1,1.E-1    !CONVERGANCE CRITERIA
/OUT,SCRATCH
SOLVE
/OUT
FINISH
/POST26
NSOL,2,4,VOLT,,
/COLOR,CURVE,BLUE,1
*IF,CAP,EQ,1,THEN
/TITLE,VM294, VLOAD WITH CAPACITANCE OF 1E-6F
*ENDIF
*IF,CAP,EQ,2,THEN
/TITLE,VM294, VLOAD WITH CAPACITANCE OF 10E-6F
*ENDIF
*IF,CAP,EQ,3,THEN
/TITLE,VM294, VLOAD WITH CAPACITANCE OF 1E-3F
*ENDIF
/AXLAB,Y,OUTPUT POTENTIAL (VOLT)
PLVAR,2,
/TITLE,VM294, FOURIER SERIES ANALYSIS OF A DIODE RECTIFIED CIRCUIT
!
! DETERMINE T0
!
T0=1/OMEGA*ATAN(1/(OMEGA*TAU))
!
! DETERMINE T0' : MACRO TO DO A BISECTION BETWEEN THE TWO CURVES
!
TINIT=2*PI/OMEGA/4
TFINAL=2*PI/OMEGA
V1=U*COS(OMEGA*TINIT)-U*COS(OMEGA*T0)*EXP(-1*(TINIT-T0)/TAU)
V2=U*COS(OMEGA*TFINAL)-U*COS(OMEGA*T0)*EXP(-1*(TFINAL-T0)/TAU)
V0=U*COS(OMEGA*T0)
*DO,I,1,10000
T3=(TINIT+TFINAL)/2
V3=U*COS(OMEGA*T3)-V0*EXP(-1*(T3-T0)/TAU)
ERROR=ABS(V1-V2)
*IF,ERROR,LT,EPS,THEN
*EXIT
*ENDIF
  *IF,V3,LT,0,THEN
      TINIT=T3
      V1=V3
     *ELSE
      TFINAL=T3
      V2=V3
  *ENDIF
*ENDDO

T01=T3
!
! SET UP TABLE ARRAYS TO DISPLAY OUTPUT RESULTS
!
*DIM,VOLTG,TABLE,250
*DIM,TARGET,ARRAY,250
*DO,INC,1,250,1
  T = INC*0.0001
  !TIME(INC) = T
  *GET,V,VARI,2,RTIME,T
  VOLTG(INC,1) = V
  VOLTG(INC,0) = T
  ANAL = U*SIN(OMEGA*T)
  *IF,T,LE,T0+PI/2/OMEGA,THEN   !SET TARGET TO ZERO IF ANALYTICAL SOLUTION
    TARGET(INC) = ANAL          ! IS NEGATIVE
  *ELSE
    *IF,T,LE,T01+PI/2/OMEGA,THEN
    TARGET(INC) = U*COS(OMEGA*T0)*EXP(-(T-T0-PI/2/OMEGA)/TAU)
    *ELSE
    *IF,T,LE,T0+PI/2/OMEGA+2*PI/OMEGA,THEN
    TARGET(INC) = ANAL
    *ELSE
    TARGET(INC) = U*COS(OMEGA*T0)*EXP(-(T-T0-PI/2/OMEGA-2*PI/OMEGA)/TAU)
    *ENDIF
    *ENDIF
  *ENDIF
*ENDDO
FINISH
*DIM,COEFF,,IFIN
*DIM,MODE,TABLE,IFIN
*DIM,ISYM,TABLE,IFIN
*DIM,THETA,TABLE,121
*DIM,CURVEI,TABLE,121                  ! CURVE INPUT TO PROGRAM

*VFILL,THETA(1),RAMP,0,3               ! THETA VALUES INCREMENT 3 DEGREES
*DO,INC,1,121,1
T=(INC-1)*3/360*2*PI/OMEGA+PI/2/OMEGA
CURVEI(INC)=VOLTG(T,1)
*ENDDO
!     CALCULATE FOURIER COEFFICIENT
MODE(1)=0
ISYM(1)=1
ISTART=2
/COM
*DO,I,ISTART,IFIN,2
        MODE(I)=I/2                        ! FILL EVEN INDICIES OF {MODE}
        ISYM(I)=1
*ENDDO
/COM
!                                       ! FILL ODD INDICIES OF {MODE}
ISTART=3
*DO,I,ISTART,IFIN,2
        MODE(I)=(I/2)-.5
        ISYM(I)=-1
*ENDDO
*MFOURI,FIT, COEFF(1),MODE(1),ISYM(1),THETA(1),CURVEI(1)

*IF,CAP,EQ,1,THEN
!
! CURVE WHICH WILL BE DEVELOPED FROM GENERATED COEFFICIENTS
!
*MFOURI,EVAL,COEFF(1),MODE(1),ISYM(1),THETA(1),CURVEO(1)


! PLOT CURVE
/TRIAD,OFF
/PLOPTS,LOGO,0
/PLOPTS,INFO,2
/PLOPTS,WP,0
/COLOR,CURVE,CBLU
/XRANGE,0,370
/YRANGE,0,140
/TSPEC,15
/TLAB,-0.25,0.75,CAPACITANCE = 1E-06 FARAD
/TSPEC,4
/TLAB,0,0.7,BLUE->ANSYS
/TSPEC,1
/TLAB,0,0.65,RED->FOURIER
*VPLOT,THETA(1),CURVEI(1)            ! PLOT INPUT CURVE VERSUS THETA
/USER
/NOERASE
/COM OVERLAY THE OUTPUT CURVE ON THE INPUT CURVE
/COLOR,CURVE,RED
/COLOR,AXLAB,BLAC
/AXLAB,X,ANGLE IN DEGREE
/AXLAB,Y,VOLT
*VPLOT,THETA(1),CURVEO(1)    ! PLOT OUTPUT CURVE VERSUS THETA
/ERASE
*ENDIF
!
!     ANALYTICAL FOURIER COEFFICIENT
!
*DIM,ANALY,ARRAY,IFINAL

! FIRST FOURIER COEFFICIENT = A0/2

A01=U/PI*(SIN(OMEGA*T0)-SIN(OMEGA*T01))
A02=2*V0*TAU*OMEGA/2/PI*(1-EXP(-(T01-T0)/TAU))

A0=1/2*(A01+A02)

!SECOND FOURIER COEFFICIENT = A1

A11=U*OMEGA/PI*((T0-T01+2*PI/OMEGA)/2)
A12=U/PI/4*(SIN(2*OMEGA*T0)-SIN(2*OMEGA*T01))
A13=COS(OMEGA*T0)-OMEGA*TAU*SIN(OMEGA*T0)
A14=(COS(OMEGA*T01)-OMEGA*TAU*SIN(OMEGA*T01))*EXP(-(T01-T0)/TAU)

A1=A11+A12+2*V0*TAU/(1+(OMEGA*TAU)**2)*60*(A13-A14)

! THIRD FOURIER COEFFICIENT = B1

B11=U/PI/2*(SIN(OMEGA*T0)*SIN(OMEGA*T0)-SIN(OMEGA*T01)*SIN(OMEGA*T01))
B12=SIN(OMEGA*T0)+OMEGA*TAU*COS(OMEGA*T0)
B13=(SIN(OMEGA*T01)+OMEGA*TAU*COS(OMEGA*T01))*EXP(-(T01-T0)/TAU)

B1=B11+2*V0*TAU/(1+(OMEGA*TAU)**2)*60*(B12-B13)

RESUL(1,3*CAP+2)=A0,A1,B1

*DO,I,1,IFINAL
RESUL(I,3*CAP+1)=COEFF(I)
RESUL(I,3*CAP+3)=RESUL(I,3*CAP+2)/RESUL(I,3*CAP+1)
*ENDDO
*ENDDO
!
! DISPLAY RESULTS
!
/OUT,vm294,vrt
/COM
/COM,------------------- VM294 RESULTS COMPARISON -------------------------
/COM
*VWRITE,TAUARR(1,1)
('                   TAU=0                       TAU=',F8.4)
/COM
/COM     Mechanical APDL    TARGET     RATIO  |  Mechanical APDL    TARGET    RATIO
/COM     ----------------------------------------------------------------------------
*VWRITE,COEFFOU(1),RESUL(1,1),RESUL(1,2),RESUL(1,3),RESUL(1,4),RESUL(1,5),RESUL(1,6)
(A5,'| ',3F11.4,' |',3F13.4)
/COM
/COM
/COM
*VWRITE,TAUARR(1,2)
('                   TAU=',F8.4)
/COM
/COM     Mechanical APDL    TARGET     RATIO  |
/COM     ------------------------------------------------------------------
*VWRITE,COEFFOU(1),RESUL(1,7),RESUL(1,8),RESUL(1,9)
(A5,'| ',3F11.4,' |',3F13.4)
/COM
/COM,------------------------------------------------------------------------
/OUT
FINISH
*LIST,vm294,vrt