1 /* 2 3 Copyright (C) 2007 Lucas K. Wagner 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 19 */ 20 #ifndef PROPERTIES_H_INCLUDED 21 #define PROPERTIES_H_INCLUDED 22 #include "Qmc_std.h" 23 #include "System.h" 24 #include "Wavefunction.h" 25 #include "Guiding_function.h" 26 #include "Properties_point.h" 27 #include "Properties_block.h" 28 #include "Properties_average.h" 29 #include "Properties_gather.h" 30 #include <list> 31 32 33 //-------------------------------------------------- 34 35 36 /*! 37 38 39 */ 40 41 class Properties_manager { 42 public: 43 44 45 Properties_manager(); 46 ~Properties_manager(); 47 void read(vector <string> & words, 48 vector <string> & systxt, 49 vector < string> & wftxt); 50 51 void setSize(int nwf_, int nblocks, int nsteps, int maxwalkers, System *, 52 Wavefunction_data *); setFirstStep(int s)53 void setFirstStep(int s) { 54 error("setFirstStep depreciated"); 55 /* 56 start_avg_step=s; 57 //int nsteps=trace.GetDim(0); 58 59 if(nsteps-start_avg_step-2 < autocorr_depth) 60 autocorr_depth=nsteps-start_avg_step-2; 61 */ 62 } 63 setLog(string & file,string & label)64 void setLog(string & file, string & label) { 65 log_file=file; 66 log_label=label; 67 } 68 getLog(string & file,string & label)69 void getLog(string & file, string & label) { 70 file=log_file; 71 label=log_label; 72 } 73 74 void insertPoint(int step, 75 int walker, 76 const Properties_point & pt); 77 78 void endBlock(); 79 80 void endBlock_per_step(); 81 82 void endBlockSHDMC(); 83 84 void initializeLog(Array1 <Average_generator*> & avg_gen); 85 void initializeLog(Array2 <Average_generator*> & avg_gen); 86 87 void printBlockSummary(ostream & os); 88 printSummary(ostream & os)89 void printSummary(ostream & os) { 90 error("update call to printSummary"); 91 } 92 void printSummary(ostream & os, Array1 <Average_generator*> & avg_gen); 93 getFinal(Properties_final_average & final)94 void getFinal(Properties_final_average & final) { 95 final=final_avg; 96 } 97 getLastBlock(Properties_block & block)98 void getLastBlock(Properties_block & block) { 99 assert(current_block > 0); 100 block=block_avg(current_block-1); 101 } 102 103 104 105 106 107 private: 108 void autocorrelation(Array2 <doublevar> &, int); 109 //Array2 < Properties_point > trace; 110 Properties_point weighted_sum,sample_avg,sample_var; 111 Array1 <doublevar> energy_avg,energy_var; 112 int npoints_this_block; 113 114 //control 115 int start_avg_step; 116 117 int max_autocorr_depth; 118 119 string log_file; 120 string log_label; 121 122 123 //Limits 124 int nwf; //!< the number of wave functions we can have in the primary walk 125 int maxchildren; //!< maximum number of children a walker can have 126 int autocorr_depth; 127 128 //Averaging 129 int current_block; 130 Array1 < Properties_block > block_avg; 131 Properties_block local_sum; 132 133 Properties_final_average final_avg; 134 }; 135 136 void update_avgvar(doublevar & avg, doublevar & var, int pt_number, doublevar nwpt); 137 138 139 //#################################################################################### 140 //--------------------------------------------------------------------- 141 //The Local_density_accumulators are for *local* averages that may be very large 142 //and shouldn't be in the normal averaging substructure. One can still evaluate error bars 143 //by printing out the average every block and then estimating from there, although 144 //in some cases, even that may be prohibitively expensive. 145 146 class Local_density_accumulator { 147 public: 148 virtual void init(vector <string> & , System *, string & runid)=0; 149 virtual void accumulate(Sample_point *, doublevar weight)=0; 150 /*! 151 Write out the density. Note that when running in parallel, this 152 must be called by all processes! 153 */ 154 virtual void write()=0; ~Local_density_accumulator()155 virtual ~Local_density_accumulator() { } 156 }; 157 158 class Nonlocal_density_accumulator { 159 public: 160 virtual void init(vector <string> & , System *, string & runid)=0; 161 virtual void accumulate(Sample_point *, doublevar weight, 162 Wavefunction_data *, Wavefunction *)=0; 163 virtual void write(string & log_label)=0; ~Nonlocal_density_accumulator()164 virtual ~Nonlocal_density_accumulator() { } 165 }; 166 167 168 class One_particle_density:public Local_density_accumulator { 169 public: 170 void init(vector <string> & , System *, string & runid); 171 void accumulate(Sample_point *, doublevar weight); 172 173 /*! 174 Add a single point.. Be careful when mixing this one and the 175 accumulate function, they may not have the expected behavior 176 */ 177 void add_single(Array1 <doublevar> & pos,doublevar val, doublevar weight); 178 /*! 179 Write out the density. Note that when running in parallel, this 180 must be called by all processes! 181 */ 182 void write(); 183 184 protected: 185 Array3 <doublevar> bin; //!< count of hits 186 Array1 <doublevar> min_; //!< min position 187 Array1 <doublevar> max; //!< max position 188 Array1 <int> npoints; 189 doublevar resolution; 190 doublevar nsample; //double because we can have weights 191 int nup; 192 string outputfile; 193 Array2 <doublevar> atominfo;//!< (ion#, [charge, x,y,z]) 194 doublevar norm; //!< renormalization for the density output 195 196 int start_electron; //!< which electrons to average over(for spin density) 197 int end_electron; 198 }; 199 200 class Local_potential_density:public Local_density_accumulator { 201 public: 202 void init(vector <string> &, System *, string & runid); 203 void accumulate(Sample_point *, doublevar weight); 204 void write(); 205 private: 206 One_particle_density density_2b; 207 One_particle_density density_1b; 208 System * sys; 209 }; 210 211 212 213 void allocate(vector<string> & words, System * sys, string & runid, 214 Local_density_accumulator *& denspt); 215 void allocate(vector<string> & words, System * sys, string & runid, 216 Nonlocal_density_accumulator *& nldenspt); 217 218 //--------------------------------------------------------------------- 219 220 221 #endif //PROPERTIES_H_INCLUDED 222 //---------------------------------------------------------------------- 223