1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2016 Frederik Heber. 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 | * detail.cpp
|
---|
25 | *
|
---|
26 | * Created on: Jun 12, 2016
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 |
|
---|
31 | // include config.h
|
---|
32 | #ifdef HAVE_CONFIG_H
|
---|
33 | #include <config.h>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include "CodePatterns/MemDebug.hpp"
|
---|
37 |
|
---|
38 | #include "Fragmentation/Summation/SetValues/detail.hpp"
|
---|
39 |
|
---|
40 | #include "CodePatterns/Assert.hpp"
|
---|
41 |
|
---|
42 | namespace detail {
|
---|
43 |
|
---|
44 | // static member variables
|
---|
45 | const size_t force::FixedSize = 3;
|
---|
46 | const force::vector_t force::nullvector( force::FixedSize, 0.);
|
---|
47 |
|
---|
48 | force::force(const vector_t &_components) :
|
---|
49 | std::vector<double>(_components)
|
---|
50 | {
|
---|
51 | ASSERT( _components.size() == FixedSize,
|
---|
52 | "force::force() - we do not have "+toString(FixedSize)
|
---|
53 | +" in given components "+toString(_components));
|
---|
54 | }
|
---|
55 |
|
---|
56 | force::force(const double &_c1, const double &_c2, const double &_c3) :
|
---|
57 | std::vector<double>(FixedSize, 0.)
|
---|
58 | {
|
---|
59 | operator[](0) = _c1;
|
---|
60 | operator[](1) = _c2;
|
---|
61 | operator[](2) = _c3;
|
---|
62 | }
|
---|
63 |
|
---|
64 | force& force::operator()(const double &_c1, const double &_c2, const double &_c3)
|
---|
65 | {
|
---|
66 | operator[](0) = _c1;
|
---|
67 | operator[](1) = _c2;
|
---|
68 | operator[](2) = _c3;
|
---|
69 |
|
---|
70 | return *this;
|
---|
71 | }
|
---|
72 |
|
---|
73 | force& force::operator()(const vector_t &_components)
|
---|
74 | {
|
---|
75 | ASSERT( _components.size() == FixedSize,
|
---|
76 | "force::operator() - we do not have "+toString(FixedSize)
|
---|
77 | +" in given components "+toString(_components));
|
---|
78 |
|
---|
79 | static_cast<vector_t>(*this) = _components;
|
---|
80 |
|
---|
81 | return *this;
|
---|
82 | }
|
---|
83 |
|
---|
84 | force& force::operator+=(const vector_t &_components)
|
---|
85 | {
|
---|
86 | ASSERT( _components.size() == FixedSize,
|
---|
87 | "force::operator+=() - we do not have "+toString(FixedSize)
|
---|
88 | +" in given components "+toString(_components));
|
---|
89 |
|
---|
90 | operator[](0) += _components[0];
|
---|
91 | operator[](1) += _components[1];
|
---|
92 | operator[](2) += _components[2];
|
---|
93 |
|
---|
94 | return *this;
|
---|
95 | }
|
---|
96 |
|
---|
97 | force& force::operator-=(const vector_t &_components)
|
---|
98 | {
|
---|
99 | ASSERT( _components.size() == FixedSize,
|
---|
100 | "force::operator-=() - we do not have "+toString(FixedSize)
|
---|
101 | +" in given components "+toString(_components));
|
---|
102 |
|
---|
103 | operator[](0) -= _components[0];
|
---|
104 | operator[](1) -= _components[1];
|
---|
105 | operator[](2) -= _components[2];
|
---|
106 |
|
---|
107 | return *this;
|
---|
108 | }
|
---|
109 |
|
---|
110 | void force::superposeOtherIndexedVectors(const force &other, const double prefactor)
|
---|
111 | {
|
---|
112 | ASSERT( other.size() == FixedSize,
|
---|
113 | "force::superposeOtherIndexedVectors() - vector to other instance has size "
|
---|
114 | +toString(other.size())+" different to FixedSize "
|
---|
115 | +toString(FixedSize)+".");
|
---|
116 | vector_t::iterator vectoriter = begin();
|
---|
117 | vector_t::const_iterator othervectoriter = other.begin();
|
---|
118 | for (;vectoriter != end(); ++vectoriter, ++othervectoriter) {
|
---|
119 | *vectoriter += prefactor * (*othervectoriter);
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | }; /* end namespace detail */
|
---|