1 | #ifndef init_h
|
---|
2 | #define init_h
|
---|
3 | /** \file init.h
|
---|
4 | * Header file for \ref init.c
|
---|
5 | *
|
---|
6 | * Contains declarations of the functions implemented in \ref init.c,
|
---|
7 | * enumeration value_type which is needed for ParseForParameters() and
|
---|
8 | * one inline function tpow() realising a "x to the power of n" where n
|
---|
9 | * may be also arbitrary (also negative) integer.
|
---|
10 | *
|
---|
11 | Project: ParallelCarParrinello
|
---|
12 | \authors Jan Hamaekers, Frederik Heber
|
---|
13 | \date 2000, 2006
|
---|
14 |
|
---|
15 | File: init.h
|
---|
16 | $Id: init.h,v 1.17 2007/02/09 09:13:48 foo Exp $
|
---|
17 | */
|
---|
18 |
|
---|
19 | // Specifting whether a value in the parameter file must be specified or is optional
|
---|
20 | enum necessity { optional, //!< parameter is optional, if not given sensible value is chosen
|
---|
21 | critical //!< parameter must be given or programme won't initiate
|
---|
22 | };
|
---|
23 |
|
---|
24 | // Specifying the cast type to be read of a parameter, see ParseForParameter()
|
---|
25 | enum value_type { string_type, double_type, int_type, row_int, row_double, grid, lower_trigrid, upper_trigrid};
|
---|
26 |
|
---|
27 | /* Bereite mainname vor: loescht von filename von rechts nach links bis zu erstem "/" oder ganz */
|
---|
28 | void CreateMainname(struct Problem *const P, const char* const filename);
|
---|
29 |
|
---|
30 | /* Einlesen der Parameterdatei */
|
---|
31 | int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, int repetition, enum necessity critical);
|
---|
32 | void ReadParameters(struct Problem *const P, const char *const filename);
|
---|
33 |
|
---|
34 | void Init(struct Problem *const P);
|
---|
35 | void InitPerturbation(struct Problem *P);
|
---|
36 | void InitPsisValue(struct Problem *const P, int start, int end);
|
---|
37 |
|
---|
38 | /** Calculate the value \a x to the power of \a n.
|
---|
39 | * \param x value
|
---|
40 | * \param n power
|
---|
41 | * \return \f$x^n\f$
|
---|
42 | */
|
---|
43 | static inline double tpow(double x, int n)
|
---|
44 | {
|
---|
45 | double y = 1;
|
---|
46 | int neg = (n < 0);
|
---|
47 |
|
---|
48 | if (neg) n = -n;
|
---|
49 |
|
---|
50 | while (n) { // go through every bit of the integer number n
|
---|
51 | if (n & 1) y *= x; // if bit set, multiply
|
---|
52 | x *= x; // go to next power of 2
|
---|
53 | n >>= 1; // and to the next bit
|
---|
54 | }
|
---|
55 | return neg ? 1.0/y : y; // if n was negative, return reciprocal value
|
---|
56 | }
|
---|
57 | #endif
|
---|
58 |
|
---|