Changeset 8f3cdd
- Timestamp:
- Feb 15, 2013, 5:07:31 PM (12 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- b123a5
- Parents:
- 64bafe0
- git-author:
- Frederik Heber <heber@…> (12/19/12 12:48:13)
- git-committer:
- Frederik Heber <heber@…> (02/15/13 17:07:31)
- Location:
- src/Jobs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Jobs/Grid/SamplingGrid.hpp
r64bafe0 r8f3cdd 177 177 const double getWindowVolume() const; 178 178 179 private:180 179 /** Sets the size of the window. 181 180 * … … 187 186 void setWindow(const double _begin_window[3], const double _end_window[3]); 188 187 188 private: 189 189 /** Sets the size of the domain. 190 190 * -
src/Jobs/InterfaceVMGJob.cpp
r64bafe0 r8f3cdd 52 52 #include <cmath> 53 53 #include <iostream> 54 #include <limits> 54 55 55 56 #include "CodePatterns/Log.hpp" 56 57 58 #include "Jobs/Grid/SamplingGrid.hpp" 57 59 58 60 using namespace VMG; 59 61 using VMGInterfaces::InterfaceVMGJob; 60 62 61 InterfaceVMGJob::InterfaceVMGJob(const std::vector< double >&_sampled_input,63 InterfaceVMGJob::InterfaceVMGJob(const SamplingGrid &_sampled_input, 62 64 VMGData &_returndata, 63 65 const std::vector< std::vector<double> > &_particle_positions, … … 66 68 int levelMin, 67 69 int levelMax, 68 const VMG::Vector & box_begin,69 vmg_float box_end,70 const VMG::Vector &_box_begin, 71 vmg_float _box_end, 70 72 const int& near_field_cells, 71 73 int coarseningSteps, 72 74 double alpha) : 73 75 VMG::Interface(boundary, levelMin, levelMax, 74 box_begin,box_end, coarseningSteps, alpha),76 _box_begin, _box_end, coarseningSteps, alpha), 75 77 spl(near_field_cells, Extent(MaxLevel()).MeshWidth().Max()), 76 78 sampled_input(_sampled_input), … … 78 80 level(levelMax) 79 81 { 82 for (size_t i=0;i<3;++i) { 83 box_begin[i] = _box_begin[i]; 84 box_end[i] = _box_end; 85 } 80 86 std::vector< std::vector<double> >::const_iterator positer = _particle_positions.begin(); 81 87 std::vector<double>::const_iterator chargeiter = _particle_charges.begin(); … … 94 100 {} 95 101 102 void InterfaceVMGJob::addGridOntoWindow( 103 VMG::Grid &grid, 104 SamplingGrid &window, 105 const double prefactor) const 106 { 107 #ifndef NDEBUG 108 for(size_t index=0;index<3;++index) { 109 ASSERT( box_begin[index] >= window.begin_window[index], 110 "InterfaceVMGJob::addGridOntoWindow() - given grid starts earlier than window in component " 111 +toString(index)+"."); 112 ASSERT( box_end[index] <= window.end_window[index], 113 "InterfaceVMGJob::addGridOntoWindow() - given grid ends later than window in component " 114 +toString(index)+"."); 115 } 116 #endif 117 // the only issue are indices 118 const size_t gridpoints_axis = window.getGridPointsPerAxis(); 119 size_t pre_offset[3]; 120 size_t post_offset[3]; 121 size_t length[3]; 122 size_t total[3]; 123 const double round_offset = 124 (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ? 125 0.5 : 0.; // need offset to get to round_toward_nearest behavior 126 for(size_t index=0;index<3;++index) { 127 const double delta = (double)gridpoints_axis/(window.end[index] - window.begin[index]); 128 // delta is conversion factor from box length to discrete length, i.e. number of points 129 pre_offset[index] = delta*(box_begin[index] - window.begin_window[index])+round_offset; 130 length[index] = delta*(box_end[index] - box_begin[index])+round_offset; 131 post_offset[index] = delta*(window.end_window[index] - box_end[index])+round_offset; 132 total[index] = delta*(window.end_window[index] - window.begin_window[index])+round_offset; 133 // total is used as safe-guard against loss due to discrete conversion 134 ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index], 135 "InterfaceVMGJob::addGridOntoWindow() - pre, post, and length don't sum up to total for " 136 +toString(index)+"th component."); 137 } 138 #ifndef NDEBUG 139 const size_t calculated_size = length[0]*length[1]*length[2]; 140 // const size_t given_size = std::distance(grid_begin, grid_end); 141 // ASSERT( calculated_size == given_size, 142 // "InterfaceVMGJob::addGridOntoWindow() - not enough sampled values given: " 143 // +toString(calculated_size)+" != "+toString(given_size)+"."); 144 ASSERT( calculated_size <= window.sampled_grid.size(), 145 "InterfaceVMGJob::addGridOntoWindow() - not enough sampled values available: " 146 +toString(calculated_size)+" <= "+toString(window.sampled_grid.size())+"."); 147 const size_t total_size = total[0]*total[1]*total[2]; 148 ASSERT( total_size == window.sampled_grid.size(), 149 "InterfaceVMGJob::addGridOntoWindow() - total size is not equal to number of present points: " 150 +toString(total_size)+" != "+toString(window.sampled_grid.size())+"."); 151 #endif 152 size_t N[3]; 153 SamplingGrid::sampledvalues_t::iterator griditer = window.sampled_grid.begin(); 154 std::advance(griditer, pre_offset[0]*total[1]*total[2]); 155 Grid::iterator copyiter = grid.Iterators().Local().Begin(); 156 for(N[0]=0; N[0] < length[0]; ++N[0]) { 157 std::advance(griditer, pre_offset[1]*total[2]); 158 for(N[1]=0; N[1] < length[1]; ++N[1]) { 159 std::advance(griditer, pre_offset[2]); 160 for(N[2]=0; N[2] < length[2]; ++N[2]) { 161 ASSERT( griditer != window.sampled_grid.end(), 162 "InterfaceVMGJob::addGridOntoWindow() - griditer is already at end of window."); 163 ASSERT( copyiter != grid.Iterators().Local().End(), 164 "InterfaceVMGJob::addGridOntoWindow() - griditer is already at end of window."); 165 *griditer++ += prefactor*grid(*copyiter++); 166 } 167 std::advance(griditer, post_offset[2]); 168 } 169 std::advance(griditer, post_offset[1]*total[2]); 170 } 171 #ifndef NDEBUG 172 std::advance(griditer, post_offset[0]*total[1]*total[2]); 173 ASSERT( griditer == window.sampled_grid.end(), 174 "InterfaceVMGJob::addGridOntoWindow() - griditer is not at end of window."); 175 ASSERT( copyiter == grid.Iterators().Local().End(), 176 "InterfaceVMGJob::addGridOntoWindow() - copyiter is not at end of window."); 177 #endif 178 } 179 180 void InterfaceVMGJob::addWindowOntoGrid( 181 VMG::Grid& window, 182 const SamplingGrid &grid, 183 const double prefactor) const 184 { 185 #ifndef NDEBUG 186 for(size_t index=0;index<3;++index) { 187 ASSERT( grid.begin_window[index] >= box_begin[index], 188 "InterfaceVMGJob::addWindowOntoGrid() - given window starts earlier than grid in component " 189 +toString(index)+"."); 190 ASSERT( grid.end_window[index] <= box_end[index], 191 "InterfaceVMGJob::addWindowOntoGrid() - given window ends later than grid in component " 192 +toString(index)+"."); 193 } 194 #endif 195 // the only issue are indices 196 const size_t gridpoints_axis = grid.getGridPointsPerAxis(); 197 size_t pre_offset[3]; 198 size_t post_offset[3]; 199 size_t length[3]; 200 size_t total[3]; 201 const double round_offset = 202 (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ? 203 0.5 : 0.; // need offset to get to round_toward_nearest behavior 204 for(size_t index=0;index<3;++index) { 205 const double delta = (double)gridpoints_axis/(grid.end[index] - grid.begin[index]); 206 // delta is conversion factor from box length to discrete length, i.e. number of points 207 pre_offset[index] = delta*(grid.begin_window[index] - box_begin[index])+round_offset; 208 length[index] = delta*(grid.end_window[index] - grid.begin_window[index])+round_offset; 209 post_offset[index] = delta*(box_end[index] - grid.end_window[index])+round_offset; 210 total[index] = delta*(box_end[index] - box_begin[index])+round_offset; 211 // total is used as safe-guard against loss due to discrete conversion 212 ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index], 213 "InterfaceVMGJob::addWindowOntoGrid() - pre, post, and length don't sum up to total for " 214 +toString(index)+"th component."); 215 } 216 #ifndef NDEBUG 217 const size_t calculated_size = length[0]*length[1]*length[2]; 218 ASSERT( calculated_size == grid.sampled_grid.size(), 219 "InterfaceVMGJob::addWindowOntoGrid() - not enough sampled values given: " 220 +toString(calculated_size)+" != "+toString(grid.sampled_grid.size())+"."); 221 // ASSERT( calculated_size <= given_size, 222 // "InterfaceVMGJob::addWindowOntoGrid() - not enough sampled values available: " 223 // +toString(calculated_size)+" <= "+toString(given_size)+"."); 224 // const size_t total_size = total[0]*total[1]*total[2]; 225 // ASSERT( total_size == given_size, 226 // "InterfaceVMGJob::addWindowOntoGrid() - total size is not equal to number of present points: " 227 // +toString(total_size)+" != "+toString(given_size)+"."); 228 #endif 229 size_t N[3]; 230 Grid::iterator griditer = window.Iterators().Local().Begin(); 231 griditer += pre_offset[0]*total[1]*total[2]; 232 SamplingGrid::sampledvalues_t::const_iterator copyiter = grid.sampled_grid.begin(); 233 for(N[0]=0; N[0] < length[0]; ++N[0]) { 234 griditer += pre_offset[1]*total[2]; 235 for(N[1]=0; N[1] < length[1]; ++N[1]) { 236 griditer += pre_offset[2]; 237 for(N[2]=0; N[2] < length[2]; ++N[2]) { 238 ASSERT( griditer != window.Iterators().Local().End(), 239 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window."); 240 ASSERT( copyiter != grid.sampled_grid.end(), 241 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window."); 242 window(*griditer++) += prefactor*(*copyiter++); 243 } 244 griditer += post_offset[2]; 245 } 246 griditer += post_offset[1]*total[2]; 247 } 248 #ifndef NDEBUG 249 griditer += post_offset[0]*total[1]*total[2]; 250 ASSERT( griditer == window.Iterators().Local().End(), 251 "InterfaceVMGJob::addWindowOntoGrid() - griditer is not at end of window."); 252 ASSERT( copyiter == grid.sampled_grid.end(), 253 "InterfaceVMGJob::addWindowOntoGrid() - copyiter is not at end of window."); 254 #endif 255 // LOG(2, "DEBUG: Grid after adding other is " << grid << "."); 256 } 257 96 258 void InterfaceVMGJob::ImportRightHandSide(Multigrid& multigrid) 97 259 { … … 142 304 143 305 // print nuclei grid to vtk 144 //comm.PrintGrid(particle_grid, "Sampled Nuclei Density");306 comm.PrintGrid(particle_grid, "Sampled Nuclei Density"); 145 307 146 308 // add sampled electron charge density onto grid 147 std::vector<double>::const_iterator sample_iter = sampled_input.begin(); 148 for (Grid::iterator iter = grid.Iterators().Local().Begin(); 149 iter != grid.Iterators().Local().End(); 150 ++iter) 151 grid(*iter) = -1. * (*sample_iter++); 152 assert( sample_iter == sampled_input.end() ); 309 addWindowOntoGrid( 310 grid, 311 sampled_input, 312 -1.); 153 313 154 314 // print electron grid to vtk 155 //comm.PrintGrid(grid, "Sampled Electron Density");315 comm.PrintGrid(grid, "Sampled Electron Density"); 156 316 157 317 // add particle_grid onto grid … … 180 340 181 341 // print total grid to vtk 182 //comm.PrintGrid(grid, "Total Charge Density");342 comm.PrintGrid(grid, "Total Charge Density"); 183 343 184 344 // delete temp_grid; … … 200 360 201 361 // obtain sampled potential from grid 202 returndata.sampled_potential.sampled_grid.clear(); 203 for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X()) 204 for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y()) 205 for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) { 206 returndata.sampled_potential.sampled_grid.push_back(grid(i)); 207 } 362 returndata.sampled_potential.setWindow( 363 box_begin, 364 box_end 365 ); 366 addGridOntoWindow( 367 grid, 368 returndata.sampled_potential, 369 +1. 370 ); 208 371 209 372 // calculate integral over potential as long-range energy contribution -
src/Jobs/InterfaceVMGJob.hpp
r64bafe0 r8f3cdd 22 22 #include "Jobs/VMGData.hpp" 23 23 24 class SamplingGrid; 25 24 26 namespace VMG 25 27 { 28 class Grid; 26 29 class MGGrid; 27 30 class MGMultigrid; … … 34 37 { 35 38 public: 36 InterfaceVMGJob(const std::vector< double >&_sampled_input,39 InterfaceVMGJob(const SamplingGrid &_sampled_input, 37 40 VMGData &returndata, 38 41 const std::vector< std::vector< double > > &_particle_positions, … … 41 44 int levelMin, 42 45 int levelMax, 43 const VMG::Vector & box_begin,44 vmg_float box_end,46 const VMG::Vector &_box_begin, 47 vmg_float _box_end, 45 48 const int& near_field_cells, 46 49 int coarseningSteps=0, … … 56 59 57 60 private: 61 /** Helper function to copy VMG's Grid onto the non-zero window of a SamplingGrid 62 * 63 * The code is very similar to SamplingGrid::addOntoWindow(). 64 * 65 * @param grid grid with non-zero window 66 * @param prefactor factor for each added value, e.g. -1. makes a subtraction 67 */ 68 void addGridOntoWindow( 69 VMG::Grid& grid, 70 SamplingGrid &window, 71 const double prefactor) const; 72 73 /** Helper function to copy non-zero window in SamplingGrid onto VMG's Grid. 74 * 75 * The code is very similar to SamplingGrid::addOntoWindow(). 76 * 77 * @param grid grid with non-zero window 78 * @param prefactor factor for each added value, e.g. -1. makes a subtraction 79 */ 80 void addWindowOntoGrid( 81 VMG::Grid& window, 82 const SamplingGrid &grid, 83 const double prefactor) const; 84 private: 58 85 //!> sampled density on the grid as input 59 const std::vector< double >sampled_input;86 const SamplingGrid sampled_input; 60 87 //!> sampled potential on the grid as output 61 88 VMGData &returndata; … … 64 91 //!> nuclei charges 65 92 std::list<VMG::Particle::Particle> particles; 93 94 //!> contains start of grid intervals 95 double box_begin[3]; 96 //!> contains end of grid intervals 97 double box_end[3]; 66 98 }; 67 99 -
src/Jobs/VMGJob.cpp
r64bafe0 r8f3cdd 207 207 new DiscretizationPoissonFD(4); 208 208 new VMGInterfaces::InterfaceVMGJob( 209 density_grid .sampled_grid,209 density_grid, 210 210 returndata, 211 211 particle_positions,
Note:
See TracChangeset
for help on using the changeset viewer.