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;
151 switch (interval_spacing)
155 const float delta = (max_value-min_value)/n_intervals;
157 for (
unsigned int n=0; n<n_intervals; ++n)
158 intervals[0].emplace_back (min_value+n*delta, min_value+(n+1)*delta);
165 const float delta = (std::log(max_value)-std::log(min_value))/n_intervals;
167 for (
unsigned int n=0; n<n_intervals; ++n)
168 intervals[0].emplace_back (std::exp(std::log(min_value)+n*delta),
169 std::exp(std::log(min_value)+(n+1)*delta));
179 for (
unsigned int i=1; i<values.size(); ++i)
184 for (
unsigned int i=0; i<values.size(); ++i)
185 for (
typename Vector<number>::const_iterator p=values[i].begin();
186 p < values[i].end(); ++p)
194 for (
unsigned int n=0; n<n_intervals; ++n)
205 template <
typename number>
207 const unsigned int n_intervals,
210 std::vector<Vector<number> > values_list (1,
212 evaluate (values_list, std::vector<double>(1,0.), n_intervals, interval_spacing);
221 ExcMessage(
"There is nothing to write into the output file. " 222 "Did you forget to call the evaluate() function?"));
228 for (
unsigned int n=0; n<
intervals[0].size(); ++n)
247 for (
int i=
intervals.size()-1; i>=0; --i)
249 for (
unsigned int n=0; n<
intervals[i].size(); ++n)
252 << (i<static_cast<int>(
intervals.size())-1 ?
260 << (i<static_cast<int>(
intervals.size())-1 ?
268 for (
unsigned int n=0; n<
intervals[i].size(); ++n)
293 return "linear|logarithmic";
303 else if (name==
"logarithmic")
326 void Histogram::evaluate<float> (
const std::vector<Vector<float> > &values,
327 const std::vector<double> &
y_values,
328 const unsigned int n_intervals,
331 void Histogram::evaluate<float> (
const Vector<float> &values,
332 const unsigned int n_intervals,
338 void Histogram::evaluate<double> (
const std::vector<Vector<double> > &values,
339 const std::vector<double> &
y_values,
340 const unsigned int n_intervals,
344 const unsigned int n_intervals,
347 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::vector< double > y_values
static IntervalSpacing parse_interval_spacing(const std::string &name)
static ::ExceptionBase & ExcEmptyData()
static std::string get_interval_spacing_names()
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()