more fix on Ec/Ev.
[gss-tcad.git] / src / include / vsource.h
blob8b1221df39810b27b7ecb6150688393a7a7a3d97
1 /*****************************************************************************/
2 /* 8888888 88888888 88888888 */
3 /* 8 8 8 */
4 /* 8 8 8 */
5 /* 8 88888888 88888888 */
6 /* 8 8888 8 8 */
7 /* 8 8 8 8 */
8 /* 888888 888888888 888888888 */
9 /* */
10 /* A Two-Dimensional General Purpose Semiconductor Simulator. */
11 /* */
12 /* GSS 0.4x */
13 /* Last update: Nov 29, 2005 */
14 /* */
15 /* Gong Ding */
16 /* gdiso@ustc.edu */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
18 /* */
19 /*****************************************************************************/
20 //sevel types of vsource are defined here
21 //reference: spice vsource model
23 #ifndef _vsource_h_
24 #define _vsource_h_
25 #include <math.h>
26 #include <dlfcn.h>
27 #include "typedef.h"
29 enum VSOURCE_CARD_ERROR
31 VSOURCE_NO_ERROR,
32 VSOURCE_NO_ID,
33 VSOURCE_UNKNOW_PARAMETER
36 //virtual base class
37 class VSource
39 public:
40 char label[32];
41 virtual double vapp(double t)=0;
42 virtual ~VSource(){}
46 class VDC: public VSource
48 private:
49 double td;
50 double Vdc;
51 public:
52 VDC(double t1,double v1): td(t1),Vdc(v1){};
53 double vapp(double t)
54 { return t>=td? Vdc:0;};
59 class VSIN: public VSource
61 private:
62 double td;
63 double V0;
64 double Vamp;
65 double fre;
66 double alpha;
67 public:
68 VSIN(double t1,double v0,double v1,double f1,double a1): td(t1),V0(v0),Vamp(v1),fre(f1),alpha(a1){};
69 double vapp(double t)
70 { return t>=td? V0+Vamp*exp(-alpha*(t-td))*sin(2*3.14159265359*fre*(t-td)):V0;};
74 class VPULSE: public VSource
76 private:
77 double td;
78 double tr;
79 double tf;
80 double pw;
81 double pr;
82 double Vlo,Vhi;
83 public:
84 VPULSE(double t1,double v1,double v2,double t2,double t3,double t4, double t5):
85 td(t1),tr(t2),tf(t3),pw(t4),pr(t5),Vlo(v1),Vhi(v2){};
86 double vapp(double t)
88 if(t<td)
89 return Vlo;
90 else
92 t-=td;
93 while(t>pr) t-=pr;
94 if(t<tr)
95 return Vlo+t*(Vhi-Vlo)/tr;
96 else if(t<tr+pw)
97 return Vhi;
98 else if(t<tr+pw+tf)
99 return Vhi-(t-tr-pw)*(Vhi-Vlo)/tf;
100 else return Vlo;
107 class VEXP: public VSource
109 private:
110 double td;
111 double trc;
112 double tfd;
113 double tfc;
114 double Vlo,Vhi;
115 public:
116 VEXP(double t1,double v1,double v2,double t2,double t3,double t4):
117 td(t1),trc(t2),tfd(t3),tfc(t4),Vlo(v1),Vhi(v2){};
118 double vapp(double t)
120 if(t<=td)
121 return Vlo;
122 else if(t<=tfd)
123 return Vlo+(Vhi-Vlo)*(1-exp(-(t-td)/trc));
124 else
125 return Vlo+(Vhi-Vlo)*(1-exp(-(t-td)/trc))+(Vlo-Vhi)*(1-exp(-(t-tfd)/tfc));
130 class VSHELL: public VSource
132 private:
133 void *dll;
134 double (*Vapp_Shell)(double);
135 double scale_t;
136 double scale_V;
137 public:
138 VSHELL(void * dp, void * fp, double s_t,double s_V)
140 dll = dp;
141 Vapp_Shell = (double (*)(double)) fp;
142 scale_t = s_t;
143 scale_V = s_V;
145 double vapp(double t)
147 return scale_V*Vapp_Shell(t/scale_t);
149 ~VSHELL() {dlclose(dll);}
152 #endif