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_data.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 //
12 
13 #ifndef KRATOS_STATISTICS_DATA_H_INCLUDED
14 #define KRATOS_STATISTICS_DATA_H_INCLUDED
15 
16 // System includes
17 #include <string>
18 #include <iostream>
19 #include <functional>
20 
21 // External includes
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "includes/element.h"
26 
27 namespace Kratos
28 {
31 
34 
36 
39 {
40 public:
43 
46 
47  typedef std::vector<double> ValueContainerType;
48 
49  typedef Matrix::iterator1 IntegrationPointDataView;
50  typedef Matrix::const_iterator1 IntegrationPointDataConstView;
51 
55 
58 
60  StatisticsData(StatisticsData const &rOther) {
61  mData = rOther.mData;
62  }
63 
65  virtual ~StatisticsData() {}
66 
70 
73  mData = rOther.mData;
74  return *this;
75  }
76 
80 
82 
86  void InitializeStorage(Element& rElement, std::size_t MeasurementSize)
87  {
88  const GeometryData::IntegrationMethod integration_method = rElement.GetIntegrationMethod();
89  std::size_t number_of_integration_points = rElement.GetGeometry().IntegrationPointsNumber(integration_method);
90 
91  mData.resize(number_of_integration_points, MeasurementSize, false);
92  mData = ZeroMatrix(number_of_integration_points, MeasurementSize);
93  }
94 
96 
103  const Element& rElement,
104  const PointerVector<StatisticsSampler>& rStatisticsSamplers,
105  const PointerVector<StatisticsSampler>& rHigherOrderStatistics,
106  ValueContainerType& rUpdate,
107  const std::size_t NumMeasurements)
108  {
109  KRATOS_DEBUG_ERROR_IF(NumMeasurements == 0)
110  << "Trying to update statistics, but providied number of recorded steps is zero" << std::endl;
111 
112  const Geometry<Node> &r_geometry = rElement.GetGeometry();
113  const GeometryData::IntegrationMethod integration_method = rElement.GetIntegrationMethod();
114  Matrix shape_functions;
115  typename Geometry<Node>::ShapeFunctionsGradientsType shape_gradients;
116  this->CalculateGeometryData(r_geometry, integration_method, shape_functions, shape_gradients);
117 
118  for (unsigned int g = 0; g < shape_functions.size1(); g++)
119  {
120  auto N = row(shape_functions, g);
121  auto &rDN_DN = shape_gradients[g];
122 
123  auto it_update_buffer = rUpdate.begin();
124  for (auto it_sampler = rStatisticsSamplers.begin(); it_sampler != rStatisticsSamplers.end(); ++it_sampler)
125  {
126  it_sampler->SampleDataPoint(r_geometry, N, rDN_DN, it_update_buffer);
127  }
128 
129  if (NumMeasurements > 1) { // Second order and higher statistics start from the second iteration
130  // loop on higer order statistics. They require the already written rMeasurements, (const) mData and the number of steps as input
131  for (auto it_statistic = rHigherOrderStatistics.begin(); it_statistic != rHigherOrderStatistics.end(); ++it_statistic)
132  {
133  it_statistic->SampleDataPoint(it_update_buffer, IntegrationPointData(g), rUpdate, NumMeasurements);
134  }
135  }
136 
137  for (unsigned int i = 0; i < rUpdate.size(); i++)
138  {
139  mData(g,i) += rUpdate[i];
140  }
141  }
142  }
143 
145 
153  std::ofstream& rOutputStream,
154  const Element& rElement,
155  const PointerVector<StatisticsSampler>& rRecordedStatistics,
156  const PointerVector<StatisticsSampler>& rHigherOrderStatistics,
157  const std::size_t NumberOfMeasurements,
158  const std::string& rSeparator) const
159  {
160  const Geometry<Node> &r_geometry = rElement.GetGeometry();
161  const GeometryData::IntegrationMethod integration_method = rElement.GetIntegrationMethod();
162  Matrix shape_functions;
163  typename Geometry<Node>::ShapeFunctionsGradientsType shape_gradients;
164  this->CalculateGeometryData(r_geometry, integration_method, shape_functions, shape_gradients);
165 
166  for (unsigned int g = 0; g < shape_functions.size1(); g++)
167  {
168  // Print element ID and integration point index
169  rOutputStream << rElement.Id() << rSeparator << g << rSeparator;
170 
171  // Print integration point coordinates
172  array_1d<double,3> coordinates(3,0.0);
173  for (unsigned int n = 0; n < shape_functions.size2(); n++)
174  coordinates += shape_functions(g,n) * r_geometry[n].Coordinates();
175  rOutputStream << coordinates[0] << rSeparator << coordinates[1] << rSeparator << coordinates[2];
176 
177  auto data_iterator = IntegrationPointData(g).begin();
178  for (auto it_sampler = rRecordedStatistics.begin(); it_sampler != rRecordedStatistics.end(); ++it_sampler)
179  {
180  it_sampler->OutputResult(rOutputStream,data_iterator,NumberOfMeasurements,rSeparator);
181  }
182 
183  for (auto it_sampler = rHigherOrderStatistics.begin(); it_sampler != rHigherOrderStatistics.end(); ++it_sampler)
184  {
185  it_sampler->OutputResult(rOutputStream,data_iterator,NumberOfMeasurements,rSeparator);
186  }
187 
188  rOutputStream << "\n";
189  }
190  }
191 
195 
197  std::size_t NumberOfIntegrationPoints() const
198  {
199  return mData.size1();
200  }
201 
203 
206  std::size_t NumberOfStatisticalQuantities() const
207  {
208  return mData.size2();
209  }
210 
214 
216 
218  IntegrationPointDataView IntegrationPointData(std::size_t IntegrationPointIndex)
219  {
220  KRATOS_DEBUG_ERROR_IF(IntegrationPointIndex >= mData.size1())
221  << "Asking for integration point number " << IntegrationPointIndex
222  << " but only " << mData.size1() << " points are recorded." << std::endl;
223  return (mData.begin1() + IntegrationPointIndex);
224  }
225 
227 
229  IntegrationPointDataConstView IntegrationPointData(std::size_t IntegrationPointIndex) const
230  {
231  KRATOS_DEBUG_ERROR_IF(IntegrationPointIndex >= mData.size1())
232  << "Asking for integration point number " << IntegrationPointIndex
233  << " but only " << mData.size1() << " points are recorded." << std::endl;
234  return (mData.begin1() + IntegrationPointIndex);
235  }
236 
240 
242  virtual std::string Info() const
243  {
244  std::stringstream buffer;
245  buffer << "StatisticsData";
246  return buffer.str();
247  }
248 
250  virtual void PrintInfo(std::ostream &rOStream) const { rOStream << "StatisticsData"; }
251 
253  virtual void PrintData(std::ostream &rOStream) const {}
254 
256 
257 protected:
258 
261 
263  const Geometry<Node>& rGeometry,
265  Matrix &rN,
266  typename Geometry<Node>::ShapeFunctionsGradientsType &rDN_DX) const
267  {
268  const unsigned int number_of_nodes = rGeometry.PointsNumber();
269  const unsigned int number_of_gauss_points = rGeometry.IntegrationPointsNumber(IntegrationMethod);
270 
271  Vector det_J;
273 
274  rN.resize(number_of_gauss_points,number_of_nodes,false);
275  rN = rGeometry.ShapeFunctionsValues(IntegrationMethod);
276  }
277 
279 
280 private:
281 
284 
285  Matrix mData;
286 
290 
291  friend class Serializer;
292 
293  void save(Serializer& rSerializer) const {}
294 
295  void load(Serializer& rSerializer) {}
296 
298 
299 }; // Class StatisticsData
300 
304 
306 inline std::istream &operator>>(std::istream &rIStream,
307  StatisticsData/*< std::vector<double> >*/ &rThis)
308 {
309  return rIStream;
310 }
311 
313 inline std::ostream &operator<<(std::ostream &rOStream,
314  const StatisticsData/*< std::vector<double> >*/ &rThis)
315 {
316  rThis.PrintInfo(rOStream);
317  rOStream << std::endl;
318  rThis.PrintData(rOStream);
319 
320  return rOStream;
321 }
323 
325 
326 } // namespace Kratos.
327 
328 #endif // KRATOS_STATISTICS_DATA_H_INCLUDED defined
Base class for all Elements.
Definition: element.h:60
virtual IntegrationMethod GetIntegrationMethod() const
Definition: element.h:285
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
const Matrix & ShapeFunctionsValues() const
Definition: geometry.h:3393
void ShapeFunctionsIntegrationPointsGradients(ShapeFunctionsGradientsType &rResult) const
Definition: geometry.h:3708
SizeType IntegrationPointsNumber() const
Definition: geometry.h:2257
IndexType Id() const
Definition: indexed_object.h:107
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
iterator begin()
Definition: amatrix_interface.h:241
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
iterator end()
Definition: pointer_vector.h:177
iterator begin()
Definition: pointer_vector.h:169
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
Internal container for integration point statistitcs on a given element.
Definition: statistics_data.h:39
StatisticsData(StatisticsData const &rOther)
Copy constructor.
Definition: statistics_data.h:60
void WriteToCSVOutput(std::ofstream &rOutputStream, const Element &rElement, const PointerVector< StatisticsSampler > &rRecordedStatistics, const PointerVector< StatisticsSampler > &rHigherOrderStatistics, const std::size_t NumberOfMeasurements, const std::string &rSeparator) const
Write computed statistics to output file.
Definition: statistics_data.h:152
virtual std::string Info() const
Turn back information as a string.
Definition: statistics_data.h:242
std::size_t NumberOfIntegrationPoints() const
How many integration points this container holds data for.
Definition: statistics_data.h:197
StatisticsData & operator=(StatisticsData const &rOther)
Assignment operator.
Definition: statistics_data.h:72
void CalculateGeometryData(const Geometry< Node > &rGeometry, const GeometryData::IntegrationMethod IntegrationMethod, Matrix &rN, typename Geometry< Node >::ShapeFunctionsGradientsType &rDN_DX) const
Definition: statistics_data.h:262
IntegrationPointDataConstView IntegrationPointData(std::size_t IntegrationPointIndex) const
Access internal data for a given integration point.
Definition: statistics_data.h:229
StatisticsData()
Default constructor.
Definition: statistics_data.h:57
IntegrationPointDataView IntegrationPointData(std::size_t IntegrationPointIndex)
Access internal data for a given integration point.
Definition: statistics_data.h:218
Matrix::const_iterator1 IntegrationPointDataConstView
Definition: statistics_data.h:50
Matrix::iterator1 IntegrationPointDataView
Definition: statistics_data.h:49
KRATOS_CLASS_POINTER_DEFINITION(StatisticsData)
Pointer definition of StatisticsData.
std::vector< double > ValueContainerType
Definition: statistics_data.h:47
void InitializeStorage(Element &rElement, std::size_t MeasurementSize)
Initialize internal storage for this container.
Definition: statistics_data.h:86
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: statistics_data.h:253
virtual ~StatisticsData()
Destructor.
Definition: statistics_data.h:65
std::size_t NumberOfStatisticalQuantities() const
How many quantities this container holds data for.
Definition: statistics_data.h:206
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: statistics_data.h:250
void UpdateMeasurement(const Element &rElement, const PointerVector< StatisticsSampler > &rStatisticsSamplers, const PointerVector< StatisticsSampler > &rHigherOrderStatistics, ValueContainerType &rUpdate, const std::size_t NumMeasurements)
Record a new realization for the measured statistics.
Definition: statistics_data.h:102
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
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
N
Definition: sensitivityMatrix.py:29
det_J
Definition: sensitivityMatrix.py:67
integer i
Definition: TensorModule.f:17