| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [bcf653] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [83c09a] | 8 | /*
 | 
|---|
 | 9 |  * Box.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Jun 30, 2010
 | 
|---|
 | 12 |  *      Author: crueger
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [6e00dd] | 21 | 
 | 
|---|
| [83c09a] | 22 | #include "Box.hpp"
 | 
|---|
 | 23 | 
 | 
|---|
| [f429d7] | 24 | #include <cmath>
 | 
|---|
| [d2938f] | 25 | #include <cstdlib>
 | 
|---|
| [c52e08] | 26 | #include <iostream>
 | 
|---|
 | 27 | #include <sstream>
 | 
|---|
| [f429d7] | 28 | 
 | 
|---|
| [06aedc] | 29 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 30 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [99f4ee] | 31 | #include "CodePatterns/Observer/Channels.hpp"
 | 
|---|
 | 32 | #include "CodePatterns/Observer/Notification.hpp"
 | 
|---|
| [06aedc] | 33 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
 | 34 | #include "Helpers/defs.hpp"
 | 
|---|
| [cca9ef] | 35 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [57f243] | 36 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 37 | #include "LinearAlgebra/Plane.hpp"
 | 
|---|
| [c538d1] | 38 | #include "Shapes/BaseShapes.hpp"
 | 
|---|
 | 39 | #include "Shapes/ShapeOps.hpp"
 | 
|---|
| [83c09a] | 40 | 
 | 
|---|
| [6e00dd] | 41 | 
 | 
|---|
| [528b3e] | 42 | Box::Box() :
 | 
|---|
| [99f4ee] | 43 |     Observable("Box"),
 | 
|---|
| [528b3e] | 44 |     M(new RealSpaceMatrix()),
 | 
|---|
 | 45 |     Minv(new RealSpaceMatrix())
 | 
|---|
| [83c09a] | 46 | {
 | 
|---|
| [de29ad6] | 47 |   internal_list.reserve(pow(3,3));
 | 
|---|
 | 48 |   coords.reserve(NDIM);
 | 
|---|
 | 49 |   index.reserve(NDIM);
 | 
|---|
| [99f4ee] | 50 | 
 | 
|---|
 | 51 |   // observable stuff
 | 
|---|
 | 52 |   Channels *OurChannel = new Channels;
 | 
|---|
 | 53 |   NotificationChannels.insert( std::make_pair(this, OurChannel) );
 | 
|---|
 | 54 |   // add instance for each notification type
 | 
|---|
 | 55 |   for (size_t type = 0; type < NotificationType_MAX; ++type)
 | 
|---|
 | 56 |     OurChannel->addChannel(type);
 | 
|---|
 | 57 | 
 | 
|---|
| [9eb7580] | 58 |   M->setIdentity();
 | 
|---|
 | 59 |   Minv->setIdentity();
 | 
|---|
| [83c09a] | 60 | }
 | 
|---|
 | 61 | 
 | 
|---|
| [528b3e] | 62 | Box::Box(const Box& src) :
 | 
|---|
| [99f4ee] | 63 |     Observable("Box"),
 | 
|---|
 | 64 |     conditions(src.conditions),
 | 
|---|
 | 65 |     M(new RealSpaceMatrix(*src.M)),
 | 
|---|
 | 66 |     Minv(new RealSpaceMatrix(*src.Minv))
 | 
|---|
| [de29ad6] | 67 | {
 | 
|---|
 | 68 |   internal_list.reserve(pow(3,3));
 | 
|---|
 | 69 |   coords.reserve(NDIM);
 | 
|---|
 | 70 |   index.reserve(NDIM);
 | 
|---|
| [99f4ee] | 71 | 
 | 
|---|
 | 72 |   // observable stuff
 | 
|---|
 | 73 |   Channels *OurChannel = new Channels;
 | 
|---|
 | 74 |   NotificationChannels.insert( std::make_pair(this, OurChannel) );
 | 
|---|
 | 75 |   // add instance for each notification type
 | 
|---|
 | 76 |   for (size_t type = 0; type < NotificationType_MAX; ++type)
 | 
|---|
 | 77 |     OurChannel->addChannel(type);
 | 
|---|
| [de29ad6] | 78 | }
 | 
|---|
| [528b3e] | 79 | 
 | 
|---|
 | 80 | Box::Box(RealSpaceMatrix _M) :
 | 
|---|
| [99f4ee] | 81 |     Observable("Box"),
 | 
|---|
| [528b3e] | 82 |     M(new RealSpaceMatrix(_M)),
 | 
|---|
 | 83 |     Minv(new RealSpaceMatrix())
 | 
|---|
 | 84 | {
 | 
|---|
| [de29ad6] | 85 |   internal_list.reserve(pow(3,3));
 | 
|---|
 | 86 |   coords.reserve(NDIM);
 | 
|---|
 | 87 |   index.reserve(NDIM);
 | 
|---|
| [99f4ee] | 88 | 
 | 
|---|
 | 89 |   // observable stuff
 | 
|---|
 | 90 |   Channels *OurChannel = new Channels;
 | 
|---|
 | 91 |   NotificationChannels.insert( std::make_pair(this, OurChannel) );
 | 
|---|
 | 92 |   // add instance for each notification type
 | 
|---|
 | 93 |   for (size_t type = 0; type < NotificationType_MAX; ++type)
 | 
|---|
 | 94 |     OurChannel->addChannel(type);
 | 
|---|
 | 95 | 
 | 
|---|
| [528b3e] | 96 |   ASSERT(M->determinant()!=0,"Matrix in Box construction was not invertible");
 | 
|---|
 | 97 |   *Minv = M->invert();
 | 
|---|
| [7579a4b] | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
| [83c09a] | 100 | Box::~Box()
 | 
|---|
 | 101 | {
 | 
|---|
| [99f4ee] | 102 |   // observable stuff
 | 
|---|
 | 103 |   std::map<Observable *, Channels*>::iterator iter = NotificationChannels.find(this);
 | 
|---|
 | 104 |   delete iter->second;
 | 
|---|
 | 105 |   NotificationChannels.erase(iter);
 | 
|---|
 | 106 | 
 | 
|---|
| [83c09a] | 107 |   delete M;
 | 
|---|
 | 108 |   delete Minv;
 | 
|---|
 | 109 | }
 | 
|---|
 | 110 | 
 | 
|---|
| [cca9ef] | 111 | const RealSpaceMatrix &Box::getM() const{
 | 
|---|
| [83c09a] | 112 |   return *M;
 | 
|---|
 | 113 | }
 | 
|---|
| [cca9ef] | 114 | const RealSpaceMatrix &Box::getMinv() const{
 | 
|---|
| [83c09a] | 115 |   return *Minv;
 | 
|---|
 | 116 | }
 | 
|---|
 | 117 | 
 | 
|---|
| [cca9ef] | 118 | void Box::setM(RealSpaceMatrix _M){
 | 
|---|
| [3bf9e2] | 119 |   ASSERT(_M.determinant()!=0,"Matrix in Box construction was not invertible");
 | 
|---|
| [99f4ee] | 120 |   OBSERVE;
 | 
|---|
 | 121 |   NOTIFY(MatrixChanged);
 | 
|---|
| [83c09a] | 122 |   *M    =_M;
 | 
|---|
 | 123 |   *Minv = M->invert();
 | 
|---|
 | 124 | }
 | 
|---|
| [7579a4b] | 125 | 
 | 
|---|
| [014475] | 126 | Vector Box::translateIn(const Vector &point) const{
 | 
|---|
| [3dcb1f] | 127 |   return (*M) * point;
 | 
|---|
 | 128 | }
 | 
|---|
 | 129 | 
 | 
|---|
| [014475] | 130 | Vector Box::translateOut(const Vector &point) const{
 | 
|---|
| [3dcb1f] | 131 |   return (*Minv) * point;
 | 
|---|
 | 132 | }
 | 
|---|
 | 133 | 
 | 
|---|
| [712886] | 134 | Vector Box::enforceBoundaryConditions(const Vector &point) const{
 | 
|---|
| [f429d7] | 135 |   Vector helper = translateOut(point);
 | 
|---|
 | 136 |   for(int i=NDIM;i--;){
 | 
|---|
| [c72562] | 137 | 
 | 
|---|
 | 138 |     switch(conditions[i]){
 | 
|---|
| [d66cb7] | 139 |     case BoundaryConditions::Wrap:
 | 
|---|
| [c72562] | 140 |       helper.at(i)=fmod(helper.at(i),1);
 | 
|---|
| [d2938f] | 141 |       helper.at(i)+=(helper.at(i)>=0)?0:1;
 | 
|---|
| [c72562] | 142 |       break;
 | 
|---|
| [d66cb7] | 143 |     case BoundaryConditions::Bounce:
 | 
|---|
| [c72562] | 144 |       {
 | 
|---|
 | 145 |         // there probably is a better way to handle this...
 | 
|---|
 | 146 |         // all the fabs and fmod modf probably makes it very slow
 | 
|---|
 | 147 |         double intpart,fracpart;
 | 
|---|
 | 148 |         fracpart = modf(fabs(helper.at(i)),&intpart);
 | 
|---|
 | 149 |         helper.at(i) = fabs(fracpart-fmod(intpart,2));
 | 
|---|
 | 150 |       }
 | 
|---|
 | 151 |       break;
 | 
|---|
| [d66cb7] | 152 |     case BoundaryConditions::Ignore:
 | 
|---|
| [c72562] | 153 |       break;
 | 
|---|
 | 154 |     default:
 | 
|---|
 | 155 |       ASSERT(0,"No default case for this");
 | 
|---|
| [68c923] | 156 |       break;
 | 
|---|
| [c72562] | 157 |     }
 | 
|---|
 | 158 | 
 | 
|---|
| [f429d7] | 159 |   }
 | 
|---|
 | 160 |   return translateIn(helper);
 | 
|---|
 | 161 | }
 | 
|---|
 | 162 | 
 | 
|---|
| [0ff6b5] | 163 | bool Box::isInside(const Vector &point) const
 | 
|---|
 | 164 | {
 | 
|---|
 | 165 |   bool result = true;
 | 
|---|
| [29ac78] | 166 |   Vector tester = translateOut(point);
 | 
|---|
| [0ff6b5] | 167 | 
 | 
|---|
 | 168 |   for(int i=0;i<NDIM;i++)
 | 
|---|
| [f3be87] | 169 |     result = result &&
 | 
|---|
| [d66cb7] | 170 |               ((conditions[i] == BoundaryConditions::Ignore) ||
 | 
|---|
| [f3be87] | 171 |                ((tester[i] >= -MYEPSILON) &&
 | 
|---|
 | 172 |                ((tester[i] - 1.) < MYEPSILON)));
 | 
|---|
| [0ff6b5] | 173 | 
 | 
|---|
 | 174 |   return result;
 | 
|---|
 | 175 | }
 | 
|---|
 | 176 | 
 | 
|---|
| [2a0271] | 177 | bool Box::isValid(const Vector &point) const
 | 
|---|
 | 178 | {
 | 
|---|
 | 179 |   bool result = true;
 | 
|---|
 | 180 |   Vector tester = translateOut(point);
 | 
|---|
 | 181 | 
 | 
|---|
 | 182 |   for(int i=0;i<NDIM;i++)
 | 
|---|
 | 183 |     result = result &&
 | 
|---|
 | 184 |               ((conditions[i] != BoundaryConditions::Ignore) ||
 | 
|---|
 | 185 |                ((tester[i] >= -MYEPSILON) &&
 | 
|---|
 | 186 |                ((tester[i] - 1.) < MYEPSILON)));
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 |   return result;
 | 
|---|
 | 189 | }
 | 
|---|
 | 190 | 
 | 
|---|
| [0ff6b5] | 191 | 
 | 
|---|
| [de29ad6] | 192 | VECTORSET(std::vector) Box::explode(const Vector &point,int n) const{
 | 
|---|
| [16648f] | 193 |   ASSERT(isInside(point),"Exploded point not inside Box");
 | 
|---|
| [025048] | 194 |   internal_explode(point, n);
 | 
|---|
| [de29ad6] | 195 |   VECTORSET(std::vector) res(internal_list);
 | 
|---|
| [025048] | 196 |   return res;
 | 
|---|
 | 197 | }
 | 
|---|
 | 198 | 
 | 
|---|
 | 199 | void Box::internal_explode(const Vector &point,int n) const{
 | 
|---|
 | 200 |   internal_list.clear();
 | 
|---|
| [de29ad6] | 201 |   size_t list_index = 0;
 | 
|---|
| [89e820] | 202 | 
 | 
|---|
| [16648f] | 203 |   Vector translater = translateOut(point);
 | 
|---|
 | 204 |   Vector mask; // contains the ignored coordinates
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 |   // count the number of coordinates we need to do
 | 
|---|
 | 207 |   int dims = 0; // number of dimensions that are not ignored
 | 
|---|
| [de29ad6] | 208 |   coords.clear();
 | 
|---|
 | 209 |   index.clear();
 | 
|---|
| [16648f] | 210 |   for(int i=0;i<NDIM;++i){
 | 
|---|
| [d66cb7] | 211 |     if(conditions[i]==BoundaryConditions::Ignore){
 | 
|---|
| [16648f] | 212 |       mask[i]=translater[i];
 | 
|---|
 | 213 |       continue;
 | 
|---|
 | 214 |     }
 | 
|---|
 | 215 |     coords.push_back(i);
 | 
|---|
 | 216 |     index.push_back(-n);
 | 
|---|
 | 217 |     dims++;
 | 
|---|
 | 218 |   } // there are max vectors in total we need to create
 | 
|---|
| [de29ad6] | 219 |   internal_list.resize(pow(2*n+1, dims));
 | 
|---|
| [16648f] | 220 | 
 | 
|---|
 | 221 |   if(!dims){
 | 
|---|
 | 222 |     // all boundaries are ignored
 | 
|---|
| [de29ad6] | 223 |     internal_list[list_index++] = point;
 | 
|---|
| [025048] | 224 |     return;
 | 
|---|
| [89e820] | 225 |   }
 | 
|---|
 | 226 | 
 | 
|---|
| [d2938f] | 227 |   bool done = false;
 | 
|---|
 | 228 |   while(!done){
 | 
|---|
| [16648f] | 229 |     // create this vector
 | 
|---|
 | 230 |     Vector helper;
 | 
|---|
 | 231 |     for(int i=0;i<dims;++i){
 | 
|---|
 | 232 |       switch(conditions[coords[i]]){
 | 
|---|
| [d66cb7] | 233 |         case BoundaryConditions::Wrap:
 | 
|---|
| [16648f] | 234 |           helper[coords[i]] = index[i]+translater[coords[i]];
 | 
|---|
 | 235 |           break;
 | 
|---|
| [d66cb7] | 236 |         case BoundaryConditions::Bounce:
 | 
|---|
| [16648f] | 237 |           {
 | 
|---|
 | 238 |             // Bouncing the coordinate x produces the series:
 | 
|---|
 | 239 |             // 0 -> x
 | 
|---|
 | 240 |             // 1 -> 2-x
 | 
|---|
 | 241 |             // 2 -> 2+x
 | 
|---|
 | 242 |             // 3 -> 4-x
 | 
|---|
 | 243 |             // 4 -> 4+x
 | 
|---|
 | 244 |             // the first number is the next bigger even number (n+n%2)
 | 
|---|
 | 245 |             // the next number is the value with alternating sign (x-2*(n%2)*x)
 | 
|---|
 | 246 |             // the negative numbers produce the same sequence reversed and shifted
 | 
|---|
| [d2938f] | 247 |             int n = abs(index[i]) + ((index[i]<0)?-1:0);
 | 
|---|
| [16648f] | 248 |             int sign = (index[i]<0)?-1:+1;
 | 
|---|
 | 249 |             int even = n%2;
 | 
|---|
 | 250 |             helper[coords[i]]=n+even+translater[coords[i]]-2*even*translater[coords[i]];
 | 
|---|
 | 251 |             helper[coords[i]]*=sign;
 | 
|---|
 | 252 |           }
 | 
|---|
 | 253 |           break;
 | 
|---|
| [d66cb7] | 254 |         case BoundaryConditions::Ignore:
 | 
|---|
| [16648f] | 255 |           ASSERT(0,"Ignored coordinate handled in generation loop");
 | 
|---|
| [025048] | 256 |           break;
 | 
|---|
| [16648f] | 257 |         default:
 | 
|---|
 | 258 |           ASSERT(0,"No default case for this switch-case");
 | 
|---|
| [025048] | 259 |           break;
 | 
|---|
| [7ac4af] | 260 |       }
 | 
|---|
 | 261 | 
 | 
|---|
| [16648f] | 262 |     }
 | 
|---|
 | 263 |     // add back all ignored coordinates (not handled in above loop)
 | 
|---|
 | 264 |     helper+=mask;
 | 
|---|
| [de29ad6] | 265 |     ASSERT(list_index < internal_list.size(),
 | 
|---|
 | 266 |         "Box::internal_explode() - we have estimated the number of vectors wrong: "
 | 
|---|
 | 267 |         +toString(list_index) +" >= "+toString(internal_list.size())+".");
 | 
|---|
 | 268 |     internal_list[list_index++] = translateIn(helper);
 | 
|---|
| [16648f] | 269 |     // set the new indexes
 | 
|---|
| [d2938f] | 270 |     int pos=0;
 | 
|---|
| [16648f] | 271 |     ++index[pos];
 | 
|---|
| [d2938f] | 272 |     while(index[pos]>n){
 | 
|---|
| [16648f] | 273 |       index[pos++]=-n;
 | 
|---|
| [d2938f] | 274 |       if(pos>=dims) { // it's trying to increase one beyond array... all vectors generated
 | 
|---|
 | 275 |         done = true;
 | 
|---|
 | 276 |         break;
 | 
|---|
| [7ac4af] | 277 |       }
 | 
|---|
| [16648f] | 278 |       ++index[pos];
 | 
|---|
| [7ac4af] | 279 |     }
 | 
|---|
 | 280 |   }
 | 
|---|
 | 281 | }
 | 
|---|
 | 282 | 
 | 
|---|
| [de29ad6] | 283 | VECTORSET(std::vector) Box::explode(const Vector &point) const{
 | 
|---|
| [16648f] | 284 |   ASSERT(isInside(point),"Exploded point not inside Box");
 | 
|---|
 | 285 |   return explode(point,1);
 | 
|---|
 | 286 | }
 | 
|---|
 | 287 | 
 | 
|---|
| [7b9fe0] | 288 | const Vector Box::periodicDistanceVector(const Vector &point1,const Vector &point2) const{
 | 
|---|
| [712886] | 289 |   Vector helper1(enforceBoundaryConditions(point1));
 | 
|---|
 | 290 |   Vector helper2(enforceBoundaryConditions(point2));
 | 
|---|
| [025048] | 291 |   internal_explode(helper1,1);
 | 
|---|
| [7b9fe0] | 292 |   const Vector res = internal_list.minDistance(helper2);
 | 
|---|
| [014475] | 293 |   return res;
 | 
|---|
 | 294 | }
 | 
|---|
 | 295 | 
 | 
|---|
| [7b9fe0] | 296 | double Box::periodicDistanceSquared(const Vector &point1,const Vector &point2) const{
 | 
|---|
 | 297 |   const Vector res = periodicDistanceVector(point1, point2);
 | 
|---|
 | 298 |   return res.NormSquared();
 | 
|---|
 | 299 | }
 | 
|---|
 | 300 | 
 | 
|---|
| [014475] | 301 | double Box::periodicDistance(const Vector &point1,const Vector &point2) const{
 | 
|---|
| [7b9fe0] | 302 |   double res = sqrt(periodicDistanceSquared(point1,point2));
 | 
|---|
| [014475] | 303 |   return res;
 | 
|---|
| [527de2] | 304 | }
 | 
|---|
 | 305 | 
 | 
|---|
| [66fd49] | 306 | double Box::DistanceToBoundary(const Vector &point) const
 | 
|---|
 | 307 | {
 | 
|---|
 | 308 |   std::map<double, Plane> DistanceSet;
 | 
|---|
 | 309 |   std::vector<std::pair<Plane,Plane> > Boundaries = getBoundingPlanes();
 | 
|---|
 | 310 |   for (int i=0;i<NDIM;++i) {
 | 
|---|
 | 311 |     const double tempres1 = Boundaries[i].first.distance(point);
 | 
|---|
 | 312 |     const double tempres2 = Boundaries[i].second.distance(point);
 | 
|---|
 | 313 |     DistanceSet.insert( make_pair(tempres1, Boundaries[i].first) );
 | 
|---|
| [47d041] | 314 |     LOG(1, "Inserting distance " << tempres1 << " and " << tempres2 << ".");
 | 
|---|
| [66fd49] | 315 |     DistanceSet.insert( make_pair(tempres2, Boundaries[i].second) );
 | 
|---|
 | 316 |   }
 | 
|---|
 | 317 |   ASSERT(!DistanceSet.empty(), "Box::DistanceToBoundary() - no distances in map!");
 | 
|---|
 | 318 |   return (DistanceSet.begin())->first;
 | 
|---|
 | 319 | }
 | 
|---|
 | 320 | 
 | 
|---|
| [c538d1] | 321 | Shape Box::getShape() const{
 | 
|---|
 | 322 |   return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M));
 | 
|---|
| [6c438f] | 323 | }
 | 
|---|
 | 324 | 
 | 
|---|
| [c52e08] | 325 | const std::string Box::getConditionNames() const
 | 
|---|
 | 326 | {
 | 
|---|
 | 327 |   std::stringstream outputstream;
 | 
|---|
 | 328 |   outputstream << conditions;
 | 
|---|
 | 329 |   return outputstream.str();
 | 
|---|
 | 330 | }
 | 
|---|
 | 331 | 
 | 
|---|
 | 332 | const BoundaryConditions::Conditions_t & Box::getConditions() const
 | 
|---|
| [66fd49] | 333 | {
 | 
|---|
| [d66cb7] | 334 |   return conditions.get();
 | 
|---|
| [77374e] | 335 | }
 | 
|---|
| [c538d1] | 336 | 
 | 
|---|
| [c52e08] | 337 | const BoundaryConditions::BoundaryCondition_t Box::getCondition(size_t i) const
 | 
|---|
 | 338 | {
 | 
|---|
 | 339 |   return conditions.get(i);
 | 
|---|
 | 340 | }
 | 
|---|
 | 341 | 
 | 
|---|
 | 342 | void Box::setCondition(size_t i, const BoundaryConditions::BoundaryCondition_t _condition)
 | 
|---|
 | 343 | {
 | 
|---|
 | 344 |   OBSERVE;
 | 
|---|
 | 345 |   NOTIFY(BoundaryConditionsChanged);
 | 
|---|
 | 346 |   conditions.set(i, _condition);
 | 
|---|
 | 347 | }
 | 
|---|
 | 348 | 
 | 
|---|
 | 349 | void Box::setConditions(const BoundaryConditions::Conditions_t & _conditions)
 | 
|---|
 | 350 | {
 | 
|---|
 | 351 |   OBSERVE;
 | 
|---|
 | 352 |   NOTIFY(BoundaryConditionsChanged);
 | 
|---|
 | 353 |   conditions.set(_conditions);
 | 
|---|
 | 354 | }
 | 
|---|
 | 355 | 
 | 
|---|
 | 356 | void Box::setConditions(const std::string & _conditions)
 | 
|---|
| [99f4ee] | 357 | {
 | 
|---|
 | 358 |   OBSERVE;
 | 
|---|
 | 359 |   NOTIFY(BoundaryConditionsChanged);
 | 
|---|
| [c52e08] | 360 |   std::stringstream inputstream(_conditions);
 | 
|---|
 | 361 |   inputstream >> conditions;
 | 
|---|
| [77374e] | 362 | }
 | 
|---|
 | 363 | 
 | 
|---|
| [de29ad6] | 364 | const std::vector<std::pair<Plane,Plane> >  Box::getBoundingPlanes() const
 | 
|---|
| [66fd49] | 365 | {
 | 
|---|
| [de29ad6] | 366 |   std::vector<std::pair<Plane,Plane> > res;
 | 
|---|
| [29ac78] | 367 |   for(int i=0;i<NDIM;++i){
 | 
|---|
 | 368 |     Vector base1,base2,base3;
 | 
|---|
 | 369 |     base2[(i+1)%NDIM] = 1.;
 | 
|---|
 | 370 |     base3[(i+2)%NDIM] = 1.;
 | 
|---|
 | 371 |     Plane p1(translateIn(base1),
 | 
|---|
 | 372 |              translateIn(base2),
 | 
|---|
 | 373 |              translateIn(base3));
 | 
|---|
 | 374 |     Vector offset;
 | 
|---|
 | 375 |     offset[i]=1;
 | 
|---|
 | 376 |     Plane p2(translateIn(base1+offset),
 | 
|---|
 | 377 |              translateIn(base2+offset),
 | 
|---|
 | 378 |              translateIn(base3+offset));
 | 
|---|
 | 379 |     res.push_back(make_pair(p1,p2));
 | 
|---|
 | 380 |   }
 | 
|---|
| [66fd49] | 381 |   ASSERT(res.size() == 3, "Box::getBoundingPlanes() - does not have three plane pairs!");
 | 
|---|
| [29ac78] | 382 |   return res;
 | 
|---|
 | 383 | }
 | 
|---|
 | 384 | 
 | 
|---|
| [99f4ee] | 385 | void Box::setCuboid(const Vector &endpoint)
 | 
|---|
 | 386 | {
 | 
|---|
 | 387 |   OBSERVE;
 | 
|---|
 | 388 |   NOTIFY(MatrixChanged);
 | 
|---|
| [e1ab97] | 389 |   ASSERT(endpoint[0]>0 && endpoint[1]>0 && endpoint[2]>0,"Vector does not define a full cuboid");
 | 
|---|
| [9eb7580] | 390 |   M->setIdentity();
 | 
|---|
| [e1ab97] | 391 |   M->diagonal()=endpoint;
 | 
|---|
 | 392 |   Vector &dinv = Minv->diagonal();
 | 
|---|
 | 393 |   for(int i=NDIM;i--;)
 | 
|---|
 | 394 |     dinv[i]=1/endpoint[i];
 | 
|---|
| [c538d1] | 395 | }
 | 
|---|
 | 396 | 
 | 
|---|
| [99f4ee] | 397 | Box &Box::operator=(const Box &src)
 | 
|---|
 | 398 | {
 | 
|---|
| [7579a4b] | 399 |   if(&src!=this){
 | 
|---|
| [99f4ee] | 400 |     OBSERVE;
 | 
|---|
 | 401 |     // new matrix
 | 
|---|
 | 402 |     NOTIFY(MatrixChanged);
 | 
|---|
| [7579a4b] | 403 |     delete M;
 | 
|---|
 | 404 |     delete Minv;
 | 
|---|
| [cca9ef] | 405 |     M    = new RealSpaceMatrix(*src.M);
 | 
|---|
 | 406 |     Minv = new RealSpaceMatrix(*src.Minv);
 | 
|---|
| [99f4ee] | 407 |     // new boundary conditions
 | 
|---|
 | 408 |     NOTIFY(BoundaryConditionsChanged);
 | 
|---|
| [77374e] | 409 |     conditions = src.conditions;
 | 
|---|
| [7579a4b] | 410 |   }
 | 
|---|
 | 411 |   return *this;
 | 
|---|
 | 412 | }
 | 
|---|
 | 413 | 
 | 
|---|
| [99f4ee] | 414 | Box &Box::operator=(const RealSpaceMatrix &mat)
 | 
|---|
 | 415 | {
 | 
|---|
 | 416 |   OBSERVE;
 | 
|---|
 | 417 |   NOTIFY(MatrixChanged);
 | 
|---|
| [7579a4b] | 418 |   setM(mat);
 | 
|---|
 | 419 |   return *this;
 | 
|---|
 | 420 | }
 | 
|---|
| [528b3e] | 421 | 
 | 
|---|
| [de29ad6] | 422 | std::ostream & operator << (std::ostream& ost, const Box &m)
 | 
|---|
| [528b3e] | 423 | {
 | 
|---|
 | 424 |   ost << m.getM();
 | 
|---|
 | 425 |   return ost;
 | 
|---|
 | 426 | }
 | 
|---|