Changeset 8f3cdd


Ignore:
Timestamp:
Feb 15, 2013, 5:07:31 PM (12 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Adapted VMGJob and its Interface to new non-zero window use.

  • we required two new functions to copy window contents onto the grid and back again.
  • SamplingGrid::setWindow() is now private.
Location:
src/Jobs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Jobs/Grid/SamplingGrid.hpp

    r64bafe0 r8f3cdd  
    177177  const double getWindowVolume() const;
    178178
    179 private:
    180179  /** Sets the size of the window.
    181180   *
     
    187186  void setWindow(const double _begin_window[3], const double _end_window[3]);
    188187
     188private:
    189189  /** Sets the size of the domain.
    190190   *
  • src/Jobs/InterfaceVMGJob.cpp

    r64bafe0 r8f3cdd  
    5252#include <cmath>
    5353#include <iostream>
     54#include <limits>
    5455
    5556#include "CodePatterns/Log.hpp"
    5657
     58#include "Jobs/Grid/SamplingGrid.hpp"
    5759
    5860using namespace VMG;
    5961using VMGInterfaces::InterfaceVMGJob;
    6062
    61 InterfaceVMGJob::InterfaceVMGJob(const std::vector< double > &_sampled_input,
     63InterfaceVMGJob::InterfaceVMGJob(const SamplingGrid &_sampled_input,
    6264    VMGData &_returndata,
    6365    const std::vector< std::vector<double> > &_particle_positions,
     
    6668    int levelMin,
    6769    int levelMax,
    68     const VMG::Vector &box_begin,
    69     vmg_float box_end,
     70    const VMG::Vector &_box_begin,
     71    vmg_float _box_end,
    7072    const int& near_field_cells,
    7173    int coarseningSteps,
    7274    double alpha) :
    7375  VMG::Interface(boundary, levelMin, levelMax,
    74       box_begin, box_end, coarseningSteps, alpha),
     76      _box_begin, _box_end, coarseningSteps, alpha),
    7577  spl(near_field_cells, Extent(MaxLevel()).MeshWidth().Max()),
    7678  sampled_input(_sampled_input),
     
    7880  level(levelMax)
    7981{
     82  for (size_t i=0;i<3;++i) {
     83    box_begin[i] = _box_begin[i];
     84    box_end[i] = _box_end;
     85  }
    8086  std::vector< std::vector<double> >::const_iterator positer = _particle_positions.begin();
    8187  std::vector<double>::const_iterator chargeiter = _particle_charges.begin();
     
    94100{}
    95101
     102void 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
     180void 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
    96258void InterfaceVMGJob::ImportRightHandSide(Multigrid& multigrid)
    97259{
     
    142304
    143305  // print nuclei grid to vtk
    144 //  comm.PrintGrid(particle_grid, "Sampled Nuclei Density");
     306  comm.PrintGrid(particle_grid, "Sampled Nuclei Density");
    145307
    146308  // 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.);
    153313
    154314  // print electron grid to vtk
    155 //  comm.PrintGrid(grid, "Sampled Electron Density");
     315  comm.PrintGrid(grid, "Sampled Electron Density");
    156316
    157317  // add particle_grid onto grid
     
    180340
    181341  // print total grid to vtk
    182 //  comm.PrintGrid(grid, "Total Charge Density");
     342  comm.PrintGrid(grid, "Total Charge Density");
    183343
    184344//  delete temp_grid;
     
    200360
    201361  // 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      );
    208371
    209372  // calculate integral over potential as long-range energy contribution
  • src/Jobs/InterfaceVMGJob.hpp

    r64bafe0 r8f3cdd  
    2222#include "Jobs/VMGData.hpp"
    2323
     24class SamplingGrid;
     25
    2426namespace VMG
    2527{
     28class Grid;
    2629class MGGrid;
    2730class MGMultigrid;
     
    3437{
    3538public:
    36   InterfaceVMGJob(const std::vector< double > &_sampled_input,
     39  InterfaceVMGJob(const SamplingGrid &_sampled_input,
    3740      VMGData &returndata,
    3841      const std::vector< std::vector< double > > &_particle_positions,
     
    4144      int levelMin,
    4245      int levelMax,
    43       const VMG::Vector &box_begin,
    44       vmg_float box_end,
     46      const VMG::Vector &_box_begin,
     47      vmg_float _box_end,
    4548      const int& near_field_cells,
    4649      int coarseningSteps=0,
     
    5659
    5760private:
     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;
     84private:
    5885  //!> sampled density on the grid as input
    59   const std::vector< double > sampled_input;
     86  const SamplingGrid sampled_input;
    6087  //!> sampled potential on the grid as output
    6188  VMGData &returndata;
     
    6491  //!> nuclei charges
    6592  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];
    6698};
    6799
  • src/Jobs/VMGJob.cpp

    r64bafe0 r8f3cdd  
    207207  new DiscretizationPoissonFD(4);
    208208  new VMGInterfaces::InterfaceVMGJob(
    209       density_grid.sampled_grid,
     209      density_grid,
    210210      returndata,
    211211      particle_positions,
Note: See TracChangeset for help on using the changeset viewer.