Changeset 16648f for src


Ignore:
Timestamp:
Jul 29, 2010, 4:09:57 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
04e61a
Parents:
f3be87
Message:

Made the Box::explode() method handle boundary conditions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Box.cpp

    rf3be87 r16648f  
    1111
    1212#include <cmath>
     13#include <iostream>
    1314
    1415#include "Matrix.hpp"
     
    1718
    1819#include "Helpers/Assert.hpp"
     20
     21using namespace std;
    1922
    2023Box::Box()
     
    105108
    106109VECTORSET(std::list) Box::explode(const Vector &point,int n) const{
     110  ASSERT(isInside(point),"Exploded point not inside Box");
    107111  VECTORSET(std::list) res;
    108112
    109   // translate the Vector into each of the 27 neighbourhoods
    110 
    111   // first create all translation Vectors
    112   // there are (n*2+1)^3 such vectors
    113   int max_dim = (n*2+1);
    114   int max_dim2 = max_dim*max_dim;
    115   int max = max_dim2*max_dim;
    116   // only one loop to avoid unneccessary jumps
    117   for(int i = 0;i<max;++i){
    118     // get all coordinates for this iteration
    119     int n1 = (i%max_dim)-n;
    120     int n2 = ((i/max_dim)%max_dim)-n;
    121     int n3 = ((i/max_dim2))-n;
    122     Vector translation = translateIn(Vector(n1,n2,n3));
    123     res.push_back(translation);
    124   }
    125   // translate all the translation vector by the offset defined by point
    126   res.translate(point);
     113  Vector translater = translateOut(point);
     114  Vector mask; // contains the ignored coordinates
     115
     116  // count the number of coordinates we need to do
     117  int dims = 0; // number of dimensions that are not ignored
     118  vector<int> coords;
     119  vector<int> index;
     120  for(int i=0;i<NDIM;++i){
     121    if(conditions[i]==Ignore){
     122      mask[i]=translater[i];
     123      continue;
     124    }
     125    coords.push_back(i);
     126    index.push_back(-n);
     127    dims++;
     128  } // there are max vectors in total we need to create
     129
     130  if(!dims){
     131    // all boundaries are ignored
     132    res.push_back(point);
     133    return res;
     134  }
     135
     136  int pos = 0;
     137  while(pos<dims){
     138    // create this vector
     139    Vector helper;
     140    for(int i=0;i<dims;++i){
     141      switch(conditions[coords[i]]){
     142        case Wrap:
     143          helper[coords[i]] = index[i]+translater[coords[i]];
     144          break;
     145        case Bounce:
     146          {
     147            // Bouncing the coordinate x produces the series:
     148            // 0 -> x
     149            // 1 -> 2-x
     150            // 2 -> 2+x
     151            // 3 -> 4-x
     152            // 4 -> 4+x
     153            // the first number is the next bigger even number (n+n%2)
     154            // the next number is the value with alternating sign (x-2*(n%2)*x)
     155            // the negative numbers produce the same sequence reversed and shifted
     156            int n = abs(index[i]) + (index[i]<0)?-1:0;
     157            int sign = (index[i]<0)?-1:+1;
     158            int even = n%2;
     159            helper[coords[i]]=n+even+translater[coords[i]]-2*even*translater[coords[i]];
     160            helper[coords[i]]*=sign;
     161          }
     162          break;
     163        case Ignore:
     164          ASSERT(0,"Ignored coordinate handled in generation loop");
     165        default:
     166          ASSERT(0,"No default case for this switch-case");
     167      }
     168
     169    }
     170    // add back all ignored coordinates (not handled in above loop)
     171    helper+=mask;
     172    res.push_back(translateIn(helper));
     173    // set the new indexes
     174    pos=0;
     175    ++index[pos];
     176    while(index[pos]>n && pos < dims){
     177      index[pos++]=-n;
     178      ++index[pos];
     179    }
     180  }
    127181  return res;
    128182}
    129183
    130184VECTORSET(std::list) Box::explode(const Vector &point) const{
    131   VECTORSET(std::list) res;
    132 
    133   // translate the Vector into each of the 27 neighbourhoods
    134 
    135   // first create all 27 translation Vectors
    136   // these loops depend on fixed parameters and can easily be expanded
    137   // by the compiler to allow code without jumps
    138   for(int n1 = -1;n1<=1;++n1){
    139     for(int n2 = -1;n2<=1;++n2){
    140       for(int n3 = -1;n3<=1;++n3){
    141         // get all coordinates for this iteration
    142         Vector translation = translateIn(Vector(n1,n2,n3));
    143         res.push_back(translation);
    144       }
    145     }
    146   }
    147   // translate all the translation vector by the offset defined by point
    148   res.translate(point);
    149   return res;
     185  ASSERT(isInside(point),"Exploded point not inside Box");
     186  return explode(point,1);
    150187}
    151188
Note: See TracChangeset for help on using the changeset viewer.