source: src/Box_BoundaryConditions.cpp@ 5f364e

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 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 5f364e was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.3 KB
Line 
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 * Box_BoundaryConditions.cpp
25 *
26 * Created on: Jan 2, 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/tokenizer.hpp>
38#include <boost/algorithm/string/trim.hpp>
39#include <iostream>
40#include <string>
41
42#include "Box_BoundaryConditions.hpp"
43
44#include "CodePatterns/Assert.hpp"
45#include "CodePatterns/Log.hpp"
46#include "CodePatterns/Range.hpp"
47#include "LinearAlgebra/defs.hpp"
48
49/** Constructor of class BCContainer.
50 *
51 * Fills member BCContainer::ConverterBiMap and
52 * BCContainer::ReConverterBiMap.
53 */
54BoundaryConditions::BCContainer::BCContainer()
55{
56 // fill static conversion maps when empty
57 ASSERT(ConverterBiMap.size() == ReConverterBiMap.size(),
58 "BCContainer::BoundaryConditions() - internal string<->enum maps differ in size.");
59 if (ConverterBiMap.empty()) {
60 // hither
61 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Wrap, std::string("Wrap")) );
62 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Bounce, std::string("Bounce")) );
63 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Ignore, std::string("Ignore")) );
64 // thither
65 ReConverterBiMap.insert( std::make_pair(std::string("Wrap"), BoundaryConditions::Wrap) );
66 ReConverterBiMap.insert( std::make_pair(std::string("Bounce"), BoundaryConditions::Bounce) );
67 ReConverterBiMap.insert( std::make_pair(std::string("Ignore"), BoundaryConditions::Ignore) );
68 }
69 ASSERT(ConverterBiMap.size() == (size_t)(BoundaryConditions::MAX_BoundaryCondition_t),
70 "BCContainer::BoundaryConditions() - internal string<->enum map has not the same number of elements "
71 +toString(ConverterBiMap.size())+" as the enum "
72 +toString((size_t)(MAX_BoundaryCondition_t))+".");
73
74 // fill us with default values
75 resize(NDIM, BoundaryConditions::Wrap);
76}
77
78/** Destructor of class BCContainer.
79 *
80 */
81BoundaryConditions::BCContainer::~BCContainer()
82{
83 ConverterBiMap.clear();
84 ReConverterBiMap.clear();
85}
86
87/** Getter for a all boundary conditions.
88 *
89 * @return vector with the boundary conditions
90 */
91const BoundaryConditions::Conditions_t & BoundaryConditions::BCContainer::get() const
92{
93 return (*this);
94}
95
96/** Getter for the boundary condition of a specific axis.
97 *
98 * @param index axis
99 * @return boundary condition of this axis.
100 */
101const BoundaryConditions::BoundaryCondition_t BoundaryConditions::BCContainer::get(size_t index) const
102{
103#ifndef NDEBUG
104 range<size_t> AllowedRange(0, this->size());
105 ASSERT(AllowedRange.isInRange(index),
106 "BCContainer::get() - index "+toString(index)+" out of bounds "
107 +toString(AllowedRange)+".");
108#endif
109 return operator[](index);
110}
111
112/** Setter for all boundary conditions.
113 *
114 * @param _conditions vector with all conditions to set.
115 */
116void BoundaryConditions::BCContainer::set(const BoundaryConditions::Conditions_t &_conditions)
117{
118 ASSERT(_conditions.size() == this->size(),
119 "BCContainer::set() - given vector of conditions and this have unequal size.");
120 for (size_t i = 0; i < _conditions.size(); ++i)
121 (*this)[i] = _conditions[i];
122}
123
124void BoundaryConditions::BCContainer::set(const std::vector< std::string > &_conditions)
125{
126 BoundaryConditions::Conditions_t newconditions;
127 for (std::vector< std::string >::const_iterator iter = _conditions.begin();
128 iter != _conditions.end(); ++iter)
129 newconditions.push_back(getEnum(*iter));
130 set(newconditions);
131}
132
133void BoundaryConditions::BCContainer::set(size_t index, const BoundaryConditions::BoundaryCondition_t _condition)
134{
135#ifndef NDEBUG
136 range<size_t> AllowedRange(0, this->size());
137 ASSERT(AllowedRange.isInRange(index),
138 "BCContainer::set() - index "+toString(index)+" out of bounds "
139 +toString(AllowedRange)+".");
140#endif
141 (*this)[index] = _condition;
142}
143
144void BoundaryConditions::BCContainer::set(size_t index, const std::string &_condition)
145{
146 set(index, getEnum(_condition));
147}
148
149/** Converter from enum to string.
150 *
151 * @param condition enum
152 * @return name of the num
153 */
154const std::string & BoundaryConditions::BCContainer::getName(const BoundaryConditions::BoundaryCondition_t &condition) const
155{
156 ASSERT( ((condition >= (BoundaryConditions::BoundaryCondition_t)0) && (condition < BoundaryConditions::MAX_BoundaryCondition_t)),
157 "BCContainer::getName() - enum "+toString(condition)+" is not a valid enum.");
158 EnumToStringMap::const_iterator iter = ConverterBiMap.find(condition);
159 ASSERT(iter != ConverterBiMap.end(),
160 "BCContainer::getName() - enum "+toString(condition)+" is unknown for any enum name.");
161 return iter->second;
162}
163
164/** Converter from string to enum.
165 *
166 * @param condition name of the condition
167 * @return enum index
168 */
169const BoundaryConditions::BoundaryCondition_t & BoundaryConditions::BCContainer::getEnum(const std::string &condition) const
170{
171 StringToEnumMap::const_iterator iter = ReConverterBiMap.find(condition);
172 ASSERT( iter != ReConverterBiMap.end(),
173 "BCContainer::getEnum() - name "+condition+" is unknown for any enum.");
174 return iter->second;
175}
176
177/** Output routine for class BCContainer to stream.
178 *
179 * @param out stream to print to
180 * @param t instance of BCContainer.
181 * @return stream for concatenation
182 */
183std::ostream &operator<<(std::ostream &out, const BoundaryConditions::BCContainer &t)
184{
185 for (BoundaryConditions::BCContainer::const_iterator iter = t.begin(); iter != t.end(); ++iter) {
186 if (iter != t.begin())
187 out << " ";
188 out << t.getName(*iter);
189 }
190 return out;
191}
192
193/** Input routine for class BCContainer from stream.
194 *
195 * We expect input as comma-separated list with NDIM values.
196 *
197 * @param in input stream
198 * @param t instance of BCContainer to set
199 * @return input stream for concatenation
200 */
201std::istream &operator>>(std::istream &in, BoundaryConditions::BCContainer &t)
202{
203 // read from stream till semicolon or end
204 std::stringbuf sbuf;
205 in.get(sbuf, ';');
206
207 // tokenize
208 typedef boost::tokenizer< boost::char_separator<char> > tokens;
209 BoundaryConditions::Conditions_t conditions;
210 boost::char_separator<char> commasep(", ");
211 // it is imperative to copy the content of the stringbuffer, otherwise we'll
212 // get strange bug where 'Wrap' != 'Wrap' and so on.
213 std::string line(sbuf.str());
214 tokens tok(line, commasep);
215 for(tokens::iterator iter=tok.begin(); iter!=tok.end();++iter) {
216 // remove leading and trailing white space
217 std::string condition(*iter);
218 boost::trim(condition);
219 conditions.push_back(t.getEnum(condition));
220 }
221
222 // set
223 t.set(conditions);
224
225 return in;
226}
Note: See TracBrowser for help on using the repository browser.