Changeset 6c438f for src/Box.cpp
- Timestamp:
- Aug 28, 2010, 3:21:11 AM (15 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:
- a6e6b5, f8982c
- Parents:
- 2ad482 (diff), fd4905 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (08/28/10 03:17:48)
- git-committer:
- Frederik Heber <heber@…> (08/28/10 03:21:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Box.cpp
r2ad482 r6c438f 1 /* 2 * Project: MoleCuilder 3 * Description: creates and alters molecular systems 4 * Copyright (C) 2010 University of Bonn. All rights reserved. 5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. 6 */ 7 1 8 /* 2 9 * Box.cpp … … 6 13 */ 7 14 8 //#include "Helpers/MemDebug.hpp" 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 20 #include "Helpers/MemDebug.hpp" 9 21 10 22 #include "Box.hpp" 11 23 12 24 #include <cmath> 13 14 #include "Matrix.hpp" 15 #include "vector.hpp" 25 #include <iostream> 26 #include <cstdlib> 27 28 #include "LinearAlgebra/Matrix.hpp" 29 #include "LinearAlgebra/Vector.hpp" 30 #include "LinearAlgebra/Plane.hpp" 16 31 #include "Shapes/BaseShapes.hpp" 17 32 #include "Shapes/ShapeOps.hpp" 18 33 19 34 #include "Helpers/Assert.hpp" 35 36 using namespace std; 20 37 21 38 Box::Box() … … 25 42 Minv = new Matrix(); 26 43 Minv->one(); 44 conditions.resize(3); 45 conditions[0] = conditions[1] = conditions[2] = Wrap; 27 46 } 28 47 … … 30 49 M=new Matrix(*src.M); 31 50 Minv = new Matrix(*src.Minv); 51 conditions = src.conditions; 32 52 } 33 53 … … 62 82 Vector helper = translateOut(point); 63 83 for(int i=NDIM;i--;){ 64 double intpart,fracpart; 65 fracpart = modf(helper.at(i),&intpart); 66 if(fracpart<0.) 67 fracpart+=1.; 68 helper.at(i)=fracpart; 84 85 switch(conditions[i]){ 86 case Wrap: 87 helper.at(i)=fmod(helper.at(i),1); 88 helper.at(i)+=(helper.at(i)>=0)?0:1; 89 break; 90 case Bounce: 91 { 92 // there probably is a better way to handle this... 93 // all the fabs and fmod modf probably makes it very slow 94 double intpart,fracpart; 95 fracpart = modf(fabs(helper.at(i)),&intpart); 96 helper.at(i) = fabs(fracpart-fmod(intpart,2)); 97 } 98 break; 99 case Ignore: 100 break; 101 default: 102 ASSERT(0,"No default case for this"); 103 } 104 69 105 } 70 106 return translateIn(helper); … … 74 110 { 75 111 bool result = true; 76 Vector tester = (*Minv) * point;112 Vector tester = translateOut(point); 77 113 78 114 for(int i=0;i<NDIM;i++) 79 result = result && ((tester[i] >= -MYEPSILON) && ((tester[i] - 1.) < MYEPSILON)); 115 result = result && 116 ((conditions[i] == Ignore) || 117 ((tester[i] >= -MYEPSILON) && 118 ((tester[i] - 1.) < MYEPSILON))); 80 119 81 120 return result; … … 84 123 85 124 VECTORSET(std::list) Box::explode(const Vector &point,int n) const{ 125 ASSERT(isInside(point),"Exploded point not inside Box"); 86 126 VECTORSET(std::list) res; 87 127 88 // translate the Vector into each of the 27 neighbourhoods 89 90 // first create all translation Vectors 91 // there are (n*2+1)^3 such vectors 92 int max_dim = (n*2+1); 93 int max_dim2 = max_dim*max_dim; 94 int max = max_dim2*max_dim; 95 // only one loop to avoid unneccessary jumps 96 for(int i = 0;i<max;++i){ 97 // get all coordinates for this iteration 98 int n1 = (i%max_dim)-n; 99 int n2 = ((i/max_dim)%max_dim)-n; 100 int n3 = ((i/max_dim2))-n; 101 Vector translation = translateIn(Vector(n1,n2,n3)); 102 res.push_back(translation); 103 } 104 // translate all the translation vector by the offset defined by point 105 res.translate(point); 128 Vector translater = translateOut(point); 129 Vector mask; // contains the ignored coordinates 130 131 // count the number of coordinates we need to do 132 int dims = 0; // number of dimensions that are not ignored 133 vector<int> coords; 134 vector<int> index; 135 for(int i=0;i<NDIM;++i){ 136 if(conditions[i]==Ignore){ 137 mask[i]=translater[i]; 138 continue; 139 } 140 coords.push_back(i); 141 index.push_back(-n); 142 dims++; 143 } // there are max vectors in total we need to create 144 145 if(!dims){ 146 // all boundaries are ignored 147 res.push_back(point); 148 return res; 149 } 150 151 bool done = false; 152 while(!done){ 153 // create this vector 154 Vector helper; 155 for(int i=0;i<dims;++i){ 156 switch(conditions[coords[i]]){ 157 case Wrap: 158 helper[coords[i]] = index[i]+translater[coords[i]]; 159 break; 160 case Bounce: 161 { 162 // Bouncing the coordinate x produces the series: 163 // 0 -> x 164 // 1 -> 2-x 165 // 2 -> 2+x 166 // 3 -> 4-x 167 // 4 -> 4+x 168 // the first number is the next bigger even number (n+n%2) 169 // the next number is the value with alternating sign (x-2*(n%2)*x) 170 // the negative numbers produce the same sequence reversed and shifted 171 int n = abs(index[i]) + ((index[i]<0)?-1:0); 172 int sign = (index[i]<0)?-1:+1; 173 int even = n%2; 174 helper[coords[i]]=n+even+translater[coords[i]]-2*even*translater[coords[i]]; 175 helper[coords[i]]*=sign; 176 } 177 break; 178 case Ignore: 179 ASSERT(0,"Ignored coordinate handled in generation loop"); 180 default: 181 ASSERT(0,"No default case for this switch-case"); 182 } 183 184 } 185 // add back all ignored coordinates (not handled in above loop) 186 helper+=mask; 187 res.push_back(translateIn(helper)); 188 // set the new indexes 189 int pos=0; 190 ++index[pos]; 191 while(index[pos]>n){ 192 index[pos++]=-n; 193 if(pos>=dims) { // it's trying to increase one beyond array... all vectors generated 194 done = true; 195 break; 196 } 197 ++index[pos]; 198 } 199 } 106 200 return res; 107 201 } 108 202 109 203 VECTORSET(std::list) Box::explode(const Vector &point) const{ 110 VECTORSET(std::list) res; 111 112 // translate the Vector into each of the 27 neighbourhoods 113 114 // first create all 27 translation Vectors 115 // these loops depend on fixed parameters and can easily be expanded 116 // by the compiler to allow code without jumps 117 for(int n1 = -1;n1<=1;++n1){ 118 for(int n2 = -1;n2<=1;++n2){ 119 for(int n3 = -1;n3<=1;++n3){ 120 // get all coordinates for this iteration 121 Vector translation = translateIn(Vector(n1,n2,n3)); 122 res.push_back(translation); 123 } 124 } 125 } 126 // translate all the translation vector by the offset defined by point 127 res.translate(point); 128 return res; 204 ASSERT(isInside(point),"Exploded point not inside Box"); 205 return explode(point,1); 129 206 } 130 207 131 208 double Box::periodicDistanceSquared(const Vector &point1,const Vector &point2) const{ 132 VECTORSET(std::list) expansion = explode(point1); 133 double res = expansion.minDistSquared(point2); 209 Vector helper1 = WrapPeriodically(point1); 210 Vector helper2 = WrapPeriodically(point2); 211 VECTORSET(std::list) expansion = explode(helper1); 212 double res = expansion.minDistSquared(helper2); 134 213 return res; 135 214 } … … 143 222 Shape Box::getShape() const{ 144 223 return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M)); 145 224 } 225 226 const Box::Conditions_t Box::getConditions(){ 227 return conditions; 228 } 229 230 void Box::setCondition(int i,Box::BoundaryCondition_t condition){ 231 conditions[i]=condition; 232 } 233 234 const vector<pair<Plane,Plane> > Box::getBoundingPlanes(){ 235 vector<pair<Plane,Plane> > res; 236 for(int i=0;i<NDIM;++i){ 237 Vector base1,base2,base3; 238 base2[(i+1)%NDIM] = 1.; 239 base3[(i+2)%NDIM] = 1.; 240 Plane p1(translateIn(base1), 241 translateIn(base2), 242 translateIn(base3)); 243 Vector offset; 244 offset[i]=1; 245 Plane p2(translateIn(base1+offset), 246 translateIn(base2+offset), 247 translateIn(base3+offset)); 248 res.push_back(make_pair(p1,p2)); 249 } 250 return res; 251 } 252 253 void Box::setCuboid(const Vector &endpoint){ 254 ASSERT(endpoint[0]>0 && endpoint[1]>0 && endpoint[2]>0,"Vector does not define a full cuboid"); 255 M->one(); 256 M->diagonal()=endpoint; 257 Vector &dinv = Minv->diagonal(); 258 for(int i=NDIM;i--;) 259 dinv[i]=1/endpoint[i]; 146 260 } 147 261 … … 152 266 M = new Matrix(*src.M); 153 267 Minv = new Matrix(*src.Minv); 268 conditions = src.conditions; 154 269 } 155 270 return *this;
Note:
See TracChangeset
for help on using the changeset viewer.