Changeset 4a8169
- Timestamp:
- Jan 2, 2012, 1:34:58 PM (13 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- cbdcb1
- Parents:
- 99f4ee
- git-author:
- Frederik Heber <heber@…> (12/21/11 18:03:15)
- git-committer:
- Frederik Heber <heber@…> (01/02/12 13:34:58)
- Location:
- src/LinkedCell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/LinkedCell/LinkedCell_Controller.cpp
r99f4ee r4a8169 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include <set> 23 22 24 #include "Box.hpp" 23 25 #include "CodePatterns/Assert.hpp" 26 #include "CodePatterns/Log.hpp" 27 #include "CodePatterns/Observer/Notification.hpp" 24 28 #include "CodePatterns/Range.hpp" 25 29 #include "LinkedCell_Controller.hpp" … … 38 42 */ 39 43 LinkedCell_Controller::LinkedCell_Controller(const Box &_domain) : 44 Observer("LinkedCell_Controller"), 40 45 domain(_domain) 41 46 { … … 175 180 } 176 181 } 182 183 /** Internal function to re-create all present and used models for the new Box. 184 * 185 * The main problem are the views currently in use. 186 * We make use of LinkedCell:LinkedCell_View::RAIIMap as there all present are 187 * listed. We go through the list, create a map with old model ref as keys to 188 * just newly created ones, and finally go again through each view and exchange 189 * the model against the new ones via a simple map lookup. 190 * 191 */ 192 void LinkedCell_Controller::updateModelsForNewBoxMatrix() 193 { 194 typedef std::map<const LinkedCell_Model *, LinkedCell_Model *> ModelLookup; 195 ModelLookup models; 196 197 // set up map, for now with NULL pointers 198 for (LinkedCell_View::ModelInstanceMap::const_iterator iter = LinkedCell_View::RAIIMap.begin(); 199 iter != LinkedCell_View::RAIIMap.end(); ++iter) { 200 #ifndef NDEBUG 201 std::pair< ModelLookup::iterator, bool > inserter = 202 #endif 203 models.insert( std::pair<const LinkedCell_Model *, LinkedCell_Model *>( &((*iter)->LC), NULL) ); 204 ASSERT( inserter.second, 205 "LinkedCell_Controller::updateModelsForNewBoxMatrix() - failed to insert old model " 206 +toString( &((*iter)->LC))+","+toString(NULL)+" into models, is already present"); 207 } 208 209 // invert MapEdgelengthModel 210 typedef std::map<const LinkedCell_Model*, double > MapEdgelengthModel_inverted; 211 MapEdgelengthModel_inverted ModelsMap_inverted; 212 for (MapEdgelengthModel::const_iterator iter = ModelsMap.begin(); 213 iter != ModelsMap.end(); ++iter) { 214 #ifndef NDEBUG 215 MapEdgelengthModel_inverted::const_iterator assertiter = ModelsMap_inverted.find(iter->second); 216 ASSERT( assertiter != ModelsMap_inverted.end(), 217 "LinkedCell_Controller::updateModelsForNewBoxMatrix() - ModelsMap is not invertible, value " 218 +toString(iter->second)+" is already present."); 219 #endif 220 ModelsMap_inverted.insert( std::make_pair(iter->second, iter->first) ); 221 } 222 223 // go through map and re-create models 224 for (ModelLookup::iterator iter = models.begin(); iter != models.end(); ++iter) { 225 // delete old model 226 const LinkedCell_Model * const oldref = iter->first; 227 #ifndef NDEBUG 228 MapEdgelengthModel_inverted::const_iterator assertiter = ModelsMap_inverted.find(oldref); 229 ASSERT( assertiter != ModelsMap_inverted.end(), 230 "LinkedCell_Controller::updateModelsForNewBoxMatrix() - ModelsMap_inverted does not contain old model " 231 +toString(oldref)+"."); 232 #endif 233 const double distance = ModelsMap_inverted[oldref]; 234 delete oldref; 235 ModelsMap.erase(distance); 236 // create new one 237 LinkedCell_Model * const newref = new LinkedCell_Model(distance, domain); 238 iter->second = newref; 239 // replace in ModelsMap 240 #ifndef NDEBUG 241 std::pair< MapEdgelengthModel::iterator, bool > inserter = 242 #endif 243 ModelsMap.insert( std::make_pair(distance, newref) ); 244 ASSERT( inserter.second, 245 "LinkedCell_Controller::updateModelsForNewBoxMatrix() - failed to insert new model " 246 +toString(distance)+","+toString(newref)+" into ModelsMap, is already present"); 247 } 248 249 // delete inverted map for safety (values are gone) 250 ModelsMap_inverted.clear(); 251 252 // go through views and exchange the models 253 for (LinkedCell_View::ModelInstanceMap::const_iterator iter = LinkedCell_View::RAIIMap.begin(); 254 iter != LinkedCell_View::RAIIMap.end(); ++iter) { 255 ModelLookup::const_iterator modeliter = models.find(&((*iter)->LC)); 256 ASSERT( modeliter != models.end(), 257 "LinkedCell_Controller::updateModelsForNewBoxMatrix() - we miss a model " 258 +toString(&((*iter)->LC))+" in ModelLookup."); 259 // this is ugly but the only place where we have to set ourselves over the constness of the member variable 260 //if (modeliter != models.end()) 261 //const_cast<LinkedCell_Model &>((*iter)->LC) = *modeliter->second; 262 } 263 } 264 265 /** Callback function for Observer mechanism. 266 * 267 * @param publisher reference to the Observable that calls 268 */ 269 void LinkedCell_Controller::update(Observable *publisher) 270 { 271 ELOG(2, "LinkedCell_Model received inconclusive general update from " 272 << publisher << "."); 273 } 274 275 /** Callback function for the Notifications mechanism. 276 * 277 * @param publisher reference to the Observable that calls 278 * @param notification specific notification as cause of the call 279 */ 280 void LinkedCell_Controller::recieveNotification(Observable *publisher, Notification_ptr notification) 281 { 282 switch(notification->getChannelNo()) { 283 case Box::MatrixChanged: 284 updateModelsForNewBoxMatrix(); 285 break; 286 default: 287 ASSERT(0, 288 "LinkedCell_Controller::recieveNotification() - unwanted notification " 289 +toString(notification->getChannelNo())+" received."); 290 break; 291 } 292 } 293 294 /** Callback function when an Observer dies. 295 * 296 * @param publisher reference to the Observable that calls 297 */ 298 void LinkedCell_Controller::subjectKilled(Observable *publisher) 299 {} 300 -
src/LinkedCell/LinkedCell_Controller.hpp
r99f4ee r4a8169 16 16 #include <map> 17 17 18 #include "CodePatterns/Observer/Observer.hpp" 18 19 #include "CodePatterns/Range.hpp" 19 20 #include "LinkedCell/LinkedCell_View.hpp" … … 40 41 * 41 42 */ 42 class LinkedCell_Controller 43 class LinkedCell_Controller : public Observer 43 44 { 44 45 //!> grant unit tests access to internal parts … … 50 51 LinkedCell_View getView(const double distance, IPointCloud &set); 51 52 53 void update(Observable *publisher); 54 void recieveNotification(Observable *publisher, Notification_ptr notification); 55 void subjectKilled(Observable *publisher); 56 52 57 private: 53 58 const LinkedCell_Model * getBestModel(const double distance) const; 54 59 const range<double> getHeuristicRange(const double distance) const; 55 60 void insertNewModel(const double edgelength, const LinkedCell_Model* instance); 61 void updateModelsForNewBoxMatrix(); 56 62 57 63 private: -
src/LinkedCell/unittests/LinkedCell_ControllerUnitTest.cpp
r99f4ee r4a8169 257 257 } 258 258 } 259 260 /** UnitTest for LinkedCell_Controller::updateModelsForNewBoxMatrix(). 261 */ 262 void LinkedCell_ControllerTest::updateBoxTest() 263 { 264 CPPUNIT_ASSERT(true); 265 } -
src/LinkedCell/unittests/LinkedCell_ControllerUnitTest.hpp
r99f4ee r4a8169 41 41 CPPUNIT_TEST ( getView_LowerThresholdViewTest ); 42 42 CPPUNIT_TEST ( getView_UpperThresholdViewTest ); 43 CPPUNIT_TEST ( updateBoxTest ); 43 44 CPPUNIT_TEST_SUITE_END(); 44 45 … … 55 56 void getView_LowerThresholdViewTest(); 56 57 void getView_UpperThresholdViewTest(); 58 void updateBoxTest(); 57 59 58 60 private:
Note:
See TracChangeset
for help on using the changeset viewer.