Changeset a0064e for src/Helpers


Ignore:
Timestamp:
Dec 23, 2010, 5:40:04 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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:
ad011c
Parents:
f28a26
git-author:
Frederik Heber <heber@…> (12/22/10 09:18:48)
git-committer:
Frederik Heber <heber@…> (12/23/10 17:40:04)
Message:

Moved stuff in src/Helpers and src/Patterns out to stand-alone project CodePatterns.

Makefile.am's:

  • CodePatterns added to AM_LDFLAGS and AM_CFLAGS
  • libMoleCuilderHelpers removed

Helpers/...

  • defs.hpp include prefixed with Helpers/
  • helpers.?pp removed lots of old, unused functions: bound, ask_value, ...
  • fast_functions.hpp has lots of functions removed as well.
  • all other files and unit tests moved to project CodePatterns.

Patterns/...

  • added ax_codepatterns.m4 containing AM_PATH_CODEPATTERNS to configure.ac
Location:
src/Helpers
Files:
22 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/fast_functions.hpp

    rf28a26 ra0064e  
    5151};
    5252
    53 /** Returns the power of \a n with respect to \a base.
    54  * \param base basis
    55  * \param n power
    56  * \return \f$base^n\f$
    57  */
    58 inline int pot(int base, int n)
    59 {
    60   int res = 1;
    61   int j;
    62   for (j=n;j--;)
    63     res *= base;
    64   return res;
    65 };
    66 
    67 /*************************** Templatized functions ************************************/
    68 
    69 /** Flips two values.
    70  * \param x first value
    71  * \param y second value
    72  */
    73 template <typename T>
    74 inline void flip(T &x, T &y)
    75 {
    76   T tmp;
    77   tmp = x;
    78   x = y;
    79   y = tmp;
    80 };
    8153
    8254#endif /* FAST_FUNCTIONS_HPP_ */
  • src/Helpers/helpers.cpp

    • Property mode changed from 100755 to 100644
    rf28a26 ra0064e  
    2828
    2929
    30 /** Asks for a double value and checks input
    31  * \param *text question
    32  */
    33 double ask_value(const char *text)
    34 {
    35   double test = 0.1439851348959832147598734598273456723948652983045928346598365;
    36   do {
    37     DoLog(0) && (Log() << Verbose(0) << text);
    38     cin >> test;
    39   } while (test == 0.1439851348959832147598734598273456723948652983045928346598365);
    40   return test;
    41 };
    42 
    4330/** Output of a debug message to stderr.
    4431 * \param *P Problem at hand, points to ParallelSimulationData#me
     
    5340#endif
    5441
    55 /** modulo operator for doubles.
    56  * \param *b pointer to double
    57  * \param lower_bound lower bound
    58  * \param upper_bound upper bound
    59  */
    60 void bound(double *b, double lower_bound, double upper_bound)
    61 {
    62   double step = (upper_bound - lower_bound);
    63   while (*b >= upper_bound)
    64     *b -= step;
    65   while (*b < lower_bound)
    66     *b += step;
    67 };
    68 
    69 /** Counts lines in file.
    70  * Note we are scanning lines from current position, not from beginning.
    71  * \param InputFile file to be scanned.
    72  */
    73 int CountLinesinFile(ifstream &InputFile)
    74 {
    75   char *buffer = new char[MAXSTRINGSIZE];
    76   int lines=0;
    77 
    78   int PositionMarker = InputFile.tellg();  // not needed as Inputfile is copied, given by value, not by ref
    79   // count the number of lines, i.e. the number of fragments
    80   InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
    81   InputFile.getline(buffer, MAXSTRINGSIZE);
    82   while(!InputFile.eof()) {
    83     InputFile.getline(buffer, MAXSTRINGSIZE);
    84     lines++;
    85   }
    86   InputFile.seekg(PositionMarker, ios::beg);
    87   delete[](buffer);
    88   return lines;
    89 };
    9042
    9143/** Returns a string with \a i prefixed with 0s to match order of total number of molecules in digits.
     
    11769};
    11870
    119 /** Tests whether a given string contains a valid number or not.
    120  * \param *string
    121  * \return true - is a number, false - is not a valid number
    122  */
    123 bool IsValidNumber( const char *string)
    124 {
    125   int ptr = 0;
    126   if ((string[ptr] == '.') || (string[ptr] == '-')) // number may be negative or start with dot
    127     ptr++;
    128   if ((string[ptr] >= '0') && (string[ptr] <= '9'))
    129     return true;
    130   return false;
    131 };
    132 
    133 /** Comparison function for GSL heapsort on distances in two molecules.
    134  * \param *a
    135  * \param *b
    136  * \return <0, \a *a less than \a *b, ==0 if equal, >0 \a *a greater than \a *b
    137  */
    138 int CompareDoubles (const void * a, const void * b)
    139 {
    140   if (*(double *)a > *(double *)b)
    141     return -1;
    142   else if (*(double *)a < *(double *)b)
    143     return 1;
    144   else
    145     return 0;
    146 };
    147 
    148 
    14971/**
    15072 * Calls exit(255).
  • src/Helpers/helpers.hpp

    rf28a26 ra0064e  
    5050} sign_t;
    5151
    52 double ask_value(const char *text);
    53 bool check_bounds(double *x, double *cell_size);
    54 void bound(double *b, double lower_bound, double upper_bound);
    55 int CountLinesinFile(ifstream &InputFile);
    5652char *FixedDigitNumber(const int FragmentNumber, const int digits);
    57 bool IsValidNumber( const char *string);
    58 int CompareDoubles (const void * a, const void * b);
    5953void performCriticalExit();
    6054sign_t sign(double value);
     
    6256/********************************************** helpful template functions *********************************/
    6357
    64 
    65 /** returns greater of the two values.
    66  * \param x first value
    67  * \param y second value
    68  * \return greater of the two (by operator>())
    69  */
    70 template <typename T> T Max(T x, T y)
    71 {
    72   if (x > y)
    73     return x;
    74   else return y;
    75 };
    76 
    77 /** returns smaller of the two values.
    78  * \param x first value
    79  * \param y second value
    80  * \return smaller of the two (by operator<())
    81  */
    82 template <typename T> T Min(T x, T y)
    83 {
    84   if (x < y)
    85     return x;
    86   else return y;
    87 };
    8858
    8959/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
     
    144114
    145115
    146 /** Frees a two-dimensional array.
    147  * \param *ptr pointer to array
    148  * \param dim first dim of array
    149  */
    150 template <typename X> void Free2DArray(X **ptr, int dim)
    151 {
    152   int i;
    153   if (ptr != NULL) {
    154     for(i=dim;i--;)
    155       if (ptr[i] != NULL)
    156         free(ptr[i]);
    157     free(ptr);
    158   }
    159 };
    160 
    161 template <typename T> void Increment(T *value, T *inc)
    162 {
    163   *value += *inc;
    164 };
    165 
    166 template <typename T> void AbsoluteValue(T *value, T *abs)
    167 {
    168   *value = *abs;
    169 };
    170 
    171 template <typename T> void IncrementalAbsoluteValue(T *value, T *abs)
    172 {
    173   *value = *abs;
    174   (*abs) += 1;
    175 };
    176 
    177116#define PLURAL_S(v) (((v)==1)?"":"s")
    178117
     
    201140};
    202141
    203 /************ struct to contain simple enumerations ***************/
    204 template <class C>
    205 struct enumeration{
    206   enumeration() : max(0) {}
    207   enumeration(unsigned int i) : max(i) {}
    208   enumeration(const enumeration &src) :
    209     there(src.there),
    210     back(src.back),
    211     max(src.max)
    212   {}
    213   enumeration &operator=(const enumeration &src){
    214     /* no self-assignment check needed */
    215     there = src.there;
    216     back = src.back;
    217     max = src.max;
    218     return *this;
    219   }
    220   void add(const C &value){
    221     if(!there.count(value)){
    222       there[value]=max;
    223       back[max++]=value;
    224     }
    225   }
    226   unsigned int getMax() const{
    227     return max;
    228   }
    229 
    230   map<C,unsigned int> there;
    231   map<unsigned int,C> back;
    232 private:
    233   unsigned int max;
    234 };
    235 
    236 /***** A counter to generate sequential numbers *******************/
    237 struct counter{
    238   inline counter() : count(0){};
    239   inline counter(int i) : count(i){};
    240   inline unsigned int operator()(){
    241     return count++;
    242   }
    243 private:
    244   unsigned int count;
    245 };
    246 
    247 template <class C,class ForwardIterator>
    248 enumeration<C> enumerate(ForwardIterator first,ForwardIterator last){
    249   enumeration<C> res;
    250   for_each(first,last,bind1st(mem_fun(&enumeration<C>::add),&res));
    251   return res;
    252 }
    253 
    254142#endif /*HELPERS_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.