13 #if !defined(KRATOS_INTEGRATION_POINT_STATISTICS_PROCESS_H_INCLUDED)
14 #define KRATOS_INTEGRATION_POINT_STATISTICS_PROCESS_H_INCLUDED
58 mrModelPart(rModelPart),
59 mpParameters(pParameters),
70 mrModelPart(rModel.GetModelPart((*pParameters)[
"model_part_name"].GetString())),
71 mpParameters(pParameters),
90 StatisticsRecord::Pointer p_turbulence_statistics = Kratos::make_shared<StatisticsRecord>();
96 p_turbulence_statistics->InitializeStorage(mrModelPart.
Elements());
108 p_turbulence_statistics->SampleIntegrationPointResults(mrModelPart);
116 p_turbulence_statistics->PrintToFile(mrModelPart, mOutputFileName);
124 std::string
Info()
const override
126 std::stringstream buffer;
127 buffer <<
"IntegrationPointStatisticsProcess";
132 void PrintInfo(std::ostream &rOStream)
const override { rOStream <<
"IntegrationPointStatisticsProcess"; }
135 void PrintData(std::ostream &rOStream)
const override {}
151 "output_file_name": "statistics",
152 "model_part_name": "",
160 mOutputFileName = r_parameters["output_file_name"].
GetString();
161 mStartTime = r_parameters[
"start_time"].
GetDouble();
163 mDimension = r_parameters[
"dimension"].
GetInt();
165 <<
"Unsupported dimension " << mDimension <<
". IntegrationPointStatisticsProcess only works for dimension 2 or 3." << std::endl;
169 for (
unsigned int i = 0;
i < r_parameters[
"statistics"].
size();
i++)
173 <<
"Element " <<
i <<
" in the list of statistics passed to IntegrationPointStatitsticsProcess"
174 <<
" has no \"type\" (string) attribute defined." << std::endl;
176 std::string statistic_type = settings[
"type"].
GetString();
178 if ( statistic_type ==
"average" )
182 else if ( statistic_type ==
"variance" )
186 else if ( statistic_type ==
"third_order_moment" )
192 KRATOS_ERROR <<
"Unknown string \"" << statistic_type <<
"\" passed as \"type\" argument in statistics definition." << std::endl;
212 std::string variable_name = rParameters["variable"].
GetString();
214 KRATOS_ERROR_IF_NOT(
type ==
"average") <<
"Trying to define an average statistic of unsupported type " <<
type <<
"." << std::endl;
216 KRATOS_ERROR_IF(rDefinedStatistics.find(variable_name) != rDefinedStatistics.end())
217 <<
"Duplicate definition of an average for " << variable_name <<
"." << std::endl;
219 StatisticsSampler::Pointer new_statistic;
225 std::string
tag = variable_name;
226 if (rParameters[
"tags"].size() > 0)
228 KRATOS_ERROR_IF(rParameters[
"tags"].size() != 1) <<
"Only one tag is needed for scalar averages, but "
229 << rParameters[
"tags"].
size() <<
" were provided for variable " << variable_name <<
"." << std::endl;
233 new_statistic = Kratos::make_shared<ScalarAverageSampler>(value_getter,
tag);
240 std::vector<std::string> tags;
241 if (rParameters[
"tags"].size() > 0)
243 KRATOS_ERROR_IF(rParameters[
"tags"].size() != mDimension) << mDimension <<
" tags are needed for vector averages, but "
244 << rParameters[
"tags"].
size() <<
" were provided for variable " << variable_name <<
"." << std::endl;
246 for (
unsigned int i = 0;
i < mDimension;
i++) {
247 tags.push_back(rParameters[
"tags"][
i].GetString());
252 tags.push_back(std::string(variable_name+
"_X"));
253 tags.push_back(std::string(variable_name+
"_Y"));
254 if (mDimension == 3) tags.push_back(std::string(variable_name+
"_Z"));
256 new_statistic = Kratos::make_shared<VectorAverageSampler<array_1d<double,3>>>(value_getter,mDimension,tags);
261 <<
"Trying to define an average statistic for variable " << variable_name
262 <<
" which is not a variable of a supported type." << std::endl;
265 rDefinedStatistics[variable_name] = new_statistic;
266 return new_statistic;
283 KRATOS_ERROR_IF(rParameters["variables"].size() < 1 || rParameters[
"variables"].size() > 2)
284 <<
"Unexpected number of arguments when reading \"variables\" list argument. "
285 <<
"Expected 1 or 2 values, got " << rParameters[
"variables"].
size() <<
"." << std::endl;
287 StatisticsSampler::Pointer new_statistic;
288 if (rParameters[
"variables"].size() == 1)
291 std::string variable_name = rParameters[
"variables"][0].
GetString();
292 StatisticsDictionary::iterator it_average = rDefinedStatistics.find(variable_name);
294 <<
"Trying to define a variance for " << variable_name
295 <<
" but no average has been defined for this variable." << std::endl;
297 new_statistic = Kratos::make_shared<SymmetricVarianceSampler>(it_average->second);
298 rDefinedStatistics[MakeVarianceKey(variable_name,variable_name)] = new_statistic;
303 std::string first_argument = rParameters[
"variables"][0].
GetString();
304 std::string first_argument_base;
305 unsigned int first_argument_index;
306 bool first_argument_is_component = ProcessComponent(first_argument,first_argument_base,first_argument_index);
308 std::string second_argument = rParameters[
"variables"][1].
GetString();
309 std::string second_argument_base;
310 unsigned int second_argument_index;
311 bool second_argument_is_component = ProcessComponent(second_argument,second_argument_base,second_argument_index);
313 StatisticsSampler::Pointer first_statistic;
314 if (first_argument_is_component)
316 auto found = rDefinedStatistics.find(first_argument_base);
318 <<
"Trying to record variance for " << first_argument <<
" and " << second_argument
319 <<
" but no average was declared for " << first_argument_base <<
"." << std::endl;
320 first_statistic = found->second;
325 auto found = rDefinedStatistics.find(first_argument);
327 <<
"Trying to record variance for " << first_argument <<
" and " << second_argument
328 <<
" but no average was declared for " << first_argument <<
"." << std::endl;
329 first_statistic = found->second;
332 StatisticsSampler::Pointer second_statistic;
333 if (second_argument_is_component)
335 auto found = rDefinedStatistics.find(second_argument_base);
337 <<
"Trying to record variance for " << first_argument <<
" and " << second_argument
338 <<
" but no average was declared for " << second_argument_base <<
"." << std::endl;
339 second_statistic = found->second;
343 auto found = rDefinedStatistics.find(second_argument);
345 <<
"Trying to record variance for " << first_argument <<
" and " << second_argument
346 <<
" but no average was declared for " << second_argument <<
"." << std::endl;
347 second_statistic = found->second;
351 (first_argument_is_component && !(second_argument_is_component || IsScalar(second_argument) )) ||
352 (second_argument_is_component && !(first_argument_is_component || IsScalar(first_argument) ))
355 KRATOS_ERROR <<
"Variances involving a component and a vector are currently not supported, please define them component-by-component." << std::endl;
358 if (first_argument_is_component || second_argument_is_component)
361 new_statistic = Kratos::make_shared<ComponentwiseVarianceSampler>(
362 first_statistic,first_argument_index,
363 second_statistic,second_argument_index);
368 new_statistic = Kratos::make_shared<VarianceSampler>(
369 first_statistic, second_statistic);
372 rDefinedStatistics[MakeVarianceKey(first_argument,second_argument)] = new_statistic;
374 return new_statistic;
392 <<
"Unexpected number of arguments when reading \"variables\" list argument. "
393 <<
"Expected 3 values, got " << rParameters[
"variables"].
size() <<
"." << std::endl;
395 const std::string first_argument = rParameters[
"variables"][0].
GetString();
396 const std::string second_argument = rParameters[
"variables"][1].
GetString();
397 const std::string third_argument = rParameters[
"variables"][2].
GetString();
399 std::string first_argument_base;
400 unsigned int first_argument_index;
401 ProcessThirdOrderInputValue(first_argument, first_argument_base, first_argument_index);
402 auto found = rDefinedStatistics.find(first_argument_base);
404 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
405 <<
" but no average was declared for " << first_argument_base <<
"." << std::endl;
406 StatisticsSampler::Pointer first_average = found->second;
408 std::string second_argument_base;
409 unsigned int second_argument_index;
410 ProcessThirdOrderInputValue(second_argument, second_argument_base, second_argument_index);
411 found = rDefinedStatistics.find(second_argument_base);
413 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
414 <<
" but no average was declared for " << second_argument_base <<
"." << std::endl;
415 StatisticsSampler::Pointer second_average = found->second;
417 std::string third_argument_base;
418 unsigned int third_argument_index;
419 ProcessThirdOrderInputValue(third_argument, third_argument_base, third_argument_index);
420 found = rDefinedStatistics.find(third_argument_base);
422 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
423 <<
" but no average was declared for " << third_argument_base <<
"." << std::endl;
424 StatisticsSampler::Pointer third_average = found->second;
426 found = rDefinedStatistics.find(MakeVarianceKey(first_argument_base,second_argument_base));
428 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
429 <<
" but no correlation was declared for " << first_argument_base <<
" and " << second_argument_base <<
"." << std::endl;
430 StatisticsSampler::Pointer first_second_correlation = found->second;
432 found = rDefinedStatistics.find(MakeVarianceKey(first_argument_base,third_argument_base));
434 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
435 <<
" but no correlation was declared for " << first_argument_base <<
" and " << third_argument_base <<
"." << std::endl;
436 StatisticsSampler::Pointer first_third_correlation = found->second;
439 found = rDefinedStatistics.find(MakeVarianceKey(second_argument_base,third_argument_base));
441 <<
"Trying to record third order moment for " << first_argument <<
", " << second_argument <<
" and " << third_argument
442 <<
" but no correlation was declared for " << second_argument_base <<
" and " << third_argument_base <<
"." << std::endl;
443 StatisticsSampler::Pointer second_third_correlation = found->second;
445 return Kratos::make_shared<ThirdOrderCorrelationSampler>(
446 first_average, first_argument_index,
447 second_average, second_argument_index,
448 third_average, third_argument_index,
449 first_second_correlation, first_second_correlation->ComponentIndex(first_argument_index,second_argument_index),
450 first_third_correlation, first_third_correlation->ComponentIndex(first_argument_index,third_argument_index),
451 second_third_correlation, second_third_correlation->ComponentIndex(second_argument_index, third_argument_index)
466 Kratos::Parameters::Pointer mpParameters;
468 unsigned int mDimension;
472 std::string mOutputFileName;
479 bool IsScalar(
const std::string& rInputName)
const
485 bool ProcessComponent(
486 const std::string& rInputName,
487 std::string& rBaseVariableName,
488 unsigned int& rComponentIndex)
const
492 bool is_component =
false;
494 const std::string x_suffix = std::string(
"_X");
495 const std::string y_suffix = std::string(
"_Y");
496 const std::string z_suffix = std::string(
"_Z");
498 if( StringEndsWith(rInputName,x_suffix) )
501 rBaseVariableName = rInputName.substr(0, rInputName.length() - 2);
504 else if ( StringEndsWith(rInputName,y_suffix) )
507 rBaseVariableName = rInputName.substr(0, rInputName.length() - 2);
510 else if ( StringEndsWith(rInputName,z_suffix) )
513 rBaseVariableName = rInputName.substr(0, rInputName.length() - 2);
516 <<
"Trying to record a statistic for " << rInputName
517 <<
" but IntegrationPointStatisticsProcess was initialized with dimension 2." << std::endl;
522 rBaseVariableName = rInputName;
531 bool StringEndsWith(std::string
const &rString, std::string
const &rEnding)
const {
532 if (rString.length() >= rEnding.length()) {
533 return (0 == rString.compare(rString.length() - rEnding.length(), rEnding.length(), rEnding));
540 std::string MakeVarianceKey(std::string
const &rFirstArgument, std::string
const &rSecondArgument)
const
542 if (rFirstArgument < rSecondArgument)
544 return std::string(
"Variance_" + rFirstArgument +
"_" + rSecondArgument);
548 return std::string(
"Variance_" + rSecondArgument +
"_" + rFirstArgument);
553 void ProcessThirdOrderInputValue(
554 const std::string& rArgument,
555 std::string& rBaseName,
556 unsigned int& rComponentIndex )
const
558 bool argument_is_scalar = IsScalar(rArgument);
559 bool argument_is_component = ProcessComponent(rArgument,rBaseName,rComponentIndex);
561 <<
"Unexpected variable " << rArgument <<
" found while defining a third order correlation. "
562 <<
"Only scalar or component variables are supported at the moment." << std::endl;
595 rOStream << std::endl;
void SetValue(const Variable< TDataType > &rThisVariable, TDataType const &rValue)
Sets the value for a given variable.
Definition: data_value_container.h:320
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
Helper process to record statistics on the integration points of the mesh.
Definition: integration_point_statistics_process.h:38
StatisticsSampler::Pointer CreateAverageSampler(Kratos::Parameters &rParameters, StatisticsDictionary &rDefinedStatistics) const
Definition: integration_point_statistics_process.h:199
void CreateStatisticsFromInput(StatisticsRecord::Pointer pRecordedStatistics)
Definition: integration_point_statistics_process.h:144
StatisticsSampler::Pointer CreateThirdOrderSampler(Kratos::Parameters &rParameters, StatisticsDictionary &rDefinedStatistics) const
Definition: integration_point_statistics_process.h:379
KRATOS_CLASS_POINTER_DEFINITION(IntegrationPointStatisticsProcess)
Pointer definition of IntegrationPointStatisticsProcess.
void ExecuteInitialize() override
Define the statistics and initialize internal storage.
Definition: integration_point_statistics_process.h:85
void ExecuteFinalize() override
Output simulation results to file.
Definition: integration_point_statistics_process.h:113
std::map< std::string, StatisticsSampler::Pointer > StatisticsDictionary
Definition: integration_point_statistics_process.h:46
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: integration_point_statistics_process.h:135
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: integration_point_statistics_process.h:132
~IntegrationPointStatisticsProcess() override
Destructor.
Definition: integration_point_statistics_process.h:77
void ExecuteFinalizeSolutionStep() override
Update statistics.
Definition: integration_point_statistics_process.h:103
IntegrationPointStatisticsProcess(Model &rModel, Kratos::Parameters::Pointer pParameters)
Constructor using a Model.
Definition: integration_point_statistics_process.h:68
std::string Info() const override
Turn back information as a string.
Definition: integration_point_statistics_process.h:124
IntegrationPointStatisticsProcess(ModelPart &rModelPart, Kratos::Parameters::Pointer pParameters)
Constructor using a ModelPart.
Definition: integration_point_statistics_process.h:56
StatisticsSampler::Pointer CreateVarianceSampler(Kratos::Parameters &rParameters, StatisticsDictionary &rDefinedStatistics) const
Definition: integration_point_statistics_process.h:271
static std::function< double(const Geometry< Node > &rGeometry, const Vector &rShapeFunctions, const Matrix &rShapeDerivatives)> ValueGetter(const Variable< double > &rVariable)
Definition: statistics_utilities.h:650
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class aims to manage different model parts across multi-physics simulations.
Definition: model.h:60
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
SizeType size() const
This method returns the total size of the current array parameter.
Definition: kratos_parameters.cpp:993
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
bool IsString() const
This method checks if the parameter is a string.
Definition: kratos_parameters.cpp:568
The base class for all processes in Kratos.
Definition: process.h:49
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
type
Definition: generate_gid_list_file.py:35
string tag
Definition: regular_mesher.py:14
integer i
Definition: TensorModule.f:17