source: src/Box.cpp@ 77374e

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 77374e was 77374e, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added BoundaryConditions to the Box class

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