M4 Circuit Macros - Advance Examples I

From Peter Jan Randewijk
Jump to: navigation, search

Utilising the power of dpic for generic (M4) Circuit Macro "pictures"

Contents

An Example of a Air-Cored PM machine with different winding configurations

All of the examples below uses the same dpic code (as shown below), but with different variable values. This is achieved by including the appropriate variable definitions (and commenting the others out) from separate M4 "library" files.

.PS
define(`HOMELIB_',`')
include(libcct.m4)
include(pstricks.m4)

# #################################################### #
# Choose one of the following Coil Configuration Files #
# #################################################### #
#include(flux_distr_2c4p3l_0_a.m4)   #compile with e.g. m4cm -a '_2c4p3l_0_a' 
#include(flux_distr_2c4p3l_0_abc.m4) #compile with e.g. m4cm -a '_2c4p3l_0_abc'
#include(flux_distr_3c2p2l_I.m4)     #compile with e.g. m4cm -a '_3c2p2l_I'
#include(flux_distr_3c4p4l_I.m4)     #compile with e.g. m4cm -a '_3c4p4l_I'
#include(flux_distr_3c4p6l_I.m4)     #compile with e.g. m4cm -a '_3c4p6l_I'
#include(flux_distr_3c4p4l_II.m4)    #compile with e.g. m4cm -a '_3c4p4l_II'
include(flux_distr_3c4p6l_II.m4)    #compile with e.g. m4cm -a '_3c4p6l_II'

scale=25.4  #Scaling Factor set to [mm] if scale=25.4 

cct_init

linethick_(0.5)

_mm=0.9  #For custum scaling

pi = atan2(0,-1)

define(`I_cross',`[\
  I: circle rad _rad fill 1;
  line from 1/5 between I.ne and I.sw to 4/5 between I.ne and I.sw;
  line from 1/5 between I.nw and I.se to 4/5 between I.nw and I.se]' )

define(`I_dot',`[\
  I: circle rad _rad fill 1;
  command "`\pscustom[fillstyle=solid]{'"
    circle rad _rad/5 with .c at I.c
  command "`}%'"]' )

#Flux Amplitude/Frequency etc.
_Af=1         #Amplitude
_f=50	        #Frequency [Hz]
_Tf=1/_f      #Period
_wf=2*pi*_f   #Frequency [rad/s]

_cycles=2     #Number of Cycles

_res=100      #Resolotion
_dt=_Tf/_res  #Step size

_xscale=140*_mm/(_cycles*_Tf)   #X-axis scaling factor [i.e. 150mm wide]
_yscale=40*_mm/_Af              #Y-axis scaling factor [i.e.50mm high]

O: (0,0)

#Draw sinusoidal flux distribution
for _t = 0 to _cycles*_Tf by _dt do {
  x0=(_t)*_xscale
  x1=(_t+_dt)*_xscale
  y0=_Af*sin(_wf*_t)*_yscale
  y1=_Af*sin(_wf*(_t+_dt))*_yscale

  \psset{linecolor=black}
  line from (x0,y0) to (x1,y1) thick 2*_mm
}

#Add labels
\psset{linecolor=black}
line from (_Tf*(1+120/360)*_xscale,_Af*sin(_wf*_Tf*(1+120/360))*_yscale) right 10 ->;"${\omega_m}$" ljust
spline 0.7 from (_Tf*90/360*_xscale,_Af*sin(_wf*_Tf*90/360)*_yscale) up 7 then right 7 <-;"${B_{p_1}\sin(\theta)}$" ljust

#Draw Axis + Labels
\psset{linecolor=black}
line from (0,-_Af*_yscale-7) to (0,_Af*_yscale+7) <->
"${B_g}$" rjust
line from O right _cycles*_Tf*_xscale+10 ->
"$\theta$" below

#The PM poles info
_K_p=2/3	# Pole-arc to Pole-pitch ratio
_offset=8*_mm	# Magnet offset [mm]
_thick=6*_mm	# Magnet thickness/height

for _c = 0 to _cycles-1 do {
  #Draw PM pole-pair
  command "`\pscustom[fillstyle=vlines, linecolor=black, fillcolor=lightgray]{'"
   B: box wid _K_p*_Tf/2*_xscale ht _thick with .nw at ((_K_p*_Tf/8+_Tf*_c)*_xscale,-_offset)
  command "`}%'"
  "\sf\textbf{N}" at B.s below
  command "`\pscustom[fillstyle=hlines, linecolor=black, fillcolor=lightgray]{'"
    B: box wid _K_p*_Tf/2*_xscale ht _thick with .nw at ((_K_p*_Tf/8+_Tf/2+_Tf*_c)*_xscale,-_offset)
  command "`}%'"
  "\sf\textbf{S}" at B.s below
  command "`\pscustom[fillstyle=hlines, linecolor=black, fillcolor=lightgray]{'"
    B: box wid _K_p*_Tf/2*_xscale ht _thick with .sw at ((_K_p*_Tf/8+_Tf*_c)*_xscale,_offset)
  command "`}%'"
  "\sf\textbf{S}" at B.n above
  command "`\pscustom[fillstyle=vlines, linecolor=black, fillcolor=lightgray]{'"
    B: box wid _K_p*_Tf/2*_xscale ht _thick with .sw at ((_K_p*_Tf/8+_Tf/2+_Tf*_c)*_xscale,_offset)
  command "`}%'"
  "\sf\textbf{N}" at B.n above
}

_rad=(_Tf/36)*_xscale

#Draw Coils
for _c = 0 to _cycles*_kq*2-1 do {
  if (_type!= 0) then {
    #For Type I & II
    _ph=_c % 3
    if _ph==0 && _color==1 then {
      #Phase A
      \psset{linecolor=ai_red}
      \psset{fillcolor=ai_red}
    } else {
      if _ph==1 && _color==1 then {
        #Phase B
        \psset{linecolor=ai_yellow}
        \psset{fillcolor=ai_yellow}
      } else {
        #Phase C
        if _ph==2 && _color==1 then {
          \psset{linecolor=ai_blue}
          \psset{fillcolor=ai_blue}
        } else {
          \psset{linecolor=black}
          \psset{fillcolor=black}
        }
      }
    }
  } else {
    #For Type 0
    if _color==1 then {
      #Draw Phase A in red
      \psset{linecolor=ai_red}
      \psset{fillcolor=ai_red}
    } else {
      #Draw Phase A in black
      \psset{linecolor=black}
      \psset{fillcolor=black}
    }#endifelse
  }
  for _i = 0 to _l-1 do {
    #Draw each layer
    if _type==2 then {
      Ic: I_cross with .c at ((_Tf*_alpha/360+_Tf*_c/(_kq*2))*_xscale+(_i*_rad*2-_rad*2*((_l-1)/2)),0)
      Id: I_dot   with .c at ((_Tf*_alpha/360+_Tf*(_c+1)/(_kq*2))*_xscale+(-_i*_rad*2-_rad*(_l+1)),0)
    } else {#_type==1 || _type==0
      Ic: I_cross with .c at ((_Tf*_alpha/360+_Tf*_c/(_kq*2))*_xscale+(_i*_rad*2-_rad*2*((_l-1)/2)),0)
      Id: I_dot   with .c at ((_Tf*_alpha/360+_Tf/(_kq*4)+_Tf*_c/(_kq*2))*xscale+(-_i*_rad*2+_rad*2*((_l-1)/2)),0)
    }
    if _l>1 then {
      sprintf("\tiny{%g}",_l-_i) at Ic.n above
      sprintf("\tiny\'{%g}",_l-_i) at Id.n above
    }
  }
}
if _draw_BC==1 && _type==0 then {
  #Draw Phases B & C for Type 0
  #Phase B
  if _color==1 then {
    #Draw Phase B in yellow
    \psset{linecolor=ai_yellow}
    \psset{fillcolor=ai_yellow}
  } else {
    #Draw Phase B in black
    \psset{linecolor=black}
    \psset{fillcolor=black}
  }#endifelse
  for _c = 0 to _cycles*_kq*2-1 do {
    #Draw coils
    for _i = 0 to _l-1 do {
      #Draw each layer
      Ic: I_cross with .c at ((_Tf*_alpha/360+_Tf*_c/(_kq*2)+_Tf/3)*_xscale+(_i*_rad*2-_rad*2*((_l-1)/2)),0)
      Id: I_dot with .c at ((_Tf*_alpha/360+_Tf/(_kq*4)+_Tf*_c/(_kq*2)+_Tf/3)*_xscale+(-_i*_rad*2+_rad*2*((_l-1)/2)),0)
      if _l>1 then {
        sprintf("\tiny{%g}",_l-_i) at Ic.n above
        sprintf("\tiny\'{%g}",_l-_i) at Id.n above
      }#endif
    }#endfor
  }#endfor
  #Phase C
  if _color==1 then {
    #Draw Phase C in blue
    \psset{linecolor=ai_blue}
    \psset{fillcolor=ai_blue}
  } else {
    #Draw Phase C in black
    \psset{linecolor=black}
    \psset{fillcolor=black}
  }#endifelse
  for _c = 0 to _cycles*_kq*2-1 do {
    #Draw coils
    for _i = 0 to _l-1 do {
      #Draw each layer
      Ic: I_dot with .c at ((_Tf*_alpha/360+_Tf*_c/(_kq*2)+_Tf/6)*_xscale+(_i*_rad*2-_rad*2*((_l-1)/2)),0)
      Id: I_cross with .c at ((_Tf*_alpha/360+_Tf/(_kq*4)+_Tf*_c/(_kq*2)+_Tf/6)*_xscale+(-_i*_rad*2+_rad*2*((_l-1)/2)),0)
      if _l>1 then {
        sprintf("\tiny{%g}",_l-_i) at Ic.n above
        sprintf("\tiny\'{%g}",_l-_i) at Id.n above
      }#endif
    }#endfor
  }#endfor
}#endif

\psset{linecolor=black}

#Draw dimensions
_tick_offset=2	#Tick offset
_tick_length=7
if _alpha>0 then {
  dimension_(from (0,-(_offset+_thick)) to (_Tf*_alpha/360*_xscale,-(_offset+_thick)),
    -_tick_length,"$_\alpha$",14pt__,_tick_offset,->)}
if _l>1 then {
  if _type==1 || _type==0 then {#Equally spaced
    dimension_(from ((_Tf*_alpha/360+_Tf/(_kq*4))*_xscale-(_rad*2*((_l-1)/2)),
      _offset+_thick) to ((_Tf*_alpha/360+_Tf/(_kq*4))*_xscale+(_rad*2*((_l-1)/2)),
      _offset+_thick),_tick_length,"$_{2\Delta}$",22pt__,_tick_offset,<->)
  } else {#As wide as possible
    dimension_(from ((_Tf*_alpha/360+_Tf/(_kq*2))*_xscale-(_rad*(3*_l-1)),
      _offset+_thick) to ((_Tf*_alpha/360+_Tf/(_kq*2))*_xscale-(_rad*(_l+1)),
      _offset+_thick),_tick_length,"$_{2\Delta}$",22pt__,_tick_offset,<->)
  }
}
dimension_(from (0,-(_offset+_thick+_tick_offset+_tick_length)) to ((_Tf/2)*_xscale,
  -(_offset+_thick+_tick_offset+_tick_length)),
  -_tick_length,"$\tfrac{2\pi}{p}$",22pt__,_tick_offset,<->)

if _type==0 then {
  #Type 0 Dimensions
  dimension_(from (_Tf*_alpha/360*_xscale,-(_offset+_thick)) to ((_Tf/(_kq*4)+_Tf*_alpha/360)*_xscale,
    -(_offset+_thick)),-_tick_length,"$\tfrac{\pi}{q}$",20pt__,_tick_offset,<->)
  dimension_(from ((_Tf/(_kq*4)+_Tf*_alpha/360)*_xscale,-(_offset+_thick)) to ((_Tf/(_kq*2)+_Tf*_alpha/360)*_xscale,
    -(_offset+_thick)),-_tick_length,"$\tfrac{\pi}{q}$",20pt__,_tick_offset,<->)
} else {
  if _type==1 then {
    #Type I Dimensions
    dimension_(from (_Tf*_alpha/360*_xscale,-(_offset+_thick)) to ((_Tf/(_kq*4)+_Tf*_alpha/360)*_xscale,
      -(_offset+_thick)),-_tick_length,"$\tfrac{\pi}{Q}$",20pt__,_tick_offset,<->)
    dimension_(from ((_Tf/(_kq*4)+_Tf*_alpha/360)*_xscale,-(_offset+_thick)) to ((_Tf/(_kq*2)+_Tf*_alpha/360)*_xscale,
      -(_offset+_thick)),-_tick_length,"$\tfrac{\pi}{Q}$",20pt__,_tick_offset,<->)
  } else {
    #Type II Dimensions
    dimension_(from (_Tf*_alpha/360*_xscale,-(_offset+_thick)) to ((_Tf/(_kq*2)+_Tf*_alpha/360)*_xscale,
      -(_offset+_thick)),-_tick_length,"$\tfrac{2\pi}{Q}$",20pt__,_tick_offset,<->)}
}
.PE

Overlap Windings

Phase A

Using: include(flux_distr_2c4p3l_0_a.m4)

#############
# Coil info #
#############
_alpha=30   #Coil centre offset [degrees]
_kq=2/4     #Coils per pole (per phase)
_l=3        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=0     #Type of winding (0="overlapped", 1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with overlap windings.

Phase A, B & C

Using: include(flux_distr_2c4p3l_0_abc.m4)

#############
# Coil info #
#############
_alpha=30   #Coil centre offset [degrees]
_kq=2/4     #Coils per pole (per phase)
_l=3        #Number of layers
_draw_BC=1  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=0     #Type of winding (0="overlapped", 1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with overlap windings.

Concentrated Type I Windings

With 3 Coils per 2 Poles

Using: include(flux_distr_3c2p2l_I.m4)

#############
# Coil info #
#############
_alpha=60   #Coil centre offset [degrees]
_kq=3/2     #Coil per pole
_l=2        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=1     #Type of winding (1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with concentrated Type I windings.

With 3 Coils per 4 Poles

Using: include(flux_distr_3c4p4l_I.m4)

#############
# Coil info #
#############
_alpha=60   #Coil centre offset [degrees]
_kq=3/4     #Coil per pole
_l=4        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=1     #Type of winding (1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with concentrated Type I windings.

With 3 Coils per 4 Poles using VERY wide Coils-side Width Coils

Using: include(flux_distr_3c4p6l_I.m4)

#############
# Coil info #
#############
_alpha=60   #Coil centre offset [degrees]
_kq=3/4     #Coil per pole
_l=6        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=1     #Type of winding (1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with concentrated Type I windings.

Concentrated Type II Windings

With 3 Coils per 4 Poles

Using: include(flux_distr_3c4p4l_II.m4)

#############
# Coil info #
#############
_alpha=45   #Coil centre offset [degrees]
_kq=3/4     #Coils per pole
_l=4        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=2     #Type of winding (1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with concentrated Type II windings.

With 3 Coils per 4 Poles using VERY wide Coil-side Width Coils

Using: include(flux_distr_3c4p6l_II.m4)

#############
# Coil info #
#############
_alpha=60   #Coil centre offset [degrees]
_kq=3/4     #Coils per pole
_l=6        #Number of layers
_draw_BC=0  #Draw phases (B & C) as well for overlap windings True=1/False=0
_type=2     #Type of winding (1="equally spaced", 2="as wide as possible")
_color=1    #Draw Phases in Color

Coil configuration for a RFAPM machine with concentrated Type II windings.

Personal tools