| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| 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/>. | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | /* | 
|---|
| 24 | * CubeMesh.cpp | 
|---|
| 25 | * | 
|---|
| 26 | *  Created on: Jan 20, 2012 | 
|---|
| 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 <boost/lambda/lambda.hpp> | 
|---|
| 38 | #include <cmath> | 
|---|
| 39 |  | 
|---|
| 40 | #include "CodePatterns/Log.hpp" | 
|---|
| 41 | #include "CubeMesh.hpp" | 
|---|
| 42 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 43 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 44 |  | 
|---|
| 45 | /** Constructor for class CubeMesh. | 
|---|
| 46 | * | 
|---|
| 47 | * Here, we generate nodes homogeneously distributed over a cuboid. | 
|---|
| 48 | * | 
|---|
| 49 | * \a offset shifts the coordinates, e.g. if counts = 2, we would set nodes at | 
|---|
| 50 | * 0 and 0.5 with offset = 0 and 0.4999... and 0.9999.. with offset = 0.999... | 
|---|
| 51 | * | 
|---|
| 52 | * @param counts number of points per axis | 
|---|
| 53 | * @param offset offset Vector (coordinates in [0,1)) | 
|---|
| 54 | * @param M matrix to transform the default cuboid from (0,0,0) to (1,1,1). | 
|---|
| 55 | */ | 
|---|
| 56 | CubeMesh::CubeMesh(const Vector &counts, const Vector &offset, const RealSpaceMatrix &M) | 
|---|
| 57 | { | 
|---|
| 58 | #ifndef NDEBUG | 
|---|
| 59 | for (size_t i=0;i<NDIM;++i) { | 
|---|
| 60 | ASSERT((offset[i] >= 0.) && (offset[i] < 1.), | 
|---|
| 61 | "CubeMesh::CubeMesh() - offset coordinates must be in [0,1) but offset[" | 
|---|
| 62 | +toString(i)+"] is "+toString(offset[i])+"."); | 
|---|
| 63 | ASSERT(counts[i] == (int)counts[i], | 
|---|
| 64 | "CubeMesh::CubeMesh() - counts["+toString(i)+"] must be integer: != "+toString(counts[i])+"."); | 
|---|
| 65 | } | 
|---|
| 66 | #endif | 
|---|
| 67 |  | 
|---|
| 68 | std::vector< unsigned int> size_counts; | 
|---|
| 69 | for (size_t i=0;i<NDIM;++i) { | 
|---|
| 70 | size_counts.push_back( (int)counts[i] ); | 
|---|
| 71 | } | 
|---|
| 72 | init(size_counts, offset, M); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | /** Constructor for class CubeMesh. | 
|---|
| 76 | * | 
|---|
| 77 | * Here, we generate nodes homogeneously distributed over a cuboid. | 
|---|
| 78 | * | 
|---|
| 79 | * \a offset shifts the coordinates, e.g. if counts = 2, we would set nodes at | 
|---|
| 80 | * 0 and 0.5 with offset = 0 and 0.4999... and 0.9999.. with offset = 0.999... | 
|---|
| 81 | * | 
|---|
| 82 | * @param counts number of points per axis | 
|---|
| 83 | * @param offset offset Vector (coordinates in [0,1)) | 
|---|
| 84 | * @param M matrix to transform the default cuboid from (0,0,0) to (1,1,1). | 
|---|
| 85 | */ | 
|---|
| 86 | CubeMesh::CubeMesh(const std::vector< unsigned int > &counts, const Vector &offset, const RealSpaceMatrix &M) | 
|---|
| 87 | { | 
|---|
| 88 | ASSERT(counts.size() == 3, | 
|---|
| 89 | "CubeMesh::CubeMesh() - counts does not have three but " | 
|---|
| 90 | +toString(counts.size())+" entries."); | 
|---|
| 91 |  | 
|---|
| 92 | init(counts, offset, M); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | void CubeMesh::init(const std::vector< unsigned int > &counts, const Vector &offset, const RealSpaceMatrix &M) | 
|---|
| 96 | { | 
|---|
| 97 | RealSpaceMatrix partition; | 
|---|
| 98 |  | 
|---|
| 99 | partition.setZero(); | 
|---|
| 100 | for(int i=0;i<NDIM;i++) | 
|---|
| 101 | partition.at(i,i) =  1./(double)counts[i]; | 
|---|
| 102 | LOG(1, "INFO: partition is " << partition << "."); | 
|---|
| 103 |  | 
|---|
| 104 | // go over [0,1]^3 filler grid | 
|---|
| 105 | size_t n[NDIM]; | 
|---|
| 106 | for (n[0] = 0; n[0] < counts[0]; n[0]++) | 
|---|
| 107 | for (n[1] = 0; n[1] < counts[1]; n[1]++) | 
|---|
| 108 | for (n[2] = 0; n[2] < counts[2]; n[2]++) { | 
|---|
| 109 | const Vector CurrentPosition((double)n[0], (double)n[1], (double)n[2]); | 
|---|
| 110 | nodes.push_back(M * partition * (CurrentPosition + offset)); | 
|---|
| 111 | } | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | /** Destructor for class CubeMesh. | 
|---|
| 115 | * | 
|---|
| 116 | */ | 
|---|
| 117 | CubeMesh::~CubeMesh() | 
|---|
| 118 | {} | 
|---|