more fix on Ec/Ev.
[gss-tcad.git] / src / material / material.cc
blob8ac7b8f3f36434d0f622fe5e92dd8f1e2a03ff01
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: Feb 15 2006 */
14 /* */
15 /* Gong Ding */
16 /* gdiso@ustc.edu */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
18 /* */
19 /*****************************************************************************/
21 #include "matdefine.h"
22 #include "material.h"
23 #include "log.h"
24 #include <stdlib.h>
25 #include <math.h>
26 #include <dlfcn.h>
30 int init_PMI_Semiconductor(CmdBuf *pcmdbuf, PMISDefine & PMIS_define)
32 //process PMIS (Physical Model Interface of Semiconductor) define here
33 for(pcmdbuf->cmd_search_begin();!pcmdbuf->cmd_search_end();pcmdbuf->goto_next_cmd())
35 if(pcmdbuf->is_current_cmd("PMIS")) //it is a set structure
37 list<Cmd>::iterator pcmd = pcmdbuf->get_current_cmd();
38 if(!pcmd->allowed_args(3,"region","mobility","ii.model"))
40 sprintf(log_buf,"line %d PMIS: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
41 GSS_LOG();
42 return 1;
44 PMIS_define.Material.push_back(pcmd->get_string("material",0,""));
45 PMIS_define.Region.push_back(pcmd->get_string("region",0,""));
46 PMIS_define.Mobility.push_back(pcmd->get_string("mobility",0,"Default"));
47 PMIS_define.IIModel.push_back(pcmd->get_string("ii.model",0,"Default"));
48 PMIS_define.OpticalModel.push_back(pcmd->get_string("optical.model",0,"Default"));
51 return 0;
55 PhysicalConst::PhysicalConst(PhysicalUnitScale *unit_scale)
57 kb = 1.3806503e-23*unit_scale->s_joule/unit_scale->s_kelvin;
58 e = 1.602176462e-19*unit_scale->s_coulomb;
59 me = 9.10938188e-31*unit_scale->s_kg;
60 eps0 = 8.854187818e-12*unit_scale->s_coulomb/unit_scale->s_volt/unit_scale->s_meter;
61 mu0 = 12.56637061e-7*pow(unit_scale->s_second,2)/unit_scale->s_coulomb*unit_scale->s_volt/unit_scale->s_meter;
62 h = 6.62606876e-34*unit_scale->s_joule*unit_scale->s_second;
63 hbar = 1.054571596e-34*unit_scale->s_joule*unit_scale->s_second;
67 MatSemiconductor::MatSemiconductor(const char * region_name, const char *material,
68 PMISDefine & PMIS_define, PhysicalUnitScale *unit_scale)
69 :PhysicalConst(unit_scale)
71 pscale = unit_scale;
72 char filename[128];
73 char model_fun_name[128];
74 int region_index = -1;
76 PMIS_Environment env(pscale,&pnode,&plocal_semi_data,&time);
77 for(int i=0;i<PMIS_define.Region.size();i++)
79 if(PMIS_define.Region[i] == region_name) region_index = i;
81 sprintf(filename,"%s/lib/lib%s.so",getenv("GSS_DIR"),material);
82 dp = dlopen(filename,RTLD_LAZY);
83 if(dp==NULL) {fprintf(stderr,"Open material file lib%s.so error\n%s\n",material,dlerror()); throw ERROR;}
84 PMIS_BasicParameter*(*wbasic) (const PMIS_Environment& env);
85 PMIS_BandStructure* (*wband) (const PMIS_Environment& env);
86 PMIS_Mobility* (*wmob) (const PMIS_Environment& env);
87 PMIS_Avalanche* (*wgen) (const PMIS_Environment& env);
88 PMIS_Thermal* (*wthermal) (const PMIS_Environment& env);
89 PMIS_Optical* (*woptical) (const PMIS_Environment& env);
91 //init AD indepedent variable set routine
92 set_ad_num = (void* (*) (const unsigned int))dlsym(dp,"set_ad_number");
93 if(dlerror()) {fprintf(stderr,"Open PMIS AD_SET_VARIABLE function error!\n");throw ERROR;}
95 // init basic parameters for the material
96 sprintf(model_fun_name,"PMIS_%s_BasicParameter_Default",material);
97 wbasic = (PMIS_BasicParameter* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
98 if(dlerror()) {fprintf(stderr,"Open PMIS %s BasicParameter function error!\n",material);throw ERROR;}
100 // init band structure model
101 sprintf(model_fun_name,"PMIS_%s_BandStructure_Default",material);
102 wband = (PMIS_BandStructure* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
103 if(dlerror()) {fprintf(stderr,"Open PMIS %s BandStructure function error!\n",material);throw ERROR;}
105 // init mobility model
106 if(region_index != -1)
107 sprintf(model_fun_name,"PMIS_%s_Mob_%s",material,PMIS_define.Mobility[region_index].c_str());
108 else
109 sprintf(model_fun_name,"PMIS_%s_Mob_%s",material,"Default");
110 wmob = (PMIS_Mobility* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
111 if(dlerror()) {fprintf(stderr,"Open PMIS Mobility function %s error!\n",model_fun_name);throw ERROR;}
113 // init Avalanche generation model
114 if(region_index != -1)
115 sprintf(model_fun_name,"PMIS_%s_Avalanche_%s",material,PMIS_define.IIModel[region_index].c_str());
116 else
117 sprintf(model_fun_name,"PMIS_%s_Avalanche_Default",material);
118 wgen = (PMIS_Avalanche* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
119 if(dlerror()) {fprintf(stderr,"Open PMIS %s Avalanche function error!\n",material);throw ERROR;}
121 // init Thermal model for lattice temperature equation
122 sprintf(model_fun_name,"PMIS_%s_Thermal_Default",material);
123 wthermal = (PMIS_Thermal* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
124 if(dlerror()) {fprintf(stderr,"Open PMIS %s Thermal function error!\n",material);throw ERROR;}
126 // init optical data
127 if(region_index != -1)
128 sprintf(model_fun_name,"PMIS_%s_Optical_%s",material,PMIS_define.OpticalModel[region_index].c_str());
129 else
130 sprintf(model_fun_name,"PMIS_%s_Optical_Default",material);
131 woptical = (PMIS_Optical* (*) (const PMIS_Environment& env))dlsym(dp,model_fun_name);
132 if(dlerror()) {fprintf(stderr,"Open PMIS %s Optical function error!\n",material);throw ERROR;}
134 basic = wbasic(env);
135 band = wband(env);
136 mob = wmob(env);
137 gen = wgen(env);
138 thermal = wthermal(env);
139 optical = woptical(env);
142 void MatSemiconductor::mapping(Node* node, SemiAuxData *data, PetscScalar clock)
144 plocal_semi_data = data;
145 pnode = node;
146 time = clock;
149 MatSemiconductor::~MatSemiconductor()
151 delete basic;
152 delete band;
153 delete mob;
154 delete gen;
155 delete thermal;
156 delete optical;
157 dlclose(dp);
163 //------------------------------------------------------------------------------------------------------
165 MatInsulator::MatInsulator(const char * region_name, const char *material,
166 PhysicalUnitScale *unit_scale)
167 :PhysicalConst(unit_scale)
169 pscale = unit_scale;
170 char filename[128];
171 char model_fun_name[128];
172 char *error;
173 PMII_Environment env(pscale,&pnode,&plocal_is_data,&time);
174 sprintf(filename,"%s/lib/lib%s.so",getenv("GSS_DIR"),material);
175 dp = dlopen(filename,RTLD_LAZY);
176 if(dp==NULL) {fprintf(stderr,"open material file lib%s.so error\n",material); throw ERROR;}
177 PMII_BasicParameter*(*wbasic) (const PMII_Environment& env);
178 PMII_Thermal* (*wthermal) (const PMII_Environment& env);
179 PMII_Optical* (*woptical) (const PMII_Environment& env);
180 // init basic parameters for the material
181 sprintf(model_fun_name,"PMII_%s_BasicParameter_Default",material);
182 wbasic = (PMII_BasicParameter* (*) (const PMII_Environment& env))dlsym(dp,model_fun_name);
183 if(dlerror()) {fprintf(stderr,"Open PMII %s BasicParameter function error!\n",material);throw ERROR;}
185 // init Thermal model for lattice temperature equation
186 sprintf(model_fun_name,"PMII_%s_Thermal_Default",material);
187 wthermal = (PMII_Thermal* (*) (const PMII_Environment& env))dlsym(dp,model_fun_name);
188 if(dlerror()) {fprintf(stderr,"Open PMII %s Thermal function error!\n",material);throw ERROR;}
190 // init optical data
191 sprintf(model_fun_name,"PMII_%s_Optical_Default",material);
192 woptical = (PMII_Optical* (*) (const PMII_Environment& env))dlsym(dp,model_fun_name);
193 if(dlerror()) {fprintf(stderr,"Open PMII %s Optical function error!\n",material);throw ERROR;}
195 basic = wbasic(env);
196 thermal = wthermal(env);
197 optical = woptical(env);
200 MatInsulator::~MatInsulator()
202 delete basic;
203 delete thermal;
204 delete optical;
205 dlclose(dp);
208 void MatInsulator::mapping(Node* node, ISAuxData *data, PetscScalar clock)
210 plocal_is_data = data;
211 pnode = node;
212 time = clock;
215 //--------------------------------------------------------------------------------------------------------------
216 MatConductor::MatConductor(const char * region_name, const char *material,
217 PhysicalUnitScale *unit_scale):
218 PhysicalConst(unit_scale)
220 pscale = unit_scale;
221 char filename[128];
222 char model_fun_name[128];
223 char *error;
224 PMIC_Environment env(pscale,&pnode,&plocal_el_data,&time);
225 sprintf(filename,"%s/lib/lib%s.so",getenv("GSS_DIR"),material);
226 dp = dlopen(filename,RTLD_LAZY);
227 if(dp==NULL) {fprintf(stderr,"open material file lib%s.so error\n",material); throw ERROR;}
228 PMIC_BasicParameter*(*wbasic) (const PMIC_Environment& env);
229 PMIC_Thermal* (*wthermal) (const PMIC_Environment& env);
230 PMIC_Optical* (*woptical) (const PMIC_Environment& env);
231 // init basic parameters for the material
232 sprintf(model_fun_name,"PMIC_%s_BasicParameter_Default",material);
233 wbasic = (PMIC_BasicParameter* (*) (const PMIC_Environment& env))dlsym(dp,model_fun_name);
234 if(dlerror()) {fprintf(stderr,"Open PMIC %s BasicParameter function error!\n",material);throw ERROR;}
236 // init Thermal model for lattice temperature equation
237 sprintf(model_fun_name,"PMIC_%s_Thermal_Default",material);
238 wthermal = (PMIC_Thermal* (*) (const PMIC_Environment& env))dlsym(dp,model_fun_name);
239 if(dlerror()) {fprintf(stderr,"Open PMIC %s Thermal function error!\n",material);throw ERROR;}
241 // init optical data
242 sprintf(model_fun_name,"PMIC_%s_Optical_Default",material);
243 woptical = (PMIC_Optical* (*) (const PMIC_Environment& env))dlsym(dp,model_fun_name);
244 if(dlerror()) {fprintf(stderr,"Open PMIC %s Optical function error!\n",material);throw ERROR;}
246 basic = wbasic(env);
247 thermal = wthermal(env);
248 optical = woptical(env);
251 MatConductor::~MatConductor()
253 delete basic;
254 delete thermal;
255 delete optical;
256 dlclose(dp);
259 void MatConductor::mapping(Node* node, ELAuxData *data, PetscScalar clock)
261 plocal_el_data = data;
262 pnode = node;
263 time = clock;
266 //----------------------------------------------------------------------------------------------------------
268 MatVacuum::MatVacuum(const char * region_name, const char *material,
269 PhysicalUnitScale *unit_scale)
270 :PhysicalConst(unit_scale)
272 pscale = unit_scale;
273 char filename[128];
274 char model_fun_name[128];
275 char *error;
276 PMIV_Environment env(pscale,&pnode,&plocal_vac_data,&time);
277 sprintf(filename,"%s/lib/lib%s.so",getenv("GSS_DIR"),material);
278 dp = dlopen(filename,RTLD_LAZY);
279 if(dp==NULL) {fprintf(stderr,"open material file lib%s.so error\n",material); throw ERROR;}
280 PMIV_BasicParameter*(*wbasic) (const PMIV_Environment& env);
281 PMIV_Thermal* (*wthermal) (const PMIV_Environment& env);
282 // init basic parameters for the material
283 sprintf(model_fun_name,"PMIV_%s_BasicParameter_Default",material);
284 wbasic = (PMIV_BasicParameter* (*) (const PMIV_Environment& env))dlsym(dp,model_fun_name);
285 if(dlerror()) {fprintf(stderr,"Open PMIV %s BasicParameter function error!\n",material);throw ERROR;}
287 // init Thermal model for lattice temperature equation
288 sprintf(model_fun_name,"PMIV_%s_Thermal_Default",material);
289 wthermal = (PMIV_Thermal* (*) (const PMIV_Environment& env))dlsym(dp,model_fun_name);
290 if(dlerror()) {fprintf(stderr,"Open PMIV %s Thermal function error!\n",material);throw ERROR;}
292 basic = wbasic(env);
293 thermal = wthermal(env);
296 MatVacuum::~MatVacuum()
298 delete basic;
299 delete thermal;
300 dlclose(dp);
303 void MatVacuum::mapping(Node* node, VacuumAuxData *data, PetscScalar clock)
305 plocal_vac_data = data;
306 pnode = node;
307 time = clock;
310 //------------------------------------------------------------------------------------------------------------
312 MatPML::MatPML(const char * region_name, const char *material, PhysicalUnitScale *unit_scale)
313 :PhysicalConst(unit_scale)
315 pscale = unit_scale;
316 char filename[128];
317 char model_fun_name[128];
318 char *error;
319 PMIP_Environment env(pscale,&pnode,&plocal_pml_data,&time);
320 sprintf(filename,"%s/lib/lib%s.so",getenv("GSS_DIR"),material);
321 dp = dlopen(filename,RTLD_LAZY);
322 if(dp==NULL) {fprintf(stderr,"open material file lib%s.so error\n",material); throw ERROR;}
323 PMIP_BasicParameter*(*wbasic) (const PMIP_Environment& env);
324 PMIP_Thermal* (*wthermal) (const PMIP_Environment& env);
325 // init basic parameters for the material
326 sprintf(model_fun_name,"PMIP_%s_BasicParameter_Default",material);
327 wbasic = (PMIP_BasicParameter* (*) (const PMIP_Environment& env))dlsym(dp,model_fun_name);
328 if(dlerror()) {fprintf(stderr,"Open PMIP %s BasicParameter function error!\n",material);throw ERROR;}
330 // init Thermal model for lattice temperature equation
331 sprintf(model_fun_name,"PMIP_%s_Thermal_Default",material);
332 wthermal = (PMIP_Thermal* (*) (const PMIP_Environment& env))dlsym(dp,model_fun_name);
333 if(dlerror()) {fprintf(stderr,"Open PMIP %s Thermal function error!\n",material);throw ERROR;}
335 basic = wbasic(env);
336 thermal = wthermal(env);
339 MatPML::~MatPML()
341 delete basic;
342 delete thermal;
343 dlclose(dp);
346 void MatPML::mapping(Node* node, PMLAuxData *data, PetscScalar clock)
348 plocal_pml_data = data;
349 pnode = node;
350 time = clock;