|
gimme-alpha 0.1
|
00001 /* 00002 ** average_efield.c 00003 ** 00004 ** Made by (Johnny Q. Hacker) 00005 ** Login <solarion@borkborkbork> 00006 ** 00007 00008 Copyright (C) 2009 Joseph Pingenot 00009 00010 This program is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Affero General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Affero General Public License for more details. 00019 00020 You should have received a copy of the GNU Affero General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 00023 ** Started on Tue Jul 14 14:49:30 2009 Johnny Q. Hacker 00024 ** Last update Wed Jun 17 15:07:42 2009 Johnny Q. Hacker 00025 */ 00026 00027 #include <stdio.h> 00028 #include <stdlib.h> 00029 #include <glib.h> 00030 #include <gio/gio.h> 00031 #include <math.h> 00032 #include <libcommon/gimme_alpha_types.h> 00033 #include <gimmeprogs/process-average-efield-args.h> 00034 #include <libnextnano/read_nextnano_inputfile.h> 00035 #include <libnextnano/read_nextnano_effectivemass_output.h> 00036 #include <libnextnano/read_nextnano_bandstructure.h> 00037 #include <libnextnano/read_nextnano_8x8kp_output.h> 00038 #include <libcommon/gimme-alpha_structs.h> 00039 #include <libpostproccalx/alpha_calc.h> 00040 #include <libmodeling/wavefunction.h> 00041 00042 int main(int argc, char* argv[]) { 00043 g_type_init(); 00044 GFile* pwd = g_file_new_for_commandline_arg("."); 00045 struct args* arg = process_args(argc, argv); 00046 if(arg == NULL) return 2; 00047 GList *l = g_list_first(arg->base_dirs); 00048 GList *p; 00049 GError *err = NULL; 00050 char* filename = NULL; 00051 for(p=l; p!= NULL; p=g_list_next(p)) { 00052 err = NULL; 00053 GFile* bd = (GFile*)(p->data); 00054 GHashTable *keys = read_nextnano_keyfile2(bd, &err); 00055 if(unlikely((err != NULL) || (keys == NULL))) { 00056 char* bdi = g_file_get_uri(bd); 00057 g_warning("average_efield.c::main: error reading keys (%s/keywords.in): %s", bdi, err->message); 00058 free(bdi); 00059 if(keys != NULL) g_hash_table_destroy(keys); 00060 continue; 00061 } 00062 GHashTable *db = read_nextnano_dbfile2(bd, &err); 00063 if(unlikely((err != NULL) || (keys == NULL))) { 00064 char* bdi = g_file_get_uri(bd); 00065 g_warning("average_efield.c::main: error reading database (%s/database.in): %s", bdi, err->message); 00066 free(bdi); 00067 g_hash_table_destroy(keys); 00068 if(db != NULL) g_hash_table_destroy(db); 00069 continue; 00070 } 00071 GHashTable *infile = read_nextnano_inputfile2(bd, keys, 1, &err, &filename); 00072 if(unlikely((err != NULL) || (keys == NULL))) { 00073 char* bdi = g_file_get_uri(bd); 00074 g_warning("average_efield.c::main: error reading input file %d (%s) (basedir: %s): %s", 1, filename, bdi, err->message); 00075 free(bdi); 00076 g_hash_table_destroy(keys); 00077 g_hash_table_destroy(db); 00078 if(infile != NULL) g_hash_table_destroy(infile); 00079 continue; 00080 } 00081 struct mstar_wavefunction_1d* wf = read_effectivemass_complex_wavefunction2(CB, 1, 1, 1, NEU, 1, 1, bd, infile, &err); 00082 if(unlikely((err != NULL) || (wf == NULL))) { 00083 char* bdi = g_file_get_uri(bd); 00084 g_warning("average_efield.c::main: error reading wavefunction solution %d (basedir: %s): %s", 1, bdi, err->message); 00085 free(bdi); 00086 g_hash_table_destroy(keys); 00087 g_hash_table_destroy(db); 00088 g_hash_table_destroy(infile); 00089 if(wf != NULL) mstar_wavefunction_1d_free(wf); 00090 continue; 00091 } 00092 double* pot_x = NULL; 00093 int pot_N; 00094 double* pot = read_nextnano_bandstructure_file(POTENTIAL_FILE, bd, infile, &err, &pot_x, &pot_N); 00095 if(unlikely((err != NULL) || (wf == NULL))) { 00096 char* bdi = g_file_get_uri(bd); 00097 g_warning("average_efield.c::main: error reading potential (basedir: %s): %s", bdi, err->message); 00098 free(bdi); 00099 g_hash_table_destroy(keys); 00100 g_hash_table_destroy(db); 00101 g_hash_table_destroy(infile); 00102 mstar_wavefunction_1d_free(wf); 00103 if(pot_x != NULL) free(pot_x); 00104 if(pot != NULL) free(pot); 00105 continue; 00106 } 00107 double err; 00108 double val = average_discrete_function(pot, pot_x, pot_N, wf, 1, arg->request_integration_abs_error, arg->request_integration_rel_error, &err); 00109 printf("%g\n", val); 00110 if(!(arg->no_print_integration_error)) { 00111 printf("%g\n", err); 00112 }else{ 00113 printf("\n"); 00114 } 00115 free(pot_x); 00116 free(pot); 00117 mstar_wavefunction_1d_free(wf); 00118 g_hash_table_destroy(keys); 00119 g_hash_table_destroy(db); 00120 g_hash_table_destroy(infile); 00121 00122 } 00123 return 0; 00124 }