KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
statistics_utilities.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Jordi Cotela
11 // Author2 Fullname
12 //
13 
14 #ifndef KRATOS_STATISTICS_UTILITIES_H_INCLUDED
15 #define KRATOS_STATISTICS_UTILITIES_H_INCLUDED
16 
17 // System includes
18 #include <string>
19 #include <iostream>
20 #include <functional>
21 
22 // External includes
23 
24 // Project includes
25 #include "includes/define.h"
26 #include "includes/node.h"
28 #include "geometries/geometry.h"
29 
30 namespace Kratos
31 {
34 
37 
40 {
41 public:
42 
44 
45 typedef Matrix::iterator1 IntegrationPointDataView;
46 typedef Matrix::const_iterator2 IntegrationPointDataViewIterator;
47 
49 
53 StatisticsSampler(std::size_t NumValues):
54  mNumValues(NumValues),
55  mOffset(0)
56 {}
57 
59 virtual ~StatisticsSampler() {}
60 
62 
69 virtual void SampleDataPoint(
70  const Geometry< Node >& rGeometry,
71  const Vector& rShapeFunctions,
72  const Matrix& rShapeDerivatives,
73  std::vector<double>::iterator& BufferIterator)
74 {}
75 
77 
84 virtual void SampleDataPoint(
85  std::vector<double>::iterator& BufferIterator,
86  const StatisticsSampler::IntegrationPointDataView& rCurrentStatistics,
87  const std::vector<double>& rNewMeasurement,
88  const std::size_t NumberOfMeasurements)
89 {}
90 
92 std::size_t GetSize() const {
93  return mNumValues;
94 }
95 
97 virtual std::size_t GetComponentOffset(std::size_t i) const
98 {
99  KRATOS_DEBUG_ERROR_IF(i >= mNumValues)
100  << "Trying to access component index " << i << ", but only "
101  << mNumValues << " components are stored." << std::endl;
102 
103  return mOffset + i;
104 }
105 
107 virtual std::size_t ComponentIndex(std::size_t i, std::size_t j) const
108 {
109  return i*mNumValues + j;
110 }
111 
113 std::size_t GetOffset() const
114 {
115  return mOffset;
116 }
117 
119 void SetOffset(std::size_t Offset) {
120  mOffset = Offset;
121 }
122 
124 
131 virtual void OutputResult(
132  std::ofstream& rOutStream,
134  std::size_t SampleSize,
135  const std::string& rSeparator) const
136 {
137  for (std::size_t i = 0; i < mNumValues; i++) {
138  rOutStream << rSeparator << Finalize(*rDataBuffer, SampleSize);
139  ++rDataBuffer;
140  }
141 }
142 
144 
148 virtual void OutputHeader(
149  std::ofstream& rOutStream,
150  const std::string& rSeparator) const
151 {
152  rOutStream << rSeparator;
153 }
154 
156 
158 virtual double Finalize(double Value, std::size_t SampleSize) const
159 {
160  return Value / SampleSize;
161 }
162 
164 
167 std::string GetTag(std::size_t ComponentIndex) const
168 {
170  << "Requesting tag for component " << ComponentIndex
171  << " but only " << mNumValues << " components are stored." << std::endl;
172  return mTags[ComponentIndex];
173 }
174 
175 protected:
176 
177 void AddTag(std::string Tag)
178 {
179  mTags.push_back(Tag);
180 }
181 
182 private:
183 
184 const std::size_t mNumValues;
185 
186 std::size_t mOffset;
187 
188 std::vector<std::string> mTags;
189 
190 friend class Serializer;
191 
192 void save(Serializer& rSerializer) const {}
193 
194 void load(Serializer& rSerializer) {}
195 
196 StatisticsSampler():
197  mNumValues(0),
198  mOffset(0)
199 {}
200 
201 };
202 
205 {
206 public:
207 
209 
214  std::function<double(const Geometry< Node >&, const Vector&, const Matrix&)> Getter,
215  const std::string& Tag)
216  :
218  mGetter(Getter)
219 {
220  AddTag(Tag);
221 }
222 
224 
225 void SampleDataPoint(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives, std::vector<double>::iterator& BufferIterator) override
226 {
227  *BufferIterator = mGetter(rGeometry,rShapeFunctions,rShapeDerivatives);
228  ++BufferIterator;
229 }
230 
232  std::ofstream& rOutStream,
233  const std::string& rSeparator) const override
234 {
235  rOutStream << "<" << GetTag(0) << ">" << rSeparator;
236 }
237 
238 private:
239 
240 std::function<double(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives)> mGetter;
241 
242 };
243 
244 
246 template< class VectorType >
248 {
249 public:
250 
252 
258  std::function<VectorType(const Geometry< Node >&, const Vector&, const Matrix&)> Getter,
259  std::size_t VectorSize,
260  std::vector<std::string>& Tags)
261  :
262  StatisticsSampler(VectorSize),
263  mGetter(Getter)
264 {
265  for (auto it_tag = Tags.begin(); it_tag != Tags.end(); ++it_tag)
266  {
267  AddTag(*it_tag);
268  }
269 }
270 
272 
273 void SampleDataPoint(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives, std::vector<double>::iterator& BufferIterator) override {
274  VectorType result = mGetter(rGeometry,rShapeFunctions,rShapeDerivatives);
275  for (unsigned int i = 0; i < this->GetSize(); i++) {
276  *BufferIterator = result[i];
277  ++BufferIterator;
278  }
279 }
280 
282  std::ofstream& rOutStream,
283  const std::string& rSeparator) const override
284 {
285  for (std::size_t i = 0; i < GetSize(); i++)
286  {
287  rOutStream << "<" << GetTag(i) << ">" << rSeparator;
288  }
289 }
290 
291 private:
292 
293 std::function<VectorType(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives)> mGetter;
294 };
295 
298 {
299 public:
300 
302 
306 VarianceSampler(const StatisticsSampler::Pointer pQuantity1, const StatisticsSampler::Pointer pQuantity2):
307  StatisticsSampler(pQuantity1->GetSize() * pQuantity2->GetSize()),
308  mpQuantity1(pQuantity1),
309  mpQuantity2(pQuantity2)
310 {}
311 
313  std::vector<double>::iterator& BufferIterator,
314  const StatisticsSampler::IntegrationPointDataView& rCurrentStatistics,
315  const std::vector<double>& rNewMeasurement,
316  const std::size_t NumberOfMeasurements) override
317 {
318  const double update_factor = 1.0 / ((NumberOfMeasurements-1)*NumberOfMeasurements);
319  for (std::size_t i = 0; i < mpQuantity1->GetSize(); i++)
320  {
321  double current_total_i = *(rCurrentStatistics.begin() + mpQuantity1->GetComponentOffset(i));
322  double new_measurement_i = rNewMeasurement[mpQuantity1->GetComponentOffset(i)];
323  double delta_i = (NumberOfMeasurements-1)*new_measurement_i - current_total_i;
324  for (std::size_t j = 0; j < mpQuantity2->GetSize(); j++)
325  {
326  double current_total_j = *(rCurrentStatistics.begin() + mpQuantity2->GetComponentOffset(j));
327  double new_measurement_j = rNewMeasurement[mpQuantity2->GetComponentOffset(j)];
328  double delta_j = (NumberOfMeasurements-1)*new_measurement_j - current_total_j;
329  (*BufferIterator) = update_factor * delta_i * delta_j;
330  ++BufferIterator;
331  }
332  }
333 
334 }
335 
336 // Override the Finalize method to implement the unbiased variance (divide by n-1)
337 double Finalize(double Value, std::size_t SampleSize) const override
338 {
339  return Value / (SampleSize - 1);
340 }
341 
342 protected:
343 
344 VarianceSampler(const StatisticsSampler::Pointer pQuantity1, const StatisticsSampler::Pointer pQuantity2, std::size_t DataSize):
345  StatisticsSampler(DataSize),
346  mpQuantity1(pQuantity1),
347  mpQuantity2(pQuantity2)
348 {}
349 
350 const StatisticsSampler::Pointer GetQuantity1() const
351 {
352  return mpQuantity1;
353 }
354 
355 const StatisticsSampler::Pointer GetQuantity2() const
356 {
357  return mpQuantity2;
358 }
359 
361  std::ofstream& rOutStream,
362  const std::string& rSeparator) const override
363 {
364  for (std::size_t i = 0; i < mpQuantity1->GetSize(); i++)
365  {
366  for (std::size_t j = 0; j < mpQuantity2->GetSize(); j++)
367  {
368  rOutStream << "<" << mpQuantity1->GetTag(i) << "'" << mpQuantity2->GetTag(j) << "'>" << rSeparator;
369  }
370  }
371 }
372 
373 private:
374 
375 const StatisticsSampler::Pointer mpQuantity1;
376 
377 const StatisticsSampler::Pointer mpQuantity2;
378 
379 };
380 
382 
387 {
388 public:
389 
391 
394 SymmetricVarianceSampler(const StatisticsSampler::Pointer pQuantity1):
395  VarianceSampler(pQuantity1, pQuantity1, ((pQuantity1->GetSize()+1) * pQuantity1->GetSize()) / 2)
396 {}
397 
398 std::size_t ComponentIndex(std::size_t i, std::size_t j) const override
399 {
400  if (i <= j)
401  {
402  return i*this->GetSize() - (i*(i+1))/2 + j;
403  }
404  else
405  {
406  return j*this->GetSize() - (j*(j+1))/2 + i;
407  }
408 }
409 
411  std::vector<double>::iterator& BufferIterator,
412  const StatisticsSampler::IntegrationPointDataView& rCurrentStatistics,
413  const std::vector<double>& rNewMeasurement,
414  const std::size_t NumberOfMeasurements) override
415 {
416  const double update_factor = 1.0 / ((NumberOfMeasurements-1)*NumberOfMeasurements);
417  for (std::size_t i = 0; i < GetQuantity1()->GetSize(); i++)
418  {
419  double current_total_i = *(rCurrentStatistics.begin() + GetQuantity1()->GetComponentOffset(i));
420  double new_measurement_i = rNewMeasurement[GetQuantity1()->GetComponentOffset(i)];
421  double delta_i = (NumberOfMeasurements-1)*new_measurement_i - current_total_i;
422  for (std::size_t j = i; j < GetQuantity1()->GetSize(); j++)
423  {
424  double current_total_j = *(rCurrentStatistics.begin() + GetQuantity1()->GetComponentOffset(j));
425  double new_measurement_j = rNewMeasurement[GetQuantity1()->GetComponentOffset(j)];
426  double delta_j = (NumberOfMeasurements-1)*new_measurement_j - current_total_j;
427  (*BufferIterator) = update_factor * delta_i * delta_j;
428  ++BufferIterator;
429  }
430  }
431 }
432 
434  std::ofstream& rOutStream,
435  const std::string& rSeparator) const override
436 {
437  for (std::size_t i = 0; i < GetQuantity1()->GetSize(); i++)
438  {
439  for (std::size_t j = i; j < GetQuantity1()->GetSize(); j++)
440  {
441  rOutStream << "<" << GetQuantity1()->GetTag(i) << "'" << GetQuantity1()->GetTag(j) << "'>" << rSeparator;
442  }
443  }
444 }
445 
446 
447 };
448 
450 
454 {
455 public:
456 
458 
466  const StatisticsSampler::Pointer pQuantity1,
467  std::size_t ComponentIndex1,
468  const StatisticsSampler::Pointer pQuantity2,
469  std::size_t ComponentIndex2)
470  : VarianceSampler(pQuantity1,pQuantity2,1)
471  , mComponent1(ComponentIndex1)
472  , mComponent2(ComponentIndex2)
473 {}
474 
476  std::vector<double>::iterator& BufferIterator,
477  const StatisticsSampler::IntegrationPointDataView& rCurrentStatistics,
478  const std::vector<double>& rNewMeasurement,
479  const std::size_t NumberOfMeasurements) override
480 {
481  const double update_factor = 1.0 / ((NumberOfMeasurements-1)*NumberOfMeasurements);
482 
483  double current_total_i = *(rCurrentStatistics.begin() + GetQuantity1()->GetComponentOffset(mComponent1));
484  double new_measurement_i = rNewMeasurement[GetQuantity1()->GetComponentOffset(mComponent1)];
485  double delta_i = (NumberOfMeasurements-1)*new_measurement_i - current_total_i;
486 
487  double current_total_j = *(rCurrentStatistics.begin() + GetQuantity2()->GetComponentOffset(mComponent2));
488  double new_measurement_j = rNewMeasurement[GetQuantity2()->GetComponentOffset(mComponent2)];
489  double delta_j = (NumberOfMeasurements-1)*new_measurement_j - current_total_j;
490  (*BufferIterator) = update_factor * delta_i * delta_j;
491  ++BufferIterator;
492 }
493 
494 
496  std::ofstream& rOutStream,
497  const std::string& rSeparator) const override
498 {
499  rOutStream << "<" << GetQuantity1()->GetTag(mComponent1) << "'" << GetQuantity2()->GetTag(mComponent2) << "'>" << rSeparator;
500 }
501 
502 private:
503 
504 std::size_t mComponent1;
505 
506 std::size_t mComponent2;
507 
508 };
509 
511 
515 {
516 public:
517 
519 
537  const StatisticsSampler::Pointer pQuantity1,
538  const std::size_t QuantityComponent1,
539  const StatisticsSampler::Pointer pQuantity2,
540  const std::size_t QuantityComponent2,
541  const StatisticsSampler::Pointer pQuantity3,
542  const std::size_t QuantityComponent3,
543  const StatisticsSampler::Pointer pVariance12,
544  const std::size_t VarianceComponent12,
545  const StatisticsSampler::Pointer pVariance13,
546  const std::size_t VarianceComponent13,
547  const StatisticsSampler::Pointer pVariance23,
548  const std::size_t VarianceComponent23):
550  mpQuantity1(pQuantity1),
551  mpQuantity2(pQuantity2),
552  mpQuantity3(pQuantity3),
553  mComponent1(QuantityComponent1),
554  mComponent2(QuantityComponent2),
555  mComponent3(QuantityComponent3),
556  mpVariance12(pVariance12),
557  mpVariance13(pVariance13),
558  mpVariance23(pVariance23),
559  mVarianceComponent12(VarianceComponent12),
560  mVarianceComponent13(VarianceComponent13),
561  mVarianceComponent23(VarianceComponent23)
562 {}
563 
565  std::vector<double>::iterator& BufferIterator,
566  const StatisticsSampler::IntegrationPointDataView& rCurrentStatistics,
567  const std::vector<double>& rNewMeasurement,
568  const std::size_t NumberOfMeasurements) override
569 {
570  const double update_factor_1 = 1.0 / ((NumberOfMeasurements-1)*NumberOfMeasurements);
571  const double update_factor_2 = (NumberOfMeasurements-2)*update_factor_1*update_factor_1;
572 
573  const std::size_t value_1_offset = mpQuantity1->GetComponentOffset(mComponent1);
574  const std::size_t value_2_offset = mpQuantity2->GetComponentOffset(mComponent2);
575  const std::size_t value_3_offset = mpQuantity3->GetComponentOffset(mComponent3);
576 
577  const std::size_t variance_12_offset = mpVariance12->GetComponentOffset(mVarianceComponent12);
578  const std::size_t variance_13_offset = mpVariance13->GetComponentOffset(mVarianceComponent13);
579  const std::size_t variance_23_offset = mpVariance23->GetComponentOffset(mVarianceComponent23);
580 
581  double current_total_1 = *(rCurrentStatistics.begin() + value_1_offset);
582  double new_measurement_1 = rNewMeasurement[value_1_offset];
583  double delta_1 = (NumberOfMeasurements-1)*new_measurement_1 - current_total_1;
584 
585  double current_total_2 = *(rCurrentStatistics.begin() + value_2_offset);
586  double new_measurement_2 = rNewMeasurement[value_2_offset];
587  double delta_2 = (NumberOfMeasurements-1)*new_measurement_2 - current_total_2;
588 
589  double current_total_3 = *(rCurrentStatistics.begin() + value_3_offset);
590  double new_measurement_3 = rNewMeasurement[value_3_offset];
591  double delta_3 = (NumberOfMeasurements-1)*new_measurement_3 - current_total_3;
592 
593  double current_variance_12 = *(rCurrentStatistics.begin() + variance_12_offset);
594  double current_variance_13 = *(rCurrentStatistics.begin() + variance_13_offset);
595  double current_variance_23 = *(rCurrentStatistics.begin() + variance_23_offset);
596 
597  double update = update_factor_2 * delta_1 * delta_2 * delta_3;
598  update -= update_factor_1 * current_variance_12 * delta_3;
599  update -= update_factor_1 * current_variance_13 * delta_2;
600  update -= update_factor_1 * current_variance_23 * delta_1;
601 
602  (*BufferIterator) = update;
603  ++BufferIterator;
604 }
605 
606 virtual void OutputHeader(
607  std::ofstream& rOutStream,
608  const std::string& rSeparator) const override
609 {
610  rOutStream << "<"
611  << mpQuantity1->GetTag(mComponent1) << "'"
612  << mpQuantity2->GetTag(mComponent2) << "'"
613  << mpQuantity3->GetTag(mComponent3) << "'>" << rSeparator;
614 }
615 
616 private:
617 
618 const StatisticsSampler::Pointer mpQuantity1;
619 
620 const StatisticsSampler::Pointer mpQuantity2;
621 
622 const StatisticsSampler::Pointer mpQuantity3;
623 
624 const std::size_t mComponent1;
625 
626 const std::size_t mComponent2;
627 
628 const std::size_t mComponent3;
629 
630 
631 const StatisticsSampler::Pointer mpVariance12;
632 
633 const StatisticsSampler::Pointer mpVariance13;
634 
635 const StatisticsSampler::Pointer mpVariance23;
636 
637 const std::size_t mVarianceComponent12;
638 
639 const std::size_t mVarianceComponent13;
640 
641 const std::size_t mVarianceComponent23;
642 
643 
644 };
645 
646 namespace Internals {
647 
649 public:
650  static std::function<double(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives)> ValueGetter(const Variable<double>& rVariable) {
651  return [&rVariable](const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) -> double {
652  KRATOS_DEBUG_ERROR_IF(rGeometry.size() != rShapeFunctions.size()) << "Number of nodes in provided geometry does not match number of shape functions" << std::endl;
653  double value = 0.0;
654  for (unsigned int i = 0; i < rGeometry.size(); i++) {
655  value += rGeometry[i].FastGetSolutionStepValue(rVariable) * rShapeFunctions[i];
656  }
657  return value;
658  };
659  }
660 
661 
662  static std::function< array_1d<double,3>(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) > ValueGetter(const Variable<array_1d<double,3>>& rVariable) {
663  return [&rVariable](const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) -> array_1d<double,3> {
664  KRATOS_DEBUG_ERROR_IF(rGeometry.size() != rShapeFunctions.size()) << "Number of nodes in provided geometry does not match number of shape functions" << std::endl;
665  array_1d<double,3> value = ZeroVector(3);
666  for (unsigned int i = 0; i < rGeometry.size(); i++) {
667  value += rGeometry[i].FastGetSolutionStepValue(rVariable) * rShapeFunctions[i];
668  }
669  return value;
670  };
671  }
672 
673  static std::function< Matrix(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) > ValueGetter(const Variable<Matrix>& rVariable) {
674  return [&rVariable](const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) -> Matrix {
675  KRATOS_DEBUG_ERROR_IF(rGeometry.size() != rShapeFunctions.size()) << "Number of nodes in provided geometry does not match number of shape functions" << std::endl;
676  Matrix value = ZeroMatrix(3,3);
677  for (unsigned int i = 0; i < rGeometry.size(); i++) {
678  value += rGeometry[i].FastGetSolutionStepValue(rVariable) * rShapeFunctions[i];
679  }
680  return value;
681  };
682  }
683 
684 
685  static std::function< array_1d<double,3>(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) > GradientGetter(const Variable<double>& rVariable) {
686  return [&rVariable](const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) -> array_1d<double,3> {
687  KRATOS_DEBUG_ERROR_IF(rGeometry.size() != rShapeDerivatives.size1()) << "Number of nodes in provided geometry does not match number of shape functions" << std::endl;
688  array_1d<double,3> gradient = ZeroVector(3);
689  for (unsigned int n = 0; n < rGeometry.size(); n++) {
690  const auto& value = rGeometry[n].FastGetSolutionStepValue(rVariable);
691  for (unsigned int i = 0; i < rShapeDerivatives.size2(); i++)
692  gradient[i] += value * rShapeDerivatives(n,i);
693  }
694  return gradient;
695  };
696  }
697 
698 
699  static std::function< Matrix(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) > GradientGetter(const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, Variable<array_1d<double,3>>& rVariable) {
700  return [&rVariable](const Geometry< Node >& rGeometry, const Vector& rShapeFunctions, const Matrix& rShapeDerivatives) -> Matrix {
701  KRATOS_DEBUG_ERROR_IF(rGeometry.size() != rShapeDerivatives.size1()) << "Number of nodes in provided geometry does not match number of shape functions" << std::endl;
702  Matrix gradient = ZeroMatrix(3,3);
703  for (unsigned int n = 0; n < rGeometry.size(); n++) {
704  const auto& value = rGeometry[n].FastGetSolutionStepValue(rVariable);
705  for (unsigned int i = 0; i < rShapeDerivatives.size2(); i++)
706  {
707  for (unsigned int j = 0; j < rShapeDerivatives.size2(); j++)
708  gradient(i,j) += value[i] * rShapeDerivatives(n,j); //dui/dxj
709  }
710  }
711  return gradient;
712  };
713  }
714 };
715 
716 }
717 
719 
722 
724 inline std::istream &operator>>(std::istream &rIStream,
725  StatisticsSampler &rThis)
726 {
727  return rIStream;
728 }
729 
731 inline std::ostream &operator<<(std::ostream &rOStream,
732  const StatisticsSampler &rThis)
733 {
734  return rOStream;
735 }
736 
738 
740 
741 } // namespace Kratos.
742 
743 #endif // KRATOS_STATISTICS_UTILITIES_H_INCLUDED defined
This class manages the computation of the (co)variance when one or both variables are Vector componen...
Definition: statistics_utilities.h:454
ComponentwiseVarianceSampler(const StatisticsSampler::Pointer pQuantity1, std::size_t ComponentIndex1, const StatisticsSampler::Pointer pQuantity2, std::size_t ComponentIndex2)
Initialize a sampler for the (co)variance between two given quantities.
Definition: statistics_utilities.h:465
void SampleDataPoint(std::vector< double >::iterator &BufferIterator, const StatisticsSampler::IntegrationPointDataView &rCurrentStatistics, const std::vector< double > &rNewMeasurement, const std::size_t NumberOfMeasurements) override
For higher-order statistics: operate on lower order data.
Definition: statistics_utilities.h:475
void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:495
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Definition: statistics_utilities.h:648
static std::function< double(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives)> ValueGetter(const Variable< double > &rVariable)
Definition: statistics_utilities.h:650
static std::function< Matrix(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives) > ValueGetter(const Variable< Matrix > &rVariable)
Definition: statistics_utilities.h:673
static std::function< array_1d< double, 3 >const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives) > GradientGetter(const Variable< double > &rVariable)
Definition: statistics_utilities.h:685
static std::function< array_1d< double, 3 >const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives) > ValueGetter(const Variable< array_1d< double, 3 >> &rVariable)
Definition: statistics_utilities.h:662
static std::function< Matrix(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives) > GradientGetter(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, Variable< array_1d< double, 3 >> &rVariable)
Definition: statistics_utilities.h:699
This class manages the computation of the average of a scalar quantity.
Definition: statistics_utilities.h:205
void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:231
~ScalarAverageSampler() override
Definition: statistics_utilities.h:223
void SampleDataPoint(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives, std::vector< double >::iterator &BufferIterator) override
For first-order statistics: read data directly.
Definition: statistics_utilities.h:225
ScalarAverageSampler(std::function< double(const Geometry< Node > &, const Vector &, const Matrix &)> Getter, const std::string &Tag)
Initialize a sampler for a scalar average quantity.
Definition: statistics_utilities.h:213
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
Base class for statistical measurements.
Definition: statistics_utilities.h:40
virtual std::size_t GetComponentOffset(std::size_t i) const
Offset (from the start of the space allocated to this statistic) for the storage of component i.
Definition: statistics_utilities.h:97
Matrix::const_iterator2 IntegrationPointDataViewIterator
Definition: statistics_utilities.h:46
std::size_t GetSize() const
Number of quantities managed by this statistic.
Definition: statistics_utilities.h:92
virtual void SampleDataPoint(std::vector< double >::iterator &BufferIterator, const StatisticsSampler::IntegrationPointDataView &rCurrentStatistics, const std::vector< double > &rNewMeasurement, const std::size_t NumberOfMeasurements)
For higher-order statistics: operate on lower order data.
Definition: statistics_utilities.h:84
virtual void OutputResult(std::ofstream &rOutStream, IntegrationPointDataViewIterator &rDataBuffer, std::size_t SampleSize, const std::string &rSeparator) const
Write results managed by this class to output buffer.
Definition: statistics_utilities.h:131
virtual void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const
Write header for the output file.
Definition: statistics_utilities.h:148
virtual std::size_t ComponentIndex(std::size_t i, std::size_t j) const
Helper returning the correct argument in calls to GetComponentOffset for matrix quantities.
Definition: statistics_utilities.h:107
virtual void SampleDataPoint(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives, std::vector< double >::iterator &BufferIterator)
For first-order statistics: read data directly.
Definition: statistics_utilities.h:69
virtual ~StatisticsSampler()
Destructor.
Definition: statistics_utilities.h:59
std::size_t GetOffset() const
Offset (from the start of the statistics container) to the first component stored by this statistic.
Definition: statistics_utilities.h:113
Matrix::iterator1 IntegrationPointDataView
Definition: statistics_utilities.h:45
std::string GetTag(std::size_t ComponentIndex) const
Get the string associated one of the components of this statistic.
Definition: statistics_utilities.h:167
void SetOffset(std::size_t Offset)
Assign a new offset (from the start of the statistics container) to the first component stored by thi...
Definition: statistics_utilities.h:119
virtual double Finalize(double Value, std::size_t SampleSize) const
Post-process internal data to produce the final value of the statistical result.
Definition: statistics_utilities.h:158
KRATOS_CLASS_POINTER_DEFINITION(StatisticsSampler)
void AddTag(std::string Tag)
Definition: statistics_utilities.h:177
StatisticsSampler(std::size_t NumValues)
Define a new StatisticsSampler instance.
Definition: statistics_utilities.h:53
This class manages the computation of the variance for a given quantity.
Definition: statistics_utilities.h:387
void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:433
SymmetricVarianceSampler(const StatisticsSampler::Pointer pQuantity1)
Initialize a sampler for the variance of a vecor quantity.
Definition: statistics_utilities.h:394
void SampleDataPoint(std::vector< double >::iterator &BufferIterator, const StatisticsSampler::IntegrationPointDataView &rCurrentStatistics, const std::vector< double > &rNewMeasurement, const std::size_t NumberOfMeasurements) override
For higher-order statistics: operate on lower order data.
Definition: statistics_utilities.h:410
std::size_t ComponentIndex(std::size_t i, std::size_t j) const override
Helper returning the correct argument in calls to GetComponentOffset for matrix quantities.
Definition: statistics_utilities.h:398
This class manages the computation of third order moments of scalars or vector components.
Definition: statistics_utilities.h:515
virtual void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:606
ThirdOrderCorrelationSampler(const StatisticsSampler::Pointer pQuantity1, const std::size_t QuantityComponent1, const StatisticsSampler::Pointer pQuantity2, const std::size_t QuantityComponent2, const StatisticsSampler::Pointer pQuantity3, const std::size_t QuantityComponent3, const StatisticsSampler::Pointer pVariance12, const std::size_t VarianceComponent12, const StatisticsSampler::Pointer pVariance13, const std::size_t VarianceComponent13, const StatisticsSampler::Pointer pVariance23, const std::size_t VarianceComponent23)
Initialize a sampler for the third order moment involving three given quantities.
Definition: statistics_utilities.h:536
void SampleDataPoint(std::vector< double >::iterator &BufferIterator, const StatisticsSampler::IntegrationPointDataView &rCurrentStatistics, const std::vector< double > &rNewMeasurement, const std::size_t NumberOfMeasurements) override
For higher-order statistics: operate on lower order data.
Definition: statistics_utilities.h:564
This class manages the computation of the (co)variance between two given quantities (scalar or vector...
Definition: statistics_utilities.h:298
const StatisticsSampler::Pointer GetQuantity2() const
Definition: statistics_utilities.h:355
void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:360
double Finalize(double Value, std::size_t SampleSize) const override
Post-process internal data to produce the final value of the statistical result.
Definition: statistics_utilities.h:337
void SampleDataPoint(std::vector< double >::iterator &BufferIterator, const StatisticsSampler::IntegrationPointDataView &rCurrentStatistics, const std::vector< double > &rNewMeasurement, const std::size_t NumberOfMeasurements) override
For higher-order statistics: operate on lower order data.
Definition: statistics_utilities.h:312
VarianceSampler(const StatisticsSampler::Pointer pQuantity1, const StatisticsSampler::Pointer pQuantity2)
Initialize a sampler for the (co)variance between two given quantities.
Definition: statistics_utilities.h:306
VarianceSampler(const StatisticsSampler::Pointer pQuantity1, const StatisticsSampler::Pointer pQuantity2, std::size_t DataSize)
Definition: statistics_utilities.h:344
const StatisticsSampler::Pointer GetQuantity1() const
Definition: statistics_utilities.h:350
This class manages the computation of the average of a vector quantity.
Definition: statistics_utilities.h:248
~VectorAverageSampler() override
Definition: statistics_utilities.h:271
void OutputHeader(std::ofstream &rOutStream, const std::string &rSeparator) const override
Write header for the output file.
Definition: statistics_utilities.h:281
VectorAverageSampler(std::function< VectorType(const Geometry< Node > &, const Vector &, const Matrix &)> Getter, std::size_t VectorSize, std::vector< std::string > &Tags)
Initialize a sampler for a vector average quantity.
Definition: statistics_utilities.h:257
void SampleDataPoint(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives, std::vector< double >::iterator &BufferIterator) override
For first-order statistics: read data directly.
Definition: statistics_utilities.h:273
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
array_1d< double, 3 > VectorType
Definition: solid_mechanics_application_variables.cpp:19
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def load(f)
Definition: ode_solve.py:307
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17