Changeset 57fda0


Ignore:
Timestamp:
Sep 14, 2016, 6:42:53 PM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
b839fb
Parents:
6a5eb2
git-author:
Frederik Heber <heber@…> (06/06/16 14:46:53)
git-committer:
Frederik Heber <heber@…> (09/14/16 18:42:53)
Message:

SamplingGrid::operator*=(), ::superposeOtherGrids() and ::integral() now allow non-equivalent grids.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/SamplingGrid.cpp

    r6a5eb2 r57fda0  
    4545#include <boost/assign.hpp>
    4646#include <boost/bind.hpp>
     47#include <boost/shared_ptr.hpp>
     48
    4749#include <algorithm>
    4850#include <limits>
     
    158160}
    159161
     162static void getDownsampledGrid(
     163    const SamplingGrid &_reference_grid,
     164    const SamplingGrid &_grid,
     165    boost::shared_ptr<SamplingGrid> &_weight_downsampled)
     166{
     167  static const double round_offset(
     168      (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
     169          0.5 : 0.); // need offset to get to round_toward_nearest behavior
     170  const int surplus_level = _reference_grid.getSurplusLevel(_grid)+round_offset;
     171  // need to downsample first
     172  _weight_downsampled.reset(new SamplingGrid); // may use default cstor as downsample does all settings
     173  SamplingGrid::downsample(*_weight_downsampled, _grid, _reference_grid.level-surplus_level);
     174}
     175
    160176SamplingGrid& SamplingGrid::operator*=(const SamplingGrid& other)
    161177{
    162178  // check that grids are compatible
    163   if (isEquivalent(other)) {
    164     /// get minimum of window
    165     double min_begin_window[NDIM];
    166     double min_end_window[NDIM];
    167     bool doShrink = false;
    168     for (size_t index=0; index<NDIM;++index) {
    169       if (begin_window[index] <= other.begin_window[index]) {
    170         min_begin_window[index] = other.begin_window[index];
    171         doShrink = true;
    172       } else {
    173         min_begin_window[index] = begin_window[index];
    174       }
    175       if (end_window[index] <= other.end_window[index]) {
    176         min_end_window[index] = end_window[index];
    177       } else {
    178         min_end_window[index] = other.end_window[index];
    179         doShrink = true;
    180       }
    181     }
    182     LOG(4, "DEBUG: min begin is " << min_begin_window[0] << "," << min_begin_window[1] << "," << min_begin_window[2] << ".");
    183     LOG(4, "DEBUG: min end is " << min_end_window[0] << "," << min_end_window[1] << "," << min_end_window[2] << ".");
    184     if (doShrink)
    185       shrinkWindow(min_begin_window, min_end_window);
    186     addWindowOntoWindow(
    187         other.begin_window,
    188         other.end_window,
    189         begin_window,
    190         end_window,
    191         sampled_grid,
    192         other.sampled_grid,
    193         boost::bind(multiplyElements, _1, _2, 1.),
    194         sourcewindow);
    195   } else {
    196     ASSERT(0, "SamplingGrid::operator*=() - multiplying incongruent grids is so far not in the cards.");
    197   }
     179  ASSERT(isCompatible(other),
     180      "SamplingGrid::operator*=() - multiplying incomatible grids is so far not in the cards.");
     181  const SamplingGrid *other_grid = &other;
     182  boost::shared_ptr<SamplingGrid> other_downsampled;
     183  if (!isEquivalent(other)) {
     184    getDownsampledGrid(*this, other, other_downsampled);
     185    other_grid = other_downsampled.get();
     186  }
     187  /// get minimum of window
     188  double min_begin_window[NDIM];
     189  double min_end_window[NDIM];
     190  bool doShrink = false;
     191  for (size_t index=0; index<NDIM;++index) {
     192    if (begin_window[index] <= other.begin_window[index]) {
     193      min_begin_window[index] = other.begin_window[index];
     194      doShrink = true;
     195    } else {
     196      min_begin_window[index] = begin_window[index];
     197    }
     198    if (end_window[index] <= other.end_window[index]) {
     199      min_end_window[index] = end_window[index];
     200    } else {
     201      min_end_window[index] = other.end_window[index];
     202      doShrink = true;
     203    }
     204  }
     205  LOG(4, "DEBUG: min begin is " << min_begin_window[0] << "," << min_begin_window[1] << "," << min_begin_window[2] << ".");
     206  LOG(4, "DEBUG: min end is " << min_end_window[0] << "," << min_end_window[1] << "," << min_end_window[2] << ".");
     207  if (doShrink)
     208    shrinkWindow(min_begin_window, min_end_window);
     209  addWindowOntoWindow(
     210      other_grid->begin_window,
     211      other_grid->end_window,
     212      begin_window,
     213      end_window,
     214      sampled_grid,
     215      other_grid->sampled_grid,
     216      boost::bind(multiplyElements, _1, _2, 1.),
     217      sourcewindow);
     218
    198219  return *this;
    199220}
     
    201222void SamplingGrid::superposeOtherGrids(const SamplingGrid &other, const double prefactor)
    202223{
    203   /// check that grids are compatible
    204   if (isEquivalent(other)) {
    205     /// get maximum of window
    206     double max_begin_window[NDIM];
    207     double max_end_window[NDIM];
    208     bool doExtend = false;
    209     for (size_t index=0; index<NDIM;++index) {
    210       if (begin_window[index] >= other.begin_window[index]) {
    211         max_begin_window[index] = other.begin_window[index];
    212         doExtend = true;
    213       } else {
    214         max_begin_window[index] = begin_window[index];
    215       }
    216       if (end_window[index] >= other.end_window[index]) {
    217         max_end_window[index] = end_window[index];
    218       } else {
    219         max_end_window[index] = other.end_window[index];
    220         doExtend = true;
    221       }
    222     }
    223     LOG(4, "DEBUG: max begin is " << max_begin_window[0] << "," << max_begin_window[1] << "," << max_begin_window[2] << ".");
    224     LOG(4, "DEBUG: max end is " << max_end_window[0] << "," << max_end_window[1] << "," << max_end_window[2] << ".");
    225     if (doExtend)
    226       extendWindow(max_begin_window, max_end_window);
    227     /// and copy other into larger window, too
    228     addOntoWindow(other.begin_window, other.end_window, other.sampled_grid, prefactor);
    229   } else {
    230     ASSERT(0, "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
    231   }
     224  // check that grids are compatible
     225  ASSERT(isCompatible(other),
     226      "SamplingGrid::superposeOtherGrids() - superposing incompatible grids is so far not in the cards.");
     227  const SamplingGrid *other_grid = &other;
     228  boost::shared_ptr<SamplingGrid> other_downsampled;
     229  if (!isEquivalent(other)) {
     230    getDownsampledGrid(*this, other, other_downsampled);
     231    other_grid = other_downsampled.get();
     232  }
     233  /// get maximum of window
     234  double max_begin_window[NDIM];
     235  double max_end_window[NDIM];
     236  bool doExtend = false;
     237  for (size_t index=0; index<NDIM;++index) {
     238    if (begin_window[index] >= other.begin_window[index]) {
     239      max_begin_window[index] = other.begin_window[index];
     240      doExtend = true;
     241    } else {
     242      max_begin_window[index] = begin_window[index];
     243    }
     244    if (end_window[index] >= other.end_window[index]) {
     245      max_end_window[index] = end_window[index];
     246    } else {
     247      max_end_window[index] = other.end_window[index];
     248      doExtend = true;
     249    }
     250  }
     251  LOG(4, "DEBUG: max begin is " << max_begin_window[0] << "," << max_begin_window[1] << "," << max_begin_window[2] << ".");
     252  LOG(4, "DEBUG: max end is " << max_end_window[0] << "," << max_end_window[1] << "," << max_end_window[2] << ".");
     253  if (doExtend)
     254    extendWindow(max_begin_window, max_end_window);
     255  /// and copy other into larger window, too
     256  addOntoWindow(other_grid->begin_window, other_grid->end_window, other_grid->sampled_grid, prefactor);
    232257}
    233258
     
    262287double SamplingGrid::integral(const SamplingGrid &weight) const
    263288{
    264   if (isEquivalent(weight)) {
    265     const double volume_element = getVolume()/(double)getTotalGridPoints();
    266     double int_value = 0.;
    267     sampledvalues_t::const_iterator iter = sampled_grid.begin();
    268     sampledvalues_t::const_iterator weightiter = weight.sampled_grid.begin();
    269     for (;iter != sampled_grid.end();++iter,++weightiter)
    270       int_value += (*weightiter) * (*iter);
    271     int_value *= volume_element;
    272     //LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
    273     return int_value;
    274   } else
    275     return 0.;
    276 }
     289  // check that grids are compatible
     290  ASSERT(isCompatible(weight),
     291      "SamplingGrid::integral() - integrating with weights from incompatible grids is so far not in the cards.");
     292  const SamplingGrid *weight_grid = &weight;
     293  boost::shared_ptr<SamplingGrid> weight_downsampled;
     294  if (!isEquivalent(weight)) {
     295    getDownsampledGrid(*this, weight, weight_downsampled);
     296    weight_grid = weight_downsampled.get();
     297  }
     298  const double volume_element = getVolume()/(double)getTotalGridPoints();
     299  double int_value = 0.;
     300  sampledvalues_t::const_iterator iter = sampled_grid.begin();
     301  sampledvalues_t::const_iterator weightiter = weight_grid->sampled_grid.begin();
     302  for (;iter != sampled_grid.end();++iter,++weightiter)
     303    int_value += (*weightiter) * (*iter);
     304  int_value *= volume_element;
     305  //LOG(2, "DEBUG: SamplingGrid::integral() is " << scientific << setprecision(13) << int_value << ".");
     306  return int_value;
     307}
     308
    277309void SamplingGrid::setWindowSize(
    278310    const double _begin_window[NDIM],
Note: See TracChangeset for help on using the changeset viewer.