16 #include <deal.II/base/memory_consumption.h> 17 #include <deal.II/lac/vector.h> 18 #include <deal.II/numerics/histogram.h> 22 DEAL_II_NAMESPACE_OPEN
25 template <
typename number>
29 return (((n1<n2) && (n1>0)) ||
30 ((n1<n2) && (n2<=0)) ||
31 ((n2<n1) && (n1>0) && (n2<=0)));
37 const double right_point) :
38 left_point (left_point),
39 right_point (right_point),
53 template <
typename number>
55 const std::vector<double> &y_values_,
56 const unsigned int n_intervals,
60 ExcMessage(
"Your input data needs to contain at least one input vector."));
62 ExcMessage(
"The number of intervals needs to be at least one."));
63 for (
unsigned int i=0; i<values.size(); ++i)
65 Assert (values.size() == y_values_.size(),
73 number min_value=0, max_value=0;
74 switch (interval_spacing)
78 min_value = *std::min_element(values[0].begin(),
80 max_value = *std::max_element(values[0].begin(),
83 for (
unsigned int i=1; i<values.size(); ++i)
85 min_value = std::min (min_value,
86 *std::min_element(values[i].begin(),
88 max_value = std::max (max_value,
89 *std::max_element(values[i].begin(),
98 typedef bool (*comparator) (
const number,
const number);
99 const comparator logarithmic_less_function
100 = &Histogram::template logarithmic_less<number>;
102 min_value = *std::min_element(values[0].begin(),
104 logarithmic_less_function);
106 max_value = *std::max_element(values[0].begin(),
108 logarithmic_less_function);
110 for (
unsigned int i=1; i<values.size(); ++i)
112 min_value = std::min (min_value,
113 *std::min_element(values[i].begin(),
115 logarithmic_less_function),
116 logarithmic_less_function);
118 max_value = std::max (max_value,
119 *std::max_element(values[i].begin(),
121 logarithmic_less_function),
122 logarithmic_less_function);
137 if (max_value <= min_value)
138 max_value = min_value+1;
149 intervals.push_back (std::vector<Interval>());
151 switch (interval_spacing)
155 const float delta = (max_value-min_value)/n_intervals;
157 for (
unsigned int n=0; n<n_intervals; ++n)
159 min_value+(n+1)*delta));
166 const float delta = (std::log(max_value)-std::log(min_value))/n_intervals;
168 for (
unsigned int n=0; n<n_intervals; ++n)
170 std::exp(std::log(min_value)+(n+1)*delta)));
180 for (
unsigned int i=1; i<values.size(); ++i)
185 for (
unsigned int i=0; i<values.size(); ++i)
187 p < values[i].
end(); ++p)
195 for (
unsigned int n=0; n<n_intervals; ++n)
206 template <
typename number>
208 const unsigned int n_intervals,
211 std::vector<Vector<number> > values_list (1,
213 evaluate (values_list, std::vector<double>(1,0.), n_intervals, interval_spacing);
222 ExcMessage(
"There is nothing to write into the output file. " 223 "Did you forget to call the evaluate() function?"));
229 for (
unsigned int n=0; n<
intervals[0].size(); ++n)
248 for (
int i=
intervals.size()-1; i>=0; --i)
250 for (
unsigned int n=0; n<
intervals[i].size(); ++n)
253 << (i<static_cast<int>(
intervals.size())-1 ?
261 << (i<static_cast<int>(
intervals.size())-1 ?
269 for (
unsigned int n=0; n<
intervals[i].size(); ++n)
294 return "linear|logarithmic";
304 else if (name==
"logarithmic")
327 void Histogram::evaluate<float> (
const std::vector<Vector<float> > &values,
328 const std::vector<double> &
y_values,
329 const unsigned int n_intervals,
332 void Histogram::evaluate<float> (
const Vector<float> &values,
333 const unsigned int n_intervals,
339 void Histogram::evaluate<double> (
const std::vector<Vector<double> > &values,
340 const std::vector<double> &
y_values,
341 const unsigned int n_intervals,
345 const unsigned int n_intervals,
348 DEAL_II_NAMESPACE_CLOSE
std::vector< std::vector< Interval > > intervals
static ::ExceptionBase & ExcInvalidName(std::string arg1)
static ::ExceptionBase & ExcIO()
Interval(const double left_point, const double right_point)
static ::ExceptionBase & ExcIncompatibleArraySize(int arg1, int arg2)
#define AssertThrow(cond, exc)
std::size_t memory_consumption() const
static ::ExceptionBase & ExcMessage(std::string arg1)
void evaluate(const std::vector< Vector< number > > &values, const std::vector< double > &y_values, const unsigned int n_intervals, const IntervalSpacing interval_spacing=linear)
void write_gnuplot(std::ostream &out) const
#define Assert(cond, exc)
static bool logarithmic_less(const number n1, const number n2)
std::size_t memory_consumption() const
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
std::vector< double > y_values
static IntervalSpacing parse_interval_spacing(const std::string &name)
static ::ExceptionBase & ExcEmptyData()
static std::string get_interval_spacing_names()
static ::ExceptionBase & ExcInternalError()