Update ChangeLog
[gss-tcad.git] / src / runctrl / ctrl.cc
blobe32789b9f7d185848b81b345de97c5914e5ed2db
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: Apr 13, 2006 */
14 /* */
15 /* Gong Ding */
16 /* gdiso@ustc.edu */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
18 /* */
19 /*****************************************************************************/
20 #include "config.h"
21 #include "log.h"
22 #include "ctrl.h"
24 #include "xgraph.h"
25 #include "wgraph.h"
26 #include "grafix3d.h"
27 #include <ctype.h>
30 int SolveControl::run_control(list<Cmd>& cmdlist)
33 //search the CmdBuf, delete each command card after its execution.
34 for(pcmdbuf->cmd_search_begin();!pcmdbuf->cmd_search_end();)
36 if(pcmdbuf->is_current_cmd("METHOD"))
38 if(set_method(pcmdbuf->get_current_cmd())) return 1;
39 pcmdbuf->delete_current_cmd();
42 else if(pcmdbuf->is_current_cmd("SOLVE"))
44 if(set_solve(pcmdbuf->get_current_cmd())) return 1;
45 if(do_solve()) return 1;
46 pcmdbuf->delete_current_cmd();
49 else if(pcmdbuf->is_current_cmd("EXPORT"))
51 if(set_export(pcmdbuf->get_current_cmd())) return 1;
52 if(do_export()) return 1;
53 pcmdbuf->delete_current_cmd();
56 else if(pcmdbuf->is_current_cmd("IMPORT"))
58 if(set_import(pcmdbuf->get_current_cmd())) return 1;
59 if(do_import()) return 1;
60 pcmdbuf->delete_current_cmd();
63 else if(pcmdbuf->is_current_cmd("ATTACH"))
65 if(set_attach(pcmdbuf->get_current_cmd())) return 1;
66 if(do_attach()) return 1;
67 pcmdbuf->delete_current_cmd();
70 else if(pcmdbuf->is_current_cmd("REFINE"))
72 if(set_refine(pcmdbuf->get_current_cmd())) return 1;
73 if(do_refine()) return 1;
74 pcmdbuf->delete_current_cmd();
77 else if(pcmdbuf->is_current_cmd("PLOT"))
79 if(set_plot(pcmdbuf->get_current_cmd())) return 1;
80 if(do_plot()) return 1;
81 pcmdbuf->delete_current_cmd();
84 else if(pcmdbuf->is_current_cmd("PLOTMESH"))
86 if(set_plotmesh(pcmdbuf->get_current_cmd())) return 1;
87 if(do_plotmesh()) return 1;
88 pcmdbuf->delete_current_cmd();
91 else if(pcmdbuf->is_current_cmd("PLOTVTK"))
93 if(set_vtk_plot(pcmdbuf->get_current_cmd())) return 1;
94 if(do_vtk_plot()) return 1;
95 pcmdbuf->delete_current_cmd();
98 else if(pcmdbuf->is_current_cmd("PROBE"))
100 if(set_probe(pcmdbuf->get_current_cmd())) return 1;
101 pcmdbuf->delete_current_cmd();
104 else if(pcmdbuf->is_current_cmd("END"))
106 return 0;
109 else
110 pcmdbuf->goto_next_cmd();
113 return 0;
119 int SolveControl::do_solve()
122 if(solve_define.Solver == DDML1E)
124 DDM_Solver_L1E::init_solver(solve_define);
125 DDM_Solver_L1E::do_solve(solve_define);
126 DDM_Solver_L1E::destroy_solver(solve_define);
129 if(solve_define.Solver == DDML1AC)
131 DDM_Solver_L1AC::init_solver(solve_define);
132 DDM_Solver_L1AC::do_solve(solve_define);
133 DDM_Solver_L1AC::destroy_solver(solve_define);
136 if(solve_define.Solver == QDDML1E)
138 QDDM_Solver_L1E::init_solver(solve_define);
139 QDDM_Solver_L1E::do_solve(solve_define);
140 QDDM_Solver_L1E::destroy_solver(solve_define);
143 if(solve_define.Solver == DDML1MIX)
145 DDM_Mix_Solver_L1E::init_solver(solve_define);
146 DDM_Mix_Solver_L1E::do_solve(solve_define);
147 DDM_Mix_Solver_L1E::destroy_solver(solve_define);
150 if(solve_define.Solver == DDML2E)
152 DDM_Solver_L2E::init_solver(solve_define);
153 DDM_Solver_L2E::do_solve(solve_define);
154 DDM_Solver_L2E::destroy_solver(solve_define);
157 if(solve_define.Solver == DDML2MIX)
159 DDM_Mix_Solver_L2E::init_solver(solve_define);
160 DDM_Mix_Solver_L2E::do_solve(solve_define);
161 DDM_Mix_Solver_L2E::destroy_solver(solve_define);
164 if(solve_define.Solver == EBML3E)
166 EBM_Solver_L3E::init_solver(solve_define);
167 EBM_Solver_L3E::do_solve(solve_define);
168 EBM_Solver_L3E::destroy_solver(solve_define);
171 if(solve_define.Solver == EMFEM)
173 if(EM_FEM_Solver::init_solver(solve_define)) return 1;
174 if(EM_FEM_Solver::do_solve(solve_define)) return 1;
175 if(EM_FEM_Solver::destroy_solver(solve_define)) return 1;
178 return 0;
181 int SolveControl::do_refine()
183 sprintf(log_buf,"Refine mesh...\n");GSS_LOG();
184 //delete old solution data
185 if(BSolver::refine(refine_define)) return 1;
186 reorder();
187 zone_to_field();
188 build_least_squares();
189 return 0;
192 int SolveControl::do_export()
194 if(export_define.core)
196 sprintf(log_buf,"Export Core Data to %s...",export_define.CoreFile);GSS_LOG();
197 //export mesh
198 export_mesh(export_define.CoreFile);
200 //export data
201 for(int z=0;z<zone_num;z++)
202 if(zonedata[z]->material_type==Semiconductor)
204 SMCZone *pzonedata = dynamic_cast< SMCZone * >(zonedata[z]);
205 pzonedata->export_doping(export_define.CoreFile,&scale_unit);
206 if(IsSingleCompSemiconductor(zone[z].zonelabel))
207 if(pzonedata->export_mole(export_define.CoreFile,1)) return 1;
208 pzonedata->export_solution(export_define.CoreFile,"solution",bc,&scale_unit);
210 else if(zonedata[z]->material_type==Insulator)
212 ISZone *pzonedata = dynamic_cast< ISZone * >(zonedata[z]);
213 pzonedata->export_solution(export_define.CoreFile,"solution",bc,&scale_unit);
215 else if(zonedata[z]->material_type==Conductor)
217 ElZone *pzonedata = dynamic_cast< ElZone * >(zonedata[z]);
218 pzonedata->export_solution(export_define.CoreFile,"solution",bc,&scale_unit);
220 sprintf(log_buf,"done\n");GSS_LOG();
224 if(export_define.ascii)
226 sprintf(log_buf,"Export Data to TIF File %s...",export_define.AscFile);GSS_LOG();
227 extract_ascii(export_define.AscFile);
228 sprintf(log_buf,"done\n");GSS_LOG();
231 if(export_define.vtk)
233 sprintf(log_buf,"Export Data to VTK File %s...",export_define.VTKFile);GSS_LOG();
234 vtk_output_file(export_define.VTKFile);
235 sprintf(log_buf,"done\n");GSS_LOG();
238 return 0;
242 int SolveControl::do_import()
245 //delete old solution data
246 bc.clear();
247 clear_mesh();
248 clear_data();
249 if(import_define.file_type==MODEL)
251 sprintf(log_buf,"Import ModelData from %s...\n",import_define.ModelFile);GSS_LOG();
252 if(import_cgns(import_define.ModelFile)) return 1;
253 build_zone();
254 if(setup_bc()) return 1;
255 if(build_zonedata()) return 1;
256 if(doping_func.size())
257 setup_doping();
258 else
259 if(import_doping_from_cgns(import_define.ModelFile)) return 1;
260 if(import_mole_from_cgns(import_define.ModelFile)) return 1;
261 if(setup_init_data()) return 1;
262 //reorder the mesh, important for implicit solver
263 reorder();
264 zone_to_field();
265 //for fast call to least-squares arithmetic
266 build_least_squares();
268 else
270 sprintf(log_buf,"Import CoreData from %s...\n",import_define.CoreFile);GSS_LOG();
271 //init new solver
272 if(import_cgns(import_define.CoreFile)) return 1;
273 build_zone();
274 if(setup_bc()) return 1;
275 if(build_zonedata()) return 1;
276 if(doping_func.size())
277 setup_doping();
278 else
279 if(import_doping_from_cgns(import_define.CoreFile)) return 1;
280 if(import_mole_from_cgns(import_define.CoreFile)) return 1;
281 if(setup_init_data()) return 1;
283 //import data
284 for(int z=0;z<zone_num;z++)
286 if(zonedata[z]->material_type==Semiconductor)
288 SMCZone *pzonedata = dynamic_cast< SMCZone * >(zonedata[z]);
289 if(pzonedata->import_solution(import_define.CoreFile,"solution",bc,&scale_unit)) return 1;
291 else if(zonedata[z]->material_type==Insulator)
293 ISZone *pzonedata = dynamic_cast< ISZone * >(zonedata[z]);
294 if(pzonedata->import_solution(import_define.CoreFile,"solution",bc,&scale_unit)) return 1;
296 else if(zonedata[z]->material_type==Conductor)
298 ElZone *pzonedata = dynamic_cast< ElZone * >(zonedata[z]);
299 if(pzonedata->import_solution(import_define.CoreFile,"solution",bc,&scale_unit)) return 1;
302 //reorder the mesh, important for implicit solver
303 reorder();
304 zone_to_field();
305 build_least_squares();
307 sprintf(log_buf,"\n");GSS_LOG();
308 return 0;
312 int SolveControl::do_attach()
314 if(attach_define.electrode_type==VoltageBC)
316 vector<VSource *> bc_vsrc;
317 for(int i=0;i<attach_define.vsrc_index.size();i++)
319 int vsrc_index=attach_define.vsrc_index[i];
320 bc_vsrc.push_back(vsrc[vsrc_index]);
321 sprintf(log_buf,"Vsource %s attached to bc %s\n",vsrc[vsrc_index]->label,attach_define.Electrode);
322 GSS_LOG();
324 bc.Attach_Vapp(attach_define.Electrode,bc_vsrc);
326 if(attach_define.electrode_type==CurrentBC)
328 vector<ISource *> bc_isrc;
329 for(int i=0;i<attach_define.isrc_index.size();i++)
331 int isrc_index=attach_define.isrc_index[i];
332 bc_isrc.push_back(isrc[isrc_index]);
333 sprintf(log_buf,"Isource %s attached to bc %s\n",isrc[isrc_index]->label,attach_define.Electrode);
334 GSS_LOG();
336 bc.Attach_Iapp(attach_define.Electrode,bc_isrc);
338 return 0;
341 int SolveControl::do_plot()
343 #ifdef HAVE_WIN32
344 pid_t pid = fork();
346 if (pid == (pid_t) 0)
348 // The child process to do plot.
349 if(plot_define.MeshOnly)
351 if(plot_define.GeneratePS)
352 plot_mesh_ps(plot_define);
353 else
354 plot_mesh_screen(plot_define);
356 else
357 plot_data(plot_define);
358 exit(0);
360 else if (pid < (pid_t) 0)
362 // The fork failed.
363 fprintf (stderr, "Fork failed.\n");
365 #endif
367 #ifdef HAVE_X11
368 if(plot_define.MeshOnly)
371 plot_mesh_screen(plot_define);
372 if(plot_define.GeneratePS)
373 plot_mesh_ps(plot_define);
375 //for X11 exist, use show mesh instead
376 show_mesh(plot_define);
378 else
379 plot_data(plot_define);
380 #endif
381 return 0;
385 int SolveControl::do_plotmesh()
387 #ifdef HAVE_X11
388 show_mesh(plot_define);
389 #endif
390 return 0;
394 int SolveControl::do_vtk_plot()
396 #ifdef HAVE_VTK
397 pid_t pid = fork();
398 if (pid == (pid_t) 0)
400 vtk_display_data(plot_define);
401 exit(0);
403 else if (pid < (pid_t) 0)
405 // The fork failed.
406 fprintf (stderr, "Fork failed.\n");
408 #endif
409 return 0;
412 //------------------------------------------------------------------------------------
415 int SolveControl::set_method(list<Cmd>::iterator pcmd)
417 PetscTruth flg;
419 if(!pcmd->allowed_args(26,"type","scheme","ns","damping","ls","serverport","ejmodel","fermi",
420 "highfieldmobility","impactionization","ii.type","bandbandtunneling","qnfactor","qpfactor",
421 "relative.tol","possion.tol","elec.continuty.tol","hole.continuty.tol","latt.temp.tol",
422 "elec.energy.tol","hole.energy.tol","elec.quantum.tol","hole.quantum.tol",
423 "electrode.tol","toler.relax","maxiteration"))
425 sprintf(log_buf,"line %d METHOD: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
426 GSS_LOG();
427 return 1;
429 solve_define.HighFieldMobility = pcmd->get_bool("highfieldmobility", 0, true);
430 solve_define.BandBandTunneling = pcmd->get_bool("bandbandtunneling", 0, false);
431 solve_define.QNFactor = pcmd->get_number("qnfactor",0,1.0);
432 solve_define.QPFactor = pcmd->get_number("qpfactor",0,1.0);
433 solve_define.EJModel = pcmd->get_bool("ejmodel", 0, false);
434 solve_define.Fermi = pcmd->get_bool("fermi", 0, false);
436 solve_define.maxit = pcmd->get_integer("maxiteration", 0, 30);
437 solve_define.relative_toler = pcmd->get_number("relative.tol",0,1e-5);
438 solve_define.toler_relax = pcmd->get_number("toler.relax",0,1e4);
439 solve_define.possion_abs_toler = pcmd->get_number("possion.tol",0,1e-29)*scale_unit.s_coulomb/scale_unit.s_micron;
440 solve_define.elec_continuty_abs_toler = pcmd->get_number("elec.continuty.tol",0,5e-18)*scale_unit.s_A/scale_unit.s_micron;
441 solve_define.hole_continuty_abs_toler = pcmd->get_number("hole.continuty.tol",0,5e-18)*scale_unit.s_A/scale_unit.s_micron;
442 solve_define.heat_equation_abs_toler = pcmd->get_number("latt.temp.tol",0,1e-11)*scale_unit.s_W/scale_unit.s_micron;
443 solve_define.elec_energy_abs_toler = pcmd->get_number("elec.energy.tol",0,1e-18)*scale_unit.s_W/scale_unit.s_micron;
444 solve_define.hole_energy_abs_toler = pcmd->get_number("hole.energy.tol",0,1e-18)*scale_unit.s_W/scale_unit.s_micron;
445 solve_define.electrode_abs_toler = pcmd->get_number("electrode.tol",0,1e-9)*scale_unit.s_volt;
446 solve_define.elec_quantum_abs_toler = pcmd->get_number("elec.quantum.tol",0,1e-29)*scale_unit.s_coulomb/scale_unit.s_micron;
447 solve_define.hole_quantum_abs_toler = pcmd->get_number("hole.quantum.tol",0,1e-29)*scale_unit.s_coulomb/scale_unit.s_micron;
449 PetscOptionsGetInt(NULL, "-serverport",&solve_define.port,&flg);
450 if(!flg) solve_define.port = pcmd->get_integer("serverport", 0, 1611);
452 if(pcmd->is_arg_exist("type"))
454 if (pcmd->is_arg_value("type", "DDML1")) solve_define.Solver = DDML1E;
455 else if (pcmd->is_arg_value("type", "DDML2")) solve_define.Solver = DDML2E;
456 else if (pcmd->is_arg_value("type", "DDML1E")) solve_define.Solver = DDML1E;
457 else if (pcmd->is_arg_value("type", "DDML2E")) solve_define.Solver = DDML2E;
458 else if (pcmd->is_arg_value("type", "DDML1AC")) solve_define.Solver = DDML1AC;
459 else if (pcmd->is_arg_value("type", "QDDML1E")) solve_define.Solver = QDDML1E;
460 else if (pcmd->is_arg_value("type", "DDML1MIX")) solve_define.Solver = DDML1MIX;
461 else if (pcmd->is_arg_value("type", "DDML2MIX")) solve_define.Solver = DDML2MIX;
462 else if (pcmd->is_arg_value("type", "EBML3")) solve_define.Solver = EBML3E;
463 else if (pcmd->is_arg_value("type", "EBML3E")) solve_define.Solver = EBML3E;
464 else if (pcmd->is_arg_value("type", "EMFEM")) solve_define.Solver = EMFEM;
465 else {sprintf(log_buf,"line %d METHOD: Type syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
468 solve_define.ImpactIonization = pcmd->get_bool("impactionization", 0, false);
469 if(solve_define.EJModel)
470 solve_define.IIType = EdotJ;
471 else if(solve_define.Solver == EBML3E)
472 solve_define.IIType = ESide;
473 else
474 solve_define.IIType = GradQf;
475 if(pcmd->is_arg_exist("ii.type"))
477 if (pcmd->is_arg_value("ii.type", "EdotJ")) solve_define.IIType = EdotJ;
478 else if (pcmd->is_arg_value("ii.type", "GradQf")) solve_define.IIType = GradQf;
479 else if (pcmd->is_arg_value("ii.type", "EVector")) solve_define.IIType = EVector;
480 else if (pcmd->is_arg_value("ii.type", "ESide")) solve_define.IIType = ESide;
481 else if (pcmd->is_arg_value("ii.type", "Soft.II")) solve_define.IIType = SoftII;
482 else if (pcmd->is_arg_value("ii.type", "Hard.II")) solve_define.IIType = HardII;
483 else if (pcmd->is_arg_value("ii.type", "Temp.II")) solve_define.IIType = TempII;
484 else {sprintf(log_buf,"line %d METHOD: II.Type syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
489 if(pcmd->is_arg_exist("scheme"))
491 if (pcmd->is_arg_value("scheme", "Newton")) solve_define.Scheme = DDM_Newton;
492 else if (pcmd->is_arg_value("scheme", "Gummel")) solve_define.Scheme = DDM_Gummel;
493 else {sprintf(log_buf,"line %d METHOD: Scheme syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
496 if(pcmd->is_arg_exist("ns"))
498 if (pcmd->is_arg_value("ns", "LineSearch")) solve_define.NS = LineSearch;
499 else if (pcmd->is_arg_value("ns", "Basic")) solve_define.NS = Basic;
500 else if (pcmd->is_arg_value("ns", "TrustRegion")) solve_define.NS = TrustRegion;
501 else {sprintf(log_buf,"line %d METHOD: NS syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
504 if(pcmd->is_arg_exist("ls"))
506 char * linear_solver = pcmd->get_string("ls",0,"lu");
507 for(int c=0;c<strlen(linear_solver);c++)
508 if(isupper(linear_solver[c])) linear_solver[c]=tolower(linear_solver[c]);
509 solve_define.LS = linear_solver;
512 if(pcmd->is_arg_exist("damping"))
514 if (pcmd->is_arg_value("damping", "No")) solve_define.Damping = DampingNo;
515 else if (pcmd->is_arg_value("damping", "BankRose")) solve_define.Damping = DampingBankRose;
516 else if (pcmd->is_arg_value("damping", "Potential")) solve_define.Damping = DampingPotential;
517 else {sprintf(log_buf,"line %d METHOD: Damping syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
520 switch(solve_define.Solver)
522 case DDML1: sprintf(log_buf,"Solver type : DDM Level 1\n"); GSS_LOG();break;
523 case DDML1E: sprintf(log_buf,"Solver type : DDM Level 1E\n"); GSS_LOG();break;
524 case DDML1AC: sprintf(log_buf,"Solver type : DDM Level 1E AC Sweep\n"); GSS_LOG();return 0;
525 case QDDML1E: sprintf(log_buf,"Solver type : DDM Level 1E with Quantum Correction\n"); GSS_LOG();break;
526 case DDML1MIX:sprintf(log_buf,"Solver type : DDM Level 1E Device/Circuit Mixed\n"); GSS_LOG();break;
527 case DDML2: sprintf(log_buf,"Solver type : DDM Level 2\n"); GSS_LOG();break;
528 case DDML2E: sprintf(log_buf,"Solver type : DDM Level 2E\n"); GSS_LOG();break;
529 case DDML2MIX:sprintf(log_buf,"Solver type : DDM Level 2E Device/Circuit Mixed\n"); GSS_LOG();break;
530 case EBML3E: sprintf(log_buf,"Solver type : EBM Level 3E\n"); GSS_LOG();break;
531 case EMFEM: sprintf(log_buf,"Solver type : EMFEM\n"); GSS_LOG();return 0;
532 case POISSON: sprintf(log_buf,"Solver type : POISSON\n"); GSS_LOG();return 0;
533 default: break;
537 switch(solve_define.Scheme)
539 case DDM_Newton: sprintf(log_buf,"Numerical scheme : Newton Iteration\n");GSS_LOG();break;
540 default: break;
543 switch(solve_define.NS)
545 case LineSearch: sprintf(log_buf,"Nonlinear method : LineSearch\n");GSS_LOG();break;
546 case Basic: sprintf(log_buf,"Nonlinear method : Basic\n");GSS_LOG();break;
547 case TrustRegion: sprintf(log_buf,"Nonlinear method : TrustRegion\n");GSS_LOG();break;
548 default: break;
550 sprintf(log_buf, "Linear Solver : %s\n",solve_define.LS.c_str());GSS_LOG();
552 if(solve_define.ImpactIonization == true)
554 sprintf(log_buf,"Impact Ionization enabled\n");GSS_LOG();
556 else
558 sprintf(log_buf,"Impact Ionization disabled\n");GSS_LOG();
561 if(solve_define.BandBandTunneling == true)
563 sprintf(log_buf,"Band to Band Tunneling enabled\n");GSS_LOG();
565 else
567 sprintf(log_buf,"Band to Band Tunneling disabled\n");GSS_LOG();
570 return 0;
574 int SolveControl::set_solve(list<Cmd>::iterator pcmd)
576 //do clear
577 solve_define.Type = 0;
578 solve_define.Electrode_Record_Name.clear();
579 solve_define.Electrode_Record_Index.clear();
580 solve_define.Electrode_Record.clear();
581 solve_define.Electrode_VScan_Name.clear();
582 solve_define.IVFile.erase();
583 solve_define.BDF_Type = BDF2;
585 solve_define.VStart = pcmd->get_number("vstart",0,0.0)*scale_unit.s_volt;
586 solve_define.VStep = pcmd->get_number("vstep",0,0.0)*scale_unit.s_volt;
587 solve_define.VStepMax = pcmd->get_number("vstepmax",0,10*solve_define.VStep)*scale_unit.s_volt;
588 solve_define.VStop = pcmd->get_number("vstop",0,1e10)*scale_unit.s_volt;
589 solve_define.IStart = pcmd->get_number("istart",0,0.0)*scale_unit.s_mA;
590 solve_define.IStep = pcmd->get_number("istep",0,0.0)*scale_unit.s_mA;
591 solve_define.IStop = pcmd->get_number("istop",0,1e10)*scale_unit.s_mA;
592 solve_define.TStart = pcmd->get_number("tstart",0,0.0)*scale_unit.s_second;
593 solve_define.TStep = pcmd->get_number("tstep",0,0.0)*scale_unit.s_second;
594 solve_define.TStop = pcmd->get_number("tstop",0,1e10)*scale_unit.s_second;
595 solve_define.VAC = pcmd->get_number("vac",0,0.0026/scale_unit.s_volt)*scale_unit.s_volt;
596 solve_define.FStart = pcmd->get_number("fstart",0,1e6)/scale_unit.s_second;
597 solve_define.FMultiple = pcmd->get_number("fmultiple",0,1.1);
598 solve_define.FStop = pcmd->get_number("fstop",0,1e9)/scale_unit.s_second;
599 solve_define.AutoStep = pcmd->get_bool("autostep",0,true);
600 solve_define.Predict = pcmd->get_bool("predict",0,true);
602 solve_define.IVFile = pcmd->get_string("ivfile",0,"");
603 solve_define.IVFileAppend = pcmd->get_bool("append",0,false);
605 if(pcmd->is_arg_exist("type"))
607 if (pcmd->is_arg_value("type", "EQUILIBRIUM")) solve_define.Type = EQUILIBRIUM;
608 else if (pcmd->is_arg_value("type", "STEADYSTATE")) solve_define.Type = STEADYSTATE;
609 else if (pcmd->is_arg_value("type", "DCSWEEP")) solve_define.Type = DCSWEEP;
610 else if (pcmd->is_arg_value("type", "ACSWEEP")) solve_define.Type = ACSWEEP;
611 else if (pcmd->is_arg_value("type", "TRANSIENT")) solve_define.Type = TRANSIENT;
612 else if (pcmd->is_arg_value("type", "TRACE")) solve_define.Type = TRACE;
613 else {sprintf(log_buf,"line %d SOLVE: Type syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
616 if(pcmd->is_arg_exist("ode.formula"))
618 if (pcmd->is_arg_value("ode.formula", "BDF1")) solve_define.BDF_Type = BDF1;
619 else if (pcmd->is_arg_value("ode.formula", "BDF2")) solve_define.BDF_Type = BDF2;
620 else {sprintf(log_buf,"line %d SOLVE: ODE.Formula syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
623 for(pcmd->arg_search_begin();!pcmd->arg_search_end();pcmd->goto_next_arg())
625 if(!strcmp(pcmd->get_current_arg_label(),"vscan"))
627 string vscan_name=pcmd->get_current_arg_value().sval;
628 solve_define.Electrode_VScan_Name.push_back(vscan_name);
629 solve_define.Electrode_VScan = 1;
630 solve_define.Electrode_IScan =-1;
631 if(!bc.is_electrode(vscan_name.c_str()))
632 {sprintf(log_buf,"line %d SOLVE: Can't find VScan Electrode!!\n",pcmd->lineno);GSS_LOG();return 1;}
636 if(pcmd->is_arg_exist("iscan"))
638 solve_define.Electrode_IScan_Name = pcmd->get_string("iscan",0,"");
639 solve_define.Electrode_VScan = -1;
640 solve_define.Electrode_IScan = 1;
641 if(!bc.is_electrode(pcmd->get_string("iscan",0,"")))
642 {sprintf(log_buf,"line %d SOLVE: Can't find IScan Electrode!\n",pcmd->lineno);GSS_LOG();return 1;}
645 if(pcmd->is_arg_exist("acscan"))
647 solve_define.Electrode_ACScan_Name = pcmd->get_string("acscan",0,"");
648 if(!bc.is_electrode(pcmd->get_string("acscan",0,"")))
649 {sprintf(log_buf,"line %d SOLVE: Can't find ACScan Electrode!\n",pcmd->lineno);GSS_LOG();return 1;}
652 for(pcmd->arg_search_begin();!pcmd->arg_search_end();pcmd->goto_next_arg())
654 if(!strcmp(pcmd->get_current_arg_label(),"ivrecord"))
656 if(!bc.is_electrode(pcmd->get_current_arg_value().sval))
657 {sprintf(log_buf,"line %d SOLVE: Can't find IVRecord Electrode!!\n",pcmd->lineno);GSS_LOG();return 1;}
658 solve_define.Electrode_Record_Name.push_back(pcmd->get_current_arg_value().sval);
661 return 0;
665 int SolveControl::set_export(list<Cmd>::iterator pcmd)
667 //do clear
668 export_define.core = false;
669 export_define.ascii = false;
670 export_define.vtk = false;
672 if(!pcmd->allowed_args(3,"corefile","ascfile","vtkfile"))
674 sprintf(log_buf,"line %d EXPORT: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
675 GSS_LOG();
676 return 1;
679 if(pcmd->is_arg_exist("corefile"))
681 export_define.core = true;
682 strcpy(export_define.CoreFile,pcmd->get_string("corefile",0,""));
685 if(pcmd->is_arg_exist("ascfile"))
687 export_define.ascii = true;
688 strcpy(export_define.AscFile,pcmd->get_string("ascfile",0,""));
691 if(pcmd->is_arg_exist("vtkfile"))
693 export_define.vtk = true;
694 strcpy(export_define.VTKFile,pcmd->get_string("vtkfile",0,""));
696 return 0;
700 int SolveControl::set_refine(list<Cmd>::iterator pcmd)
702 refine_define.Measure = Linear;
703 refine_define.Dispersion = pcmd->get_number("dispersion",0,3.0);
704 refine_define.DivisionRatio = pcmd->get_number("divisionratio",0,0.25);
705 strcpy(refine_define.tri_cmd, pcmd->get_string("triangle", 0, "praq30DzQ"));
707 if(!pcmd->allowed_args(5,"variable","measure","dispersion","divisionratio","triangle"))
709 sprintf(log_buf,"line %d REFINE: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
710 GSS_LOG();
711 return 1;
714 if(pcmd->is_arg_exist("variable"))
716 if (pcmd->is_arg_value("variable", "Potential")) refine_define.Variable = Potential;
717 else if (pcmd->is_arg_value("variable", "Doping")) refine_define.Variable = Doping;
718 else {sprintf(log_buf,"line %d REFINE: Variable syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
721 if(pcmd->is_arg_exist("measure"))
723 if (pcmd->is_arg_value("measure", "Linear")) refine_define.Measure = Linear;
724 else if (pcmd->is_arg_value("measure", "SignedLog")) refine_define.Measure = SignedLog;
725 else {sprintf(log_buf,"line %d REFINE: Measure syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
728 return 0;
732 int SolveControl::set_import(list<Cmd>::iterator pcmd)
734 //do clear
735 import_define.file_type = 0;
737 if(!pcmd->allowed_args(2,"corefile","modelfile"))
739 sprintf(log_buf,"line %d IMPORT: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
740 GSS_LOG();
741 return 1;
744 if(pcmd->is_arg_exist("corefile"))
746 import_define.file_type = CORE;
747 strcpy(import_define.CoreFile,pcmd->get_string("corefile",0,""));
750 if(pcmd->is_arg_exist("modelfile"))
752 import_define.file_type = MODEL;
753 strcpy(import_define.ModelFile,pcmd->get_string("modelfile",0,""));
756 return 0;
760 int SolveControl::set_attach(list<Cmd>::iterator pcmd)
762 //do clear
763 attach_define.vsrc_name.clear();
764 attach_define.vsrc_index.clear();
765 attach_define.isrc_name.clear();
766 attach_define.isrc_index.clear();
767 attach_define.electrode_type = VoltageBC;
769 if(!pcmd->allowed_args(4,"electrode","vapp","iapp","type"))
771 sprintf(log_buf,"line %d ATTACH: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
772 GSS_LOG();
773 return 1;
776 if(pcmd->is_arg_exist("electrode"))
778 strcpy(attach_define.Electrode,pcmd->get_string("electrode",0,""));
779 if(!bc.is_electrode(attach_define.Electrode))
781 sprintf(log_buf,"line %d ATTACH: Can't find Electrode %s!\n",pcmd->lineno,attach_define.Electrode);
782 GSS_LOG();
783 return 1;
787 if(pcmd->is_arg_exist("type"))
789 if (pcmd->is_arg_value("type", "Current")) attach_define.electrode_type = CurrentBC;
790 else if(pcmd->is_arg_value("type", "Voltage")) attach_define.electrode_type = VoltageBC;
791 else {sprintf(log_buf,"line %d ATTACH: No such electrode type !\n",pcmd->lineno);GSS_LOG();return 1;}
794 for(pcmd->arg_search_begin();!pcmd->arg_search_end();pcmd->goto_next_arg())
796 if(!strcmp(pcmd->get_current_arg_label(),"vapp"))
798 string vsrc_name=pcmd->get_current_arg_value().sval;
799 attach_define.vsrc_name.push_back(vsrc_name);
800 int flag=0;
801 for(int j=0;j<vsrc.size();j++)
802 if(!strcmp(vsrc_name.c_str(),vsrc[j]->label))
804 attach_define.vsrc_index.push_back(j);
805 flag=1;
807 if(flag==0)
809 sprintf(log_buf,"line %d ATTACH:Can't find VApp %s!\n",pcmd->lineno,pcmd->get_current_arg_value().sval);
810 GSS_LOG();
811 return 1;
815 else if(!strcmp(pcmd->get_current_arg_label(),"iapp"))
817 string isrc_name=pcmd->get_current_arg_value().sval;
818 attach_define.isrc_name.push_back(isrc_name);
819 int flag=0;
820 for(int j=0;j<isrc.size();j++)
821 if(!strcmp(isrc_name.c_str(),isrc[j]->label))
823 attach_define.isrc_index.push_back(j);
824 flag=1;
826 if(flag==0)
828 sprintf(log_buf,"line %d ATTACH:Can't find IApp %s!\n",pcmd->lineno,pcmd->get_current_arg_value().sval);
829 GSS_LOG();
830 return 1;
835 return 0;
840 int SolveControl::set_plot(list<Cmd>::iterator pcmd)
843 //set default value
844 plot_define.MeshOnly = 0;
845 plot_define.Resolution = RES_800x600;
846 plot_define.Measure = Linear;
847 plot_define.GeneratePS = 0;
848 plot_define.GenerateTIFF = 0;
849 plot_define.Style = F_COLOR;
850 plot_define.az = pcmd->get_number("azangle",0,240.0);
851 plot_define.el = pcmd->get_number("elangle",0,60.0);
852 plot_define.Persp = 0;
853 plot_define.ztick = -1;
855 if(!pcmd->allowed_args(8,"variable","resolution","ps.out","tiff.out","measure","azangle","elangle","style"))
857 sprintf(log_buf,"line %d PLOT: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
858 GSS_LOG();
859 return 1;
862 if(pcmd->is_arg_exist("variable"))
864 plot_define.VariableName=pcmd->get_string("variable",0,"");
865 if (pcmd->is_arg_value("variable", "Potential")) plot_define.Variable = Potential;
866 else if (pcmd->is_arg_value("variable", "Doping")) plot_define.Variable = Doping;
867 else if (pcmd->is_arg_value("variable", "Na")) plot_define.Variable = DopingNa;
868 else if (pcmd->is_arg_value("variable", "Nd")) plot_define.Variable = DopingNd;
869 else if (pcmd->is_arg_value("variable", "ElecDensity")) plot_define.Variable = ElecDensity;
870 else if (pcmd->is_arg_value("variable", "HoleDensity")) plot_define.Variable = HoleDensity;
871 else if (pcmd->is_arg_value("variable", "ElecTemp")) plot_define.Variable = ElecTemp;
872 else if (pcmd->is_arg_value("variable", "HoleTemp")) plot_define.Variable = HoleTemp;
873 else if (pcmd->is_arg_value("variable", "Phi.Intrinsic")) plot_define.Variable = Phi_Intrinsic;
874 else if (pcmd->is_arg_value("variable", "PhiN")) plot_define.Variable = PhiN;
875 else if (pcmd->is_arg_value("variable", "PhiP")) plot_define.Variable = PhiP;
876 else if (pcmd->is_arg_value("variable", "QuantumEc")) plot_define.Variable = QuantumEc;
877 else if (pcmd->is_arg_value("variable", "QuantumEv")) plot_define.Variable = QuantumEv;
878 else if (pcmd->is_arg_value("variable", "Temperature")) plot_define.Variable = Temperature;
879 else if (pcmd->is_arg_value("variable", "EFieldX")) plot_define.Variable = EFieldX;
880 else if (pcmd->is_arg_value("variable", "EFieldY")) plot_define.Variable = EFieldY;
881 else if (pcmd->is_arg_value("variable", "E.Field")) plot_define.Variable = EField;
882 else if (pcmd->is_arg_value("variable", "OpticalEx")) plot_define.Variable = OpticalEx;//```
883 else if (pcmd->is_arg_value("variable", "OpticalEy")) plot_define.Variable = OpticalEy;
884 else if (pcmd->is_arg_value("variable", "OpticalEz")) plot_define.Variable = OpticalEz;
885 else if (pcmd->is_arg_value("variable", "OpticalHx")) plot_define.Variable = OpticalHx;
886 else if (pcmd->is_arg_value("variable", "OpticalHy")) plot_define.Variable = OpticalHy;
887 else if (pcmd->is_arg_value("variable", "OpticalHz")) plot_define.Variable = OpticalHz;
888 else if (pcmd->is_arg_value("variable", "OpticalG")) plot_define.Variable = OpticalG;
889 else if (pcmd->is_arg_value("variable", "Mesh")) plot_define.MeshOnly = MeshObject;
890 else if (pcmd->is_arg_value("variable", "DeviceMesh")) plot_define.MeshOnly = MeshObject;
891 else {sprintf(log_buf,"line %d PLOT: Variable syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
894 if(pcmd->is_arg_exist("resolution"))
896 if (pcmd->is_arg_value("resolution", "RES.Low")) plot_define.Resolution = RES_640x480;
897 else if (pcmd->is_arg_value("resolution", "RES.Middle")) plot_define.Resolution = RES_800x600;
898 else if (pcmd->is_arg_value("resolution", "RES.High")) plot_define.Resolution = RES_1024x768;
899 else {sprintf(log_buf,"line %d PLOT: Resolution syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
902 if(pcmd->is_arg_exist("ps.out"))
904 plot_define.GeneratePS = 1;
905 plot_define.PSFileName=pcmd->get_string("ps.out",0,"");
908 if(pcmd->is_arg_exist("tiff.out"))
910 plot_define.GenerateTIFF = 1;
911 plot_define.TIFFFileName=pcmd->get_string("tiff.out",0,"");
914 if(pcmd->is_arg_exist("measure"))
916 if (pcmd->is_arg_value("measure", "Linear")) plot_define.Measure = Linear;
917 else if (pcmd->is_arg_value("measure", "SignedLog")) plot_define.Measure = SignedLog;
918 else {sprintf(log_buf,"line %d PLOT: Measure syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
921 if(pcmd->is_arg_exist("style"))
923 if (pcmd->is_arg_value("style", "Scale")) plot_define.Style = F_SCALE;
924 else if (pcmd->is_arg_value("style", "Color")) plot_define.Style = F_COLOR;
925 else if (pcmd->is_arg_value("style", "GrayLevel")) plot_define.Style = F_GRAYLEVEL;
926 else {sprintf(log_buf,"line %d PLOT: Style syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
929 return 0;
933 int SolveControl::set_plotmesh(list<Cmd>::iterator pcmd)
935 #ifdef HAVE_X11
936 plot_define.GenerateTIFF = 0;
937 if(!pcmd->allowed_args(1,"tiff.out"))
939 sprintf(log_buf,"line %d PLOTMESH: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
940 GSS_LOG();
941 return 1;
943 if(pcmd->is_arg_exist("tiff.out"))
945 plot_define.GenerateTIFF = 1;
946 plot_define.TIFFFileName=pcmd->get_string("tiff.out",0,"");
948 #endif
949 return 0;
952 int SolveControl::set_vtk_plot(list<Cmd>::iterator pcmd)
955 //set default value
956 plot_define.MeshOnly = 0;
957 plot_define.Resolution = RES_800x600;
958 plot_define.Measure = Linear;
960 if(!pcmd->allowed_args(3,"variable","resolution","measure"))
962 sprintf(log_buf,"line %d PLOTVTK: unrecognized parameter(s)!\n",pcmd->get_current_lineno());
963 GSS_LOG();
964 return 1;
967 if(pcmd->is_arg_exist("variable"))
969 plot_define.VariableName=pcmd->get_string("variable",0,"");
970 if (pcmd->is_arg_value("variable", "Potential")) plot_define.Variable = Potential;
971 else if (pcmd->is_arg_value("variable", "Doping")) plot_define.Variable = Doping;
972 else if (pcmd->is_arg_value("variable", "Na")) plot_define.Variable = DopingNa;
973 else if (pcmd->is_arg_value("variable", "Nd")) plot_define.Variable = DopingNd;
974 else if (pcmd->is_arg_value("variable", "ElecDensity")) plot_define.Variable = ElecDensity;
975 else if (pcmd->is_arg_value("variable", "HoleDensity")) plot_define.Variable = HoleDensity;
976 else if (pcmd->is_arg_value("variable", "ElecTemp")) plot_define.Variable = ElecTemp;
977 else if (pcmd->is_arg_value("variable", "HoleTemp")) plot_define.Variable = HoleTemp;
978 else if (pcmd->is_arg_value("variable", "Phi.Intrinsic")) plot_define.Variable = Phi_Intrinsic;
979 else if (pcmd->is_arg_value("variable", "PhiN")) plot_define.Variable = PhiN;
980 else if (pcmd->is_arg_value("variable", "PhiP")) plot_define.Variable = PhiP;
981 else if (pcmd->is_arg_value("variable", "QuantumEc")) plot_define.Variable = QuantumEc;
982 else if (pcmd->is_arg_value("variable", "QuantumEv")) plot_define.Variable = QuantumEv;
983 else if (pcmd->is_arg_value("variable", "Temperature")) plot_define.Variable = Temperature;
984 else if (pcmd->is_arg_value("variable", "EFieldX")) plot_define.Variable = EFieldX;
985 else if (pcmd->is_arg_value("variable", "EFieldY")) plot_define.Variable = EFieldY;
986 else if (pcmd->is_arg_value("variable", "E.Field")) plot_define.Variable = EField;
987 else if (pcmd->is_arg_value("variable", "OpticalEx")) plot_define.Variable = OpticalEx;//```
988 else if (pcmd->is_arg_value("variable", "OpticalEy")) plot_define.Variable = OpticalEy;
989 else if (pcmd->is_arg_value("variable", "OpticalEz")) plot_define.Variable = OpticalEz;
990 else if (pcmd->is_arg_value("variable", "OpticalHx")) plot_define.Variable = OpticalHx;
991 else if (pcmd->is_arg_value("variable", "OpticalHy")) plot_define.Variable = OpticalHy;
992 else if (pcmd->is_arg_value("variable", "OpticalHz")) plot_define.Variable = OpticalHz;
993 else if (pcmd->is_arg_value("variable", "OpticalG")) plot_define.Variable = OpticalG;
994 else {sprintf(log_buf,"line %d PLOTVTK: Variable syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
997 if(pcmd->is_arg_exist("measure"))
999 if (pcmd->is_arg_value("measure", "Linear")) plot_define.Measure = Linear;
1000 else if (pcmd->is_arg_value("measure", "SignedLog")) plot_define.Measure = SignedLog;
1001 else {sprintf(log_buf,"line %d PLOTVTK: Measure syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
1004 if(pcmd->is_arg_exist("resolution"))
1006 if (pcmd->is_arg_value("resolution", "RES.Low")) plot_define.Resolution = RES_640x480;
1007 else if (pcmd->is_arg_value("resolution", "RES.Middle")) plot_define.Resolution = RES_800x600;
1008 else if (pcmd->is_arg_value("resolution", "RES.High")) plot_define.Resolution = RES_1024x768;
1009 else {sprintf(log_buf,"line %d PLOTVTK: Resolution syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
1011 return 0;
1015 int SolveControl::set_probe(list<Cmd>::iterator pcmd)
1017 ProbeDefine probe;
1018 probe.Region = pcmd->get_string("region", 0, "");
1019 probe.Segment = pcmd->get_string("segment", 0, "");
1020 probe.zone_index = Get_zone_index(probe.Region.c_str());
1021 if(probe.zone_index == -1)
1022 {sprintf(log_buf,"line %d PROBE: I can't find region for probing!\n",pcmd->lineno);GSS_LOG();return 1;}
1023 probe.bc_index = bc.Get_bc_index(probe.zone_index,probe.Segment.c_str());
1024 if(probe.bc_index == -1)
1025 {sprintf(log_buf,"line %d PROBE: I can't find segment for probing!\n",pcmd->lineno);GSS_LOG();return 1;}
1027 probe.ProbeFile = pcmd->get_string("probefile", 0, "");
1028 probe.Append = pcmd->get_bool("append", 0, false);
1030 probe.VariableName = pcmd->get_string("variable",0,"");
1031 if (pcmd->is_arg_value("variable", "Potential")) probe.Variable = Potential;
1032 else if (pcmd->is_arg_value("variable", "Doping")) probe.Variable = Doping;
1033 else if (pcmd->is_arg_value("variable", "Na")) probe.Variable = DopingNa;
1034 else if (pcmd->is_arg_value("variable", "Nd")) probe.Variable = DopingNd;
1035 else if (pcmd->is_arg_value("variable", "ElecDensity")) probe.Variable = ElecDensity;
1036 else if (pcmd->is_arg_value("variable", "HoleDensity")) probe.Variable = HoleDensity;
1037 else if (pcmd->is_arg_value("variable", "ElecTemp")) probe.Variable = ElecTemp;
1038 else if (pcmd->is_arg_value("variable", "HoleTemp")) probe.Variable = HoleTemp;
1039 else if (pcmd->is_arg_value("variable", "Phi.Intrinsic")) probe.Variable = Phi_Intrinsic;
1040 else if (pcmd->is_arg_value("variable", "PhiN")) probe.Variable = PhiN;
1041 else if (pcmd->is_arg_value("variable", "PhiP")) probe.Variable = PhiP;
1042 else if (pcmd->is_arg_value("variable", "QuantumEc")) probe.Variable = QuantumEc;
1043 else if (pcmd->is_arg_value("variable", "QuantumEv")) probe.Variable = QuantumEv;
1044 else if (pcmd->is_arg_value("variable", "Temperature")) probe.Variable = Temperature;
1045 else if (pcmd->is_arg_value("variable", "EFieldX")) probe.Variable = EFieldX;
1046 else if (pcmd->is_arg_value("variable", "EFieldY")) probe.Variable = EFieldY;
1047 else if (pcmd->is_arg_value("variable", "E.Field")) probe.Variable = EField;
1048 else if (pcmd->is_arg_value("variable", "OpticalEx")) probe.Variable = OpticalEx;//```
1049 else if (pcmd->is_arg_value("variable", "OpticalEy")) probe.Variable = OpticalEy;
1050 else if (pcmd->is_arg_value("variable", "OpticalEz")) probe.Variable = OpticalEz;
1051 else if (pcmd->is_arg_value("variable", "OpticalHx")) probe.Variable = OpticalHx;
1052 else if (pcmd->is_arg_value("variable", "OpticalHy")) probe.Variable = OpticalHy;
1053 else if (pcmd->is_arg_value("variable", "OpticalHz")) probe.Variable = OpticalHz;
1054 else if (pcmd->is_arg_value("variable", "OpticalG")) probe.Variable = OpticalG;
1055 else {sprintf(log_buf,"line %d PROBE: Variable syntax error!\n",pcmd->lineno);GSS_LOG();return 1;}
1056 probe_define.push_back(probe);
1057 return 0;