A monte carlo pin cell spectral code for nuclear engineering applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
arraycreator.h
Go to the documentation of this file.
1 
9 #ifndef ARRAYCREATOR_H_
10 #define ARRAYCREATOR_H_
11 
12 #ifdef __cplusplus
13 #include <limits>
14 #endif
15 
26 template <typename T, typename U>
27 U* linspace(T start, T end, int num_values) {
28 
29  U* values = new U[num_values];
30 
31  /* Spacing between values */
32  double delta = double(end - start) / double(num_values-1);
33 
34  /* Loop over all values */
35  for (int i=0; i < num_values; i++)
36  values[i] = delta * i + start;
37 
38  return values;
39 }
40 
41 
52 template <typename T, typename U>
53 U* logspace(T start, T end, int num_values) {
54 
55  /* Create an equally spaced array of base 10 exponent values */
56  U* values = linspace<T,U>(log10(start), log10(end), num_values);
57 
58  /* Loop over all values and project back original space */
59  for (int i=0; i < num_values; i++)
60  values[i] = pow(10, values[i]);
61 
62  return values;
63 }
64 
65 
66 #endif /* ARRAYCREATOR_H_ */
U * logspace(T start, T end, int num_values)
Creates an array of equal logarithmically spaced values.
Definition: arraycreator.h:53
U * linspace(T start, T end, int num_values)
Creates an array of equally spaced values.
Definition: arraycreator.h:27