[5344e4] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[5344e4] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * LinkedCell_View.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Nov 15, 2011
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 36 |
|
---|
| 37 | #include "LinkedCell_View.hpp"
|
---|
| 38 |
|
---|
[9ed706] | 39 | #include <algorithm>
|
---|
| 40 |
|
---|
| 41 | #include "CodePatterns/Assert.hpp"
|
---|
[53d894] | 42 | #include "CodePatterns/Log.hpp"
|
---|
| 43 |
|
---|
[5344e4] | 44 | #include "Atom/TesselPoint.hpp"
|
---|
[cbcda6] | 45 | #include "Box.hpp"
|
---|
[5344e4] | 46 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 47 | #include "LinkedCell.hpp"
|
---|
| 48 | #include "LinkedCell_Model.hpp"
|
---|
[cbdcb1] | 49 | #include "LinkedCell_View_ModelWrapper.hpp"
|
---|
[4459fc] | 50 | #include "tripleIndex.hpp"
|
---|
[5344e4] | 51 |
|
---|
| 52 | using namespace LinkedCell;
|
---|
| 53 |
|
---|
[9ed706] | 54 | // static multimap instance
|
---|
| 55 | LinkedCell_View::ModelInstanceMap LinkedCell_View::RAIIMap;
|
---|
| 56 |
|
---|
| 57 | /** Constructor of class LinkedCell_View.
|
---|
| 58 | *
|
---|
| 59 | * We add ourselves to RAIIMap here.
|
---|
| 60 | */
|
---|
[5344e4] | 61 | LinkedCell_View::LinkedCell_View(const LinkedCell_Model &_LC) :
|
---|
[cbdcb1] | 62 | LC( new LinkedCell_View_ModelWrapper(&_LC) )
|
---|
[9ed706] | 63 | {
|
---|
| 64 | // add us to RAII counting map
|
---|
| 65 | #ifndef NDEBUG
|
---|
| 66 | std::pair< ModelInstanceMap::iterator, bool> inserter =
|
---|
| 67 | #endif
|
---|
| 68 | RAIIMap.insert( this );
|
---|
| 69 | ASSERT( inserter.second,
|
---|
| 70 | "LinkedCell_View::LinkedCell_View() - we "+toString(this)+" are already present in RAIIMap.");
|
---|
[b75386] | 71 | LOG(3, "INFO: Placing instance "+toString(this)+" into RAIIMap.");
|
---|
[9ed706] | 72 | }
|
---|
[5344e4] | 73 |
|
---|
[9ed706] | 74 | /** Copy Constructor of class LinkedCell_View.
|
---|
| 75 | *
|
---|
| 76 | * We add ourselves to RAIIMap here.
|
---|
| 77 | */
|
---|
| 78 | LinkedCell_View::LinkedCell_View(const LinkedCell_View &_view) :
|
---|
[cbdcb1] | 79 | LC( new LinkedCell_View_ModelWrapper(_view.LC->getModel()) )
|
---|
[5344e4] | 80 | {
|
---|
[9ed706] | 81 | if (this != &_view) {
|
---|
| 82 | // add us to RAII counting map
|
---|
| 83 | #ifndef NDEBUG
|
---|
| 84 | std::pair< ModelInstanceMap::iterator, bool> inserter =
|
---|
| 85 | #endif
|
---|
| 86 | RAIIMap.insert( this );
|
---|
| 87 | ASSERT( inserter.second,
|
---|
| 88 | "LinkedCell_View::LinkedCell_View(&view) - we "+toString(this)+" are already present in RAIIMap.");
|
---|
[b75386] | 89 | LOG(3, "INFO: Placing instance "+toString(this)+" copied from "+toString(&_view)+" into RAIIMap.");
|
---|
[9ed706] | 90 | }
|
---|
[5344e4] | 91 | }
|
---|
| 92 |
|
---|
[9ed706] | 93 | /** Destructor of class LinkedCell_View.
|
---|
| 94 | *
|
---|
| 95 | * We remove ourselves from RAIIMap here.
|
---|
| 96 | */
|
---|
| 97 | LinkedCell_View::~LinkedCell_View()
|
---|
| 98 | {
|
---|
| 99 | ModelInstanceMap::iterator iter = RAIIMap.find(this);
|
---|
| 100 | ASSERT( iter != RAIIMap.end(),
|
---|
| 101 | "LinkedCell_View::~LinkedCell_View() - there is no instance "
|
---|
| 102 | +toString(this)+" in RAIIMap.");
|
---|
| 103 | if (iter != RAIIMap.end()) {
|
---|
| 104 | RAIIMap.erase(iter);
|
---|
[b75386] | 105 | LOG(3, "INFO: Removing instance "+toString(this)+" from RAIIMap.");
|
---|
[9ed706] | 106 | } else {
|
---|
| 107 | ELOG(1, "Failed to remove instance "+toString(this)+" from RAIIMap.");
|
---|
| 108 | }
|
---|
[cbdcb1] | 109 | delete LC;
|
---|
[9ed706] | 110 | }
|
---|
[53d894] | 111 |
|
---|
[5344e4] | 112 | /** Return at least as many points as are inside a sphere of \a radius around \a center.
|
---|
| 113 | *
|
---|
| 114 | * \sa LinkedCell_View::getPointsInsideSphere()
|
---|
| 115 | *
|
---|
| 116 | * @param radius radius of sphere
|
---|
| 117 | * @param center center of sphere
|
---|
| 118 | * @return a list containing at least all points inside described sphere
|
---|
| 119 | */
|
---|
| 120 | LinkedList LinkedCell_View::getAllNeighbors(const double radius, const Vector ¢er) const
|
---|
| 121 | {
|
---|
| 122 | LinkedList TesselList; // we do not need a set, as nodes are uniquely associated to a cell.
|
---|
| 123 |
|
---|
[cbdcb1] | 124 | const LinkedCell_Model * const LCmodel = LC->getModel(); // get quick ref to model
|
---|
[5344e4] | 125 | // get relative bounds
|
---|
[cbdcb1] | 126 | const tripleIndex step = LCmodel->getStep(radius);
|
---|
| 127 | const tripleIndex index = LCmodel->getIndexToVector(center);
|
---|
[5344e4] | 128 | LinkedCell_Model::LinkedCellNeighborhoodBounds neighbors =
|
---|
[cbdcb1] | 129 | LCmodel->getNeighborhoodBounds(index, step);
|
---|
[5344e4] | 130 |
|
---|
| 131 | tripleIndex n;
|
---|
[53d894] | 132 | for (n[0] = 0; n[0] < neighbors.second[0]; n[0]++)
|
---|
| 133 | for (n[1] = 0; n[1] < neighbors.second[1]; n[1]++)
|
---|
| 134 | for (n[2] = 0; n[2] < neighbors.second[2]; n[2]++) {
|
---|
| 135 | tripleIndex absolute_n = neighbors.first + n;
|
---|
[cbdcb1] | 136 | if (!LCmodel->checkArrayBounds(absolute_n))
|
---|
| 137 | LCmodel->applyBoundaryConditions(absolute_n);
|
---|
| 138 | const LinkedCell &List = LCmodel->getCell(absolute_n);
|
---|
[b75386] | 139 | LOG(3, "INFO: Current cell is " << neighbors.first << " plus " << n << ", yielding " << absolute_n << ".");
|
---|
[5344e4] | 140 | for (LinkedCell::const_iterator Runner = List.begin(); Runner != List.end(); Runner++)
|
---|
[fbbcde] | 141 | TesselList.insert(*Runner);
|
---|
[5344e4] | 142 | }
|
---|
| 143 | return TesselList;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | LinkedList LinkedCell_View::getPointsInsideSphere(const double radius, const Vector ¢er) const
|
---|
| 147 | {
|
---|
| 148 | // get overly much points
|
---|
| 149 | const LinkedList TesselList = getAllNeighbors(radius, center);
|
---|
| 150 | LinkedList ReturnList;
|
---|
| 151 |
|
---|
| 152 | // remove all unnecessary ones
|
---|
[cbcda6] | 153 | const Box& domain = LC->getModel()->getDomain();
|
---|
[5344e4] | 154 | for (LinkedList::const_iterator iter = TesselList.begin(); iter != TesselList.end(); ++iter) {
|
---|
[cbcda6] | 155 | if (domain.periodicDistanceSquared(center, (*iter)->getPosition()) <= radius*radius)
|
---|
[fbbcde] | 156 | ReturnList.insert(*iter);
|
---|
[5344e4] | 157 | }
|
---|
| 158 |
|
---|
| 159 | return ReturnList;
|
---|
| 160 | }
|
---|