source: src/Box_BoundaryConditions.cpp@ 8ea3e7

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 8ea3e7 was c52e08, checked in by Frederik Heber <heber@…>, 13 years ago

Added new action SetBoundaryConditionsAction.

  • Property mode set to 100644
File size: 6.2 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(size_t index, const BoundaryConditions::BoundaryCondition_t _condition)
110{
111#ifndef NDEBUG
112 range<size_t> AllowedRange(0, this->size());
113 ASSERT(AllowedRange.isInRange(index),
114 "BCContainer::set() - index "+toString(index)+" out of bounds "
115 +toString(AllowedRange)+".");
116#endif
117 (*this)[index] = _condition;
118}
119
120/** Converter from enum to string.
121 *
122 * @param condition enum
123 * @return name of the num
124 */
125const std::string & BoundaryConditions::BCContainer::getName(const BoundaryConditions::BoundaryCondition_t &condition) const
126{
127 ASSERT( ((condition >= (BoundaryConditions::BoundaryCondition_t)0) && (condition < BoundaryConditions::MAX_BoundaryCondition_t)),
128 "BCContainer::getName() - enum "+toString(condition)+" is not a valid enum.");
129 EnumToStringMap::const_iterator iter = ConverterBiMap.find(condition);
130 ASSERT(iter != ConverterBiMap.end(),
131 "BCContainer::getName() - enum "+toString(condition)+" is unknown for any enum name.");
132 return iter->second;
133}
134
135/** Converter from string to enum.
136 *
137 * @param condition name of the condition
138 * @return enum index
139 */
140const BoundaryConditions::BoundaryCondition_t & BoundaryConditions::BCContainer::getEnum(const std::string &condition) const
141{
142 StringToEnumMap::const_iterator iter = ReConverterBiMap.find(condition);
143 ASSERT( iter != ReConverterBiMap.end(),
144 "BCContainer::getEnum() - name "+condition+" is unknown for any enum.");
145 return iter->second;
146}
147
148/** Output routine for class BCContainer to stream.
149 *
150 * @param out stream to print to
151 * @param t instance of BCContainer.
152 * @return stream for concatenation
153 */
154std::ostream &operator<<(std::ostream &out, const BoundaryConditions::BCContainer &t)
155{
156 for (BoundaryConditions::BCContainer::const_iterator iter = t.begin(); iter != t.end(); ++iter) {
157 if (iter != t.begin())
158 out << ", ";
159 out << t.getName(*iter);
160 }
161 return out;
162}
163
164/** Input routine for class BCContainer from stream.
165 *
166 * We expect input as comma-separated list with NDIM values.
167 *
168 * @param in input stream
169 * @param t instance of BCContainer to set
170 * @return input stream for concatenation
171 */
172std::istream &operator>>(std::istream &in, BoundaryConditions::BCContainer &t)
173{
174 // read from stream till semicolon or end
175 std::stringbuf sbuf;
176 in.get(sbuf, ';');
177
178 // tokenize
179 typedef boost::tokenizer< boost::char_separator<char> > tokens;
180 BoundaryConditions::Conditions_t conditions;
181 boost::char_separator<char> commasep(",");
182 // it is imperative to copy the content of the stringbuffer, otherwise we'll
183 // get strange bug where 'Wrap' != 'Wrap' and so on.
184 std::string line(sbuf.str());
185 tokens tok(line, commasep);
186 for(tokens::iterator iter=tok.begin(); iter!=tok.end();++iter) {
187 // remove leading and trailing white space
188 std::string condition(*iter);
189 boost::trim(condition);
190 conditions.push_back(t.getEnum(condition));
191 }
192
193 // set
194 t.set(conditions);
195
196 return in;
197}
Note: See TracBrowser for help on using the repository browser.