source: src/Box.cpp@ 29ac78

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 Candidate_v1.7.0 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
Last change on this file since 29ac78 was 29ac78, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added a method that produces the bounding planes for a Box

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Box.cpp
3 *
4 * Created on: Jun 30, 2010
5 * Author: crueger
6 */
7
8//#include "Helpers/MemDebug.hpp"
9
10#include "Box.hpp"
11
12#include <cmath>
13
14#include "Matrix.hpp"
15#include "vector.hpp"
16#include "Plane.hpp"
17
18#include "Helpers/Assert.hpp"
19
20Box::Box()
21{
22 M= new Matrix();
23 M->one();
24 Minv = new Matrix();
25 Minv->one();
26 conditions.resize(3);
27 conditions[0] = conditions[1] = conditions[2] = Wrap;
28}
29
30Box::Box(const Box& src){
31 M=new Matrix(*src.M);
32 Minv = new Matrix(*src.Minv);
33 conditions = src.conditions;
34}
35
36Box::~Box()
37{
38 delete M;
39 delete Minv;
40}
41
42const Matrix &Box::getM() const{
43 return *M;
44}
45const Matrix &Box::getMinv() const{
46 return *Minv;
47}
48
49void Box::setM(Matrix _M){
50 ASSERT(_M.determinant()!=0,"Matrix in Box construction was not invertible");
51 *M =_M;
52 *Minv = M->invert();
53}
54
55Vector Box::translateIn(const Vector &point) const{
56 return (*M) * point;
57}
58
59Vector Box::translateOut(const Vector &point) const{
60 return (*Minv) * point;
61}
62
63Vector Box::WrapPeriodically(const Vector &point) const{
64 Vector helper = translateOut(point);
65 for(int i=NDIM;i--;){
66 double intpart,fracpart;
67 fracpart = modf(helper.at(i),&intpart);
68 if(fracpart<0.)
69 fracpart+=1.;
70 helper.at(i)=fracpart;
71 }
72 return translateIn(helper);
73}
74
75bool Box::isInside(const Vector &point) const
76{
77 bool result = true;
78 Vector tester = translateOut(point);
79
80 for(int i=0;i<NDIM;i++)
81 result = result && ((tester[i] >= -MYEPSILON) && ((tester[i] - 1.) < MYEPSILON));
82
83 return result;
84}
85
86
87VECTORSET(std::list) Box::explode(const Vector &point,int n) const{
88 VECTORSET(std::list) res;
89
90 // translate the Vector into each of the 27 neighbourhoods
91
92 // first create all translation Vectors
93 // there are (n*2+1)^3 such vectors
94 int max_dim = (n*2+1);
95 int max_dim2 = max_dim*max_dim;
96 int max = max_dim2*max_dim;
97 // only one loop to avoid unneccessary jumps
98 for(int i = 0;i<max;++i){
99 // get all coordinates for this iteration
100 int n1 = (i%max_dim)-n;
101 int n2 = ((i/max_dim)%max_dim)-n;
102 int n3 = ((i/max_dim2))-n;
103 Vector translation = translateIn(Vector(n1,n2,n3));
104 res.push_back(translation);
105 }
106 // translate all the translation vector by the offset defined by point
107 res.translate(point);
108 return res;
109}
110
111VECTORSET(std::list) Box::explode(const Vector &point) const{
112 VECTORSET(std::list) res;
113
114 // translate the Vector into each of the 27 neighbourhoods
115
116 // first create all 27 translation Vectors
117 // these loops depend on fixed parameters and can easily be expanded
118 // by the compiler to allow code without jumps
119 for(int n1 = -1;n1<=1;++n1){
120 for(int n2 = -1;n2<=1;++n2){
121 for(int n3 = -1;n3<=1;++n3){
122 // get all coordinates for this iteration
123 Vector translation = translateIn(Vector(n1,n2,n3));
124 res.push_back(translation);
125 }
126 }
127 }
128 // translate all the translation vector by the offset defined by point
129 res.translate(point);
130 return res;
131}
132
133double Box::periodicDistanceSquared(const Vector &point1,const Vector &point2) const{
134 VECTORSET(std::list) expansion = explode(point1);
135 double res = expansion.minDistSquared(point2);
136 return res;
137}
138
139double Box::periodicDistance(const Vector &point1,const Vector &point2) const{
140 double res;
141 res = sqrt(periodicDistanceSquared(point1,point2));
142 return res;
143}
144
145const Box::Conditions_t Box::getConditions(){
146 return conditions;
147}
148
149void Box::setCondition(int i,Box::BoundaryCondition_t condition){
150 conditions[i]=condition;
151}
152
153const vector<pair<Plane,Plane> > Box::getBoundingPlanes(){
154 vector<pair<Plane,Plane> > res;
155 for(int i=0;i<NDIM;++i){
156 Vector base1,base2,base3;
157 base2[(i+1)%NDIM] = 1.;
158 base3[(i+2)%NDIM] = 1.;
159 Plane p1(translateIn(base1),
160 translateIn(base2),
161 translateIn(base3));
162 Vector offset;
163 offset[i]=1;
164 Plane p2(translateIn(base1+offset),
165 translateIn(base2+offset),
166 translateIn(base3+offset));
167 res.push_back(make_pair(p1,p2));
168 }
169 return res;
170}
171
172Box &Box::operator=(const Box &src){
173 if(&src!=this){
174 delete M;
175 delete Minv;
176 M = new Matrix(*src.M);
177 Minv = new Matrix(*src.Minv);
178 conditions = src.conditions;
179 }
180 return *this;
181}
182
183Box &Box::operator=(const Matrix &mat){
184 setM(mat);
185 return *this;
186}
Note: See TracBrowser for help on using the repository browser.