source: src/helpers.hpp@ bbc338

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since bbc338 was 6cd79d, checked in by Frederik Heber <heber@…>, 16 years ago

performCriticalExit() must not be defined static.

Note that static global functions are only visible within the specific source file. Removed static keyword.

  • Property mode set to 100755
File size: 4.2 KB
Line 
1/** \file helpers.hpp
2 *
3 * Declaration of some auxiliary functions for memory dis-/allocation and so on
4 */
5
6#ifndef HELPERS_HPP_
7#define HELPERS_HPP_
8
9using namespace std;
10
11/*********************************************** includes ***********************************/
12
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include <fstream>
19
20#include "memoryallocator.hpp"
21
22/********************************************** helpful functions *********************************/
23
24// taken out of TREMOLO
25/*@-namechecks@*/
26#ifndef __GNUC__
27# undef __attribute__
28# define __attribute__(x)
29#endif
30/*@=namechecks@*/
31
32/* Behandelt aufgetretene Fehler. error ist der Fehlertyp(enum Errors)
33 void *SpecialData ist ein untypisierter Zeiger auf Spezielle Daten zur Fehlerbehandlung.
34 Man koennte auch noch einen Zeiger auf eine Funktion uebergeben */
35extern void /*@exits@*/ debug(const char *output);
36 //__attribute__ ((__return__));
37#define debug(data) debug_in((data), __FILE__, __LINE__)
38
39extern void /*@exits@*/ debug_in(const char *output,
40 const char *file, const int line);
41 //__attribute__ ((__return__));
42
43double ask_value(const char *text);
44bool check_bounds(double *x, double *cell_size);
45void bound(double *b, double lower_bound, double upper_bound);
46void flip(double *x, double *y);
47int pot(int base, int n);
48int CountLinesinFile(ifstream &InputFile);
49char *FixedDigitNumber(const int FragmentNumber, const int digits);
50bool IsValidNumber( const char *string);
51int CompareDoubles (const void * a, const void * b);
52double * ReturnFullMatrixforSymmetric(double *cell_size);
53void performCriticalExit();
54
55/********************************************** helpful template functions *********************************/
56
57/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
58 * \param *out output stream for debugging
59 * \param *start begin of chain list
60 * \paran *end end of chain list
61 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
62 * \param count optional predetermined count for table (otherwise we set the count to highest true father id)
63 * \return true - success, false - failure
64 */
65template <typename T> bool CreateFatherLookupTable(ofstream *out, T *start, T *end, T **&LookupTable, int count = 0)
66{
67 bool status = true;
68 T *Walker = NULL;
69 int AtomNo;
70
71 if (LookupTable != NULL) {
72 *out << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
73 return false;
74 }
75
76 // count them
77 if (count == 0) {
78 Walker = start;
79 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
80 Walker = Walker->next;
81 count = (count < Walker->GetTrueFather()->nr) ? Walker->GetTrueFather()->nr : count;
82 }
83 }
84 if (count <= 0) {
85 *out << "Count of lookup list is 0 or less." << endl;
86 return false;
87 }
88
89 // allocat and fill
90 LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
91 if (LookupTable == NULL) {
92 cerr << "LookupTable memory allocation failed!" << endl;
93 status = false;
94 } else {
95 for (int i=0;i<count;i++)
96 LookupTable[i] = NULL;
97 Walker = start;
98 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
99 Walker = Walker->next;
100 AtomNo = Walker->GetTrueFather()->nr;
101 if ((AtomNo >= 0) && (AtomNo < count)) {
102 //*out << "Setting LookupTable[" << AtomNo << "] to " << *Walker << endl;
103 LookupTable[AtomNo] = Walker;
104 } else {
105 *out << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl;
106 status = false;
107 break;
108 }
109 }
110 }
111
112 return status;
113};
114
115/** Frees a two-dimensional array.
116 * \param *ptr pointer to array
117 * \param dim first dim of array
118 */
119template <typename X> void Free2DArray(X **ptr, int dim)
120{
121 int i;
122 if (ptr != NULL) {
123 for(i=dim;i--;)
124 if (ptr[i] != NULL)
125 free(ptr[i]);
126 free(ptr);
127 }
128};
129
130template <typename T> void Increment(T *value, T *inc)
131{
132 *value += *inc;
133};
134
135template <typename T> void AbsoluteValue(T *value, T *abs)
136{
137 *value = *abs;
138};
139
140template <typename T> void IncrementalAbsoluteValue(T *value, T *abs)
141{
142 *value = *abs;
143 (*abs) += 1;
144};
145
146
147
148#endif /*HELPERS_HPP_*/
Note: See TracBrowser for help on using the repository browser.