Changes in / [c695c9:5f612ee]
- Files:
-
- 113 added
- 68 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
rc695c9 r5f612ee 3 3 4 4 EXTRA_DIST = autogen.sh 5 6 .PHONY: doc 7 doc: 8 cd doc && make doxygen-docs -
configure.ac
rc695c9 r5f612ee 27 27 28 28 # Boost libraries 29 #AX_BOOST_BASE([1.33.1])29 AX_BOOST_BASE([1.33.1]) 30 30 #AX_BOOST_PROGRAM_OPTIONS 31 31 #AX_BOOST_FOREACH 32 32 #AX_BOOST_FILESYSTEM 33 #AX_BOOST_THREAD33 AX_BOOST_THREAD 34 34 #AX_BOOST_PROGRAM_OPTIONS 35 35 #AX_BOOST_SERIALIZATION … … 66 66 fi 67 67 68 # add replacement/saturation hydrogen or not 69 AC_ARG_ENABLE([ecut],AS_HELP_STRING([--enable-ecut],[Use ECut TestRunnerClient (default is yes)]), 70 [enable_ecut=$enableval], [enable_ecut=yes]) 71 if test x"$enable_ecut" = xyes; then 72 AC_DEFINE(HAVE_ECUT,1, ["Use ECut TestRunnerClient instead of our own."]) 73 AC_SUBST(HAVE_ECUT) 74 fi 75 68 76 # Check for "extern inline", using a modified version 69 77 # of the test for AC_C_INLINE from acspecific.mt -
doc/Doxyfile
rc695c9 r5f612ee 114 114 EXCLUDE = 115 115 EXCLUDE_SYMLINKS = NO 116 EXCLUDE_PATTERNS = 116 EXCLUDE_PATTERNS = */unittests/* \ 117 */test/* 117 118 EXAMPLE_PATH = 118 119 EXAMPLE_PATTERNS = * … … 125 126 # configuration options related to source browsing 126 127 #--------------------------------------------------------------------------- 127 SOURCE_BROWSER = NO128 INLINE_SOURCES = NO129 STRIP_CODE_COMMENTS = YES128 SOURCE_BROWSER = YES 129 INLINE_SOURCES = YES 130 STRIP_CODE_COMMENTS = NO 130 131 REFERENCED_BY_RELATION = NO 131 132 REFERENCES_RELATION = NO -
src/Makefile.am
rc695c9 r5f612ee 8 8 ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp 9 9 10 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp triangleintersectionlist.cpp vector.cpp verbose.cpp World.cpp 11 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp triangleintersectionlist.cpp vector.hpp verbose.hpp World.hpp 10 ACTIONSSOURCE = Actions/Action.cpp \ 11 Actions/ActionHistory.cpp \ 12 Actions/ActionRegistry.cpp \ 13 Actions/ActionSequence.cpp \ 14 Actions/ErrorAction.cpp \ 15 Actions/MakroAction.cpp \ 16 Actions/ManipulateAtomsProcess.cpp \ 17 Actions/MethodAction.cpp \ 18 Actions/Process.cpp \ 19 Actions/small_actions.cpp 20 21 22 ACTIONSHEADER = Actions/Action.hpp \ 23 Actions/ActionHistory.hpp \ 24 Actions/ActionRegistry.hpp \ 25 Actions/ActionSequence.hpp \ 26 Actions/Calculation.hpp \ 27 Actions/Calculation_impl.hpp \ 28 Actions/ErrorAction.hpp \ 29 Actions/MakroAction.hpp \ 30 Actions/ManipulateAtomsProcess.hpp \ 31 Actions/MethodAction.hpp \ 32 Actions/Process.hpp \ 33 Actions/small_actions.hpp 34 35 36 37 PATTERNSOURCE = Patterns/Observer.cpp 38 PATTERNHEADER = Patterns/Cacheable.hpp \ 39 Patterns/Observer.hpp \ 40 Patterns/Singleton.hpp 41 42 VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp 43 VIEWHEADER = Views/View.hpp Views/StringView.hpp Views/MethodStringView.hpp Views/StreamStringView.hpp 44 45 MENUSOURCE = Menu/Menu.cpp Menu/TextMenu.cpp Menu/MenuItem.cpp Menu/SubMenuItem.cpp Menu/ActionMenuItem.cpp Menu/SeperatorItem.cpp Menu/DisplayMenuItem.cpp 46 MENUHEADER = Menu/Menu.hpp Menu/TextMenu.hpp Menu/MenuItem.hpp Menu/SubMenuItem.hpp Menu/ActionMenuItem.hpp Menu/SeperatorItem.hpp Menu/DisplayMenuItem.hpp 47 48 UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/UIFactory.cpp UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/TextStatusIndicator.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp 49 UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/UIFactory.hpp UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/TextStatusIndicator.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp 50 51 # all these files are only used for legacy reasons while the transition is in progress 52 # they are only needed to keep the program usable at any point of the transition and will be 53 # deleted once everything is fully refactored 54 LEGACYSOURCE = Legacy/oldmenu.cpp 55 LEGACYHEADER = Legacy/oldmenu.hpp 56 57 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp \ 58 Descriptors/AtomIdDescriptor.cpp \ 59 Descriptors/AtomTypeDescriptor.cpp \ 60 Descriptors/MoleculeDescriptor.cpp \ 61 Descriptors/MoleculeIdDescriptor.cpp 62 63 64 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \ 65 Descriptors/AtomIdDescriptor.hpp \ 66 Descriptors/AtomTypeDescriptor.hpp \ 67 Descriptors/MoleculeDescriptor.hpp \ 68 Descriptors/MoleculeIdDescriptor.hpp 69 70 71 72 SOURCE = ${ANALYSISSOURCE} \ 73 ${ATOMSOURCE} \ 74 ${PATTERNSOURCE} \ 75 ${UISOURCE} \ 76 ${DESCRIPTORSOURCE} \ 77 ${LEGACYSOURCE} \ 78 bond.cpp \ 79 bondgraph.cpp \ 80 boundary.cpp \ 81 config.cpp \ 82 element.cpp \ 83 ellipsoid.cpp \ 84 errorlogger.cpp \ 85 graph.cpp \ 86 helpers.cpp \ 87 Helpers/Assert.cpp \ 88 info.cpp \ 89 leastsquaremin.cpp \ 90 linkedcell.cpp \ 91 lists.cpp \ 92 log.cpp \ 93 logger.cpp \ 94 memoryusageobserver.cpp \ 95 moleculelist.cpp \ 96 molecule.cpp \ 97 molecule_dynamics.cpp \ 98 molecule_fragmentation.cpp \ 99 molecule_geometry.cpp \ 100 molecule_graph.cpp \ 101 molecule_pointcloud.cpp \ 102 parser.cpp \ 103 periodentafel.cpp \ 104 tesselation.cpp \ 105 tesselationhelpers.cpp \ 106 triangleintersectionlist.cpp \ 107 vector.cpp \ 108 verbose.cpp \ 109 World.cpp 110 111 HEADER = \ 112 ${ANALYSISHEADER} \ 113 ${ATOMHEADER} \ 114 ${PATTERNHEADER} \ 115 ${UIHEADER} \ 116 ${DESCRIPTORHEADER} \ 117 ${LEGACYHEADER} \ 118 bond.hpp \ 119 bondgraph.hpp \ 120 boundary.hpp \ 121 config.hpp \ 122 defs.hpp \ 123 element.hpp \ 124 ellipsoid.hpp \ 125 errorlogger.hpp \ 126 graph.hpp \ 127 helpers.hpp \ 128 info.hpp \ 129 leastsquaremin.hpp \ 130 linkedcell.hpp \ 131 lists.hpp \ 132 log.hpp \ 133 logger.hpp \ 134 memoryallocator.hpp \ 135 memoryusageobserver.hpp \ 136 molecule.hpp \ 137 molecule_template.hpp \ 138 parser.hpp \ 139 periodentafel.hpp \ 140 stackclass.hpp \ 141 tesselation.hpp \ 142 tesselationhelpers.hpp \ 143 triangleintersectionlist.hpp \ 144 vector.hpp \ 145 verbose.hpp \ 146 World.hpp 12 147 13 148 BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB) … … 20 155 libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER} 21 156 molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db 22 molecuilder_LDFLAGS = $(BOOST_L IB)157 molecuilder_LDFLAGS = $(BOOST_LDFLAGS) 23 158 molecuilder_SOURCES = builder.cpp 24 molecuilder_LDADD = libmolecuilder.a libgslwrapper.a 159 molecuilder_LDADD = libmolecuilder.a libgslwrapper.a $(BOOST_LIB) ${BOOST_THREAD_LIB} 25 160 joiner_SOURCES = joiner.cpp datacreator.cpp parser.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp 26 joiner_LDADD = libmolecuilder.a 161 joiner_LDADD = libmolecuilder.a $(BOOST_LIB) ${BOOST_THREAD_LIB} 27 162 analyzer_SOURCES = analyzer.cpp datacreator.cpp parser.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp 28 analyzer_LDADD = libmolecuilder.a 163 analyzer_LDADD = libmolecuilder.a $(BOOST_LIB) ${BOOST_THREAD_LIB} 29 164 30 165 #EXTRA_DIST = ${molecuilder_DATA} -
src/World.cpp
rc695c9 r5f612ee 1 1 /* 2 * world.cpp2 * World.cpp 3 3 * 4 * Created on: Mar3, 20104 * Created on: Feb 3, 2010 5 5 * Author: crueger 6 6 */ 7 7 8 #include <string.h>9 10 #include "defs.hpp"11 8 #include "World.hpp" 12 9 13 double *World::cell_size = 0; 14 char *World::DefaultName = 0; 15 16 /** Constructor of World. 17 * 18 */ 19 World::World() 10 #include "atom.hpp" 11 #include "molecule.hpp" 12 #include "periodentafel.hpp" 13 #include "Descriptors/AtomDescriptor.hpp" 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Descriptors/MoleculeDescriptor.hpp" 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 17 #include "Descriptors/SelectiveIterator_impl.hpp" 18 #include "Actions/ManipulateAtomsProcess.hpp" 19 20 #include "Patterns/Singleton_impl.hpp" 21 22 using namespace std; 23 24 /******************************* getter and setter ************************/ 25 periodentafel *&World::getPeriode(){ 26 return periode; 27 } 28 29 // Atoms 30 31 atom* World::getAtom(AtomDescriptor descriptor){ 32 return descriptor.find(); 33 } 34 35 vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){ 36 return descriptor.findAll(); 37 } 38 39 vector<atom*> World::getAllAtoms(){ 40 return getAllAtoms(AllAtoms()); 41 } 42 43 int World::numAtoms(){ 44 return atoms.size(); 45 } 46 47 // Molecules 48 49 molecule *World::getMolecule(MoleculeDescriptor descriptor){ 50 return descriptor.find(); 51 } 52 53 std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){ 54 return descriptor.findAll(); 55 } 56 57 int World::numMolecules(){ 58 return molecules_deprecated->ListOfMolecules.size(); 59 } 60 61 // system 62 63 double * World::getDomain() { 64 return cell_size; 65 } 66 67 void World::setDomain(double * matrix) 68 { 69 70 } 71 72 char * World::getDefaultName() { 73 return defaultName; 74 } 75 76 void World::setDefaultName(char * name) 77 { 78 delete[](defaultName); 79 const int length = strlen(name); 80 defaultName = new char[length+2]; 81 if (length < MAXSTRINGSIZE) 82 strncpy(defaultName, name, length); 83 else 84 strcpy(defaultName, "none"); 85 }; 86 87 88 /******************** Methods to change World state *********************/ 89 90 molecule* World::createMolecule(){ 91 OBSERVE; 92 molecule *mol = NULL; 93 mol = NewMolecule(); 94 assert(!molecules.count(currMoleculeId)); 95 mol->setId(currMoleculeId++); 96 // store the molecule by ID 97 molecules[mol->getId()] = mol; 98 mol->signOn(this); 99 return mol; 100 } 101 102 void World::destroyMolecule(molecule* mol){ 103 OBSERVE; 104 destroyMolecule(mol->getId()); 105 } 106 107 void World::destroyMolecule(moleculeId_t id){ 108 OBSERVE; 109 molecule *mol = molecules[id]; 110 assert(mol); 111 DeleteMolecule(mol); 112 molecules.erase(id); 113 } 114 115 double *World::cell_size = NULL; 116 char *World::defaultName = NULL; 117 118 atom *World::createAtom(){ 119 OBSERVE; 120 atomId_t id = getNextAtomId(); 121 atom *res = NewAtom(id); 122 res->setWorld(this); 123 // store the atom by ID 124 atoms[res->getId()] = res; 125 return res; 126 } 127 128 129 int World::registerAtom(atom *atom){ 130 OBSERVE; 131 atomId_t id = getNextAtomId(); 132 atom->setId(id); 133 atom->setWorld(this); 134 atoms[atom->getId()] = atom; 135 return atom->getId(); 136 } 137 138 void World::destroyAtom(atom* atom){ 139 OBSERVE; 140 int id = atom->getId(); 141 destroyAtom(id); 142 } 143 144 void World::destroyAtom(atomId_t id) { 145 OBSERVE; 146 atom *atom = atoms[id]; 147 assert(atom); 148 DeleteAtom(atom); 149 atoms.erase(id); 150 releaseAtomId(id); 151 } 152 153 bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){ 154 OBSERVE; 155 // in case this call did not originate from inside the atom, we redirect it, 156 // to also let it know that it has changed 157 if(!target){ 158 target = atoms[oldId]; 159 assert(target && "Atom with that ID not found"); 160 return target->changeId(newId); 161 } 162 else{ 163 if(reserveAtomId(newId)){ 164 atoms.erase(oldId); 165 atoms.insert(pair<atomId_t,atom*>(newId,target)); 166 return true; 167 } 168 else{ 169 return false; 170 } 171 } 172 } 173 174 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 175 return new ManipulateAtomsProcess(op, descr,name,true); 176 } 177 178 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){ 179 return manipulateAtoms(op,name,AllAtoms()); 180 } 181 182 /********************* Internal Change methods for double Callback and Observer mechanism ********/ 183 184 void World::doManipulate(ManipulateAtomsProcess *proc){ 185 proc->signOn(this); 186 { 187 OBSERVE; 188 proc->doManipulate(this); 189 } 190 proc->signOff(this); 191 } 192 /******************************* IDManagement *****************************/ 193 194 // Atoms 195 196 atomId_t World::getNextAtomId(){ 197 // see if we can reuse some Id 198 if(atomIdPool.empty()){ 199 return currAtomId++; 200 } 201 else{ 202 // we give out the first ID from the pool 203 atomId_t id = *(atomIdPool.begin()); 204 atomIdPool.erase(id); 205 return id; 206 } 207 } 208 209 void World::releaseAtomId(atomId_t id){ 210 atomIdPool.insert(id); 211 // defragmentation of the pool 212 set<atomId_t>::reverse_iterator iter; 213 // go through all Ids in the pool that lie immediately below the border 214 while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){ 215 atomIdPool.erase(--currAtomId); 216 } 217 } 218 219 bool World::reserveAtomId(atomId_t id){ 220 if(id>=currAtomId ){ 221 // add all ids between the new one and current border as available 222 for(atomId_t pos=currAtomId; pos<id; ++pos){ 223 atomIdPool.insert(pos); 224 } 225 currAtomId=id+1; 226 return true; 227 } 228 else if(atomIdPool.count(id)){ 229 atomIdPool.erase(id); 230 return true; 231 } 232 else{ 233 // this ID could not be reserved 234 return false; 235 } 236 } 237 238 // Molecules 239 240 /******************************* Iterators ********************************/ 241 242 // Build the AtomIterator from template 243 CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor); 244 245 246 World::AtomIterator World::getAtomIter(AtomDescriptor descr){ 247 return AtomIterator(descr,atoms); 248 } 249 250 World::AtomIterator World::atomEnd(){ 251 return AtomIterator(AllAtoms(),atoms,atoms.end()); 252 } 253 254 // build the MoleculeIterator from template 255 CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor); 256 257 World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){ 258 return MoleculeIterator(descr,molecules); 259 } 260 261 World::MoleculeIterator World::moleculeEnd(){ 262 return MoleculeIterator(AllMolecules(),molecules,molecules.end()); 263 } 264 265 /******************************* Singleton Stuff **************************/ 266 267 World::World() : 268 periode(new periodentafel), 269 atoms(), 270 currAtomId(0), 271 molecules(), 272 currMoleculeId(0), 273 molecules_deprecated(new MoleculeListClass(this)) 20 274 { 21 275 cell_size = new double[6]; … … 26 280 cell_size[4] = 0.; 27 281 cell_size[5] = 20.; 28 DefaultName = new char[MAXSTRINGSIZE]; 29 strcpy(DefaultName, "none"); 30 }; 31 32 /** Destructor of World. 33 * 34 */ 282 defaultName = new char[MAXSTRINGSIZE]; 283 strcpy(defaultName, "none"); 284 molecules_deprecated->signOn(this); 285 } 286 35 287 World::~World() 36 288 { 37 delete[](cell_size); 38 delete[](DefaultName); 39 }; 40 41 42 // TODO: Hide boost-thread using Autotools stuff when no threads are used 43 World* World::theWorld = 0; 44 45 46 World* World::get(){ 47 // boost supports RAII-Style locking, so we don't need to unlock 48 if(!theWorld) { 49 theWorld = new World(); 50 } 51 return theWorld; 52 } 53 54 void World::destroy(){ 55 delete theWorld; 56 theWorld = 0; 57 } 58 59 World* World::reset(){ 60 World* oldWorld = 0; 61 { 62 oldWorld = theWorld; 63 theWorld = new World(); 64 // oldworld does not need protection any more, 65 // since we should have the only reference 66 67 // worldLock handles access to the pointer, 68 // not to the object 69 } // scope-end releases the lock 70 71 // we have to let all the observers know that the 72 // oldWorld was destroyed. oldWorld calls subjectKilled 73 // upon destruction. Every Observer getting that signal 74 // should see that it gets the updated new world 75 delete oldWorld; 76 } 289 molecules_deprecated->signOff(this); 290 delete[] cell_size; 291 delete[] defaultName; 292 delete molecules_deprecated; 293 delete periode; 294 MoleculeSet::iterator molIter; 295 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){ 296 DeleteMolecule((*molIter).second); 297 } 298 molecules.clear(); 299 AtomSet::iterator atIter; 300 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){ 301 DeleteAtom((*atIter).second); 302 } 303 atoms.clear(); 304 } 305 306 // Explicit instantiation of the singleton mechanism at this point 307 308 CONSTRUCT_SINGLETON(World) 309 310 /******************************* deprecated Legacy Stuff ***********************/ 311 312 MoleculeListClass *&World::getMolecules() { 313 return molecules_deprecated; 314 } -
src/World.hpp
rc695c9 r5f612ee 1 1 /* 2 * world.hpp2 * World.hpp 3 3 * 4 * Created on: Mar3, 20105 * Author: heber4 * Created on: Feb 3, 2010 5 * Author: crueger 6 6 */ 7 7 … … 9 9 #define WORLD_HPP_ 10 10 11 using namespace std;12 13 11 /*********************************************** includes ***********************************/ 12 13 #include <string> 14 #include <map> 15 #include <vector> 16 #include <set> 17 #include <boost/thread.hpp> 18 #include <boost/shared_ptr.hpp> 19 20 #include "types.hpp" 21 #include "Descriptors/SelectiveIterator.hpp" 22 #include "Patterns/Observer.hpp" 23 #include "Patterns/Cacheable.hpp" 24 #include "Patterns/Singleton.hpp" 14 25 15 26 // include config.h … … 18 29 #endif 19 30 31 // forward declarations 32 class periodentafel; 33 class MoleculeListClass; 34 class atom; 35 class molecule; 36 class AtomDescriptor; 37 class AtomDescriptor_impl; 38 class MoleculeDescriptor; 39 class MoleculeDescriptor_impl; 40 class ManipulateAtomsProcess; 41 template<typename T> 42 class AtomsCalculation; 20 43 21 44 /****************************************** forward declarations *****************************/ … … 23 46 /********************************************** Class World *******************************/ 24 47 25 class World 48 class World : public Singleton<World>, public Observable 26 49 { 27 /***** singleton Stuff *****/ 50 51 // Make access to constructor and destructor possible from inside the singleton 52 friend class Singleton<World>; 53 54 // necessary for coupling with descriptors 55 friend class AtomDescriptor_impl; 56 friend class AtomDescriptor; 57 friend class MoleculeDescriptor_impl; 58 friend class MoleculeDescriptor; 59 60 // Actions, calculations etc associated with the World 61 friend class ManipulateAtomsProcess; 62 template<typename> friend class AtomsCalculation; 28 63 public: 29 static World* get(); 30 static void destroy(); 31 static World* reset(); 32 64 65 // Types for Atom and Molecule structures 66 typedef std::map<atomId_t,atom*> AtomSet; 67 typedef std::map<moleculeId_t,molecule*> MoleculeSet; 68 69 /***** getter and setter *****/ 70 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object 71 /** 72 * returns the periodentafel for the world. 73 */ 74 periodentafel *&getPeriode(); 75 76 /** 77 * returns the first atom that matches a given descriptor. 78 * Do not rely on ordering for descriptors that match more than one atom. 79 */ 80 atom* getAtom(AtomDescriptor descriptor); 81 82 /** 83 * returns a vector containing all atoms that match a given descriptor 84 */ 85 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor); 86 std::vector<atom*> getAllAtoms(); 87 88 /** 89 * returns a calculation that calls a given function on all atoms matching a descriptor. 90 * the calculation is not called at this point and can be used as an action, i.e. be stored in 91 * menus, be kept around for later use etc. 92 */ 93 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor); 94 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string); 95 96 /** 97 * get the number of atoms in the World 98 */ 99 int numAtoms(); 100 101 /** 102 * returns the first molecule that matches a given descriptor. 103 * Do not rely on ordering for descriptors that match more than one molecule. 104 */ 105 molecule *getMolecule(MoleculeDescriptor descriptor); 106 107 /** 108 * returns a vector containing all molecules that match a given descriptor 109 */ 110 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor); 111 112 /** 113 * get the number of molecules in the World 114 */ 115 int numMolecules(); 116 117 /** 118 * get the domain size as a symmetric matrix (6 components) 119 */ 120 double * getDomain(); 121 122 /** 123 * set the domain size as a symmetric matrix (6 components) 124 */ 125 void setDomain(double * matrix); 126 127 /** 128 * get the default name 129 */ 130 char * getDefaultName(); 131 132 /** 133 * set the default name 134 */ 135 void setDefaultName(char * name); 136 137 /***** Methods to work with the World *****/ 138 139 /** 140 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique 141 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly. 142 */ 143 molecule *createMolecule(); 144 145 void destroyMolecule(molecule*); 146 void destroyMolecule(moleculeId_t); 147 148 /** 149 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores 150 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends. 151 */ 152 atom *createAtom(); 153 154 /** 155 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests. 156 * Do not re-register Atoms already known to the world since this will cause double-frees. 157 */ 158 int registerAtom(atom*); 159 160 /** 161 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 162 * atom directly since this will leave the pointer inside the world. 163 */ 164 void destroyAtom(atom*); 165 166 /** 167 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 168 * atom directly since this will leave the pointer inside the world. 169 */ 170 void destroyAtom(atomId_t); 171 172 /** 173 * used when changing an atom Id. 174 * Unless you are calling this method from inside an atom don't fiddle with the third parameter. 175 * 176 * Return value indicates wether the change could be done or not. 177 */ 178 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0); 179 180 /** 181 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not 182 * called at this time, so it can be passed around, stored inside menuItems etc. 183 */ 184 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor); 185 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string); 186 187 protected: 188 /**** Iterators to use internal data structures */ 189 190 // Atoms 191 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator; 192 193 /** 194 * returns an iterator over all Atoms matching a given descriptor. 195 * used for internal purposes, like AtomProcesses and AtomCalculations. 196 */ 197 AtomIterator getAtomIter(AtomDescriptor descr); 198 199 /** 200 * returns an iterator to the end of the AtomSet. Due to overloading this iterator 201 * can be compared to iterators produced by getAtomIter (see the mis-matching types). 202 * Thus it can be used to detect when such an iterator is at the end of the list. 203 * used for internal purposes, like AtomProcesses and AtomCalculations. 204 */ 205 AtomIterator atomEnd(); 206 207 // Molecules 208 209 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator; 210 211 /** 212 * returns an iterator over all Molecules matching a given descriptor. 213 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 214 */ 215 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr); 216 217 /** 218 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator 219 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types). 220 * Thus it can be used to detect when such an iterator is at the end of the list. 221 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 222 */ 223 MoleculeIterator moleculeEnd(); 224 225 226 /******* Internal manipulation routines for double callback and Observer mechanism ******/ 227 void doManipulate(ManipulateAtomsProcess *); 228 229 private: 230 231 atomId_t getNextAtomId(); 232 void releaseAtomId(atomId_t); 233 bool reserveAtomId(atomId_t); 234 235 periodentafel *periode; 33 236 static double *cell_size; 34 static char *DefaultName; 35 36 private: 237 static char *defaultName; 238 public: 239 AtomSet atoms; 240 private: 241 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 242 atomId_t currAtomId; //!< stores the next available Id for atoms 243 MoleculeSet molecules; 244 moleculeId_t currMoleculeId; 245 private: 246 /** 247 * private constructor to ensure creation of the world using 248 * the singleton pattern. 249 */ 37 250 World(); 251 252 /** 253 * private destructor to ensure destruction of the world using the 254 * singleton pattern. 255 */ 38 256 virtual ~World(); 39 257 40 static World *theWorld; 258 /***** 259 * some legacy stuff that is include for now but will be removed later 260 *****/ 261 public: 262 MoleculeListClass *&getMolecules(); 263 264 private: 265 MoleculeListClass *molecules_deprecated; 41 266 }; 42 267 -
src/analysis_correlation.cpp
rc695c9 r5f612ee 57 57 if (Walker->nr < OtherWalker->nr) 58 58 if ((type2 == NULL) || (OtherWalker->type == type2)) { 59 distance = Walker->node->PeriodicDistance(OtherWalker->node, World::get ()->cell_size);59 distance = Walker->node->PeriodicDistance(OtherWalker->node, World::getInstance().getDomain()); 60 60 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 61 61 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 98 98 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 99 99 if ((*MolWalker)->ActiveFlag) { 100 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get ()->cell_size);100 double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain()); 101 101 double * FullInverseMatrix = InverseMatrix(FullMatrix); 102 102 DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); … … 176 176 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 177 177 if ((type == NULL) || (Walker->type == type)) { 178 distance = Walker->node->PeriodicDistance(point, World::get ()->cell_size);178 distance = Walker->node->PeriodicDistance(point, World::getInstance().getDomain()); 179 179 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 180 180 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); … … 210 210 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 211 211 if ((*MolWalker)->ActiveFlag) { 212 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get ()->cell_size);212 double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain()); 213 213 double * FullInverseMatrix = InverseMatrix(FullMatrix); 214 214 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); … … 278 278 DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl); 279 279 280 281 280 return outmap; 282 281 }; … … 315 314 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++) 316 315 if ((*MolWalker)->ActiveFlag) { 317 double * FullMatrix = ReturnFullMatrixforSymmetric(World::get ()->cell_size);316 double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain()); 318 317 double * FullInverseMatrix = InverseMatrix(FullMatrix); 319 318 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl); -
src/atom.cpp
rc695c9 r5f612ee 13 13 #include "parser.hpp" 14 14 #include "vector.hpp" 15 #include "World.hpp" 15 16 16 17 /************************************* Functions for class atom *************************************/ … … 19 20 /** Constructor of class atom. 20 21 */ 21 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr) 22 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr) 22 24 { 23 25 node = &x; // TesselPoint::x can only be referenced from here … … 26 28 /** Constructor of class atom. 27 29 */ 28 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr) 30 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 29 33 { 30 34 type = pointer->type; // copy element of atom … … 34 38 node = &x; 35 39 }; 40 41 atom *atom::clone(){ 42 atom *res = new atom(); 43 res->previous=0; 44 res->next=0; 45 res->father = this; 46 res->sort = &res->nr; 47 res->type = type; 48 res->x.CopyVector(&this->x); 49 res->v.CopyVector(&this->v); 50 res->FixedIon = FixedIon; 51 res->node = &x; 52 World::getInstance().registerAtom(res); 53 return res; 54 } 36 55 37 56 … … 263 282 }; 264 283 284 World *atom::getWorld(){ 285 return world; 286 } 287 288 void atom::setWorld(World* _world){ 289 world = _world; 290 } 291 292 bool atom::changeId(atomId_t newId){ 293 // first we move ourselves in the world 294 // the world lets us know if that succeeded 295 if(world->changeAtomId(id,newId,this)){ 296 id = newId; 297 return true; 298 } 299 else{ 300 return false; 301 } 302 } 303 304 void atom::setId(atomId_t _id) { 305 id=_id; 306 } 307 308 atomId_t atom::getId() { 309 return id; 310 } 311 312 atom* NewAtom(atomId_t _id){ 313 atom * res =new atom(); 314 res->setId(_id); 315 return res; 316 } 317 318 void DeleteAtom(atom* atom){ 319 delete atom; 320 } -
src/atom.hpp
rc695c9 r5f612ee 28 28 #include "atom_trajectoryparticle.hpp" 29 29 #include "tesselation.hpp" 30 #include "types.hpp" 30 31 31 32 /****************************************** forward declarations *****************************/ 32 33 33 34 class Vector; 35 class World; 34 36 35 37 /********************************************** declarations *******************************/ … … 39 41 */ 40 42 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 43 friend atom* NewAtom(atomId_t); 44 friend void DeleteAtom(atom*); 41 45 public: 42 46 atom *previous; //!< previous atom in molecule list … … 45 49 int *sort; //!< sort criteria 46 50 47 atom(); 48 atom(class atom *pointer); 49 virtual ~atom(); 51 virtual atom *clone(); 50 52 51 53 bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const; … … 67 69 bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const; 68 70 71 // getter and setter 72 73 /** 74 * returns the World that contains this atom. 75 * Use this if you need to get the world without locking 76 * the singleton for example. 77 * 78 */ 79 World *getWorld(); 80 void setWorld(World*); 81 82 virtual atomId_t getId(); 83 virtual bool changeId(atomId_t newId); 84 85 /** 86 * this function sets the Id without notifying the world. Only use it, if the world has already 87 * gotten an ID for this Atom. 88 */ 89 virtual void setId(atomId_t); 90 91 protected: 92 /** 93 * Protected constructor to ensure construction of atoms through the world. 94 * see World::createAtom() 95 */ 96 atom(); 97 98 /** 99 * Protected copy-constructor to ensure construction of atoms by cloning. 100 * see atom::clone() 101 */ 102 atom(class atom *pointer); 103 104 /** 105 * Protected destructor to ensure destruction of atoms through the world. 106 * see World::destroyAtom() 107 */ 108 virtual ~atom(); 69 109 private: 110 World* world; 111 atomId_t id; 70 112 }; 71 113 114 /** 115 * internal method used by the world. Do not use if you don't know what you are doing. 116 * You might get burned... 117 * Use World::createAtom() instead. 118 */ 119 atom* NewAtom(atomId_t _id); 120 121 /** 122 * internal method used by the world. Do not use if you don't know what you are doing. 123 * You might get burned... 124 * Use World::destroyAtom() instead. 125 */ 126 void DeleteAtom(atom*); 127 128 72 129 #endif /* ATOM_HPP_ */ -
src/atom_atominfo.cpp
rc695c9 r5f612ee 6 6 */ 7 7 8 #include "periodentafel.hpp" 9 #include "World.hpp" 8 10 #include "atom_atominfo.hpp" 9 11 … … 18 20 }; 19 21 22 const element *AtomInfo::getType(){ 23 return type; 24 } 25 26 void AtomInfo::setType(const element* _type) { 27 type = _type; 28 } 29 30 void AtomInfo::setType(int Z) { 31 const element *elem = World::getInstance().getPeriode()->FindElement(Z); 32 setType(elem); 33 } -
src/atom_atominfo.hpp
rc695c9 r5f612ee 32 32 Vector v; //!< velocity vector of atom, giving last velocity within cell 33 33 Vector F; //!< Force vector of atom, giving last force within cell 34 element *type; //!< pointing to element34 const element *type; //!< pointing to element 35 35 36 36 AtomInfo(); 37 37 ~AtomInfo(); 38 39 const element *getType(); 40 void setType(const element *); 41 void setType(int); 38 42 39 43 private: -
src/atom_particleinfo.cpp
rc695c9 r5f612ee 12 12 */ 13 13 ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {}; 14 15 ParticleInfo::ParticleInfo(ParticleInfo *pointer) : 16 nr(pointer->nr), 17 Name(pointer->Name) 18 {} 19 14 20 15 21 /** Destructor of ParticleInfo. -
src/atom_particleinfo.hpp
rc695c9 r5f612ee 31 31 32 32 ParticleInfo(); 33 ParticleInfo(ParticleInfo*); 33 34 ~ParticleInfo(); 34 35 -
src/boundary.cpp
rc695c9 r5f612ee 4 4 */ 5 5 6 #include "World.hpp" 6 7 #include "atom.hpp" 7 8 #include "bond.hpp" … … 802 803 { 803 804 Info FunctionInfo(__func__); 804 molecule *Filling = new molecule(filler->elemente);805 molecule *Filling = World::getInstance().createMolecule(); 805 806 Vector CurrentPosition; 806 807 int N[NDIM]; 807 808 int n[NDIM]; 808 double *M = ReturnFullMatrixforSymmetric(World::get ()->cell_size);809 double *M = ReturnFullMatrixforSymmetric(World::getInstance().getDomain()); 809 810 double Rotations[NDIM*NDIM]; 810 811 double *MInverse = InverseMatrix(M); … … 919 920 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl); 920 921 // copy atom ... 921 CopyAtoms[Walker->nr] = new atom(Walker);922 CopyAtoms[Walker->nr] = Walker->clone(); 922 923 CopyAtoms[Walker->nr]->x.CopyVector(&Inserter); 923 924 Filling->AddAtom(CopyAtoms[Walker->nr]); -
src/builder.cpp
rc695c9 r5f612ee 48 48 49 49 50 #include <boost/bind.hpp> 51 50 52 using namespace std; 51 53 … … 65 67 #include "linkedcell.hpp" 66 68 #include "log.hpp" 67 #include "memoryusageobserver unittest.hpp"69 #include "memoryusageobserver.hpp" 68 70 #include "molecule.hpp" 69 71 #include "periodentafel.hpp" 72 #include "UIElements/UIFactory.hpp" 73 #include "UIElements/MainWindow.hpp" 74 #include "UIElements/Dialog.hpp" 75 #include "Menu/ActionMenuItem.hpp" 76 #include "Actions/ActionRegistry.hpp" 77 #include "Actions/ActionHistory.hpp" 78 #include "Actions/MethodAction.hpp" 79 #include "Actions/small_actions.hpp" 80 #include "World.hpp" 70 81 #include "version.h" 71 82 #include "World.hpp" 72 83 73 84 /********************************************* Subsubmenu routine ************************************/ 74 85 #if 0 75 86 /** Submenu for adding atoms to the molecule. 76 87 * \param *periode periodentafel … … 105 116 cout << Verbose(0) << "Enter absolute coordinates." << endl; 106 117 first = new atom; 107 first->x.AskPosition(World::get ()->cell_size, false);118 first->x.AskPosition(World::getInstance().getDomain(), false); 108 119 first->type = periode->AskElement(); // give type 109 120 mol->AddAtom(first); // add to molecule … … 116 127 if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl); 117 128 cout << Verbose(0) << "Enter reference coordinates." << endl; 118 x.AskPosition(World::get ()->cell_size, true);129 x.AskPosition(World::getInstance().getDomain(), true); 119 130 cout << Verbose(0) << "Enter relative coordinates." << endl; 120 first->x.AskPosition(World::get ()->cell_size, false);131 first->x.AskPosition(World::getInstance().getDomain(), false); 121 132 first->x.AddVector((const Vector *)&x); 122 133 cout << Verbose(0) << "\n"; … … 133 144 second = mol->AskAtom("Enter atom number: "); 134 145 DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl); 135 first->x.AskPosition(World::get ()->cell_size, false);146 first->x.AskPosition(World::getInstance().getDomain(), false); 136 147 for (int i=NDIM;i--;) { 137 148 first->x.x[i] += second->x.x[i]; … … 260 271 if (i >= 2) { 261 272 first->x.LSQdistance((const Vector **)atoms, i); 262 263 273 first->x.Output(); 264 274 first->type = periode->AskElement(); // give type … … 360 370 case 'b': // normal vector of mirror plane 361 371 cout << Verbose(0) << "Enter normal vector of mirror plane." << endl; 362 n.AskPosition(World::get ()->cell_size,0);372 n.AskPosition(World::getInstance().getDomain(),0); 363 373 n.Normalize(); 364 374 break; … … 427 437 case 'b': // normal vector of mirror plane 428 438 DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl); 429 n.AskPosition(World::get ()->cell_size,0);439 n.AskPosition(World::getInstance().getDomain(),0); 430 440 n.Normalize(); 431 441 break; … … 867 877 x.Zero(); 868 878 y.Zero(); 869 y.x[abs(axis)-1] = World::get ()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude879 y.x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 870 880 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 871 881 x.AddVector(&y); // per factor one cell width further … … 890 900 mol->Translate(&x); 891 901 } 892 World::get ()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;902 World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; 893 903 } 894 904 } … … 947 957 DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); 948 958 DoLog(0) && (Log() << Verbose(0) << "Enter translation vector." << endl); 949 x.AskPosition(World::get ()->cell_size,0);959 x.AskPosition(World::getInstance().getDomain(),0); 950 960 mol->Center.AddVector((const Vector *)&x); 951 961 } … … 991 1001 break; 992 1002 case 'c': 993 mol = new molecule(periode);1003 mol = World::getInstance().createMolecule(); 994 1004 molecules->insert(mol); 995 1005 break; … … 999 1009 char filename[MAXSTRINGSIZE]; 1000 1010 DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl); 1001 mol = new molecule(periode);1011 mol = World::getInstance().createMolecule(); 1002 1012 do { 1003 1013 DoLog(0) && (Log() << Verbose(0) << "Enter file name: "); … … 1007 1017 // center at set box dimensions 1008 1018 mol->CenterEdge(¢er); 1009 double * const cell_size = World::get ()->cell_size;1019 double * const cell_size = World::getInstance().getDomain(); 1010 1020 cell_size[0] = center.x[0]; 1011 1021 cell_size[1] = 0; … … 1258 1268 }; 1259 1269 1260 1261 1270 /********************************************** Test routine **************************************/ 1262 1271 … … 1342 1351 }; 1343 1352 1353 #endif 1354 1344 1355 /** Tries given filename or standard on saving the config file. 1345 1356 * \param *ConfigFileName name of file … … 1352 1363 char filename[MAXSTRINGSIZE]; 1353 1364 ofstream output; 1354 molecule *mol = new molecule(periode);1365 molecule *mol = World::getInstance().createMolecule(); 1355 1366 mol->SetNameFromFilename(ConfigFileName); 1356 1367 … … 1463 1474 } 1464 1475 1465 delete(mol);1476 World::getInstance().destroyMolecule(mol); 1466 1477 }; 1467 1478 … … 1476 1487 * \return exit code (0 - successful, all else - something's wrong) 1477 1488 */ 1478 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName) 1489 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\ 1490 config& configuration, char *&ConfigFileName) 1479 1491 { 1480 1492 Vector x,y,z,n; // coordinates for absolute point in cell volume … … 1573 1585 j = -1; 1574 1586 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 1575 double * const cell_size = World::get ()->cell_size;1587 double * const cell_size = World::getInstance().getDomain(); 1576 1588 for (int i=0;i<6;i++) { 1577 1589 cell_size[i] = atof(argv[argptr+i]); … … 1606 1618 case 'X': 1607 1619 { 1608 char **name = &(World::get()->DefaultName); 1609 delete[](*name); 1610 const int length = strlen(argv[argptr]); 1611 *name = new char[length+2]; 1612 strncpy(*name, argv[argptr], length); 1613 DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *name << "." << endl); 1620 World::getInstance().setDefaultName(argv[argptr]); 1621 DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *World::getInstance().getDefaultName() << "." << endl); 1614 1622 } 1615 1623 break; … … 1678 1686 } 1679 1687 if (mol == NULL) { 1680 mol = new molecule(periode);1688 mol = World::getInstance().createMolecule(); 1681 1689 mol->ActiveFlag = true; 1682 1690 if (ConfigFileName != NULL) … … 1726 1734 } else { 1727 1735 SaveFlag = true; 1728 DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ");1729 first = new atom;1736 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1737 first = World::getInstance().createAtom(); 1730 1738 first->type = periode->FindElement(atoi(argv[argptr])); 1731 1739 if (first->type != NULL) … … 1833 1841 const double BinEnd = atof(argv[argptr+6]); 1834 1842 1835 element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));1836 element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2]));1843 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1844 const element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2])); 1837 1845 PairCorrelationMap *correlationmap = NULL; 1838 1846 if (periodic) … … 1864 1872 const double BinEnd = atof(argv[argptr+8]); 1865 1873 1866 element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));1874 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1867 1875 Vector *Point = new Vector((const double) atof(argv[argptr+1]),(const double) atof(argv[argptr+2]),(const double) atof(argv[argptr+3])); 1868 1876 CorrelationToPointMap *correlationmap = NULL; … … 1924 1932 } 1925 1933 LCList = new LinkedCell(Boundary, LCWidth); 1926 element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));1934 const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1])); 1927 1935 FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL); 1928 1936 CorrelationToSurfaceMap *surfacemap = NULL; … … 1994 2002 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl); 1995 2003 // construct water molecule 1996 molecule *filler = new molecule(periode);2004 molecule *filler = World::getInstance().createMolecule(); 1997 2005 if (!filler->AddXYZFile(argv[argptr])) { 1998 2006 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl); … … 2001 2009 configuration.BG->ConstructBondGraph(filler); 2002 2010 molecule *Filling = NULL; 2011 atom *second = NULL, *third = NULL; 2012 first = World::getInstance().createAtom(); 2013 first->type = periode->FindElement(1); 2014 first->x.Init(0.441, -0.143, 0.); 2015 filler->AddAtom(first); 2016 second = World::getInstance().createAtom(); 2017 second->type = periode->FindElement(1); 2018 second->x.Init(-0.464, 1.137, 0.0); 2019 filler->AddAtom(second); 2020 third = World::getInstance().createAtom(); 2021 third->type = periode->FindElement(8); 2022 third->x.Init(-0.464, 0.177, 0.); 2023 filler->AddAtom(third); 2024 filler->AddBond(first, third, 1); 2025 filler->AddBond(second, third, 1); 2003 2026 // call routine 2004 2027 double distance[NDIM]; … … 2010 2033 molecules->insert(Filling); 2011 2034 } 2012 delete(filler);2035 World::getInstance().destroyMolecule(filler); 2013 2036 argptr+=6; 2014 2037 } … … 2218 2241 factor[2] = atof(argv[argptr+2]); 2219 2242 mol->Scale((const double ** const)&factor); 2220 double * const cell_size = World::get ()->cell_size;2243 double * const cell_size = World::getInstance().getDomain(); 2221 2244 for (int i=0;i<NDIM;i++) { 2222 2245 j += i+1; … … 2238 2261 j = -1; 2239 2262 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2240 double * const cell_size = World::get ()->cell_size;2263 double * const cell_size = World::getInstance().getDomain(); 2241 2264 for (int i=0;i<6;i++) { 2242 2265 cell_size[i] = atof(argv[argptr+i]); … … 2257 2280 j = -1; 2258 2281 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl); 2259 double * const cell_size = World::get ()->cell_size;2282 double * const cell_size = World::getInstance().getDomain(); 2260 2283 for (int i=0;i<6;i++) { 2261 2284 cell_size[i] = atof(argv[argptr+i]); … … 2281 2304 mol->SetBoxDimension(&x); 2282 2305 // translate each coordinate by boundary 2283 double * const cell_size = World::get ()->cell_size;2306 double * const cell_size = World::getInstance().getDomain(); 2284 2307 j=-1; 2285 2308 for (int i=0;i<NDIM;i++) { … … 2325 2348 DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl); 2326 2349 start = clock(); 2327 mol->CreateAdjacencyList(atof(argv[argptr ++]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);2350 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 2328 2351 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl); 2329 2352 if (mol->first->next != mol->last) { 2330 ExitFlag = mol->FragmentMolecule(atoi(argv[argptr ]), &configuration);2353 ExitFlag = mol->FragmentMolecule(atoi(argv[argptr+1]), &configuration); 2331 2354 } 2332 2355 end = clock(); … … 2417 2440 } else { 2418 2441 SaveFlag = true; 2419 double * const cell_size = World::get ()->cell_size;2442 double * const cell_size = World::getInstance().getDomain(); 2420 2443 for (int axis = 1; axis <= NDIM; axis++) { 2421 2444 int faktor = atoi(argv[argptr++]); 2422 2445 int count; 2423 element ** Elements;2446 const element ** Elements; 2424 2447 Vector ** vectors; 2425 2448 if (faktor < 1) { … … 2430 2453 if (mol->AtomCount != 0) { // if there is more than none 2431 2454 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 2432 Elements = new element *[count];2455 Elements = new const element *[count]; 2433 2456 vectors = new Vector *[count]; 2434 2457 j = 0; … … 2448 2471 x.AddVector(&y); // per factor one cell width further 2449 2472 for (int k=count;k--;) { // go through every atom of the original cell 2450 first = new atom(); // create a new body2473 first = World::getInstance().createAtom(); // create a new body 2451 2474 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2452 2475 first->x.AddVector(&x); // translate the coordinates … … 2479 2502 } while (argptr < argc); 2480 2503 if (SaveFlag) 2481 SaveConfig(ConfigFileName, &configuration, periode, molecules);2504 configuration.SaveAll(ConfigFileName, periode, molecules); 2482 2505 } else { // no arguments, hence scan the elements db 2483 2506 if (periode->LoadPeriodentafel(configuration.databasepath)) … … 2490 2513 }; 2491 2514 2515 /***************************************** Functions used to build all menus **********************/ 2516 2517 void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){ 2518 // build the EditMoleculesMenu 2519 Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode)); 2520 new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction); 2521 2522 Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode)); 2523 new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction); 2524 2525 Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules); 2526 new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction); 2527 2528 Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules)); 2529 new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction); 2530 2531 Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules)); 2532 new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction); 2533 2534 Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules)); 2535 new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction); 2536 2537 } 2538 2539 2492 2540 /********************************************** Main routine **************************************/ 2493 2541 2494 int main(int argc, char **argv) 2495 { 2496 periodentafel *periode = new periodentafel; // and a period table of all elements 2497 MoleculeListClass *molecules = new MoleculeListClass; // list of all molecules 2498 molecule *mol = NULL; 2499 config *configuration = new config; 2500 char choice; // menu choice char 2501 Vector x,y,z,n; // coordinates for absolute point in cell volume 2502 ifstream test; 2503 ofstream output; 2504 string line; 2505 char *ConfigFileName = NULL; 2506 int j; 2507 2508 cout << ESPACKVersion << endl; 2509 2510 DoLog(1) && (Log() << Verbose(1) << "test" << endl); 2511 DoLog(3) && (Log() << Verbose(1) << "test"); 2512 2513 setVerbosity(0); 2514 2515 // =========================== PARSE COMMAND LINE OPTIONS ==================================== 2516 j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName); 2517 switch(j) { 2518 case 255: // something went wrong 2519 case 2: // just for -f option 2520 case 1: // just for -v and -h options 2521 delete(molecules); // also free's all molecules contained 2522 delete(periode); 2523 delete(configuration); 2524 Log() << Verbose(0) << "Maximum of allocated memory: " 2525 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; 2526 Log() << Verbose(0) << "Remaining non-freed memory: " 2527 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; 2528 MemoryUsageObserver::getInstance()->purgeInstance(); 2529 logger::purgeInstance(); 2530 errorLogger::purgeInstance(); 2531 return (j == 1 ? 0 : j); 2532 default: 2533 break; 2534 } 2535 2536 // General stuff 2537 if (molecules->ListOfMolecules.size() == 0) { 2538 mol = new molecule(periode); 2539 double * const cell_size = World::get()->cell_size; 2540 if (cell_size[0] == 0.) { 2541 DoLog(0) && (Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl); 2542 for (int i=0;i<6;i++) { 2543 DoLog(1) && (Log() << Verbose(1) << "Cell size" << i << ": "); 2544 cin >> cell_size[i]; 2545 } 2546 } 2547 mol->ActiveFlag = true; 2548 molecules->insert(mol); 2549 } 2550 2551 // =========================== START INTERACTIVE SESSION ==================================== 2552 2553 // now the main construction loop 2554 DoLog(0) && (Log() << Verbose(0) << endl << "Now comes the real construction..." << endl); 2555 do { 2556 DoLog(0) && (Log() << Verbose(0) << endl << endl); 2557 DoLog(0) && (Log() << Verbose(0) << "============Molecule list=======================" << endl); 2558 molecules->Enumerate((ofstream *)&cout); 2559 DoLog(0) && (Log() << Verbose(0) << "============Menu===============================" << endl); 2560 DoLog(0) && (Log() << Verbose(0) << "a - set molecule (in)active" << endl); 2561 DoLog(0) && (Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl); 2562 DoLog(0) && (Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl); 2563 DoLog(0) && (Log() << Verbose(0) << "M - Merge molecules" << endl); 2564 DoLog(0) && (Log() << Verbose(0) << "m - manipulate atoms" << endl); 2565 DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl); 2566 DoLog(0) && (Log() << Verbose(0) << "c - edit the current configuration" << endl); 2567 DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl); 2568 DoLog(0) && (Log() << Verbose(0) << "s - save current setup to config file" << endl); 2569 DoLog(0) && (Log() << Verbose(0) << "T - call the current test routine" << endl); 2570 DoLog(0) && (Log() << Verbose(0) << "q - quit" << endl); 2571 DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl); 2572 DoLog(0) && (Log() << Verbose(0) << "Input: "); 2573 cin >> choice; 2574 2575 switch (choice) { 2576 case 'a': // (in)activate molecule 2577 { 2578 DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: "); 2579 cin >> j; 2580 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) 2581 if ((*ListRunner)->IndexNr == j) 2582 (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag; 2583 } 2584 break; 2585 2586 case 'c': // edit each field of the configuration 2587 configuration->Edit(); 2588 break; 2589 2590 case 'e': // create molecule 2591 EditMolecules(periode, molecules); 2592 break; 2593 2594 case 'g': // manipulate molecules 2595 ManipulateMolecules(periode, molecules, configuration); 2596 break; 2597 2598 case 'M': // merge molecules 2599 MergeMolecules(periode, molecules); 2600 break; 2601 2602 case 'm': // manipulate atoms 2603 ManipulateAtoms(periode, molecules, configuration); 2604 break; 2605 2606 case 'q': // quit 2607 break; 2608 2609 case 's': // save to config file 2610 SaveConfig(ConfigFileName, configuration, periode, molecules); 2611 break; 2612 2613 case 'T': 2614 testroutine(molecules); 2615 break; 2616 2617 default: 2618 break; 2619 }; 2620 } while (choice != 'q'); 2621 2622 // save element data base 2623 if (periode->StorePeriodentafel(configuration->databasepath)) //ElementsFileName 2624 DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db successful." << endl); 2625 else 2626 DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db failed." << endl); 2627 2628 delete(molecules); // also free's all molecules contained 2629 delete(periode); 2542 void cleanUp(config *configuration){ 2543 UIFactory::purgeInstance(); 2544 World::purgeInstance(); 2630 2545 delete(configuration); 2631 2632 2546 Log() << Verbose(0) << "Maximum of allocated memory: " 2633 2547 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; … … 2637 2551 logger::purgeInstance(); 2638 2552 errorLogger::purgeInstance(); 2639 2553 ActionRegistry::purgeInstance(); 2554 } 2555 2556 int main(int argc, char **argv) 2557 { 2558 molecule *mol = NULL; 2559 config *configuration = new config; 2560 Vector x, y, z, n; 2561 ifstream test; 2562 ofstream output; 2563 string line; 2564 char *ConfigFileName = NULL; 2565 int j; 2566 2567 cout << ESPACKVersion << endl; 2568 2569 setVerbosity(0); 2570 // need to init the history before any action is created 2571 ActionHistory::init(); 2572 /* structure of ParseCommandLineOptions will be refactored later */ 2573 j = ParseCommandLineOptions(argc, argv, World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName); 2574 switch (j){ 2575 case 255: 2576 case 2: 2577 case 1: 2578 cleanUp(configuration); 2579 return (j == 1 ? 0 : j); 2580 default: 2581 break; 2582 } 2583 if(World::getInstance().numMolecules() == 0){ 2584 mol = World::getInstance().createMolecule(); 2585 World::getInstance().getMolecules()->insert(mol); 2586 cout << "Molecule created" << endl; 2587 if(World::getInstance().getDomain()[0] == 0.){ 2588 Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl; 2589 for(int i = 0;i < 6;i++){ 2590 Log() << Verbose(1) << "Cell size" << i << ": "; 2591 cin >> World::getInstance().getDomain()[i]; 2592 } 2593 } 2594 mol->ActiveFlag = true; 2595 } 2596 2597 { 2598 cout << ESPACKVersion << endl; 2599 2600 setVerbosity(0); 2601 2602 menuPopulaters populaters; 2603 populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu; 2604 2605 UIFactory::makeUserInterface(UIFactory::Text); 2606 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName); 2607 mainWindow->display(); 2608 delete mainWindow; 2609 } 2610 2611 if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath)) 2612 Log() << Verbose(0) << "Saving of elements.db successful." << endl; 2613 2614 else 2615 Log() << Verbose(0) << "Saving of elements.db failed." << endl; 2616 2617 cleanUp(configuration); 2640 2618 return (0); 2641 2619 } -
src/config.cpp
rc695c9 r5f612ee 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 500 501 // case 'j': // BoxLength 501 502 // Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl; 502 // double * const cell_size = World::get ()->cell_size;503 // double * const cell_size = World::getInstance().getDomain(); 503 504 // for (int i=0;i<6;i++) { 504 505 // Log() << Verbose(0) << "Cell size" << i << ": "; … … 676 677 { 677 678 int MaxTypes = 0; 678 element *elementhash[MAX_ELEMENTS];679 const element *elementhash[MAX_ELEMENTS]; 679 680 char name[MAX_ELEMENTS]; 680 681 char keyword[MAX_ELEMENTS]; … … 734 735 sprintf(keyword,"%s_%i",name, j+1); 735 736 if (repetition == 0) { 736 neues = new atom();737 neues = World::getInstance().createAtom(); 737 738 AtomList[i][j] = neues; 738 739 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 813 814 sprintf(keyword,"%s_%i",name, j+1); 814 815 if (repetition == 0) { 815 neues = new atom();816 neues = World::getInstance().createAtom(); 816 817 AtomList[i][j] = neues; 817 818 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 852 853 void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 853 854 { 854 molecule *mol = new molecule(periode);855 molecule *mol = World::getInstance().createMolecule(); 855 856 ifstream *file = new ifstream(filename); 856 857 if (file == NULL) { … … 967 968 // Unit cell and magnetic field 968 969 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */ 969 double * const cell_size = World::get ()->cell_size;970 double * const cell_size = World::getInstance().getDomain(); 970 971 cell_size[0] = BoxLength[0]; 971 972 cell_size[1] = BoxLength[3]; … … 1091 1092 void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 1092 1093 { 1093 molecule *mol = new molecule(periode);1094 molecule *mol = World::getInstance().createMolecule(); 1094 1095 ifstream *file = new ifstream(filename); 1095 1096 if (file == NULL) { … … 1109 1110 string zeile; 1110 1111 string dummy; 1111 element *elementhash[128];1112 const element *elementhash[128]; 1112 1113 int Z = -1; 1113 1114 int No = -1; … … 1172 1173 1173 1174 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */ 1174 double * const cell_size = World::get ()->cell_size;1175 double * const cell_size = World::getInstance().getDomain(); 1175 1176 cell_size[0] = BoxLength[0]; 1176 1177 cell_size[1] = BoxLength[3]; … … 1291 1292 } 1292 1293 istringstream input2(zeile); 1293 atom *neues = new atom();1294 atom *neues = World::getInstance().createAtom(); 1294 1295 input2 >> neues->x.x[0]; // x 1295 1296 input2 >> neues->x.x[1]; // y … … 1316 1317 // bring MaxTypes up to date 1317 1318 mol->CountElements(); 1318 const double * const cell_size = World::get ()->cell_size;1319 const double * const cell_size = World::getInstance().getDomain(); 1319 1320 ofstream * const output = new ofstream(filename, ios::out); 1320 1321 if (output != NULL) { … … 1784 1785 }; 1785 1786 1787 1788 /** Tries given filename or standard on saving the config file. 1789 * \param *ConfigFileName name of file 1790 * \param *periode pointer to periodentafel structure with all the elements 1791 * \param *molecules list of molecules structure with all the atoms and coordinates 1792 */ 1793 void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules) 1794 { 1795 char filename[MAXSTRINGSIZE]; 1796 ofstream output; 1797 molecule *mol = World::getInstance().createMolecule(); 1798 mol->SetNameFromFilename(ConfigFileName); 1799 1800 if (!strcmp(configpath, GetDefaultPath())) { 1801 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; 1802 } 1803 1804 1805 // first save as PDB data 1806 if (ConfigFileName != NULL) 1807 strcpy(filename, ConfigFileName); 1808 if (output == NULL) 1809 strcpy(filename,"main_pcp_linux"); 1810 Log() << Verbose(0) << "Saving as pdb input "; 1811 if (SavePDB(filename, molecules)) 1812 Log() << Verbose(0) << "done." << endl; 1813 else 1814 Log() << Verbose(0) << "failed." << endl; 1815 1816 // then save as tremolo data file 1817 if (ConfigFileName != NULL) 1818 strcpy(filename, ConfigFileName); 1819 if (output == NULL) 1820 strcpy(filename,"main_pcp_linux"); 1821 Log() << Verbose(0) << "Saving as tremolo data input "; 1822 if (SaveTREMOLO(filename, molecules)) 1823 Log() << Verbose(0) << "done." << endl; 1824 else 1825 Log() << Verbose(0) << "failed." << endl; 1826 1827 // translate each to its center and merge all molecules in MoleculeListClass into this molecule 1828 int N = molecules->ListOfMolecules.size(); 1829 int *src = new int[N]; 1830 N=0; 1831 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { 1832 src[N++] = (*ListRunner)->IndexNr; 1833 (*ListRunner)->Translate(&(*ListRunner)->Center); 1834 } 1835 molecules->SimpleMultiAdd(mol, src, N); 1836 delete[](src); 1837 1838 // ... and translate back 1839 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { 1840 (*ListRunner)->Center.Scale(-1.); 1841 (*ListRunner)->Translate(&(*ListRunner)->Center); 1842 (*ListRunner)->Center.Scale(-1.); 1843 } 1844 1845 Log() << Verbose(0) << "Storing configuration ... " << endl; 1846 // get correct valence orbitals 1847 mol->CalculateOrbitals(*this); 1848 InitMaxMinStopStep = MaxMinStopStep = MaxPsiDouble; 1849 if (ConfigFileName != NULL) { // test the file name 1850 strcpy(filename, ConfigFileName); 1851 output.open(filename, ios::trunc); 1852 } else if (strlen(configname) != 0) { 1853 strcpy(filename, configname); 1854 output.open(configname, ios::trunc); 1855 } else { 1856 strcpy(filename, DEFAULTCONFIG); 1857 output.open(DEFAULTCONFIG, ios::trunc); 1858 } 1859 output.close(); 1860 output.clear(); 1861 Log() << Verbose(0) << "Saving of config file "; 1862 if (Save(filename, periode, mol)) 1863 Log() << Verbose(0) << "successful." << endl; 1864 else 1865 Log() << Verbose(0) << "failed." << endl; 1866 1867 // and save to xyz file 1868 if (ConfigFileName != NULL) { 1869 strcpy(filename, ConfigFileName); 1870 strcat(filename, ".xyz"); 1871 output.open(filename, ios::trunc); 1872 } 1873 if (output == NULL) { 1874 strcpy(filename,"main_pcp_linux"); 1875 strcat(filename, ".xyz"); 1876 output.open(filename, ios::trunc); 1877 } 1878 Log() << Verbose(0) << "Saving of XYZ file "; 1879 if (mol->MDSteps <= 1) { 1880 if (mol->OutputXYZ(&output)) 1881 Log() << Verbose(0) << "successful." << endl; 1882 else 1883 Log() << Verbose(0) << "failed." << endl; 1884 } else { 1885 if (mol->OutputTrajectoriesXYZ(&output)) 1886 Log() << Verbose(0) << "successful." << endl; 1887 else 1888 Log() << Verbose(0) << "failed." << endl; 1889 } 1890 output.close(); 1891 output.clear(); 1892 1893 // and save as MPQC configuration 1894 if (ConfigFileName != NULL) 1895 strcpy(filename, ConfigFileName); 1896 if (output == NULL) 1897 strcpy(filename,"main_pcp_linux"); 1898 Log() << Verbose(0) << "Saving as mpqc input "; 1899 if (SaveMPQC(filename, mol)) 1900 Log() << Verbose(0) << "done." << endl; 1901 else 1902 Log() << Verbose(0) << "failed." << endl; 1903 1904 if (!strcmp(configpath, GetDefaultPath())) { 1905 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; 1906 } 1907 1908 World::getInstance().destroyMolecule(mol); 1909 }; 1910 1786 1911 /** Reads parameter from a parsed file. 1787 1912 * The file is either parsed for a certain keyword or if null is given for -
src/config.hpp
rc695c9 r5f612ee 146 146 bool SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const; 147 147 148 void SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules); 149 148 150 void Edit(); 149 151 bool GetIsAngstroem() const; -
src/datacreator.cpp
rc695c9 r5f612ee 771 771 { 772 772 stringstream line(Force.Header[Force.MatrixCounter]); 773 c har *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};773 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; 774 774 string token; 775 775 … … 803 803 { 804 804 stringstream line(Force.Header[Force.MatrixCounter]); 805 c har *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};805 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; 806 806 string token; 807 807 -
src/defs.hpp
rc695c9 r5f612ee 31 31 32 32 enum Shading { white, lightgray, darkgray, black }; //!< color in Breadth-First-Search analysis 33 34 33 35 34 36 //enum CutCyclicBond { KeepBond, SaturateBond }; //!< Saturation scheme either atom- or bondwise … … 76 78 #define UPDATECOUNT 10 //!< update ten sites per BOSSANOVA interval 77 79 80 #define STD_MENU_LENGTH 60 81 #define STD_MENU_TITLE_SPACER '=' 82 #define STD_SEPERATOR_SPACER '-' 83 78 84 #endif /*DEFS_HPP_*/ -
src/element.cpp
rc695c9 r5f612ee 10 10 #include "element.hpp" 11 11 12 using namespace std; 13 12 14 /************************************* Functions for class element **********************************/ 13 15 14 16 /** Constructor of class element. 15 17 */ 16 element::element() { 17 Z = -1; 18 No = -1; 19 previous = NULL; 20 next = NULL; 21 sort = NULL; 18 element::element() : 19 mass(0), 20 CovalentRadius(0), 21 VanDerWaalsRadius(0), 22 Z(-1), 23 previous(NULL), 24 next(NULL), 25 sort(NULL), 26 No(-1), 27 Valence(0), 28 NoValenceOrbitals(0) 29 { 22 30 }; 23 31 … … 29 37 * \param *out outstream 30 38 */ 31 bool element::Output(o fstream * const out) const39 bool element::Output(ostream * const out) const 32 40 { 33 41 if (out != NULL) { … … 44 52 * \param NoOfAtoms total number of atom of this element type 45 53 */ 46 bool element::Checkout(o fstream * const out, const int Number, const int NoOfAtoms) const54 bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const 47 55 { 48 56 if (out != NULL) { … … 52 60 return false; 53 61 }; 62 63 atomicNumber_t element::getNumber() const{ 64 return Z; 65 } 66 67 string element::getSymbol() const{ 68 return string(symbol); 69 } -
src/element.hpp
rc695c9 r5f612ee 9 9 #define ELEMENT_HPP_ 10 10 11 using namespace std;12 13 11 /*********************************************** includes ***********************************/ 14 12 … … 19 17 20 18 #include <iostream> 19 #include <string> 21 20 22 21 #include "defs.hpp" 22 #include "types.hpp" 23 23 24 24 /********************************************** declarations *******************************/ … … 50 50 ~element(); 51 51 52 // accessor functions 53 atomicNumber_t getNumber() const; 54 std::string getSymbol() const; 55 52 56 //> print element entries to screen 53 bool Output( ofstream * const out) const;54 bool Checkout( ofstream * const out, const int No, const int NoOfAtoms) const;57 bool Output(std::ostream * const out) const; 58 bool Checkout(std::ostream * const out, const int No, const int NoOfAtoms) const; 55 59 56 60 private: -
src/errorlogger.cpp
rc695c9 r5f612ee 9 9 #include "errorlogger.hpp" 10 10 #include "verbose.hpp" 11 #include "Patterns/Singleton_impl.hpp" 11 12 12 13 ofstream null("/dev/null"); 13 14 errorLogger* errorLogger::instance = NULL;15 14 int errorLogger::verbosity = 2; 16 15 ostream* errorLogger::nix = &null; … … 23 22 errorLogger::errorLogger() 24 23 { 25 instance = NULL;26 24 verbosity = 2; 27 25 }; … … 34 32 } 35 33 36 /** 37 * Returns the singleton errorLogger instance. 38 * 39 * \return errorLogger instance 40 */ 41 errorLogger* errorLogger::getInstance() { 42 if (instance == NULL) { 43 instance = new errorLogger(); 44 } 45 46 return instance; 47 } 48 49 50 /** 51 * Purges the current errorLogger instance. 52 */ 53 void errorLogger::purgeInstance() { 54 if (instance != NULL) { 55 delete instance; 56 } 57 58 instance = NULL; 59 } 34 CONSTRUCT_SINGLETON(errorLogger) 60 35 61 36 /** -
src/errorlogger.hpp
rc695c9 r5f612ee 11 11 #include <iostream> 12 12 13 #include "Patterns/Singleton.hpp" 14 13 15 using namespace std; 14 16 15 17 class Verbose; 16 18 17 class errorLogger { 19 class errorLogger : public Singleton<errorLogger>{ 20 friend class Singleton<errorLogger>; 18 21 public : 19 22 static ostream *nix; 20 23 static int verbosity; 21 24 22 static errorLogger* getInstance();23 static void purgeInstance();24 25 static bool DoOutput(); 25 26 static void setVerbosity(int verbosityLevel); … … 31 32 ~errorLogger(); 32 33 33 private:34 static errorLogger* instance;35 34 }; 36 35 -
src/gslmatrix.cpp
rc695c9 r5f612ee 178 178 gsl_matrix_set(dest, j,i, gsl_matrix_get(matrix, i,j) ); 179 179 } 180 delete(matrix);180 gsl_matrix_free(matrix); 181 181 matrix = dest; 182 182 flip(rows, columns); -
src/helpers.hpp
rc695c9 r5f612ee 187 187 }; 188 188 189 189 #define PLURAL_S(v) (((v)==1)?"":"s") 190 191 // this is to allow different modes of access for 192 // maps and sets 193 template<typename Res,typename T> 194 struct _take{ 195 Res get(T value) const; 196 }; 197 198 // if we have a set,vector etc we can directly access the result 199 template<typename Res> 200 struct _take<Res,Res>{ 201 static inline Res get(Res value){ 202 return value; 203 } 204 }; 205 206 // if we have a map we have to access the second part of 207 // the pair 208 template<typename Res,typename T1> 209 struct _take<Res,std::pair<T1,Res> >{ 210 static inline Res get(std::pair<T1,Res> value){ 211 return value.second; 212 } 213 }; 190 214 191 215 #endif /*HELPERS_HPP_*/ -
src/leastsquaremin.hpp
rc695c9 r5f612ee 42 42 gsl_vector *x; 43 43 const molecule *mol; 44 element *type;44 const element *type; 45 45 }; 46 46 -
src/lists.hpp
rc695c9 r5f612ee 9 9 #define LISTS_HPP_ 10 10 11 class atom; 12 11 13 /******************************** Some templates for list management ***********************************/ 12 14 … … 18 20 { 19 21 X *vorher = end->previous; 20 if (vorher != NULL)22 if (vorher != 0) 21 23 vorher->next = walker; 22 24 end->previous = walker; … … 31 33 template <typename X> void unlink(X *walker) 32 34 { 33 if (walker->next != NULL)35 if (walker->next != 0) 34 36 walker->next->previous = walker->previous; 35 if (walker->previous != NULL)37 if (walker->previous != 0) 36 38 walker->previous->next = walker->next; 37 walker->next = NULL;38 walker->previous= NULL;39 walker->next = 0; 40 walker->previous= 0; 39 41 }; 40 42 … … 46 48 template <typename X> bool add(X *pointer, X *end) 47 49 { 48 if (end != NULL) {50 if (end != 0) { 49 51 link(pointer, end); 50 52 } else { 51 pointer->previous = NULL;52 pointer->next = NULL;53 pointer->previous = 0; 54 pointer->next = 0; 53 55 } 54 56 return true; … … 59 61 * \param *start begin of list 60 62 * \param *end end of list 61 * \return X - if found, NULL- if not found63 * \return X - if found, 0 - if not found 62 64 */ 63 65 template <typename X, typename Y> X * find(Y *suche, X *start, X *end) … … 68 70 if (*walker->sort == *suche) return (walker); 69 71 } 70 return NULL;72 return 0; 71 73 }; 72 74 … … 77 79 template <typename X> void removewithoutcheck(X *walker) 78 80 { 79 if (walker != NULL) {81 if (walker != 0) { 80 82 unlink(walker); 81 83 delete(walker); 82 walker = NULL;84 walker = 0; 83 85 } 84 86 }; 87 88 /** Removes an item from the list without check. 89 * specialized for atoms, because these have to be removed from the world as well 90 * the implementation for this declaration is in lists.cpp 91 * \param *walker item to be removed 92 * \return true - removing succeeded, false - given item not found in list 93 */ 94 template <> void removewithoutcheck<atom>(atom *walker); 85 95 86 96 /** Removes an item from the list, checks if exists. … … 99 109 }*/ 100 110 // atom found, now unlink 101 if (walker != NULL)111 if (walker != 0) 102 112 removewithoutcheck(walker); 103 113 else … … 114 124 { 115 125 X *pointer = start->next; 116 X *walker = NULL;126 X *walker = 0; 117 127 while (pointer != end) { // go through list 118 128 walker = pointer; // mark current … … 131 141 { 132 142 X *Binder = me; 133 while(Binder->previous != NULL)143 while(Binder->previous != 0) 134 144 Binder = Binder->previous; 135 145 return Binder; … … 143 153 { 144 154 X *Binder = me; 145 while(Binder->next != NULL)155 while(Binder->next != 0) 146 156 Binder = Binder->next; 147 157 return Binder; -
src/log.cpp
rc695c9 r5f612ee 15 15 */ 16 16 void setVerbosity(int verbosityLevel) { 17 logger::getInstance() ->setVerbosity(verbosityLevel);17 logger::getInstance().setVerbosity(verbosityLevel); 18 18 } 19 19 … … 23 23 * \param indentation level of the message to log 24 24 */ 25 class logger *Log() {25 class logger& Log() { 26 26 return logger::getInstance(); 27 27 } … … 35 35 */ 36 36 bool DoLog(int verbose) { 37 return (verbose <= logger::getInstance() ->verbosity);37 return (verbose <= logger::getInstance().verbosity); 38 38 } 39 39 … … 46 46 */ 47 47 bool DoeLog(int verbose) { 48 return (verbose <= errorLogger::getInstance() ->verbosity);48 return (verbose <= errorLogger::getInstance().verbosity); 49 49 } 50 50 … … 54 54 * \param indentation level of the message to log 55 55 */ 56 class errorLogger *eLog() {56 class errorLogger & eLog() { 57 57 return errorLogger::getInstance(); 58 58 } -
src/logger.cpp
rc695c9 r5f612ee 9 9 #include "logger.hpp" 10 10 #include "verbose.hpp" 11 #include "Patterns/Singleton_impl.hpp" 11 12 12 13 ofstream nullStream("/dev/null"); 13 14 14 logger* logger::instance = NULL;15 15 int logger::verbosity = 2; 16 16 ostream* logger::nix = &nullStream; … … 23 23 logger::logger() 24 24 { 25 instance = NULL;26 25 verbosity = 2; 27 26 }; … … 34 33 } 35 34 36 /** 37 * Returns the singleton logger instance. 38 * 39 * \return logger instance 40 */ 41 logger* logger::getInstance() { 42 if (instance == NULL) { 43 instance = new logger(); 44 } 45 46 return instance; 47 } 48 49 50 /** 51 * Purges the current logger instance. 52 */ 53 void logger::purgeInstance() { 54 if (instance != NULL) { 55 delete instance; 56 } 57 58 instance = NULL; 59 } 35 CONSTRUCT_SINGLETON(logger) 60 36 61 37 /** -
src/logger.hpp
rc695c9 r5f612ee 11 11 #include <iostream> 12 12 13 #include "Patterns/Singleton.hpp" 14 13 15 using namespace std; 14 16 15 17 class Verbose; 16 18 17 class logger { 19 class logger : public Singleton<logger> { 20 friend class Singleton<logger>; 18 21 public : 19 22 static ostream *nix; 20 23 static int verbosity; 21 24 22 static logger* getInstance();23 static void purgeInstance();24 25 static bool DoOutput(); 25 26 static void setVerbosity(int verbosityLevel); … … 30 31 /** Do not call this destructor directly, use purgeInstance() instead. */ 31 32 ~logger(); 32 33 private:34 static logger* instance;35 33 }; 36 34 -
src/molecule.cpp
rc695c9 r5f612ee 6 6 7 7 #include <cstring> 8 8 #include <boost/bind.hpp> 9 10 #include "World.hpp" 9 11 #include "atom.hpp" 10 12 #include "bond.hpp" … … 30 32 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 31 33 */ 32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start( new atom), end(new atom),34 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()), 33 35 first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0), 34 36 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), 35 ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start) 37 ActiveFlag(false), IndexNr(-1), 38 formula(this,boost::bind(&molecule::calcFormula,this)), 39 last_atom(0), 40 InternalPointer(start) 36 41 { 37 42 // init atom chain list … … 46 51 for(int i=MAX_ELEMENTS;i--;) 47 52 ElementsInMolecule[i] = 0; 48 strcpy(name,World::get()->DefaultName); 49 }; 53 strcpy(name,World::getInstance().getDefaultName()); 54 }; 55 56 molecule *NewMolecule(){ 57 return new molecule(World::getInstance().getPeriode()); 58 } 50 59 51 60 /** Destructor of class molecule. … … 57 66 delete(first); 58 67 delete(last); 59 delete(end); 60 delete(start); 61 }; 68 end->getWorld()->destroyAtom(end); 69 start->getWorld()->destroyAtom(start); 70 }; 71 72 73 void DeleteMolecule(molecule *mol){ 74 delete mol; 75 } 76 77 // getter and setter 78 const std::string molecule::getName(){ 79 return std::string(name); 80 } 81 82 void molecule::setName(const std::string _name){ 83 OBSERVE; 84 strncpy(name,_name.c_str(),MAXSTRINGSIZE); 85 } 86 87 moleculeId_t molecule::getId(){ 88 return id; 89 } 90 91 void molecule::setId(moleculeId_t _id){ 92 id =_id; 93 } 94 95 const std::string molecule::getFormula(){ 96 return *formula; 97 } 98 99 std::string molecule::calcFormula(){ 100 std::map<atomicNumber_t,unsigned int> counts; 101 stringstream sstr; 102 periodentafel *periode = World::getInstance().getPeriode(); 103 for(atom *Walker = start; Walker != end; Walker = Walker->next) { 104 counts[Walker->type->getNumber()]++; 105 } 106 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; 107 for(iter = counts.rbegin(); iter != counts.rend(); ++iter) { 108 atomicNumber_t Z = (*iter).first; 109 sstr << periode->FindElement(Z)->symbol << (*iter).second; 110 } 111 return sstr.str(); 112 } 62 113 63 114 … … 69 120 bool molecule::AddAtom(atom *pointer) 70 121 { 122 bool retval = false; 123 OBSERVE; 71 124 if (pointer != NULL) { 72 125 pointer->sort = &pointer->nr; … … 85 138 } 86 139 } 87 ret urnadd(pointer, end);88 } else89 return false;140 retval = add(pointer, end); 141 } 142 return retval; 90 143 }; 91 144 … … 97 150 atom * molecule::AddCopyAtom(atom *pointer) 98 151 { 152 atom *retval = NULL; 153 OBSERVE; 99 154 if (pointer != NULL) { 100 atom *walker = new atom(pointer);155 atom *walker = pointer->clone(); 101 156 walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name"); 102 157 strcpy (walker->Name, pointer->Name); … … 106 161 NoNonHydrogen++; 107 162 AtomCount++; 108 ret urnwalker;109 } else110 return NULL;163 retval=walker; 164 } 165 return retval; 111 166 }; 112 167 … … 147 202 bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem) 148 203 { 204 bool AllWentWell = true; // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit 205 OBSERVE; 149 206 double bondlength; // bond length of the bond to be replaced/cut 150 207 double bondangle; // bond angle of the bond to be replaced/cut 151 208 double BondRescale; // rescale value for the hydrogen bond length 152 bool AllWentWell = true; // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit153 209 bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane 154 210 atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added … … 158 214 double *matrix = NULL; 159 215 bond *Binder = NULL; 160 double * const cell_size = World::get ()->cell_size;216 double * const cell_size = World::getInstance().getDomain(); 161 217 162 218 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; … … 205 261 switch(TopBond->BondDegree) { 206 262 case 1: 207 FirstOtherAtom = new atom(); // new atom263 FirstOtherAtom = World::getInstance().createAtom(); // new atom 208 264 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 209 265 FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity … … 262 318 263 319 // create the two Hydrogens ... 264 FirstOtherAtom = new atom();265 SecondOtherAtom = new atom();320 FirstOtherAtom = World::getInstance().createAtom(); 321 SecondOtherAtom = World::getInstance().createAtom(); 266 322 FirstOtherAtom->type = elemente->FindElement(1); 267 323 SecondOtherAtom->type = elemente->FindElement(1); … … 317 373 case 3: 318 374 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid) 319 FirstOtherAtom = new atom();320 SecondOtherAtom = new atom();321 ThirdOtherAtom = new atom();375 FirstOtherAtom = World::getInstance().createAtom(); 376 SecondOtherAtom = World::getInstance().createAtom(); 377 ThirdOtherAtom = World::getInstance().createAtom(); 322 378 FirstOtherAtom->type = elemente->FindElement(1); 323 379 SecondOtherAtom->type = elemente->FindElement(1); … … 413 469 bool molecule::AddXYZFile(string filename) 414 470 { 471 415 472 istringstream *input = NULL; 416 473 int NumberOfAtoms = 0; // atom number in xyz read … … 426 483 return false; 427 484 485 OBSERVE; 428 486 getline(xyzfile,line,'\n'); // Read numer of atoms in file 429 487 input = new istringstream(line); … … 436 494 MDSteps++; 437 495 for(i=0;i<NumberOfAtoms;i++){ 438 Walker = new atom;496 Walker = World::getInstance().createAtom(); 439 497 getline(xyzfile,line,'\n'); 440 498 istringstream *item = new istringstream(line); … … 474 532 molecule *molecule::CopyMolecule() 475 533 { 476 molecule *copy = new molecule(elemente);534 molecule *copy = World::getInstance().createMolecule(); 477 535 atom *LeftAtom = NULL, *RightAtom = NULL; 478 536 … … 517 575 */ 518 576 molecule* molecule::CopyMoleculeFromSubRegion(const Vector offset, const double *parallelepiped) const { 519 molecule *copy = new molecule(elemente);577 molecule *copy = World::getInstance().createMolecule(); 520 578 521 579 ActOnCopyWithEachAtomIfTrue ( &molecule::AddCopyAtom, copy, &atom::IsInParallelepiped, offset, parallelepiped ); … … 603 661 void molecule::SetBoxDimension(Vector *dim) 604 662 { 605 double * const cell_size = World::get ()->cell_size;663 double * const cell_size = World::getInstance().getDomain(); 606 664 cell_size[0] = dim->x[0]; 607 665 cell_size[1] = 0.; … … 694 752 bool molecule::CheckBounds(const Vector *x) const 695 753 { 696 double * const cell_size = World::get ()->cell_size;754 double * const cell_size = World::getInstance().getDomain(); 697 755 bool result = true; 698 756 int j =-1; … … 1085 1143 } 1086 1144 }; 1145 1146 void molecule::flipActiveFlag(){ 1147 ActiveFlag = !ActiveFlag; 1148 } -
src/molecule.hpp
rc695c9 r5f612ee 27 27 #include <vector> 28 28 29 #include <string> 30 31 #include "defs.hpp" 29 32 #include "graph.hpp" 30 33 #include "stackclass.hpp" 31 34 #include "tesselation.hpp" 35 #include "Patterns/Observer.hpp" 36 #include "Patterns/Cacheable.hpp" 32 37 33 38 /****************************************** forward declarations *****************************/ … … 80 85 * Class incorporates number of types 81 86 */ 82 class molecule : public PointCloud { 87 class molecule : public PointCloud , public Observable { 88 friend molecule *NewMolecule(); 89 friend void DeleteMolecule(molecule *); 83 90 public: 84 91 const periodentafel * const elemente; //!< periodic table with each element … … 98 105 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules 99 106 Vector Center; //!< Center of molecule in a global box 107 int IndexNr; //!< index of molecule in a MoleculeListClass 100 108 char name[MAXSTRINGSIZE]; //!< arbitrary name 101 int IndexNr; //!< index of molecule in a MoleculeListClass 102 103 molecule(const periodentafel * const teil); 104 virtual ~molecule(); 109 110 private: 111 Cacheable<string> formula; 112 moleculeId_t id; 113 protected: 114 molecule(const periodentafel * const teil); 115 virtual ~molecule(); 116 117 118 public: 119 //getter and setter 120 const std::string getName(); 121 moleculeId_t getId(); 122 void setId(moleculeId_t); 123 void setName(const std::string); 124 const std::string getFormula(); 125 std::string calcFormula(); 126 105 127 106 128 // re-definition of virtual functions from PointCloud … … 298 320 bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep); 299 321 322 // Manipulation routines 323 void flipActiveFlag(); 324 300 325 private: 301 326 int last_atom; //!< number given to last atom … … 303 328 }; 304 329 330 molecule *NewMolecule(); 331 void DeleteMolecule(molecule* mol); 332 305 333 #include "molecule_template.hpp" 306 334 307 335 /** A list of \a molecule classes. 308 336 */ 309 class MoleculeListClass {337 class MoleculeListClass : public Observable { 310 338 public: 311 339 MoleculeList ListOfMolecules; //!< List of the contained molecules 312 340 int MaxIndex; 313 341 314 MoleculeListClass( );342 MoleculeListClass(World *world); 315 343 ~MoleculeListClass(); 316 344 … … 321 349 bool OutputConfigForListOfFragments(config *configuration, int *SortIndex); 322 350 int NumberOfActiveMolecules(); 323 void Enumerate(o fstream *out);351 void Enumerate(ostream *out); 324 352 void Output(ofstream *out); 325 353 void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration); 326 354 int CountAllAtoms() const; 355 356 // Methods moved here from the menus 357 // TODO: more refactoring needed on these methods 358 void flipChosen(); 359 void createNewMolecule(periodentafel *periode); 360 void loadFromXYZ(periodentafel *periode); 361 void setMoleculeFilename(); 362 void parseXYZIntoMolecule(); 363 void eraseMolecule(); 364 327 365 328 366 // merging of molecules … … 335 373 336 374 private: 375 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor 337 376 }; 338 377 -
src/molecule_dynamics.cpp
rc695c9 r5f612ee 6 6 */ 7 7 8 #include "World.hpp" 8 9 #include "atom.hpp" 9 10 #include "config.hpp" … … 162 163 double molecule::ConstrainedPotential(struct EvaluatePotential &Params) 163 164 { 164 double tmp , result;165 165 double tmp = 0.; 166 double result = 0.; 166 167 // go through every atom 167 168 atom *Runner = NULL; … … 485 486 bool status = true; 486 487 int MaxSteps = configuration.MaxOuterStep; 487 MoleculeListClass *MoleculePerStep = new MoleculeListClass( );488 MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer()); 488 489 // Get the Permutation Map by MinimiseConstrainedPotential 489 490 atom **PermutationMap = NULL; … … 505 506 DoLog(1) && (Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl); 506 507 for (int step = 0; step <= MaxSteps; step++) { 507 mol = new molecule(elemente);508 mol = World::getInstance().createMolecule(); 508 509 MoleculePerStep->insert(mol); 509 510 Walker = start; -
src/molecule_fragmentation.cpp
rc695c9 r5f612ee 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 676 677 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 677 678 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 678 BondFragments = new MoleculeListClass( );679 BondFragments = new MoleculeListClass(World::getPointer()); 679 680 int k=0; 680 681 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { … … 929 930 { 930 931 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList"); 931 molecule *Leaf = new molecule(elemente);932 molecule *Leaf = World::getInstance().createMolecule(); 932 933 933 934 // Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl; … … 1657 1658 atom *Walker = NULL; 1658 1659 atom *OtherWalker = NULL; 1659 double * const cell_size = World::get ()->cell_size;1660 double * const cell_size = World::getInstance().getDomain(); 1660 1661 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 1661 1662 enum Shading *ColorList = NULL; -
src/molecule_geometry.cpp
rc695c9 r5f612ee 27 27 bool status = true; 28 28 const Vector *Center = DetermineCenterOfAll(); 29 double * const cell_size = World::get ()->cell_size;29 double * const cell_size = World::getInstance().getDomain(); 30 30 double *M = ReturnFullMatrixforSymmetric(cell_size); 31 31 double *Minv = InverseMatrix(M); … … 48 48 { 49 49 bool status = true; 50 double * const cell_size = World::get ()->cell_size;50 double * const cell_size = World::getInstance().getDomain(); 51 51 double *M = ReturnFullMatrixforSymmetric(cell_size); 52 52 double *Minv = InverseMatrix(M); … … 229 229 void molecule::TranslatePeriodically(const Vector *trans) 230 230 { 231 double * const cell_size = World::get ()->cell_size;231 double * const cell_size = World::getInstance().getDomain(); 232 232 double *M = ReturnFullMatrixforSymmetric(cell_size); 233 233 double *Minv = InverseMatrix(M); … … 256 256 { 257 257 atom *Walker = start; 258 double * const cell_size = World::get ()->cell_size;258 double * const cell_size = World::getInstance().getDomain(); 259 259 double *matrix = ReturnFullMatrixforSymmetric(cell_size); 260 260 double *inversematrix = InverseMatrix(cell_size); -
src/molecule_graph.cpp
rc695c9 r5f612ee 107 107 LinkedCell *LC = NULL; 108 108 bool free_BG = false; 109 double * const cell_size = World::get ()->cell_size;109 double * const cell_size = World::getInstance().getDomain(); 110 110 111 111 if (BG == NULL) { … … 513 513 // put into new subgraph molecule and add this to list of subgraphs 514 514 LeafWalker = new MoleculeLeafClass(LeafWalker); 515 LeafWalker->Leaf = new molecule(elemente);515 LeafWalker->Leaf = World::getInstance().createMolecule(); 516 516 LeafWalker->Leaf->AddCopyAtom(DFS.Root); 517 517 -
src/molecule_template.hpp
rc695c9 r5f612ee 16 16 #endif 17 17 18 #include "atom.hpp" 18 19 /********************************************** declarations *******************************/ 19 20 -
src/moleculelist.cpp
rc695c9 r5f612ee 7 7 #include <cstring> 8 8 9 #include "World.hpp" 9 10 #include "atom.hpp" 10 11 #include "bond.hpp" … … 25 26 /** Constructor for MoleculeListClass. 26 27 */ 27 MoleculeListClass::MoleculeListClass() 28 MoleculeListClass::MoleculeListClass(World *_world) : 29 world(_world) 28 30 { 29 31 // empty lists … … 39 41 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 40 42 DoLog(4) && (Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl); 41 delete(*ListRunner);43 world->destroyMolecule(*ListRunner); 42 44 } 43 45 DoLog(4) && (Log() << Verbose(4) << "Freeing ListOfMolecules." << endl); … … 51 53 void MoleculeListClass::insert(molecule *mol) 52 54 { 55 OBSERVE; 53 56 mol->IndexNr = MaxIndex++; 54 57 ListOfMolecules.push_back(mol); 58 mol->signOn(this); 55 59 }; 56 60 … … 136 140 * \param *out output stream 137 141 */ 138 void MoleculeListClass::Enumerate(ofstream *out) 139 { 140 element* Elemental = NULL; 142 void MoleculeListClass::Enumerate(ostream *out) 143 { 141 144 atom *Walker = NULL; 142 int Counts[MAX_ELEMENTS]; 145 periodentafel *periode = World::getInstance().getPeriode(); 146 std::map<atomicNumber_t,unsigned int> counts; 143 147 double size=0; 144 148 Vector Origin; 145 149 146 150 // header 147 DoLog(0) && (Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl);148 DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);151 (*out) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl; 152 (*out) << "-----------------------------------------------" << endl; 149 153 if (ListOfMolecules.size() == 0) 150 DoLog(0) && (Log() << Verbose(0) << "\tNone" << endl);154 (*out) << "\tNone" << endl; 151 155 else { 152 156 Origin.Zero(); 153 157 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 154 // reset element counts155 for (int j = 0; j<MAX_ELEMENTS;j++)156 Counts[j] = 0;157 158 // count atoms per element and determine size of bounding sphere 158 159 size=0.; … … 160 161 while (Walker->next != (*ListRunner)->end) { 161 162 Walker = Walker->next; 162 Counts[Walker->type->Z]++;163 counts[Walker->type->getNumber()]++; 163 164 if (Walker->x.DistanceSquared(&Origin) > size) 164 165 size = Walker->x.DistanceSquared(&Origin); 165 166 } 166 167 // output Index, Name, number of atoms, chemical formula 167 DoLog(0) && (Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t");168 Elemental = (*ListRunner)->elemente->end; 169 while(Elemental->previous != (*ListRunner)->elemente->start) {170 Elemental = Elemental->previous;171 if (Counts[Elemental->Z] != 0)172 DoLog(0) && (Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z]);168 (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t"; 169 170 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; 171 for(iter=counts.rbegin(); iter!=counts.rend();++iter){ 172 atomicNumber_t Z =(*iter).first; 173 (*out) << periode->FindElement(Z)->getSymbol() << (*iter).second; 173 174 } 174 175 // Center and size 175 DoLog(0) && (Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl);176 (*out) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl; 176 177 } 177 178 } … … 212 213 // remove src 213 214 ListOfMolecules.remove(srcmol); 214 delete(srcmol);215 World::getInstance().destroyMolecule(srcmol); 215 216 return true; 216 217 }; … … 341 342 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl); 342 343 if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) { 343 CopyAtoms[Walker->nr] = new atom(Walker);344 CopyAtoms[Walker->nr] = Walker->clone(); 344 345 mol->AddAtom(CopyAtoms[Walker->nr]); 345 346 nr++; … … 577 578 stringstream line; 578 579 atom *Walker = NULL; 579 element *runner = NULL;580 periodentafel *periode=World::getInstance().getPeriode(); 580 581 581 582 // open file for the force factors … … 587 588 //output << prefix << "Forces" << endl; 588 589 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 589 runner = (*ListRunner)->elemente->start; 590 while (runner->next != (*ListRunner)->elemente->end) { // go through every element 591 runner = runner->next; 592 if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms 590 periodentafel::const_iterator elemIter; 591 for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){ 592 if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms 593 593 Walker = (*ListRunner)->start; 594 594 while (Walker->next != (*ListRunner)->end) { // go through every atom of this element 595 595 Walker = Walker->next; 596 if (Walker->type-> Z == runner->Z) {596 if (Walker->type->getNumber() == (*elemIter).first) { 597 597 if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea 598 598 //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it … … 640 640 ofstream output; 641 641 double cell_size_backup[6]; 642 double * const cell_size = World::get ()->cell_size;642 double * const cell_size = World::getInstance().getDomain(); 643 643 644 644 // backup cell_size … … 756 756 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration) 757 757 { 758 molecule *mol = new molecule(periode);758 molecule *mol = World::getInstance().createMolecule(); 759 759 atom *Walker = NULL; 760 760 atom *Advancer = NULL; … … 781 781 } 782 782 // remove the molecule 783 delete(*MolRunner);783 World::getInstance().destroyMolecule(*MolRunner); 784 784 ListOfMolecules.erase(MolRunner); 785 785 } … … 787 787 // 1. dissect the molecule into connected subgraphs 788 788 if (!configuration->BG->ConstructBondGraph(mol)) { 789 delete(mol);789 World::getInstance().destroyMolecule(mol); 790 790 DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl); 791 791 return; … … 798 798 delete(BackEdgeStack); 799 799 if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) { 800 delete(mol);800 World::getInstance().destroyMolecule(mol); 801 801 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl); 802 802 return; … … 812 812 molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules"); 813 813 for (int i=0;i<MolCount;i++) { 814 molecules[i] = (molecule*) new molecule(mol->elemente);814 molecules[i] = World::getInstance().createMolecule(); 815 815 molecules[i]->ActiveFlag = true; 816 816 strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE); … … 893 893 return AtomNo; 894 894 } 895 896 /*********** 897 * Methods Moved here from the menus 898 */ 899 900 void MoleculeListClass::flipChosen() { 901 int j; 902 Log() << Verbose(0) << "Enter index of molecule: "; 903 cin >> j; 904 for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) 905 if ((*ListRunner)->IndexNr == j) 906 (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag; 907 } 908 909 void MoleculeListClass::createNewMolecule(periodentafel *periode) { 910 OBSERVE; 911 molecule *mol = NULL; 912 mol = World::getInstance().createMolecule(); 913 insert(mol); 914 }; 915 916 void MoleculeListClass::loadFromXYZ(periodentafel *periode){ 917 molecule *mol = NULL; 918 Vector center; 919 char filename[MAXSTRINGSIZE]; 920 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; 921 mol = World::getInstance().createMolecule(); 922 do { 923 Log() << Verbose(0) << "Enter file name: "; 924 cin >> filename; 925 } while (!mol->AddXYZFile(filename)); 926 mol->SetNameFromFilename(filename); 927 // center at set box dimensions 928 mol->CenterEdge(¢er); 929 World::getInstance().getDomain()[0] = center.x[0]; 930 World::getInstance().getDomain()[1] = 0; 931 World::getInstance().getDomain()[2] = center.x[1]; 932 World::getInstance().getDomain()[3] = 0; 933 World::getInstance().getDomain()[4] = 0; 934 World::getInstance().getDomain()[5] = center.x[2]; 935 insert(mol); 936 } 937 938 void MoleculeListClass::setMoleculeFilename() { 939 char filename[MAXSTRINGSIZE]; 940 int nr; 941 molecule *mol = NULL; 942 do { 943 Log() << Verbose(0) << "Enter index of molecule: "; 944 cin >> nr; 945 mol = ReturnIndex(nr); 946 } while (mol == NULL); 947 Log() << Verbose(0) << "Enter name: "; 948 cin >> filename; 949 mol->SetNameFromFilename(filename); 950 } 951 952 void MoleculeListClass::parseXYZIntoMolecule(){ 953 char filename[MAXSTRINGSIZE]; 954 int nr; 955 molecule *mol = NULL; 956 mol = NULL; 957 do { 958 Log() << Verbose(0) << "Enter index of molecule: "; 959 cin >> nr; 960 mol = ReturnIndex(nr); 961 } while (mol == NULL); 962 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; 963 do { 964 Log() << Verbose(0) << "Enter file name: "; 965 cin >> filename; 966 } while (!mol->AddXYZFile(filename)); 967 mol->SetNameFromFilename(filename); 968 }; 969 970 void MoleculeListClass::eraseMolecule(){ 971 int nr; 972 molecule *mol = NULL; 973 Log() << Verbose(0) << "Enter index of molecule: "; 974 cin >> nr; 975 for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) 976 if (nr == (*ListRunner)->IndexNr) { 977 mol = *ListRunner; 978 ListOfMolecules.erase(ListRunner); 979 World::getInstance().destroyMolecule(mol); 980 break; 981 } 982 }; 895 983 896 984 … … 936 1024 // remove the leaf itself 937 1025 if (Leaf != NULL) { 938 delete(Leaf);1026 World::getInstance().destroyMolecule(Leaf); 939 1027 Leaf = NULL; 940 1028 } -
src/periodentafel.cpp
rc695c9 r5f612ee 10 10 #include <fstream> 11 11 #include <cstring> 12 #include <cassert> 12 13 13 14 #include "element.hpp" … … 18 19 #include "verbose.hpp" 19 20 21 using namespace std; 22 20 23 /************************************* Functions for class periodentafel ***************************/ 21 24 … … 23 26 * Initialises start and end of list and resets periodentafel::checkliste to false. 24 27 */ 25 periodentafel::periodentafel() : start(new element), end(new element) 26 { 27 start->previous = NULL; 28 start->next = end; 29 end->previous = start; 30 end->next = NULL; 31 }; 28 periodentafel::periodentafel() 29 {}; 32 30 33 31 /** destructor for class periodentafel … … 37 35 { 38 36 CleanupPeriodtable(); 39 delete(end);40 delete(start);41 37 }; 42 38 … … 45 41 * \return true - succeeded, false - does not occur 46 42 */ 47 bool periodentafel::AddElement(element * const pointer) 48 { 43 periodentafel::iterator periodentafel::AddElement(element * const pointer) 44 { 45 atomicNumber_t Z = pointer->getNumber(); 46 assert(!elements.count(Z)); 49 47 pointer->sort = &pointer->Z; 50 if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS) 51 DoLog(0) && (Log() << Verbose(0) << "Invalid Z number!\n"); 52 return add(pointer, end); 48 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) 49 DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n"); 50 pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer)); 51 return res.first; 53 52 }; 54 53 … … 57 56 * \return true - succeeded, false - element not found 58 57 */ 59 bool periodentafel::RemoveElement(element * const pointer) 60 { 61 return remove(pointer, start, end); 58 void periodentafel::RemoveElement(element * const pointer) 59 { 60 atomicNumber_t Z = pointer->getNumber(); 61 elements.erase(Z); 62 62 }; 63 63 … … 65 65 * \return true - succeeded, false - does not occur 66 66 */ 67 bool periodentafel::CleanupPeriodtable() 68 { 69 return cleanup(start,end); 67 void periodentafel::CleanupPeriodtable() 68 { 69 for(iterator iter=elements.begin();iter!=elements.end();++iter){ 70 delete(*iter).second; 71 } 72 elements.clear(); 70 73 }; 71 74 … … 75 78 * \return pointer to element or NULL if not found 76 79 */ 77 element * const periodentafel::FindElement(const int Z) const78 { 79 element *walker = find(&Z, start,end);80 return (walker);80 const element * periodentafel::FindElement(atomicNumber_t Z) const 81 { 82 const_iterator res = elements.find(Z); 83 return res!=elements.end()?((*res).second):0; 81 84 }; 82 85 … … 86 89 * \return pointer to element 87 90 */ 88 element * const periodentafel::FindElement(const char * const shorthand) const 89 { 90 element *walker = periodentafel::start; 91 while (walker->next != periodentafel::end) { 92 walker = walker->next; 93 if (strncmp(walker->symbol, shorthand, 3) == 0) 94 return(walker); 95 } 96 return (NULL); 91 const element * periodentafel::FindElement(const char * const shorthand) const 92 { 93 element *res = 0; 94 for(const_iterator iter=elements.begin();iter!=elements.end();++iter) { 95 if((*iter).second->getSymbol() == shorthand){ 96 res = (*iter).second; 97 break; 98 } 99 } 100 return res; 97 101 }; 98 102 99 103 /** Asks for element number and returns pointer to element 100 104 */ 101 element * constperiodentafel::AskElement() const102 { 103 element *walker = NULL;105 const element * periodentafel::AskElement() const 106 { 107 const element *walker = NULL; 104 108 int Z; 105 109 do { … … 114 118 * \return pointer to either present or newly created element 115 119 */ 116 element * constperiodentafel::EnterElement()117 { 118 element *walker= NULL;119 int Z = -1;120 const element * periodentafel::EnterElement() 121 { 122 const element *res = NULL; 123 atomicNumber_t Z = 0; 120 124 DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl); 121 125 cin >> Z; 122 walker = FindElement(Z); 123 if (walker == NULL) { 126 res = FindElement(Z); 127 if (!res) { 128 // TODO: make this using the constructor 129 element *tmp; 124 130 DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl); 125 walker= new element;126 walker->Z = Z;131 tmp = new element; 132 tmp->Z = Z; 127 133 DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl); 128 cin >> walker->mass;134 cin >> tmp->mass; 129 135 DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl); 130 cin >> walker->name;136 cin >> tmp->name; 131 137 DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl); 132 cin >> walker->symbol; 133 periodentafel::AddElement(walker); 134 } 135 return(walker); 136 }; 138 cin >> tmp->symbol; 139 AddElement(tmp); 140 res = tmp; 141 } 142 return res; 143 }; 144 145 146 /******************** Access to iterators ****************************/ 147 periodentafel::const_iterator periodentafel::begin(){ 148 return elements.begin(); 149 } 150 151 periodentafel::const_iterator periodentafel::end(){ 152 return elements.end(); 153 } 154 155 periodentafel::reverse_iterator periodentafel::rbegin(){ 156 return reverse_iterator(elements.end()); 157 } 158 159 periodentafel::reverse_iterator periodentafel::rend(){ 160 return reverse_iterator(elements.begin()); 161 } 137 162 138 163 /** Prints period table to given stream. 139 164 * \param output stream 140 165 */ 141 bool periodentafel::Output(o fstream * const output) const166 bool periodentafel::Output(ostream * const output) const 142 167 { 143 168 bool result = true; 144 element *walker = start;145 169 if (output != NULL) { 146 while (walker->next != end) { 147 walker = walker->next; 148 result = result && walker->Output(output); 170 for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){ 171 result = result && (*iter).second->Output(output); 149 172 } 150 173 return result; … … 157 180 * \param *checkliste elements table for this molecule 158 181 */ 159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const 160 { 161 element *walker = start; 182 bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const 183 { 162 184 bool result = true; 163 185 int No = 1; … … 166 188 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 167 189 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; 168 while (walker->next != end) { 169 walker = walker->next; 170 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) { 171 walker->No = No; 172 result = result && walker->Checkout(output, No++, checkliste[walker->Z]); 190 for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){ 191 if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) { 192 (*iter).second->No = No; 193 result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]); 173 194 } 174 195 } … … 184 205 { 185 206 ifstream infile; 186 double tmp;187 207 element *ptr; 208 map<atomicNumber_t,element*> parsedElems; 188 209 bool status = true; 189 210 bool otherstatus = true; … … 223 244 //neues->Output((ofstream *)&cout); 224 245 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 225 p eriodentafel::AddElement(neues);246 parsedElems[neues->getNumber()] = neues; 226 247 else { 227 248 DoLog(0) && (Log() << Verbose(0) << "Could not parse element: "); … … 243 264 if (infile != NULL) { 244 265 while (!infile.eof()) { 245 infile >> tmp; 246 infile >> ws; 247 infile >> FindElement((int)tmp)->Valence; 266 atomicNumber_t Z; 267 infile >> Z; 268 infile >> ws; 269 infile >> parsedElems[Z]->Valence; 248 270 infile >> ws; 249 271 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; … … 261 283 if (infile != NULL) { 262 284 while (!infile.eof()) { 263 infile >> tmp; 264 infile >> ws; 265 infile >> FindElement((int)tmp)->NoValenceOrbitals; 285 atomicNumber_t Z; 286 infile >> Z; 287 infile >> ws; 288 infile >> parsedElems[Z]->NoValenceOrbitals; 266 289 infile >> ws; 267 290 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; … … 279 302 if (infile != NULL) { 280 303 while (!infile.eof()) { 281 infile >> tmp; 282 ptr = FindElement((int)tmp); 304 atomicNumber_t Z; 305 infile >> Z; 306 ptr = parsedElems[Z]; 283 307 infile >> ws; 284 308 infile >> ptr->HBondDistance[0]; … … 300 324 if (infile != NULL) { 301 325 while (!infile.eof()) { 302 infile >> tmp; 303 ptr = FindElement((int)tmp); 326 atomicNumber_t Z; 327 infile >> Z; 328 ptr = parsedElems[Z]; 304 329 infile >> ws; 305 330 infile >> ptr->HBondAngle[0]; … … 313 338 otherstatus = false; 314 339 315 if (!otherstatus) 340 if (otherstatus){ 341 map<atomicNumber_t,element*>::iterator iter; 342 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 343 AddElement((*iter).second); 344 } 345 } 346 else{ 316 347 DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl); 348 map<atomicNumber_t,element*>::iterator iter; 349 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 350 AddElement((*iter).second); 351 } 352 } 317 353 318 354 return status; … … 334 370 f << header1 << endl; 335 371 f << header2 << endl; 336 element *walker = periodentafel::start; 337 while (walker->next != periodentafel::end) { 338 walker = walker->next; 339 result = result && walker->Output(&f); 372 for(const_iterator iter=elements.begin();iter!=elements.end();++iter){ 373 result = result && (*iter).second->Output(&f); 340 374 } 341 375 f.close(); -
src/periodentafel.hpp
rc695c9 r5f612ee 1 1 #ifndef PERIODENTAFEL_HPP_ 2 2 #define PERIODENTAFEL_HPP_ 3 4 using namespace std;5 3 6 4 /*********************************************** includes ***********************************/ … … 12 10 13 11 #include <iostream> 12 #include <map> 13 #include <iterator> 14 14 15 15 #include "defs.hpp" 16 #include "types.hpp" 16 17 17 18 /****************************************** forward declarations *****************************/ … … 25 26 */ 26 27 class periodentafel { 28 /******* Types *********/ 29 private: 30 typedef std::map<atomicNumber_t,element*> elementSet; 27 31 public: 28 element *start; //!< start of element list 29 element *end; //!< end of element list 32 typedef elementSet::iterator iterator; 33 typedef elementSet::const_iterator const_iterator; 34 typedef std::reverse_iterator<const_iterator> reverse_iterator; 35 public: 36 30 37 char header1[MAXSTRINGSIZE]; //!< store first header line 31 38 char header2[MAXSTRINGSIZE]; //!< store second header line … … 34 41 ~periodentafel(); 35 42 36 bool AddElement(element * const pointer); 37 bool RemoveElement(element * const pointer); 38 bool CleanupPeriodtable(); 39 element * const FindElement(const int Z) const; 40 element * const FindElement(const char * const shorthand) const; 41 element * const AskElement() const; 42 element * const EnterElement(); 43 bool Output(ofstream * const output) const; 44 bool Checkout(ofstream * const output, const int * const checkliste) const; 43 iterator AddElement(element * const pointer); 44 void RemoveElement(element * const pointer); 45 void CleanupPeriodtable(); 46 const element *FindElement(atomicNumber_t) const; 47 const element *FindElement(const char * const shorthand) const; 48 const element *AskElement() const; 49 const element *EnterElement(); 50 51 const_iterator begin(); 52 const_iterator end(); 53 reverse_iterator rbegin(); 54 reverse_iterator rend(); 55 bool Output(std::ostream * const output) const; 56 bool Checkout(std::ostream * const output, const int * const checkliste) const; 45 57 bool LoadPeriodentafel(const char * const path); 46 58 bool StorePeriodentafel(const char * const path) const; 47 59 48 60 private: 61 elementSet elements; 49 62 }; 50 63 -
src/tesselation.cpp
rc695c9 r5f612ee 4938 4938 } 4939 4939 } 4940 delete (DegeneratedTriangles); 4940 delete DegeneratedTriangles; 4941 4941 4942 /// 3. Find connected endpoint candidates and put them into a polygon 4942 4943 UniquePolygonSet ListofDegeneratedPolygons; -
src/tesselationhelpers.cpp
rc695c9 r5f612ee 27 27 int signum; 28 28 gsl_permutation *p = gsl_permutation_alloc(A->size1); 29 gsl_matrix *tmpA ;29 gsl_matrix *tmpA=0; 30 30 31 31 if (inPlace) -
src/unittests/ActOnAllUnitTest.cpp
rc695c9 r5f612ee 16 16 #include "memoryallocator.hpp" 17 17 #include "vector.hpp" 18 19 #ifdef HAVE_TESTRUNNER 20 #include "UnitTestMain.hpp" 21 #endif /*HAVE_TESTRUNNER*/ 18 22 19 23 /********************************************** Test classes **************************************/ … … 40 44 { 41 45 VL.EmptyList(); 46 // Ref was copy constructed, hence has to be cleaned, too! 47 Ref.EmptyList(); 48 MemoryUsageObserver::purgeInstance(); 42 49 }; 43 50 … … 88 95 VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses ); 89 96 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 97 Free(factors); 98 Free(inverses); 90 99 }; 91 100 … … 108 117 } 109 118 }; 110 111 112 /********************************************** Main routine **************************************/113 114 int main(int argc, char **argv)115 {116 // Get the top level suite from the registry117 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();118 119 // Adds the test to the list of test to run120 CppUnit::TextUi::TestRunner runner;121 runner.addTest( suite );122 123 // Change the default outputter to a compiler error format outputter124 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),125 std::cerr ) );126 // Run the tests.127 bool wasSucessful = runner.run();128 129 // Return error code 1 if the one of test failed.130 return wasSucessful ? 0 : 1;131 }; -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
rc695c9 r5f612ee 17 17 #include "AnalysisCorrelationToPointUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 24 25 #include "periodentafel.hpp" 25 26 #include "tesselation.hpp" 27 #include "World.hpp" 28 29 #ifdef HAVE_TESTRUNNER 30 #include "UnitTestMain.hpp" 31 #endif /*HAVE_TESTRUNNER*/ 26 32 27 33 /********************************************** Test classes **************************************/ … … 51 57 52 58 // construct periodentafel 53 tafel = new periodentafel;59 tafel = World::getInstance().getPeriode(); 54 60 tafel->AddElement(hydrogen); 55 61 56 62 // construct molecule (tetraeder of hydrogens) 57 TestMolecule = new molecule(tafel);58 Walker = new atom();63 TestMolecule = World::getInstance().createMolecule(); 64 Walker = World::getInstance().createAtom(); 59 65 Walker->type = hydrogen; 60 66 Walker->node->Init(1., 0., 1. ); 61 67 TestMolecule->AddAtom(Walker); 62 Walker = new atom();68 Walker = World::getInstance().createAtom(); 63 69 Walker->type = hydrogen; 64 70 Walker->node->Init(0., 1., 1. ); 65 71 TestMolecule->AddAtom(Walker); 66 Walker = new atom();72 Walker = World::getInstance().createAtom(); 67 73 Walker->type = hydrogen; 68 74 Walker->node->Init(1., 1., 0. ); 69 75 TestMolecule->AddAtom(Walker); 70 Walker = new atom();76 Walker = World::getInstance().createAtom(); 71 77 Walker->type = hydrogen; 72 78 Walker->node->Init(0., 0., 0. ); … … 76 82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 77 83 78 TestList = new MoleculeListClass; 84 TestList = World::getInstance().getMolecules(); 85 TestList->insert(TestMolecule); 79 86 TestMolecule->ActiveFlag = true; 80 TestList->insert(TestMolecule);81 87 82 88 // init point … … 97 103 delete(binmap); 98 104 99 // remove100 delete(TestList);101 // note that all the atoms are cleaned by TestMolecule102 105 delete(point); 103 delete(tafel); 104 // note that element is cleaned by periodentafel 106 World::purgeInstance(); 107 MemoryUsageObserver::purgeInstance(); 108 logger::purgeInstance(); 105 109 }; 106 110 … … 140 144 141 145 }; 142 143 /********************************************** Main routine **************************************/144 145 int main(int argc, char **argv)146 {147 // Get the top level suite from the registry148 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();149 150 // Adds the test to the list of test to run151 CppUnit::TextUi::TestRunner runner;152 runner.addTest( suite );153 154 // Change the default outputter to a compiler error format outputter155 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),156 std::cerr ) );157 // Run the tests.158 bool wasSucessful = runner.run();159 160 // Return error code 1 if the one of test failed.161 return wasSucessful ? 0 : 1;162 }; -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
rc695c9 r5f612ee 17 17 #include "AnalysisCorrelationToSurfaceUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 24 25 #include "periodentafel.hpp" 25 26 #include "tesselation.hpp" 27 #include "World.hpp" 28 29 #include "Helpers/Assert.hpp" 30 31 #ifdef HAVE_TESTRUNNER 32 #include "UnitTestMain.hpp" 33 #endif /*HAVE_TESTRUNNER*/ 26 34 27 35 /********************************************** Test classes **************************************/ … … 32 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 33 41 { 42 ASSERT_DO(Assert::Throw); 43 34 44 atom *Walker = NULL; 35 45 … … 55 65 56 66 // construct periodentafel 57 tafel = new periodentafel;67 tafel = World::getInstance().getPeriode(); 58 68 tafel->AddElement(hydrogen); 59 69 tafel->AddElement(carbon); 60 70 61 71 // construct molecule (tetraeder of hydrogens) base 62 TestSurfaceMolecule = new molecule(tafel);63 Walker = new atom();72 TestSurfaceMolecule = World::getInstance().createMolecule(); 73 Walker = World::getInstance().createAtom(); 64 74 Walker->type = hydrogen; 65 75 Walker->node->Init(1., 0., 1. ); 66 76 TestSurfaceMolecule->AddAtom(Walker); 67 Walker = new atom();77 Walker = World::getInstance().createAtom(); 68 78 Walker->type = hydrogen; 69 79 Walker->node->Init(0., 1., 1. ); 70 80 TestSurfaceMolecule->AddAtom(Walker); 71 Walker = new atom();81 Walker = World::getInstance().createAtom(); 72 82 Walker->type = hydrogen; 73 83 Walker->node->Init(1., 1., 0. ); 74 84 TestSurfaceMolecule->AddAtom(Walker); 75 Walker = new atom();85 Walker = World::getInstance().createAtom(); 76 86 Walker->type = hydrogen; 77 87 Walker->node->Init(0., 0., 0. ); … … 81 91 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 ); 82 92 83 TestList = new MoleculeListClass;93 TestList = World::getInstance().getMolecules(); 84 94 TestSurfaceMolecule->ActiveFlag = true; 85 95 TestList->insert(TestSurfaceMolecule); … … 91 101 92 102 // add outer atoms 93 TestMolecule = new molecule(tafel);94 Walker = new atom();103 TestMolecule = World::getInstance().createMolecule(); 104 Walker = World::getInstance().createAtom(); 95 105 Walker->type = carbon; 96 106 Walker->node->Init(4., 0., 4. ); 97 107 TestMolecule->AddAtom(Walker); 98 Walker = new atom();108 Walker = World::getInstance().createAtom(); 99 109 Walker->type = carbon; 100 110 Walker->node->Init(0., 4., 4. ); 101 111 TestMolecule->AddAtom(Walker); 102 Walker = new atom();112 Walker = World::getInstance().createAtom(); 103 113 Walker->type = carbon; 104 114 Walker->node->Init(4., 4., 0. ); 105 115 TestMolecule->AddAtom(Walker); 106 116 // add inner atoms 107 Walker = new atom();117 Walker = World::getInstance().createAtom(); 108 118 Walker->type = carbon; 109 119 Walker->node->Init(0.5, 0.5, 0.5 ); … … 126 136 delete(binmap); 127 137 128 // remove129 delete(TestList);130 138 delete(Surface); 131 139 // note that all the atoms are cleaned by TestMolecule 132 140 delete(LC); 133 delete(tafel); 134 // note that element is cleaned by periodentafel 141 World::purgeInstance(); 142 MemoryUsageObserver::purgeInstance(); 143 logger::purgeInstance(); 135 144 }; 136 145 … … 227 236 CPPUNIT_ASSERT_EQUAL( 1, tester->second ); 228 237 }; 229 230 /********************************************** Main routine **************************************/231 232 int main(int argc, char **argv)233 {234 // Get the top level suite from the registry235 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();236 237 // Adds the test to the list of test to run238 CppUnit::TextUi::TestRunner runner;239 runner.addTest( suite );240 241 // Change the default outputter to a compiler error format outputter242 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),243 std::cerr ) );244 // Run the tests.245 bool wasSucessful = runner.run();246 247 // Return error code 1 if the one of test failed.248 return wasSucessful ? 0 : 1;249 }; -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
rc695c9 r5f612ee 17 17 #include "AnalysisPairCorrelationUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 24 25 #include "periodentafel.hpp" 25 26 #include "tesselation.hpp" 27 #include "World.hpp" 28 29 #ifdef HAVE_TESTRUNNER 30 #include "UnitTestMain.hpp" 31 #endif /*HAVE_TESTRUNNER*/ 26 32 27 33 /********************************************** Test classes **************************************/ … … 50 56 51 57 // construct periodentafel 52 tafel = new periodentafel;58 tafel = World::getInstance().getPeriode(); 53 59 tafel->AddElement(hydrogen); 54 60 55 61 // construct molecule (tetraeder of hydrogens) 56 TestMolecule = new molecule(tafel);57 Walker = new atom();62 TestMolecule = World::getInstance().createMolecule(); 63 Walker = World::getInstance().createAtom(); 58 64 Walker->type = hydrogen; 59 65 Walker->node->Init(1., 0., 1. ); 60 66 TestMolecule->AddAtom(Walker); 61 Walker = new atom();67 Walker = World::getInstance().createAtom(); 62 68 Walker->type = hydrogen; 63 69 Walker->node->Init(0., 1., 1. ); 64 70 TestMolecule->AddAtom(Walker); 65 Walker = new atom();71 Walker = World::getInstance().createAtom(); 66 72 Walker->type = hydrogen; 67 73 Walker->node->Init(1., 1., 0. ); 68 74 TestMolecule->AddAtom(Walker); 69 Walker = new atom();75 Walker = World::getInstance().createAtom(); 70 76 Walker->type = hydrogen; 71 77 Walker->node->Init(0., 0., 0. ); … … 75 81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 76 82 77 TestList = new MoleculeListClass;83 TestList = World::getInstance().getMolecules(); 78 84 TestMolecule->ActiveFlag = true; 79 85 TestList->insert(TestMolecule); … … 93 99 delete(binmap); 94 100 95 // remove96 delete(TestList);97 101 // note that all the atoms are cleaned by TestMolecule 98 delete(tafel); 99 // note that element is cleaned by periodentafel 102 World::purgeInstance(); 103 MemoryUsageObserver::purgeInstance(); 104 logger::purgeInstance(); 105 errorLogger::purgeInstance(); 100 106 }; 101 107 … … 132 138 CPPUNIT_ASSERT_EQUAL( 6, tester->second ); 133 139 }; 134 135 /********************************************** Main routine **************************************/136 137 int main(int argc, char **argv)138 {139 // Get the top level suite from the registry140 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();141 142 // Adds the test to the list of test to run143 CppUnit::TextUi::TestRunner runner;144 runner.addTest( suite );145 146 // Change the default outputter to a compiler error format outputter147 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),148 std::cerr ) );149 // Run the tests.150 bool wasSucessful = runner.run();151 152 // Return error code 1 if the one of test failed.153 return wasSucessful ? 0 : 1;154 }; -
src/unittests/CountBondsUnitTest.cpp
rc695c9 r5f612ee 24 24 #include "molecule.hpp" 25 25 #include "periodentafel.hpp" 26 #include "World.hpp" 26 27 #include "CountBondsUnitTest.hpp" 28 29 #ifdef HAVE_TESTRUNNER 30 #include "UnitTestMain.hpp" 31 #endif /*HAVE_TESTRUNNER*/ 27 32 28 33 /********************************************** Test classes **************************************/ … … 35 40 { 36 41 atom *Walker = NULL; 42 BG = NULL; 43 filename = NULL; 37 44 38 45 // init private all pointers to zero … … 57 64 58 65 // construct periodentafel 59 tafel = new periodentafel;66 tafel = World::getInstance().getPeriode(); 60 67 tafel->AddElement(hydrogen); 61 68 tafel->AddElement(oxygen); 62 69 63 70 // construct molecule (water molecule) 64 molecules = new MoleculeListClass; 65 TestMolecule1 = new molecule(tafel); 66 Walker = new atom(); 71 TestMolecule1 = World::getInstance().createMolecule(); 72 Walker = World::getInstance().createAtom(); 67 73 Walker->type = hydrogen; 68 74 Walker->node->Init(-0.2418, 0.9350, 0. ); 69 75 TestMolecule1->AddAtom(Walker); 70 Walker = new atom();76 Walker = World::getInstance().createAtom(); 71 77 Walker->type = hydrogen; 72 78 Walker->node->Init(0.9658, 0., 0. ); 73 79 TestMolecule1->AddAtom(Walker); 74 Walker = new atom();80 Walker = World::getInstance().createAtom(); 75 81 Walker->type = oxygen; 76 82 Walker->node->Init(0., 0., 0. ); 77 83 TestMolecule1->AddAtom(Walker); 78 molecules->insert(TestMolecule1); 79 80 TestMolecule2 = new molecule(tafel); 81 Walker = new atom(); 84 85 TestMolecule2 = World::getInstance().createMolecule(); 86 Walker = World::getInstance().createAtom(); 82 87 Walker->type = hydrogen; 83 88 Walker->node->Init(-0.2418, 0.9350, 0. ); 84 89 TestMolecule2->AddAtom(Walker); 85 Walker = new atom();90 Walker = World::getInstance().createAtom(); 86 91 Walker->type = hydrogen; 87 92 Walker->node->Init(0.9658, 0., 0. ); 88 93 TestMolecule2->AddAtom(Walker); 89 Walker = new atom();94 Walker = World::getInstance().createAtom(); 90 95 Walker->type = oxygen; 91 96 Walker->node->Init(0., 0., 0. ); 92 97 TestMolecule2->AddAtom(Walker); 98 99 molecules = World::getInstance().getMolecules(); 100 molecules->insert(TestMolecule1); 93 101 molecules->insert(TestMolecule2); 94 102 … … 117 125 delete(BG); 118 126 119 // remove molecule 120 delete(molecules); 121 // note that all the atoms are cleaned by TestMolecule 122 delete(tafel); 123 // note that element is cleaned by periodentafel 127 World::purgeInstance(); 128 MemoryUsageObserver::purgeInstance(); 124 129 }; 125 130 … … 232 237 TestMolecule2->Scale((const double ** const)&mirror); 233 238 234 delete(mirror); 235 }; 236 237 238 /********************************************** Main routine **************************************/ 239 240 int main(int argc, char **argv) 241 { 242 // Get the top level suite from the registry 243 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); 244 245 // Adds the test to the list of test to run 246 CppUnit::TextUi::TestRunner runner; 247 runner.addTest( suite ); 248 249 // Change the default outputter to a compiler error format outputter 250 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), 251 std::cerr ) ); 252 // Run the tests. 253 bool wasSucessful = runner.run(); 254 255 // Return error code 1 if the one of test failed. 256 return wasSucessful ? 0 : 1; 257 }; 239 delete[](mirror); 240 }; -
src/unittests/LinkedCellUnitTest.cpp
rc695c9 r5f612ee 22 22 #include "periodentafel.hpp" 23 23 #include "LinkedCellUnitTest.hpp" 24 #include "World.hpp" 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 24 29 25 30 /********************************************** Test classes **************************************/ … … 46 51 47 52 // construct periodentafel 48 tafel = new periodentafel;53 tafel = World::getInstance().getPeriode(); 49 54 tafel->AddElement(hydrogen); 50 55 51 56 // construct molecule (water molecule) 52 TestMolecule = new molecule(tafel);57 TestMolecule = World::getInstance().createMolecule(); 53 58 for (double x=0.5;x<3;x+=1.) 54 59 for (double y=0.5;y<3;y+=1.) 55 60 for (double z=0.5;z<3;z+=1.) { 56 Walker = new atom();61 Walker = World::getInstance().createAtom(); 57 62 Walker->type = hydrogen; 58 63 Walker->node->Init(x, y, z ); … … 73 78 { 74 79 delete(LC); 75 delete(TestMolecule); 76 // note that all the atoms are cleaned by TestMolecule 77 delete(tafel); 78 // note that element is cleaned by periodentafel 80 World::purgeInstance(); 81 MemoryUsageObserver::purgeInstance(); 79 82 }; 80 83 … … 201 204 202 205 // check internal vectors, returns false, because this atom is not in LC-list! 203 Walker = new atom();206 Walker = World::getInstance().createAtom(); 204 207 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 205 208 strcpy(Walker->Name, "test"); 206 209 Walker->x.Init(1,1,1); 207 210 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 208 delete(Walker);211 World::getInstance().destroyAtom(Walker); 209 212 210 213 // check out of bounds vectors 211 Walker = new atom();214 Walker = World::getInstance().createAtom(); 212 215 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 213 216 strcpy(Walker->Name, "test"); 214 217 Walker->x.Init(0,-1,0); 215 218 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 216 delete(Walker);219 World::getInstance().destroyAtom(Walker); 217 220 }; 218 221 … … 368 371 delete(ListOfPoints); 369 372 }; 370 371 /********************************************** Main routine **************************************/372 373 int main(int argc, char **argv)374 {375 // Get the top level suite from the registry376 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();377 378 // Adds the test to the list of test to run379 CppUnit::TextUi::TestRunner runner;380 runner.addTest( suite );381 382 // Change the default outputter to a compiler error format outputter383 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),384 std::cerr ) );385 // Run the tests.386 bool wasSucessful = runner.run();387 388 // Return error code 1 if the one of test failed.389 return wasSucessful ? 0 : 1;390 };391 -
src/unittests/Makefile.am
rc695c9 r5f612ee 3 3 AM_LDFLAGS = $(CPPUNIT_LIBS) -ldl 4 4 AM_CXXFLAGS = $(CPPUNIT_CFLAGS) 5 6 MENUTESTS = \ 7 ActionSequenceTest 5 8 6 9 TESTS = \ … … 10 13 AnalysisCorrelationToSurfaceUnitTest \ 11 14 AnalysisPairCorrelationUnitTest \ 15 atomsCalculationTest \ 16 AtomDescriptorTest \ 12 17 BondGraphUnitTest \ 18 CacheableTest \ 13 19 CountBondsUnitTest \ 14 20 GSLMatrixSymmetricUnitTest \ … … 20 26 ListOfBondsUnitTest \ 21 27 LogUnitTest \ 28 manipulateAtomsTest \ 22 29 MemoryUsageObserverUnitTest \ 23 30 MemoryAllocatorUnitTest \ 31 MoleculeDescriptorTest \ 32 ObserverTest \ 33 SingletonTest \ 24 34 StackClassUnitTest \ 25 35 TesselationUnitTest \ 26 36 Tesselation_BoundaryTriangleUnitTest \ 27 37 Tesselation_InOutsideUnitTest \ 28 VectorUnitTest 38 VectorUnitTest \ 39 ${MENUTESTS} 29 40 30 check_PROGRAMS = $(TESTS) 31 noinst_PROGRAMS = $(TESTS) 32 33 ActOnAllUnitTest_SOURCES = ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp 34 ActOnAllUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 35 36 AnalysisBondsUnitTests_SOURCES = analysisbondsunittest.cpp analysisbondsunittest.hpp 37 AnalysisBondsUnitTests_LDADD = ../libmolecuilder.a ../libgslwrapper.a 38 39 AnalysisCorrelationToPointUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp 40 AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 41 42 AnalysisCorrelationToSurfaceUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp 43 AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 44 45 AnalysisPairCorrelationUnitTest_SOURCES = analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp 46 AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 47 48 BondGraphUnitTest_SOURCES = bondgraphunittest.cpp bondgraphunittest.hpp 49 BondGraphUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 50 51 CountBondsUnitTest_SOURCES = CountBondsUnitTest.cpp CountBondsUnitTest.hpp 52 CountBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 53 54 GSLMatrixSymmetricUnitTest_SOURCES = gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp 55 GSLMatrixSymmetricUnitTest_LDADD = ../libgslwrapper.a 56 57 GSLMatrixUnitTest_SOURCES = gslmatrixunittest.cpp gslmatrixunittest.hpp 58 GSLMatrixUnitTest_LDADD = ../libgslwrapper.a 59 60 GSLVectorUnitTest_SOURCES = gslvectorunittest.cpp gslvectorunittest.hpp 61 GSLVectorUnitTest_LDADD = ../libgslwrapper.a 62 63 InfoUnitTest_SOURCES = infounittest.cpp infounittest.hpp 64 InfoUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 65 66 LinearSystemOfEquationsUnitTest_SOURCES = linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp 67 LinearSystemOfEquationsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 68 69 LinkedCellUnitTest_SOURCES = LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 70 LinkedCellUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 71 72 ListOfBondsUnitTest_SOURCES = listofbondsunittest.cpp listofbondsunittest.hpp 73 ListOfBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 74 75 LogUnitTest_SOURCES = logunittest.cpp logunittest.hpp 76 LogUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 77 78 MemoryAllocatorUnitTest_SOURCES = memoryallocatorunittest.cpp memoryallocatorunittest.hpp 79 MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 80 81 MemoryUsageObserverUnitTest_SOURCES = memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp 82 MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 83 84 StackClassUnitTest_SOURCES = stackclassunittest.cpp stackclassunittest.hpp 85 StackClassUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 86 87 TesselationUnitTest_SOURCES = tesselationunittest.cpp tesselationunittest.hpp 88 TesselationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 89 90 Tesselation_BoundaryTriangleUnitTest_SOURCES = tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp 91 Tesselation_BoundaryTriangleUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 92 93 Tesselation_InOutsideUnitTest_SOURCES = tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp 94 Tesselation_InOutsideUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 95 96 VectorUnitTest_SOURCES = vectorunittest.cpp vectorunittest.hpp 97 VectorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a 98 41 42 check_PROGRAMS = $(TESTS) 43 noinst_PROGRAMS = $(TESTS) TestRunner 44 45 GSLLIBS = ../libgslwrapper.a 46 ALLLIBS = ../libmolecuilder.a ${GSLLIBS} $(BOOST_LIB) ${BOOST_THREAD_LIB} 47 48 TESTSOURCES = \ 49 ActOnAllUnitTest.cpp \ 50 ActionSequenceTest.cpp \ 51 analysisbondsunittest.cpp \ 52 AnalysisCorrelationToPointUnitTest.cpp \ 53 AnalysisCorrelationToSurfaceUnitTest.cpp \ 54 AnalysisPairCorrelationUnitTest.cpp \ 55 AtomDescriptorTest.cpp \ 56 atomsCalculationTest.cpp \ 57 bondgraphunittest.cpp \ 58 CacheableTest.cpp \ 59 CountBondsUnitTest.cpp \ 60 gslmatrixsymmetricunittest.cpp \ 61 gslmatrixunittest.cpp \ 62 gslvectorunittest.cpp \ 63 infounittest.cpp \ 64 linearsystemofequationsunittest.cpp \ 65 LinkedCellUnitTest.cpp \ 66 listofbondsunittest.cpp \ 67 logunittest.cpp \ 68 manipulateAtomsTest.cpp \ 69 memoryallocatorunittest.cpp \ 70 memoryusageobserverunittest.cpp \ 71 MoleculeDescriptorTest.cpp \ 72 ObserverTest.cpp \ 73 SingletonTest.cpp \ 74 stackclassunittest.cpp \ 75 tesselationunittest.cpp \ 76 tesselation_boundarytriangleunittest.cpp \ 77 tesselation_insideoutsideunittest.cpp \ 78 vectorunittest.cpp 79 80 TESTHEADERS = \ 81 ActOnAllUnitTest.hpp \ 82 ActionSequenceTest.hpp \ 83 analysisbondsunittest.hpp \ 84 AnalysisCorrelationToPointUnitTest.hpp \ 85 AnalysisCorrelationToSurfaceUnitTest.hpp \ 86 AnalysisPairCorrelationUnitTest.hpp \ 87 AtomDescriptorTest.hpp \ 88 atomsCalculationTest.hpp \ 89 bondgraphunittest.hpp \ 90 CacheableTest.hpp \ 91 CountBondsUnitTest.hpp \ 92 gslmatrixsymmetricunittest.hpp \ 93 gslmatrixunittest.hpp \ 94 gslvectorunittest.hpp \ 95 infounittest.hpp \ 96 linearsystemofequationsunittest.hpp \ 97 LinkedCellUnitTest.hpp \ 98 listofbondsunittest.hpp \ 99 logunittest.hpp \ 100 manipulateAtomsTest.hpp \ 101 memoryallocatorunittest.hpp \ 102 memoryusageobserverunittest.hpp \ 103 MoleculeDescriptorTest.hpp \ 104 ObserverTest.hpp \ 105 SingletonTest.hpp \ 106 stackclassunittest.hpp \ 107 tesselationunittest.hpp \ 108 tesselation_boundarytriangleunittest.hpp \ 109 tesselation_insideoutsideunittest.hpp \ 110 vectorunittest.hpp 111 112 113 ActOnAllUnitTest_SOURCES = UnitTestMain.cpp ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp 114 ActOnAllUnitTest_LDADD = ${ALLLIBS} 115 116 AnalysisBondsUnitTests_SOURCES = UnitTestMain.cpp analysisbondsunittest.cpp analysisbondsunittest.hpp 117 AnalysisBondsUnitTests_LDADD = ${ALLLIBS} 118 119 AnalysisCorrelationToPointUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp 120 AnalysisCorrelationToPointUnitTest_LDADD = ${ALLLIBS} 121 122 AnalysisCorrelationToSurfaceUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp 123 AnalysisCorrelationToSurfaceUnitTest_LDADD = ${ALLLIBS} 124 125 AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp 126 AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS} 127 128 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp 129 atomsCalculationTest_LDADD = ${ALLLIBS} 130 131 BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp 132 BondGraphUnitTest_LDADD = ${ALLLIBS} 133 134 CountBondsUnitTest_SOURCES = UnitTestMain.cpp CountBondsUnitTest.cpp CountBondsUnitTest.hpp 135 CountBondsUnitTest_LDADD = ${ALLLIBS} 136 137 GSLMatrixSymmetricUnitTest_SOURCES = UnitTestMain.cpp gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp 138 GSLMatrixSymmetricUnitTest_LDADD = ${GSLLIBS} 139 140 GSLMatrixUnitTest_SOURCES = UnitTestMain.cpp gslmatrixunittest.cpp gslmatrixunittest.hpp 141 GSLMatrixUnitTest_LDADD = ${GSLLIBS} 142 143 GSLVectorUnitTest_SOURCES = UnitTestMain.cpp gslvectorunittest.cpp gslvectorunittest.hpp 144 GSLVectorUnitTest_LDADD = ${GSLLIBS} 145 146 InfoUnitTest_SOURCES = UnitTestMain.cpp infounittest.cpp infounittest.hpp 147 InfoUnitTest_LDADD = ${ALLLIBS} 148 149 LinearSystemOfEquationsUnitTest_SOURCES = UnitTestMain.cpp linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp 150 LinearSystemOfEquationsUnitTest_LDADD = ${ALLLIBS} 151 152 LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 153 LinkedCellUnitTest_LDADD = ${ALLLIBS} 154 155 ListOfBondsUnitTest_SOURCES = UnitTestMain.cpp listofbondsunittest.cpp listofbondsunittest.hpp 156 ListOfBondsUnitTest_LDADD = ${ALLLIBS} 157 158 LogUnitTest_SOURCES = UnitTestMain.cpp logunittest.cpp logunittest.hpp 159 LogUnitTest_LDADD = ${ALLLIBS} 160 161 MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp 162 MemoryAllocatorUnitTest_LDADD = ${ALLLIBS} 163 164 MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp 165 MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS} 166 167 MoleculeDescriptorTest_SOURCES = UnitTestMain.cpp MoleculeDescriptorTest.cpp MoleculeDescriptorTest.hpp 168 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 169 170 SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp 171 SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB} 172 173 StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp 174 StackClassUnitTest_LDADD = ${ALLLIBS} 175 176 TesselationUnitTest_SOURCES = UnitTestMain.cpp tesselationunittest.cpp tesselationunittest.hpp 177 TesselationUnitTest_LDADD = ${ALLLIBS} 178 179 Tesselation_BoundaryTriangleUnitTest_SOURCES = UnitTestMain.cpp tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp 180 Tesselation_BoundaryTriangleUnitTest_LDADD = ${ALLLIBS} 181 182 Tesselation_InOutsideUnitTest_SOURCES = UnitTestMain.cpp tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp 183 Tesselation_InOutsideUnitTest_LDADD = ${ALLLIBS} 184 185 VectorUnitTest_SOURCES = UnitTestMain.cpp vectorunittest.cpp vectorunittest.hpp 186 VectorUnitTest_LDADD = ${ALLLIBS} 187 188 ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp 189 ActionSequenceTest_LDADD = ${ALLLIBS} 190 191 ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp 192 ObserverTest_LDADD = ${ALLLIBS} 193 194 CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp 195 CacheableTest_LDADD = ${ALLLIBS} 196 197 AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp 198 AtomDescriptorTest_LDADD = ${ALLLIBS} 199 200 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp 201 manipulateAtomsTest_LDADD = ${ALLLIBS} 202 203 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS) 204 TestRunner_LDADD = ${ALLLIBS} 99 205 100 206 #AUTOMAKE_OPTIONS = parallel-tests -
src/unittests/analysisbondsunittest.cpp
rc695c9 r5f612ee 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "analysis_bonds.hpp" 19 20 #include "analysisbondsunittest.hpp" … … 24 25 #include "molecule.hpp" 25 26 #include "periodentafel.hpp" 27 28 #ifdef HAVE_TESTRUNNER 29 #include "UnitTestMain.hpp" 30 #endif /*HAVE_TESTRUNNER*/ 26 31 27 32 /********************************************** Test classes **************************************/ … … 56 61 57 62 // construct periodentafel 58 tafel = new periodentafel;63 tafel = World::getInstance().getPeriode(); 59 64 tafel->AddElement(hydrogen); 60 65 tafel->AddElement(carbon); 61 66 62 67 // construct molecule (tetraeder of hydrogens) 63 TestMolecule = new molecule(tafel);64 Walker = new atom();68 TestMolecule = World::getInstance().createMolecule(); 69 Walker = World::getInstance().createAtom(); 65 70 Walker->type = hydrogen; 66 71 Walker->node->Init(1.5, 0., 1.5 ); 67 72 TestMolecule->AddAtom(Walker); 68 Walker = new atom();73 Walker = World::getInstance().createAtom(); 69 74 Walker->type = hydrogen; 70 75 Walker->node->Init(0., 1.5, 1.5 ); 71 76 TestMolecule->AddAtom(Walker); 72 Walker = new atom();77 Walker = World::getInstance().createAtom(); 73 78 Walker->type = hydrogen; 74 79 Walker->node->Init(1.5, 1.5, 0. ); 75 80 TestMolecule->AddAtom(Walker); 76 Walker = new atom();81 Walker = World::getInstance().createAtom(); 77 82 Walker->type = hydrogen; 78 83 Walker->node->Init(0., 0., 0. ); 79 84 TestMolecule->AddAtom(Walker); 80 Walker = new atom();85 Walker = World::getInstance().createAtom(); 81 86 Walker->type = carbon; 82 87 Walker->node->Init(0.5, 0.5, 0.5 ); … … 112 117 113 118 // remove molecule 114 delete(TestMolecule);119 World::getInstance().destroyMolecule(TestMolecule); 115 120 // note that all the atoms are cleaned by TestMolecule 116 delete(tafel); 117 // note that element is cleaned by periodentafel 121 World::purgeInstance(); 118 122 }; 119 123 … … 163 167 CPPUNIT_ASSERT_EQUAL( 0. , Max ); 164 168 }; 165 166 167 /********************************************** Main routine **************************************/168 169 int main(int argc, char **argv)170 {171 // Get the top level suite from the registry172 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();173 174 // Adds the test to the list of test to run175 CppUnit::TextUi::TestRunner runner;176 runner.addTest( suite );177 178 // Change the default outputter to a compiler error format outputter179 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),180 std::cerr ) );181 // Run the tests.182 bool wasSucessful = runner.run();183 184 // Return error code 1 if the one of test failed.185 return wasSucessful ? 0 : 1;186 }; -
src/unittests/bondgraphunittest.cpp
rc695c9 r5f612ee 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 24 25 #include "periodentafel.hpp" 25 26 #include "bondgraphunittest.hpp" 27 #include "World.hpp" 28 29 #ifdef HAVE_TESTRUNNER 30 #include "UnitTestMain.hpp" 31 #endif /*HAVE_TESTRUNNER*/ 26 32 27 33 /********************************************** Test classes **************************************/ … … 56 62 57 63 // construct periodentafel 58 tafel = new periodentafel;64 tafel = World::getInstance().getPeriode(); 59 65 tafel->AddElement(hydrogen); 60 66 tafel->AddElement(carbon); 61 67 62 68 // construct molecule (tetraeder of hydrogens) 63 TestMolecule = new molecule(tafel);64 Walker = new atom();69 TestMolecule = World::getInstance().createMolecule(); 70 Walker = World::getInstance().createAtom(); 65 71 Walker->type = carbon; 66 72 Walker->node->Init(1., 0., 1. ); 67 73 TestMolecule->AddAtom(Walker); 68 Walker = new atom();74 Walker = World::getInstance().createAtom(); 69 75 Walker->type = carbon; 70 76 Walker->node->Init(0., 1., 1. ); 71 77 TestMolecule->AddAtom(Walker); 72 Walker = new atom();78 Walker = World::getInstance().createAtom(); 73 79 Walker->type = carbon; 74 80 Walker->node->Init(1., 1., 0. ); 75 81 TestMolecule->AddAtom(Walker); 76 Walker = new atom();82 Walker = World::getInstance().createAtom(); 77 83 Walker->type = carbon; 78 84 Walker->node->Init(0., 0., 0. ); … … 103 109 104 110 // remove molecule 105 delete(TestMolecule); 106 // note that all the atoms are cleaned by TestMolecule 107 delete(tafel); 108 // note that element is cleaned by periodentafel 111 World::getInstance().destroyMolecule(TestMolecule); 112 // note that all the atoms, molecules, the tafel and the elements 113 // are all cleaned when the world is destroyed 114 World::purgeInstance(); 115 MemoryUsageObserver::purgeInstance(); 116 logger::purgeInstance(); 109 117 }; 110 118 … … 143 151 }; 144 152 145 146 /********************************************** Main routine **************************************/147 148 int main(int argc, char **argv)149 {150 // Get the top level suite from the registry151 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();152 153 // Adds the test to the list of test to run154 CppUnit::TextUi::TestRunner runner;155 runner.addTest( suite );156 157 // Change the default outputter to a compiler error format outputter158 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),159 std::cerr ) );160 // Run the tests.161 bool wasSucessful = runner.run();162 163 // Return error code 1 if the one of test failed.164 return wasSucessful ? 0 : 1;165 }; -
src/unittests/gslmatrixsymmetricunittest.cpp
rc695c9 r5f612ee 13 13 14 14 #include "gslmatrixsymmetricunittest.hpp" 15 16 #ifdef HAVE_TESTRUNNER 17 #include "UnitTestMain.hpp" 18 #endif /*HAVE_TESTRUNNER*/ 15 19 16 20 /********************************************** Test classes **************************************/ … … 266 270 CPPUNIT_ASSERT_EQUAL( -26.5, m->Determinant() ); 267 271 }; 268 269 /********************************************** Main routine **************************************/270 271 int main(int argc, char **argv)272 {273 // Get the top level suite from the registry274 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();275 276 // Adds the test to the list of test to run277 CppUnit::TextUi::TestRunner runner;278 runner.addTest( suite );279 280 // Change the default outputter to a compiler error format outputter281 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),282 std::cerr ) );283 // Run the tests.284 bool wasSucessful = runner.run();285 286 // Return error code 1 if the one of test failed.287 return wasSucessful ? 0 : 1;288 }; -
src/unittests/gslmatrixunittest.cpp
rc695c9 r5f612ee 13 13 14 14 #include "gslmatrixunittest.hpp" 15 16 #ifdef HAVE_TESTRUNNER 17 #include "UnitTestMain.hpp" 18 #endif /*HAVE_TESTRUNNER*/ 15 19 16 20 /********************************************** Test classes **************************************/ … … 248 252 CPPUNIT_ASSERT_EQUAL( false, m->IsPositiveDefinite() ); 249 253 }; 250 251 /********************************************** Main routine **************************************/252 253 int main(int argc, char **argv)254 {255 // Get the top level suite from the registry256 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();257 258 // Adds the test to the list of test to run259 CppUnit::TextUi::TestRunner runner;260 runner.addTest( suite );261 262 // Change the default outputter to a compiler error format outputter263 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),264 std::cerr ) );265 // Run the tests.266 bool wasSucessful = runner.run();267 268 // Return error code 1 if the one of test failed.269 return wasSucessful ? 0 : 1;270 }; -
src/unittests/gslvectorunittest.cpp
rc695c9 r5f612ee 13 13 14 14 #include "gslvectorunittest.hpp" 15 16 #ifdef HAVE_TESTRUNNER 17 #include "UnitTestMain.hpp" 18 #endif /*HAVE_TESTRUNNER*/ 15 19 16 20 /********************************************** Test classes **************************************/ … … 114 118 }; 115 119 116 117 120 /** UnitTest for operators. 118 121 */ … … 160 163 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() ); 161 164 }; 162 163 /********************************************** Main routine **************************************/164 165 int main(int argc, char **argv)166 {167 // Get the top level suite from the registry168 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();169 170 // Adds the test to the list of test to run171 CppUnit::TextUi::TestRunner runner;172 runner.addTest( suite );173 174 // Change the default outputter to a compiler error format outputter175 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),176 std::cerr ) );177 // Run the tests.178 bool wasSucessful = runner.run();179 180 // Return error code 1 if the one of test failed.181 return wasSucessful ? 0 : 1;182 }; -
src/unittests/infounittest.cpp
rc695c9 r5f612ee 17 17 #include "info.hpp" 18 18 #include "infounittest.hpp" 19 #include "log.hpp" 20 21 #ifdef HAVE_TESTRUNNER 22 #include "UnitTestMain.hpp" 23 #endif /*HAVE_TESTRUNNER*/ 19 24 20 25 /********************************************** Test classes **************************************/ … … 31 36 void InfoTest::tearDown() 32 37 { 38 logger::purgeInstance(); 33 39 }; 34 40 … … 43 49 CPPUNIT_ASSERT_EQUAL( 1, test.verbosity ); 44 50 }; 45 46 47 /********************************************** Main routine **************************************/48 49 int main(int argc, char **argv)50 {51 // Get the top level suite from the registry52 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();53 54 // Adds the test to the list of test to run55 CppUnit::TextUi::TestRunner runner;56 runner.addTest( suite );57 58 // Change the default outputter to a compiler error format outputter59 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),60 std::cerr ) );61 // Run the tests.62 bool wasSucessful = runner.run();63 64 // Return error code 1 if the one of test failed.65 return wasSucessful ? 0 : 1;66 }; -
src/unittests/linearsystemofequationsunittest.cpp
rc695c9 r5f612ee 15 15 #include "linearsystemofequationsunittest.hpp" 16 16 #include "vector.hpp" 17 18 #ifdef HAVE_TESTRUNNER 19 #include "UnitTestMain.hpp" 20 #endif /*HAVE_TESTRUNNER*/ 17 21 18 22 /********************************************** Test classes **************************************/ … … 103 107 delete[](array); 104 108 }; 105 106 /********************************************** Main routine **************************************/107 108 int main(int argc, char **argv)109 {110 // Get the top level suite from the registry111 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();112 113 // Adds the test to the list of test to run114 CppUnit::TextUi::TestRunner runner;115 runner.addTest( suite );116 117 // Change the default outputter to a compiler error format outputter118 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),119 std::cerr ) );120 // Run the tests.121 bool wasSucessful = runner.run();122 123 // Return error code 1 if the one of test failed.124 return wasSucessful ? 0 : 1;125 }; -
src/unittests/listofbondsunittest.cpp
rc695c9 r5f612ee 16 16 #include "listofbondsunittest.hpp" 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 21 22 #include "molecule.hpp" 22 23 #include "periodentafel.hpp" 24 #include "World.hpp" 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 23 29 24 30 /********************************************** Test classes **************************************/ … … 45 51 46 52 // construct periodentafel 47 tafel = new periodentafel;53 tafel = World::getInstance().getPeriode(); 48 54 tafel->AddElement(hydrogen); 49 55 50 56 // construct molecule (tetraeder of hydrogens) 51 TestMolecule = new molecule(tafel);52 Walker = new atom();57 TestMolecule = World::getInstance().createMolecule(); 58 Walker = World::getInstance().createAtom(); 53 59 Walker->type = hydrogen; 54 60 Walker->node->Init(1., 0., 1. ); 55 61 TestMolecule->AddAtom(Walker); 56 Walker = new atom();62 Walker = World::getInstance().createAtom(); 57 63 Walker->type = hydrogen; 58 64 Walker->node->Init(0., 1., 1. ); 59 65 TestMolecule->AddAtom(Walker); 60 Walker = new atom();66 Walker = World::getInstance().createAtom(); 61 67 Walker->type = hydrogen; 62 68 Walker->node->Init(1., 1., 0. ); 63 69 TestMolecule->AddAtom(Walker); 64 Walker = new atom();70 Walker = World::getInstance().createAtom(); 65 71 Walker->type = hydrogen; 66 72 Walker->node->Init(0., 0., 0. ); … … 76 82 { 77 83 // remove 78 delete(TestMolecule); 79 // note that all the atoms are cleaned by TestMolecule 80 delete(tafel); 81 // note that element is cleaned by periodentafel 84 World::getInstance().destroyMolecule(TestMolecule); 85 // note that all the atoms, molecules, the tafel and the elements 86 // are all cleaned when the world is destroyed 87 World::purgeInstance(); 88 MemoryUsageObserver::purgeInstance(); 89 logger::purgeInstance(); 82 90 }; 83 91 … … 242 250 243 251 // remove atom2 244 delete(atom2);252 World::getInstance().destroyAtom(atom2); 245 253 246 254 // check bond if removed from other atom … … 250 258 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last ); 251 259 }; 252 253 /********************************************** Main routine **************************************/254 255 int main(int argc, char **argv)256 {257 // Get the top level suite from the registry258 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();259 260 // Adds the test to the list of test to run261 CppUnit::TextUi::TestRunner runner;262 runner.addTest( suite );263 264 // Change the default outputter to a compiler error format outputter265 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),266 std::cerr ) );267 // Run the tests.268 bool wasSucessful = runner.run();269 270 // Return error code 1 if the one of test failed.271 return wasSucessful ? 0 : 1;272 }; -
src/unittests/logunittest.cpp
rc695c9 r5f612ee 15 15 #include "verbose.hpp" 16 16 17 #ifdef HAVE_TESTRUNNER 18 #include "UnitTestMain.hpp" 19 #endif /*HAVE_TESTRUNNER*/ 20 17 21 /********************************************** Test classes **************************************/ 18 22 … … 27 31 void LogTest::tearDown() 28 32 { 33 logger::purgeInstance(); 34 errorLogger::purgeInstance(); 29 35 }; 30 36 … … 34 40 void LogTest::logTest() 35 41 { 36 logger::getInstance() ->setVerbosity(2);42 logger::getInstance().setVerbosity(2); 37 43 DoLog(0) && (Log() << Verbose(0) << "Verbosity level is set to 2." << endl); 38 44 DoLog(0) && (Log() << Verbose(0) << "Test level 0" << endl); … … 48 54 DoeLog(4) && (eLog()<< Verbose(4) << "This should not be printed." << endl); 49 55 }; 50 51 52 /********************************************** Main routine **************************************/53 54 int main(int argc, char **argv)55 {56 // Get the top level suite from the registry57 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();58 59 // Adds the test to the list of test to run60 CppUnit::TextUi::TestRunner runner;61 runner.addTest( suite );62 63 // Change the default outputter to a compiler error format outputter64 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),65 std::cerr ) );66 // Run the tests.67 bool wasSucessful = runner.run();68 69 // Return error code 1 if the one of test failed.70 return wasSucessful ? 0 : 1;71 }; -
src/unittests/memoryallocatorunittest.cpp
rc695c9 r5f612ee 13 13 #include "memoryallocatorunittest.hpp" 14 14 #include "helpers.hpp" 15 #include "log.hpp" 15 16 #include "defs.hpp" 17 18 #ifdef HAVE_TESTRUNNER 19 #include "UnitTestMain.hpp" 20 #endif /*HAVE_TESTRUNNER*/ 16 21 17 22 /********************************************** Test classes **************************************/ … … 29 34 { 30 35 MemoryUsageObserver::getInstance()->purgeInstance(); 36 logger::purgeInstance(); 31 37 }; 32 38 … … 102 108 Free(buffer2); 103 109 }; 104 105 106 /********************************************** Main routine **************************************/107 108 int main(int argc, char **argv)109 {110 // Get the top level suite from the registry111 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();112 113 // Adds the test to the list of test to run114 CppUnit::TextUi::TestRunner runner;115 runner.addTest( suite );116 117 // Change the default outputter to a compiler error format outputter118 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),119 std::cerr ) );120 // Run the tests.121 bool wasSucessful = runner.run();122 123 // Return error code 1 if the one of test failed.124 return wasSucessful ? 0 : 1;125 }; -
src/unittests/memoryusageobserverunittest.cpp
rc695c9 r5f612ee 14 14 #include "memoryusageobserverunittest.hpp" 15 15 16 #ifdef HAVE_TESTRUNNER 17 #include "UnitTestMain.hpp" 18 #endif /*HAVE_TESTRUNNER*/ 19 16 20 /********************************************** Test classes **************************************/ 17 21 // Registers the fixture into the 'registry' … … 27 31 { 28 32 MemoryUsageObserver::purgeInstance(); 33 logger::purgeInstance(); 34 errorLogger::purgeInstance(); 29 35 }; 30 36 … … 70 76 MemoryUsageObserver::getInstance()->removeMemory(i); 71 77 CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize()); 78 Free(i); 72 79 }; 73 80 … … 80 87 MemoryUsageObserver::getInstance()->removeMemory(i); 81 88 CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize()); 89 Free(i); 82 90 }; 83 91 … … 92 100 MemoryUsageObserver::getInstance()->addMemory(j, sizeof(int)); 93 101 CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize()); 102 Free(i); 103 Free(j); 94 104 }; 95 105 … … 103 113 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int)); 104 114 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize()); 115 Free(i); 105 116 }; 106 117 … … 114 125 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int)); 115 126 CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory()); 127 Free(i); 116 128 }; 117 129 … … 125 137 MemoryUsageObserver::getInstance()->removeMemory(i); 126 138 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory()); 139 Free(i); 127 140 }; 128 141 … … 135 148 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int)); 136 149 CPPUNIT_ASSERT_EQUAL(i, (int*) MemoryUsageObserver::getInstance()->getPointersToAllocatedMemory().begin()->first); 150 Free(i); 137 151 }; 138 139 140 /********************************************** Main routine **************************************/141 142 int main(int argc, char **argv)143 {144 // Get the top level suite from the registry145 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();146 147 // Adds the test to the list of test to run148 CppUnit::TextUi::TestRunner runner;149 runner.addTest( suite );150 151 // Change the default outputter to a compiler error format outputter152 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),153 std::cerr ) );154 // Run the tests.155 bool wasSucessful = runner.run();156 157 // Return error code 1 if the one of test failed.158 return wasSucessful ? 0 : 1;159 }; -
src/unittests/stackclassunittest.cpp
rc695c9 r5f612ee 14 14 #include "stackclassunittest.hpp" 15 15 #include "log.hpp" 16 17 #ifdef HAVE_TESTRUNNER 18 #include "UnitTestMain.hpp" 19 #endif /*HAVE_TESTRUNNER*/ 16 20 17 21 enum { testdimension=3 }; … … 33 37 Stack->ClearStack(); 34 38 delete(Stack); 39 MemoryUsageObserver::purgeInstance(); 40 logger::purgeInstance(); 35 41 }; 36 42 … … 67 73 CPPUNIT_ASSERT_EQUAL(0, Stack->ItemCount()); 68 74 }; 69 70 71 /********************************************** Main routine **************************************/72 73 int main(int argc, char **argv)74 {75 // Get the top level suite from the registry76 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();77 78 // Adds the test to the list of test to run79 CppUnit::TextUi::TestRunner runner;80 runner.addTest( suite );81 82 // Change the default outputter to a compiler error format outputter83 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),84 std::cerr ) );85 // Run the tests.86 bool wasSucessful = runner.run();87 88 // Return error code 1 if the one of test failed.89 return wasSucessful ? 0 : 1;90 }; -
src/unittests/tesselation_boundarytriangleunittest.cpp
rc695c9 r5f612ee 18 18 #include "tesselation_boundarytriangleunittest.hpp" 19 19 20 #ifdef HAVE_TESTRUNNER 21 #include "UnitTestMain.hpp" 22 #endif /*HAVE_TESTRUNNER*/ 23 20 24 #define SPHERERADIUS 2. 21 25 … … 31 35 32 36 // create nodes 33 TesselPoint *Walker = NULL; 34 Walker = new TesselPoint; 35 Walker->node = new Vector(0., 0., 0.); 36 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 37 strcpy(Walker->Name, "1"); 38 Walker->nr = 1; 39 points[0] = new BoundaryPointSet(Walker); 40 Walker = new TesselPoint; 41 Walker->node = new Vector(0., 1., 0.); 42 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 43 strcpy(Walker->Name, "2"); 44 Walker->nr = 2; 45 points[1] = new BoundaryPointSet(Walker); 46 Walker = new TesselPoint; 47 Walker->node = new Vector(1., 0., 0.); 48 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 49 strcpy(Walker->Name, "3"); 50 Walker->nr = 3; 51 points[2] = new BoundaryPointSet(Walker); 37 tesselpoints[0] = new TesselPoint; 38 tesselpoints[0]->node = new Vector(0., 0., 0.); 39 tesselpoints[0]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 40 strcpy(tesselpoints[0]->Name, "1"); 41 tesselpoints[0]->nr = 1; 42 points[0] = new BoundaryPointSet(tesselpoints[0]); 43 tesselpoints[1] = new TesselPoint; 44 tesselpoints[1]->node = new Vector(0., 1., 0.); 45 tesselpoints[1]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 46 strcpy(tesselpoints[1]->Name, "2"); 47 tesselpoints[1]->nr = 2; 48 points[1] = new BoundaryPointSet(tesselpoints[1]); 49 tesselpoints[2] = new TesselPoint; 50 tesselpoints[2] ->node = new Vector(1., 0., 0.); 51 tesselpoints[2] ->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name"); 52 strcpy(tesselpoints[2] ->Name, "3"); 53 tesselpoints[2] ->nr = 3; 54 points[2] = new BoundaryPointSet(tesselpoints[2] ); 52 55 53 56 // create line … … 65 68 { 66 69 delete(triangle); 70 for (int i=0;i<3;++i) { 71 // TesselPoint does not delete its vector as it only got a reference 72 delete tesselpoints[i]->node; 73 delete tesselpoints[i]; 74 } 67 75 MemoryUsageObserver::purgeInstance(); 68 76 logger::purgeInstance(); … … 191 199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 192 200 }; 193 194 195 /********************************************** Main routine **************************************/196 197 int main(int argc, char **argv)198 {199 // Get the top level suite from the registry200 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();201 202 // Adds the test to the list of test to run203 CppUnit::TextUi::TestRunner runner;204 runner.addTest( suite );205 206 // Change the default outputter to a compiler error format outputter207 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),208 std::cerr ) );209 // Run the tests.210 bool wasSucessful = runner.run();211 212 // Return error code 1 if the one of test failed.213 return wasSucessful ? 0 : 1;214 }; -
src/unittests/tesselation_boundarytriangleunittest.hpp
rc695c9 r5f612ee 35 35 class BoundaryLineSet *lines[3]; 36 36 class BoundaryPointSet *points[3]; 37 class TesselPoint *tesselpoints[3]; 37 38 LinkedCell::LinkedNodes Corners; 38 39 }; -
src/unittests/tesselation_insideoutsideunittest.cpp
rc695c9 r5f612ee 17 17 #include "tesselation.hpp" 18 18 #include "tesselation_insideoutsideunittest.hpp" 19 20 #ifdef HAVE_TESTRUNNER 21 #include "UnitTestMain.hpp" 22 #endif /*HAVE_TESTRUNNER*/ 19 23 20 24 #define SPHERERADIUS 2. … … 161 165 } 162 166 }; 163 164 /********************************************** Main routine **************************************/165 166 int main(int argc, char **argv)167 {168 // Get the top level suite from the registry169 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();170 171 // Adds the test to the list of test to run172 CppUnit::TextUi::TestRunner runner;173 runner.addTest( suite );174 175 // Change the default outputter to a compiler error format outputter176 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),177 std::cerr ) );178 // Run the tests.179 bool wasSucessful = runner.run();180 181 // Return error code 1 if the one of test failed.182 return wasSucessful ? 0 : 1;183 }; -
src/unittests/tesselationunittest.cpp
rc695c9 r5f612ee 18 18 #include "tesselation.hpp" 19 19 #include "tesselationunittest.hpp" 20 21 #ifdef HAVE_TESTRUNNER 22 #include "UnitTestMain.hpp" 23 #endif /*HAVE_TESTRUNNER*/ 20 24 21 25 #define SPHERERADIUS 2. … … 177 181 } 178 182 } 179 180 /********************************************** Main routine **************************************/181 182 int main(int argc, char **argv)183 {184 // Get the top level suite from the registry185 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();186 187 // Adds the test to the list of test to run188 CppUnit::TextUi::TestRunner runner;189 runner.addTest( suite );190 191 // Change the default outputter to a compiler error format outputter192 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),193 std::cerr ) );194 // Run the tests.195 bool wasSucessful = runner.run();196 197 // Return error code 1 if the one of test failed.198 return wasSucessful ? 0 : 1;199 }; -
src/unittests/vectorunittest.cpp
rc695c9 r5f612ee 14 14 15 15 #include "defs.hpp" 16 #include "log.hpp" 17 #include "memoryusageobserver.hpp" 16 18 #include "vector.hpp" 17 19 #include "vectorunittest.hpp" 20 21 #ifdef HAVE_TESTRUNNER 22 #include "UnitTestMain.hpp" 23 #endif /*HAVE_TESTRUNNER*/ 18 24 19 25 /********************************************** Test classes **************************************/ … … 35 41 void VectorTest::tearDown() 36 42 { 43 MemoryUsageObserver::purgeInstance(); 44 logger::purgeInstance(); 45 errorLogger::purgeInstance(); 37 46 }; 38 47 … … 290 299 } 291 300 292 293 /********************************************** Main routine **************************************/294 295 int main(int argc, char **argv)296 {297 // Get the top level suite from the registry298 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();299 300 // Adds the test to the list of test to run301 CppUnit::TextUi::TestRunner runner;302 runner.addTest( suite );303 304 // Change the default outputter to a compiler error format outputter305 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),306 std::cerr ) );307 // Run the tests.308 bool wasSucessful = runner.run();309 310 // Return error code 1 if the one of test failed.311 return wasSucessful ? 0 : 1;312 }; -
src/vector.cpp
rc695c9 r5f612ee 362 362 return false; 363 363 } 364 delete(M); 364 365 DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl); 365 366 … … 617 618 * \return lhs + a 618 619 */ 619 Vector& operator+=(Vector& a, const Vector& b)620 const Vector& operator+=(Vector& a, const Vector& b) 620 621 { 621 622 a.AddVector(&b); … … 628 629 * \return lhs - a 629 630 */ 630 Vector& operator-=(Vector& a, const Vector& b)631 const Vector& operator-=(Vector& a, const Vector& b) 631 632 { 632 633 a.SubtractVector(&b); … … 639 640 * \return lhs.x[i] * m 640 641 */ 641 Vector& operator*=(Vector& a, const double m)642 const Vector& operator*=(Vector& a, const double m) 642 643 { 643 644 a.Scale(m); … … 650 651 * \return a + b 651 652 */ 652 Vector& operator+(const Vector& a, const Vector& b) 653 { 654 Vector *x = new Vector; 655 x->CopyVector(&a); 656 x->AddVector(&b); 657 return *x; 653 Vector const operator+(const Vector& a, const Vector& b) 654 { 655 Vector x(a); 656 x.AddVector(&b); 657 return x; 658 658 }; 659 659 … … 663 663 * \return a - b 664 664 */ 665 Vector& operator-(const Vector& a, const Vector& b) 666 { 667 Vector *x = new Vector; 668 x->CopyVector(&a); 669 x->SubtractVector(&b); 670 return *x; 665 Vector const operator-(const Vector& a, const Vector& b) 666 { 667 Vector x(a); 668 x.SubtractVector(&b); 669 return x; 671 670 }; 672 671 … … 676 675 * \return m * a 677 676 */ 678 Vector& operator*(const Vector& a, const double m) 679 { 680 Vector *x = new Vector; 681 x->CopyVector(&a); 682 x->Scale(m); 683 return *x; 677 Vector const operator*(const Vector& a, const double m) 678 { 679 Vector x(a); 680 x.Scale(m); 681 return x; 684 682 }; 685 683 … … 689 687 * \return m * a 690 688 */ 691 Vector& operator*(const double m, const Vector& a ) 692 { 693 Vector *x = new Vector; 694 x->CopyVector(&a); 695 x->Scale(m); 696 return *x; 689 Vector const operator*(const double m, const Vector& a ) 690 { 691 Vector x(a); 692 x.Scale(m); 693 return x; 697 694 }; 698 695 … … 1110 1107 void Vector::CopyVector(const Vector * const y) 1111 1108 { 1112 for (int i=NDIM;i--;) 1113 this->x[i] = y->x[i]; 1109 // check for self assignment 1110 if(y!=this){ 1111 for (int i=NDIM;i--;) 1112 this->x[i] = y->x[i]; 1113 } 1114 1114 } 1115 1115 … … 1119 1119 void Vector::CopyVector(const Vector &y) 1120 1120 { 1121 for (int i=NDIM;i--;) 1122 this->x[i] = y.x[i]; 1121 // check for self assignment 1122 if(&y!=this) { 1123 for (int i=NDIM;i--;) 1124 this->x[i] = y.x[i]; 1125 } 1123 1126 } 1124 1127 -
src/vector.hpp
rc695c9 r5f612ee 82 82 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 83 83 void WrapPeriodically(const double * const M, const double * const Minv); 84 84 85 }; 85 86 86 87 ostream & operator << (ostream& ost, const Vector &m); 87 88 bool operator==(const Vector& a, const Vector& b); 88 Vector& operator+=(Vector& a, const Vector& b);89 Vector& operator-=(Vector& a, const Vector& b);90 Vector& operator*=(Vector& a, const double m);91 Vector &operator*(const Vector& a, const double m);92 Vector &operator*(const double m, const Vector& a);93 Vector &operator+(const Vector& a, const Vector& b);94 Vector &operator-(const Vector& a, const Vector& b);89 const Vector& operator+=(Vector& a, const Vector& b); 90 const Vector& operator-=(Vector& a, const Vector& b); 91 const Vector& operator*=(Vector& a, const double m); 92 Vector const operator*(const Vector& a, const double m); 93 Vector const operator*(const double m, const Vector& a); 94 Vector const operator+(const Vector& a, const Vector& b); 95 Vector const operator-(const Vector& a, const Vector& b); 95 96 96 97
Note:
See TracChangeset
for help on using the changeset viewer.