more fix on Ec/Ev.
[gss-tcad.git] / src / solver / probe.cc
blobd09604e477ee50d4ebeddd7efd4fcd4a61b75744
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, 2007 */
14 /* */
15 /* Gong Ding */
16 /* gdiso@ustc.edu */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
18 /* */
19 /*****************************************************************************/
20 #include "bsolver.h"
21 #include "log.h"
23 int BSolver::probe_open(int solver_type)
25 for(int i=0;i<probe_define.size();i++)
27 BaseBC * pbc = bc.Get_pointer(probe_define[i].bc_index);
28 int node_num=pbc->psegment->node_array.size();
29 if(probe_define[i].Append)
30 probe_define[i].pFile = fopen(probe_define[i].ProbeFile.c_str(),"a");
31 else
32 probe_define[i].pFile = fopen(probe_define[i].ProbeFile.c_str(),"w");
33 if(!probe_define[i].pFile)
34 {sprintf(log_buf,"I can't open file %s for writing!\n",probe_define[i].ProbeFile.c_str());GSS_LOG();return 1;}
35 fprintf(probe_define[i].pFile,"#Region: %s Segment: %s\n",probe_define[i].Region.c_str(), probe_define[i].Segment.c_str());
36 fprintf(probe_define[i].pFile,"#%d\tX\tY\t\n",node_num);
37 for(int p=0;p<node_num;p++)
39 int node = pbc->psegment->node_array[p];
40 double x = zone[probe_define[i].zone_index].danode[node].x/scale_unit.s_micron;
41 double y = zone[probe_define[i].zone_index].danode[node].y/scale_unit.s_micron;
42 fprintf(probe_define[i].pFile,"#%d\t%f\t%f\n",p,x,y);
45 return 0;
50 int BSolver::probe(int solver_type, PetscScalar x)
52 for(int i=0;i<probe_define.size();i++)
54 BaseBC * pbc = bc.Get_pointer(probe_define[i].bc_index);
55 int node_num=pbc->psegment->node_array.size();
56 //write information
57 if(!probe_define[i].flag)
59 switch(solver_type)
61 case DCSWEEP_VSCAN:
62 fprintf(probe_define[i].pFile,"#DCSWEEP_VSCAN(V)\t[%s]\n",probe_define[i].VariableName.c_str());break;
63 case DCSWEEP_ISCAN:
64 fprintf(probe_define[i].pFile,"#DCSWEEP_ISCAN(mA)\t[%s]\n",probe_define[i].VariableName.c_str());break;
65 case TRANSIENT:
66 fprintf(probe_define[i].pFile,"#TRANSIENT(ps)\t[%s]\n",probe_define[i].VariableName.c_str());break;
67 case EQUILIBRIUM:
68 fprintf(probe_define[i].pFile,"#EQUILIBRIUM\t[%s]\n",probe_define[i].VariableName.c_str());break;
69 case STEADYSTATE:
70 fprintf(probe_define[i].pFile,"#STEADYSTATE\t[%s]\n",probe_define[i].VariableName.c_str());break;
71 default:
72 fprintf(probe_define[i].pFile,"#[%s]\n",probe_define[i].VariableName.c_str());break;
74 probe_define[i].flag=true;
76 //write scan information
77 switch(solver_type)
79 case DCSWEEP_VSCAN:
80 fprintf(probe_define[i].pFile,"%e\t",double(x)/scale_unit.s_volt);break;
81 case DCSWEEP_ISCAN:
82 fprintf(probe_define[i].pFile,"%e\t",double(x)/scale_unit.s_mA);break;
83 case TRANSIENT:
84 fprintf(probe_define[i].pFile,"%e\t",double(x));break;
86 //record data for semiconductor zone only
87 if( probe_define[i].Variable==Doping ||
88 probe_define[i].Variable==DopingNd ||
89 probe_define[i].Variable==DopingNa ||
90 probe_define[i].Variable==ElecDensity ||
91 probe_define[i].Variable==HoleDensity ||
92 probe_define[i].Variable==ElecTemp ||
93 probe_define[i].Variable==HoleTemp ||
94 probe_define[i].Variable==PhiP ||
95 probe_define[i].Variable==PhiN ||
96 probe_define[i].Variable==Phi_Intrinsic ||
97 probe_define[i].Variable==QuantumEc ||
98 probe_define[i].Variable==QuantumEv ||
99 probe_define[i].Variable==OpticalEz ||
100 probe_define[i].Variable==OpticalHz ||
101 probe_define[i].Variable==OpticalG)
103 if(zonedata[probe_define[i].zone_index]->material_type == Semiconductor)
105 SMCZone *pzonedata = dynamic_cast<SMCZone *> (zonedata[probe_define[i].zone_index]);
106 for(int p=0;p<node_num;p++)
108 int node = pbc->psegment->node_array[p];
109 switch(probe_define[i].Variable)
111 case DopingNd:
112 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Nd*pow(scale_unit.s_centimeter,3)));break;
113 case DopingNa:
114 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Na*pow(scale_unit.s_centimeter,3)));break;
115 case Doping:
116 fprintf(probe_define[i].pFile,"%e\t",double((pzonedata->aux[node].Nd-pzonedata->aux[node].Na)*pow(scale_unit.s_centimeter,3)));break;
117 case ElecDensity:
118 fprintf(probe_define[i].pFile,"%e\t",double(fabs(pzonedata->fs[node].n)*pow(scale_unit.s_centimeter,3)));break;
119 case HoleDensity:
120 fprintf(probe_define[i].pFile,"%e\t",double(fabs(pzonedata->fs[node].p)*pow(scale_unit.s_centimeter,3)));break;
121 case ElecTemp:
122 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].Tn/scale_unit.s_kelvin));break;
123 case HoleTemp:
124 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].Tp/scale_unit.s_kelvin));break;
125 case Phi_Intrinsic:
126 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].phi_intrinsic/scale_unit.s_volt));break;
127 case PhiP:
128 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].phip/scale_unit.s_volt));break;
129 case PhiN:
130 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].phin/scale_unit.s_volt));break;
131 case QuantumEc:
132 fprintf(probe_define[i].pFile,"%e\t",double((pzonedata->fs[node].Eqc+pzonedata->fs[node].P+pzonedata->aux[node].affinity)/scale_unit.s_volt));break;
133 case QuantumEv:
134 fprintf(probe_define[i].pFile,"%e\t",double((pzonedata->fs[node].Eqv+pzonedata->fs[node].P+pzonedata->aux[node].affinity+pzonedata->aux[node].Eg)/scale_unit.s_volt));break;
135 case OpticalEz:
136 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].OpEz/scale_unit.s_volt*scale_unit.s_centimeter));break;
137 case OpticalHz:
138 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].OpHz/scale_unit.s_A*scale_unit.s_centimeter));break;
139 case OpticalG:
140 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].OptG*pow(scale_unit.s_centimeter,3)));break;
145 //record data for all zones
146 if( probe_define[i].Variable==Potential ||
147 probe_define[i].Variable==EFieldX ||
148 probe_define[i].Variable==EFieldY ||
149 probe_define[i].Variable==Temperature)
151 if(zonedata[probe_define[i].zone_index]->material_type == Semiconductor)
153 SMCZone *pzonedata = dynamic_cast<SMCZone *> (zonedata[probe_define[i].zone_index]);
154 for(int p=0;p<node_num;p++)
156 int node = pbc->psegment->node_array[p];
157 switch(probe_define[i].Variable)
159 case Potential:
160 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].P/scale_unit.s_volt));break;
161 case EFieldX:
162 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ex/scale_unit.s_volt*scale_unit.s_centimeter));break;
163 case EFieldY:
164 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ey/scale_unit.s_volt*scale_unit.s_centimeter));break;
165 case Temperature:
166 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].T/scale_unit.s_kelvin));break;
171 if(zonedata[probe_define[i].zone_index]->material_type == Insulator)
173 ISZone *pzonedata = dynamic_cast<ISZone *> (zonedata[probe_define[i].zone_index]);
174 for(int p=0;p<node_num;p++)
176 int node = pbc->psegment->node_array[p];
177 switch(probe_define[i].Variable)
179 case Potential:
180 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].P/scale_unit.s_volt));break;
181 case EFieldX:
182 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ex/scale_unit.s_volt*scale_unit.s_centimeter));break;
183 case EFieldY:
184 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ey/scale_unit.s_volt*scale_unit.s_centimeter));break;
185 case Temperature:
186 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].T/scale_unit.s_kelvin));break;
191 if(zonedata[probe_define[i].zone_index]->material_type == Conductor)
193 ElZone *pzonedata = dynamic_cast<ElZone *> (zonedata[probe_define[i].zone_index]);
194 for(int p=0;p<node_num;p++)
196 int node = pbc->psegment->node_array[p];
197 switch(probe_define[i].Variable)
199 case Potential:
200 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].P/scale_unit.s_volt));break;
201 case EFieldX:
202 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ex/scale_unit.s_volt*scale_unit.s_centimeter));break;
203 case EFieldY:
204 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->aux[node].Ey/scale_unit.s_volt*scale_unit.s_centimeter));break;
205 case Temperature:
206 fprintf(probe_define[i].pFile,"%e\t",double(pzonedata->fs[node].T/scale_unit.s_kelvin));break;
212 fprintf(probe_define[i].pFile,"\n");
213 fflush(probe_define[i].pFile);
216 return 0;
219 int BSolver::probe_close()
221 for(int i=0;i<probe_define.size();i++)
223 if(probe_define[i].pFile)
224 fclose(probe_define[i].pFile);
226 probe_define.clear();
227 return 0;