SPHinXsys  alpha version
ensemble_averaged_method.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------*
2 * SPHinXsys *
3 * --------------------------------------------------------------------------*
4 * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5 * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6 * physical accurate simulation and aims to model coupled industrial dynamic *
7 * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8 * (smoothed particle hydrodynamics), a meshless computational method using *
9 * particle discretization. *
10 * *
11 * SPHinXsys is partially funded by German Research Foundation *
12 * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13 * and HU1527/12-1. *
14 * *
15 * Portions copyright (c) 2017-2020 Technical University of Munich and *
16 * the authors' affiliations. *
17 * *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19 * not use this file except in compliance with the License. You may obtain a *
20 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21 * *
22 * --------------------------------------------------------------------------*/
31 #pragma once
32 #include "regression_test_base.hpp"
33 
34 namespace SPH
35 {
40  template<class ObserveMethodType>
42  {
43  /* identify the variable type from the parent class. */
44  using VariableType = decltype(ObserveMethodType::type_indicator_);
45 
46  protected:
47  DoubleVec<VariableType> meanvalue_, meanvalue_new_; /* the container of (new) meanvalue. [different from time-averaged]*/
48  DoubleVec<VariableType> variance_, variance_new_; /* the container of (new) variance. [different from time-averaged]*/
49 
51  void calculateNewVariance(TripleVec<Real> &result, DoubleVec<Real> &meanvalue_new, DoubleVec<Real> &variance, DoubleVec<Real> &variance_new);
52  void calculateNewVariance(TripleVec<Vecd> &result, DoubleVec<Vecd> &meanvalue_new, DoubleVec<Vecd> &variance, DoubleVec<Vecd> &variance_new);
53  void calculateNewVariance(TripleVec<Matd> &result, DoubleVec<Matd> &meanvalue_new, DoubleVec<Matd> &variance, DoubleVec<Matd> &variance_new);
54 
56  int compareParameter(string par_name, DoubleVec<Real> &parameter, DoubleVec<Real> &parameter_new, Real &threshold);
57  int compareParameter(string par_name, DoubleVec<Vecd> &parameter, DoubleVec<Vecd> &parameter_new, Vecd &threshold);
58  int compareParameter(string par_name, DoubleVec<Matd> &parameter, DoubleVec<Matd> &parameter_new, Matd &threshold);
59 
61  int testNewResult(int diff, DoubleVec<Real> &current_result, DoubleVec<Real> &meanvalue, DoubleVec<Real> &variance);
62  int testNewResult(int diff, DoubleVec<Vecd> &current_result, DoubleVec<Vecd> &meanvalue, DoubleVec<Vecd> &variance);
63  int testNewResult(int diff, DoubleVec<Matd> &current_result, DoubleVec<Matd> &meanvalue, DoubleVec<Matd> &variance);
64 
65  public:
66  template<typename... ConstructorArgs>
67  explicit RegressionTestEnsembleAveraged(ConstructorArgs &&...args) :
68  RegressionTestTimeAveraged<ObserveMethodType>(std::forward<ConstructorArgs>(args)...)
69  {
70  this->mean_variance_filefullpath_ = this->input_folder_path_ + "/" + this->body_name_
71  + "_" + this->quantity_name_ + "_ensemble_averaged_mean_variance.xml";
72  };
73  virtual ~RegressionTestEnsembleAveraged() {};
74 
75  void settingupAndCorrection();
77  void updateMeanVariance();
78  void writeMeanVarianceToXml();
79  bool compareMeanVariance();
80  void resultTest();
82  /* the interface for generating the priori converged result with M&V. */
83  void generateDataBase(VariableType threshold_mean, VariableType threshold_variance, string filter = "false")
84  {
85  this->writeXmlToXmlFile();
86  this->readXmlFromXmlFile();
87  this->initializeThreshold(threshold_mean, threshold_variance);
88  if (this->converged == "false")
89  {
91  this->readResultFromXml();
92  if (filter == "true")
93  this->filterExtremeValues();
96  this->writeResultToXml();
99  };
100  /*else
101  std::cout << "The results have been converged." << endl;*/
102  };
103 
105  void newResultTest(string filter = "false")
106  {
107  this->writeXmlToXmlFile();
108  this->readXmlFromXmlFile();
110  if (filter == "true")
111  this->filterExtremeValues();
113  resultTest();
114  };
115  };
116 };
void writeXmlToXmlFile()
Definition: regression_test_base.h:139
void writeResultToXml()
Definition: regression_test_base.hpp:112
void readMeanVarianceFromXml()
Definition: ensemble_averaged_method.hpp:246
void filterExtremeValues()
Definition: time_averaged_method.hpp:465
int testNewResult(int diff, DoubleVec< Real > &current_result, DoubleVec< Real > &meanvalue, DoubleVec< Real > &variance)
Definition: ensemble_averaged_method.hpp:114
void generateDataBase(VariableType threshold_mean, VariableType threshold_variance, string filter="false")
Definition: ensemble_averaged_method.h:83
void writeMeanVarianceToXml()
Definition: ensemble_averaged_method.hpp:286
void initializeThreshold(VariableType &threshold_mean, VariableType &threshold_variance)
Definition: time_averaged_method.hpp:404
the regression test is based on the ensemble-averaged meanvalue and variance.
Definition: ensemble_averaged_method.h:41
bool compareMeanVariance()
Definition: ensemble_averaged_method.hpp:300
void readResultFromXml()
Definition: regression_test_base.hpp:90
int compareParameter(string par_name, DoubleVec< Real > &parameter, DoubleVec< Real > &parameter_new, Real &threshold)
Definition: ensemble_averaged_method.hpp:53
void resultTest()
Definition: ensemble_averaged_method.hpp:345
void readXmlFromXmlFile()
Definition: regression_test_base.h:145
void updateMeanVariance()
Definition: ensemble_averaged_method.hpp:263
void calculateNewVariance(TripleVec< Real > &result, DoubleVec< Real > &meanvalue_new, DoubleVec< Real > &variance, DoubleVec< Real > &variance_new)
Definition: ensemble_averaged_method.hpp:15
void newResultTest(string filter="false")
Definition: ensemble_averaged_method.h:105
void settingupAndCorrection()
Definition: ensemble_averaged_method.hpp:187
Definition: solid_body_supplementary.cpp:9
The regression test is based on the time-averaged meanvalue and variance.
Definition: time_averaged_method.h:40