source: src/Box_BoundaryConditions.cpp@ 361805

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 361805 was 97f9b9, checked in by Frederik Heber <heber@…>, 13 years ago

SetBoundaryConditionsAction requires vector<string> instead of string for parameter newconditions.

  • we also added new setters to Box and Box_BoundaryConditions to enable it.
  • TESTFIX: Boundary conditions now have to be supplied as e.g. Wrap Wrap Wrap and not "Wrap,Wrap,Wrap" on the command line.
  • stream operator for Box_BoundaryConditions now also splits by "," and by " ", enhanced unit test function inputTest() on this.
  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Box_BoundaryConditions.cpp
10 *
11 * Created on: Jan 2, 2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <boost/tokenizer.hpp>
23#include <boost/algorithm/string/trim.hpp>
24#include <iostream>
25#include <string>
26
27#include "Box_BoundaryConditions.hpp"
28
29#include "CodePatterns/Assert.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/Range.hpp"
32#include "LinearAlgebra/defs.hpp"
33
34/** Constructor of class BCContainer.
35 *
36 * Fills member BCContainer::ConverterBiMap and
37 * BCContainer::ReConverterBiMap.
38 */
39BoundaryConditions::BCContainer::BCContainer()
40{
41 // fill static conversion maps when empty
42 ASSERT(ConverterBiMap.size() == ReConverterBiMap.size(),
43 "BCContainer::BoundaryConditions() - internal string<->enum maps differ in size.");
44 if (ConverterBiMap.empty()) {
45 // hither
46 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Wrap, std::string("Wrap")) );
47 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Bounce, std::string("Bounce")) );
48 ConverterBiMap.insert( std::make_pair(BoundaryConditions::Ignore, std::string("Ignore")) );
49 // thither
50 ReConverterBiMap.insert( std::make_pair(std::string("Wrap"), BoundaryConditions::Wrap) );
51 ReConverterBiMap.insert( std::make_pair(std::string("Bounce"), BoundaryConditions::Bounce) );
52 ReConverterBiMap.insert( std::make_pair(std::string("Ignore"), BoundaryConditions::Ignore) );
53 }
54 ASSERT(ConverterBiMap.size() == (size_t)(BoundaryConditions::MAX_BoundaryCondition_t),
55 "BCContainer::BoundaryConditions() - internal string<->enum map has not the same number of elements "
56 +toString(ConverterBiMap.size())+" as the enum "
57 +toString((size_t)(MAX_BoundaryCondition_t))+".");
58
59 // fill us with default values
60 resize(NDIM, BoundaryConditions::Wrap);
61}
62
63/** Destructor of class BCContainer.
64 *
65 */
66BoundaryConditions::BCContainer::~BCContainer()
67{
68 ConverterBiMap.clear();
69 ReConverterBiMap.clear();
70}
71
72/** Getter for a all boundary conditions.
73 *
74 * @return vector with the boundary conditions
75 */
76const BoundaryConditions::Conditions_t & BoundaryConditions::BCContainer::get() const
77{
78 return (*this);
79}
80
81/** Getter for the boundary condition of a specific axis.
82 *
83 * @param index axis
84 * @return boundary condition of this axis.
85 */
86const BoundaryConditions::BoundaryCondition_t BoundaryConditions::BCContainer::get(size_t index) const
87{
88#ifndef NDEBUG
89 range<size_t> AllowedRange(0, this->size());
90 ASSERT(AllowedRange.isInRange(index),
91 "BCContainer::get() - index "+toString(index)+" out of bounds "
92 +toString(AllowedRange)+".");
93#endif
94 return operator[](index);
95}
96
97/** Setter for all boundary conditions.
98 *
99 * @param _conditions vector with all conditions to set.
100 */
101void BoundaryConditions::BCContainer::set(const BoundaryConditions::Conditions_t &_conditions)
102{
103 ASSERT(_conditions.size() == this->size(),
104 "BCContainer::set() - given vector of conditions and this have unequal size.");
105 for (size_t i = 0; i < _conditions.size(); ++i)
106 (*this)[i] = _conditions[i];
107}
108
109void BoundaryConditions::BCContainer::set(const std::vector< std::string > &_conditions)
110{
111 BoundaryConditions::Conditions_t newconditions;
112 for (std::vector< std::string >::const_iterator iter = _conditions.begin();
113 iter != _conditions.end(); ++iter)
114 newconditions.push_back(getEnum(*iter));
115 set(newconditions);
116}
117
118void BoundaryConditions::BCContainer::set(size_t index, const BoundaryConditions::BoundaryCondition_t _condition)
119{
120#ifndef NDEBUG
121 range<size_t> AllowedRange(0, this->size());
122 ASSERT(AllowedRange.isInRange(index),
123 "BCContainer::set() - index "+toString(index)+" out of bounds "
124 +toString(AllowedRange)+".");
125#endif
126 (*this)[index] = _condition;
127}
128
129void BoundaryConditions::BCContainer::set(size_t index, const std::string &_condition)
130{
131 set(index, getEnum(_condition));
132}
133
134/** Converter from enum to string.
135 *
136 * @param condition enum
137 * @return name of the num
138 */
139const std::string & BoundaryConditions::BCContainer::getName(const BoundaryConditions::BoundaryCondition_t &condition) const
140{
141 ASSERT( ((condition >= (BoundaryConditions::BoundaryCondition_t)0) && (condition < BoundaryConditions::MAX_BoundaryCondition_t)),
142 "BCContainer::getName() - enum "+toString(condition)+" is not a valid enum.");
143 EnumToStringMap::const_iterator iter = ConverterBiMap.find(condition);
144 ASSERT(iter != ConverterBiMap.end(),
145 "BCContainer::getName() - enum "+toString(condition)+" is unknown for any enum name.");
146 return iter->second;
147}
148
149/** Converter from string to enum.
150 *
151 * @param condition name of the condition
152 * @return enum index
153 */
154const BoundaryConditions::BoundaryCondition_t & BoundaryConditions::BCContainer::getEnum(const std::string &condition) const
155{
156 StringToEnumMap::const_iterator iter = ReConverterBiMap.find(condition);
157 ASSERT( iter != ReConverterBiMap.end(),
158 "BCContainer::getEnum() - name "+condition+" is unknown for any enum.");
159 return iter->second;
160}
161
162/** Output routine for class BCContainer to stream.
163 *
164 * @param out stream to print to
165 * @param t instance of BCContainer.
166 * @return stream for concatenation
167 */
168std::ostream &operator<<(std::ostream &out, const BoundaryConditions::BCContainer &t)
169{
170 for (BoundaryConditions::BCContainer::const_iterator iter = t.begin(); iter != t.end(); ++iter) {
171 if (iter != t.begin())
172 out << " ";
173 out << t.getName(*iter);
174 }
175 return out;
176}
177
178/** Input routine for class BCContainer from stream.
179 *
180 * We expect input as comma-separated list with NDIM values.
181 *
182 * @param in input stream
183 * @param t instance of BCContainer to set
184 * @return input stream for concatenation
185 */
186std::istream &operator>>(std::istream &in, BoundaryConditions::BCContainer &t)
187{
188 // read from stream till semicolon or end
189 std::stringbuf sbuf;
190 in.get(sbuf, ';');
191
192 // tokenize
193 typedef boost::tokenizer< boost::char_separator<char> > tokens;
194 BoundaryConditions::Conditions_t conditions;
195 boost::char_separator<char> commasep(", ");
196 // it is imperative to copy the content of the stringbuffer, otherwise we'll
197 // get strange bug where 'Wrap' != 'Wrap' and so on.
198 std::string line(sbuf.str());
199 tokens tok(line, commasep);
200 for(tokens::iterator iter=tok.begin(); iter!=tok.end();++iter) {
201 // remove leading and trailing white space
202 std::string condition(*iter);
203 boost::trim(condition);
204 conditions.push_back(t.getEnum(condition));
205 }
206
207 // set
208 t.set(conditions);
209
210 return in;
211}
Note: See TracBrowser for help on using the repository browser.