Changeset 51e0e3
- Timestamp:
- Aug 9, 2013, 2:20:35 PM (11 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:
- a633f6
- Parents:
- 0f5d38
- git-author:
- Frederik Heber <heber@…> (06/25/13 12:41:01)
- git-committer:
- Frederik Heber <heber@…> (08/09/13 14:20:35)
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
r0f5d38 r51e0e3 182 182 183 183 184 # CodePatterns library ( needs fixes w.r.t Notifications giving note when destroyed)185 AM_PATH_CODEPATTERNS([1.2. 6], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])184 # CodePatterns library (extended toString.hpp) 185 AM_PATH_CODEPATTERNS([1.2.7], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])]) 186 186 187 187 # JobMarket library (needs boost/archive/iserializer.hpp before MemDebug.hpp) -
src/FunctionApproximation/Extractors.cpp
r0f5d38 r51e0e3 45 45 46 46 #include "CodePatterns/Assert.hpp" 47 #include "CodePatterns/IteratorAdaptors.hpp" 47 48 #include "CodePatterns/Log.hpp" 49 #include "CodePatterns/toString.hpp" 48 50 49 51 #include "LinearAlgebra/Vector.hpp" … … 538 540 } 539 541 542 543 struct ParticleTypesComparator { 544 bool operator()(const argument_t::types_t &a, const argument_t::types_t &b) 545 { 546 if (a.first < a.second) { 547 if (b.first < b.second) { 548 if (a.first < b.first) 549 return true; 550 else if (a.first > b.first) 551 return false; 552 else 553 return (a.second < b.second); 554 } else { 555 if (a.first < b.second) 556 return true; 557 else if (a.first > b.second) 558 return false; 559 else 560 return (a.second < b.first); 561 } 562 } else { 563 if (b.first < b.second) { 564 if (a.second < b.first) 565 return true; 566 else if (a.second > b.first) 567 return false; 568 else 569 return (a.first < b.second); 570 } else { 571 if (a.second < b.second) 572 return true; 573 else if (a.second > b.second) 574 return false; 575 else 576 return (a.first < b.first); 577 } 578 } 579 } 580 }; 581 582 std::ostream& operator<<(std::ostream &out, const argument_t::types_t &a) 583 { 584 out << "[" << a.first << "," << a.second << "]"; 585 return out; 586 } 587 540 588 FunctionModel::arguments_t Extractors::reorderArgumentsByParticleTypes( 589 const FunctionModel::arguments_t &args, 590 const ParticleTypes_t &_types 591 ) 592 { 593 /// We place all arguments into multimap according to particle type pair. 594 // here, we need a special comparator such that types in key pair are always 595 // properly ordered. 596 typedef std::multimap< 597 argument_t::types_t, 598 argument_t, 599 ParticleTypesComparator> TypePair_Argument_Map_t; 600 TypePair_Argument_Map_t argument_map; 601 for(FunctionModel::arguments_t::const_iterator iter = args.begin(); 602 iter != args.end(); ++iter) { 603 argument_map.insert( std::make_pair(iter->types, *iter) ); 604 } 605 LOG(4, "DEBUG: particle_type map is " << argument_map << "."); 606 607 /// Then, we create the desired unique keys 608 typedef std::vector<argument_t::types_t> UniqueTypes_t; 609 UniqueTypes_t UniqueTypes; 610 for (ParticleTypes_t::const_iterator firstiter = _types.begin(); 611 firstiter != _types.end(); 612 ++firstiter) { 613 for (ParticleTypes_t::const_iterator seconditer = firstiter; 614 seconditer != _types.end(); 615 ++seconditer) { 616 if (seconditer == firstiter) 617 continue; 618 UniqueTypes.push_back( std::make_pair(*firstiter, *seconditer) ); 619 } 620 } 621 LOG(4, "DEBUG: Created unique types as keys " << UniqueTypes << "."); 622 623 /// Finally, we use the unique key list to pick corresponding arguments from the map 624 FunctionModel::arguments_t returnargs; 625 returnargs.reserve(args.size()); 626 while (!argument_map.empty()) { 627 // note that particle_types_t may be flipped, i.e. 1,8 is equal to 8,1, but we 628 // must maintain the correct order in indices in accordance with the order 629 // in _types, i.e. 1,8,1 must match with e.g. ids 1,0,2 where 1 has type 1, 630 // 0 has type 8, and 2 has type 2. 631 // In other words: We do not want to flip/modify arguments such that they match 632 // with the specific type pair we seek but then this comes at the price that we 633 // have flip indices when the types in a pair are flipped. 634 635 typedef std::vector<size_t> indices_t; 636 //!> here, we gather the indices as we discover them 637 indices_t indices; 638 indices.resize(_types.size(), (size_t)-1); 639 640 // these are two iterators that create index pairs in the same way as we have 641 // created type pairs. If a -1 is still present in indices, then the index is 642 // still arbitrary but is then set by the next found index 643 indices_t::iterator firstindex = indices.begin(); 644 indices_t::iterator secondindex = firstindex+1; 645 646 //!> here, we gather the current bunch of arguments as we find them 647 FunctionModel::arguments_t argumentbunch; 648 argumentbunch.reserve(UniqueTypes.size()); 649 650 for (UniqueTypes_t::const_iterator typeiter = UniqueTypes.begin(); 651 typeiter != UniqueTypes.end(); ++typeiter) { 652 // have all arguments to same type pair as list within the found range 653 std::pair< 654 TypePair_Argument_Map_t::iterator, 655 TypePair_Argument_Map_t::iterator> range_t = 656 argument_map.equal_range(*typeiter); 657 LOG(4, "DEBUG: Set of arguments to current key [" << typeiter->first << "," 658 << typeiter->second << "] is " << std::list<argument_t>( 659 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.first), 660 MapValueIterator<TypePair_Argument_Map_t::iterator>(range_t.second) 661 ) << "."); 662 // the first key is always easy and is pivot which the rest has to be associated to 663 if (typeiter == UniqueTypes.begin()) { 664 const argument_t & arg = range_t.first->second; 665 if ((typeiter->first == arg.types.first) && (typeiter->second == arg.types.second)) { 666 // store in correct order 667 *firstindex = arg.indices.first; 668 *secondindex = arg.indices.second; 669 } else { 670 // store in flipped order 671 *firstindex = arg.indices.second; 672 *secondindex = arg.indices.first; 673 } 674 argumentbunch.push_back(arg); 675 argument_map.erase(range_t.first); 676 LOG(4, "DEBUG: Gathered first argument " << arg << "."); 677 } else { 678 // go through the range and pick the first argument matching the index constraints 679 for (TypePair_Argument_Map_t::iterator argiter = range_t.first; 680 argiter != range_t.second; ++argiter) { 681 // seconditer may be -1 still 682 const argument_t &arg = argiter->second; 683 if (arg.indices.first == *firstindex) { 684 if ((arg.indices.second == *secondindex) || (*secondindex == (size_t)-1)) { 685 if (*secondindex == -1) 686 *secondindex = arg.indices.second; 687 argumentbunch.push_back(arg); 688 argument_map.erase(argiter); 689 LOG(4, "DEBUG: Gathered another argument " << arg << "."); 690 break; 691 } 692 } else if ((arg.indices.first == *secondindex) || (*secondindex == (size_t)-1)) { 693 if (arg.indices.second == *firstindex) { 694 if (*secondindex == (size_t)-1) 695 *secondindex = arg.indices.first; 696 argumentbunch.push_back(arg); 697 argument_map.erase(argiter); 698 LOG(4, "DEBUG: Gathered another (flipped) argument " << arg << "."); 699 break; 700 } 701 } 702 } 703 } 704 // move along in indices and check bounds 705 ++secondindex; 706 if (secondindex == indices.end()) { 707 ++firstindex; 708 if (firstindex != indices.end()-1) 709 secondindex = firstindex+1; 710 } 711 } 712 ASSERT( (firstindex == indices.end()-1) && (secondindex == indices.end()), 713 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 714 ASSERT( argumentbunch.size() == UniqueTypes.size(), 715 "Extractors::reorderArgumentsByParticleTypes() - we have not gathered enough arguments."); 716 // place bunch of arguments in return args 717 LOG(3, "DEBUG: Given types " << _types << " and found indices " << indices << "."); 718 LOG(3, "DEBUG: Final bunch of arguments is " << argumentbunch << "."); 719 returnargs.insert(returnargs.end(), argumentbunch.begin(), argumentbunch.end()); 720 } 721 722 return returnargs; 723 } 724 725 FunctionModel::arguments_t Extractors::filterArgumentsByParticleTypes( 541 726 const FunctionModel::arguments_t &args, 542 727 const ParticleTypes_t &_types … … 557 742 558 743 // basically, we have two choose any two pairs out of types but only those 559 // where the first is less than the l etter. Hence, we start the second744 // where the first is less than the latter. Hence, we start the second 560 745 // iterator at the current position of the first one and skip the equal case. 561 746 for (ParticleTypes_t::const_iterator firstiter = _types.begin(); … … 580 765 else if ((iter->types.first == *seconditer) 581 766 && (iter->types.second == *firstiter)) { 582 argument_t flippedtypes(*iter); 583 std::swap( flippedtypes.indices.first, flippedtypes.indices.second ); 584 std::swap( flippedtypes.types.first, flippedtypes.types.second ); 585 returnargs.push_back( flippedtypes ); 586 break; 767 // argument_t flippedtypes(*iter); 768 // std::swap( flippedtypes.indices.first, flippedtypes.indices.second ); 769 // std::swap( flippedtypes.types.first, flippedtypes.types.second ); 770 returnargs.push_back( *iter ); 771 iter = availableList.erase(iter); 772 LOG(4, "DEBUG: Accepted (flipped) argument."); 773 } else { 774 ++iter; 775 LOG(4, "DEBUG: Rejected argument."); 587 776 } 588 777 } -
src/FunctionApproximation/Extractors.hpp
r0f5d38 r51e0e3 301 301 ); 302 302 303 /** Reorder arguments according to types. 304 * 305 * If particle types is (0,1,2) and three argumens, each with a pair of types, 306 * are given, then the alignment will be: (0,1), (0,2), and (1,2). 303 /** Reorder the arguments to bring adjacent ones together. 304 * 305 * After filtering via particle types arguments related via same indices 306 * must not necessarily be contained in the same bunch. This reordering 307 * is done here, preserving the alignment given in 308 * \sa filterArgumentsByParticleTypes() 307 309 * 308 310 * \param args arguments to reorder … … 315 317 ); 316 318 319 /** Filter arguments according to types. 320 * 321 * If particle types is (0,1,2) and three arguments, each with a pair of types, 322 * are given, then the alignment will be: (0,1), (0,2), and (1,2). 323 * 324 * \param args arguments to reorder 325 * \param _types particle type vector 326 * \return filtered args 327 */ 328 FunctionModel::arguments_t filterArgumentsByParticleTypes( 329 const FunctionModel::arguments_t &args, 330 const ParticleTypes_t &_types 331 ); 332 317 333 /** Combines two argument lists by sorting and making unique. 318 334 * -
src/Potentials/Specifics/ConstantPotential.cpp
r0f5d38 r51e0e3 180 180 { 181 181 FunctionModel::filter_t returnfunction = 182 boost::bind(&Helpers::NoOp_Filterfunction, 183 _1); 182 boost::bind(&Extractors::filterArgumentsByParticleTypes, 183 _1, 184 getParticleTypes()); 184 185 return returnfunction; 185 186 } -
src/Potentials/Specifics/ManyBodyPotential_Tersoff.cpp
r0f5d38 r51e0e3 701 701 { 702 702 FunctionModel::filter_t returnfunction = 703 boost::bind(&Helpers::NoOp_Filterfunction, 704 _1); 703 boost::bind(&Extractors::filterArgumentsByParticleTypes, 704 _1, 705 getParticleTypes()); 705 706 return returnfunction; 706 707 } -
src/Potentials/Specifics/PairPotential_Angle.cpp
r0f5d38 r51e0e3 225 225 FunctionModel::filter_t returnfunction = 226 226 boost::bind(&Extractors::reorderArgumentsByParticleTypes, 227 _1, 228 getParticleTypes() 227 boost::bind(&Extractors::filterArgumentsByParticleTypes, 228 _1, 229 getParticleTypes()), 230 getParticleTypes() 229 231 ); 230 232 return returnfunction; -
src/Potentials/Specifics/PairPotential_Harmonic.cpp
r0f5d38 r51e0e3 201 201 { 202 202 FunctionModel::filter_t returnfunction = 203 boost::bind(&Helpers::NoOp_Filterfunction, 204 _1); 203 boost::bind(&Extractors::filterArgumentsByParticleTypes, 204 _1, 205 getParticleTypes()); 205 206 return returnfunction; 206 207 } -
src/Potentials/Specifics/PairPotential_Morse.cpp
r0f5d38 r51e0e3 230 230 { 231 231 FunctionModel::filter_t returnfunction = 232 boost::bind(&Helpers::NoOp_Filterfunction, 233 _1); 232 boost::bind(&Extractors::filterArgumentsByParticleTypes, 233 _1, 234 getParticleTypes()); 234 235 return returnfunction; 235 236 }
Note:
See TracChangeset
for help on using the changeset viewer.