19 "min=0 max=1 sum=2 mean=3 stddev=4 norm2=5 ratio=6 stderr=7 median=8 meanabs=9");
23template <
typename InType,
typename OutType>
31template <
typename InType,
typename OutType>
36 _sum +=
static_cast<OutType
>(val);
39template <
typename InType,
typename OutType>
45 this->_communicator.sum(_count);
46 this->_communicator.sum(_sum);
49 _sum /=
static_cast<OutType
>(_count);
53template <
typename InType,
typename OutType>
61template <
typename InType,
typename OutType>
66 this->_communicator.sum(this->_sum);
70template <
typename InType,
typename OutType>
76 _sum_of_square = OutType();
79template <
typename InType,
typename OutType>
84 _sum +=
static_cast<OutType
>(val);
88template <
typename InType,
typename OutType>
94 this->_communicator.sum(_count);
95 this->_communicator.sum(_sum);
96 this->_communicator.sum(_sum_of_square);
102 _sum_of_square = std::sqrt(std::abs(_sum_of_square - _sum * _sum / _count) / (_count - 1));
106template <
typename InType,
typename OutType>
111 this->_sum_of_square /= std::sqrt(this->_count);
115template <
typename InType,
typename OutType>
119 _min = std::numeric_limits<OutType>::max();
120 _max = std::numeric_limits<OutType>::min();
123template <
typename InType,
typename OutType>
128 _min =
static_cast<OutType
>(val);
130 _max =
static_cast<OutType
>(val);
133template <
typename InType,
typename OutType>
139 this->_communicator.min(_min);
140 this->_communicator.max(_max);
145template <
typename InType,
typename OutType>
149 _l2_norm = OutType();
152template <
typename InType,
typename OutType>
159template <
typename InType,
typename OutType>
164 this->_communicator.sum(_l2_norm);
165 _l2_norm = std::sqrt(_l2_norm);
169template <
typename InType,
typename OutType>
176template <
typename InType,
typename OutType>
180 _storage.push_back(
static_cast<OutType
>(val));
183template <
typename InType,
typename OutType>
189 auto count = _storage.size();
191 this->_communicator.sum(
count);
195 if (!is_distributed || this->n_processors() == 1)
197 std::sort(_storage.begin(), _storage.end());
199 _median = _storage[
count / 2];
201 _median += (_storage[
count / 2] + _storage[
count / 2 - 1]) / 2;
206 dof_id_type klt = kgt;
210 std::vector<std::size_t> sz = {_storage.size()};
211 this->_communicator.allgather(sz);
212 dof_id_type n = std::accumulate(sz.begin(), sz.end(), 0);
215 for (
const auto & i : index_range(sz))
218 if (this->processor_id() == i)
219 _median = _storage[0];
220 this->_communicator.broadcast(_median, i);
225 std::vector<dof_id_type> m(3, 0);
226 for (
const auto & val : _storage)
230 else if (val < _median)
233 this->_communicator.sum(m);
234 m[2] = n - m[0] - m[1];
237 if ((m[0] + m[2]) <= kgt)
239 _storage.erase(std::remove_if(_storage.begin(),
241 [
this](
const OutType & val) { return val >= _median; }),
246 else if ((m[1] + m[2]) <= klt)
248 _storage.erase(std::remove_if(_storage.begin(),
250 [
this](
const OutType & val) { return val <= _median; }),
264 num2 = std::numeric_limits<OutType>::max();
265 for (
const auto & val : _storage)
266 if (_median < val && val < num2)
268 this->_communicator.min(num2);
273 num2 = std::numeric_limits<OutType>::min();
274 for (
const auto & val : _storage)
275 if (val < _median && num2 < val)
277 this->_communicator.max(num2);
283 _median = (_median + num2) / 2;
291template <
typename InType,
typename OutType>
292std::unique_ptr<Calculator<InType, OutType>>
297 return std::make_unique<Min<InType, OutType>>(other, item);
299 else if (item ==
"max")
300 return std::make_unique<Max<InType, OutType>>(other, item);
302 else if (item ==
"sum")
303 return std::make_unique<Sum<InType, OutType>>(other, item);
305 else if (item ==
"mean" || item ==
"average")
306 return std::make_unique<Mean<InType, OutType>>(other, item);
308 else if (item ==
"stddev")
309 return std::make_unique<StdDev<InType, OutType>>(other, item);
311 else if (item ==
"stderr")
312 return std::make_unique<StdErr<InType, OutType>>(other, item);
314 else if (item ==
"norm2")
315 return std::make_unique<L2Norm<InType, OutType>>(other, item);
317 else if (item ==
"ratio")
318 return std::make_unique<Ratio<InType, OutType>>(other, item);
320 else if (item ==
"median")
321 return std::make_unique<Median<InType, OutType>>(other, item);
323 else if (item ==
"meanabs")
324 return std::make_unique<MeanAbsoluteValue<InType, OutType>>(other, item);
326 ::mooseError(
"Failed to create Statistics::Calculator object for ", item);
330#define createCalculators(InType, OutType) \
331 template class Mean<InType, OutType>; \
332 template class Max<InType, OutType>; \
333 template class Min<InType, OutType>; \
334 template class Sum<InType, OutType>; \
335 template class StdDev<InType, OutType>; \
336 template class StdErr<InType, OutType>; \
337 template class Ratio<InType, OutType>; \
338 template class L2Norm<InType, OutType>; \
339 template class Median<InType, OutType>; \
340 template struct CalculatorBuilder<InType, OutType>