v0.14.0
ScalingMethod.hpp
Go to the documentation of this file.
1 /**
2  * @file ScalingMethod.hpp
3  * @brief
4  * @version 0.13.1
5  * @date 2022-08-12
6  *
7  * @copyright Copyright (c) 2022
8  *
9  */
10 
11 #ifndef _TIME_SCALING_HPP_
12 #define _TIME_SCALING_HPP_
13 
14 namespace MoFEM {
15 
16 struct ScalingMethod {
17 
18  /**
19  * @brief Get scaling at given time
20  *
21  * @param time
22  * @return double
23  */
24  virtual double getScale(const double time);
25 
26  ScalingMethod() = default;
27  virtual ~ScalingMethod() = default;
28 };
29 
30 /** \brief Force scale operator for reading two columns
31  */
32 struct TimeScale : public ScalingMethod {
33 
34  /**
35  * @brief TimeScale constructor
36  *
37  * @param file_name Path to input CSV data file
38  * @param error_if_file_not_given If file name is not provided, the
39  * constructor will throw an error if this flag is set to true or throw a
40  * warning and use linear scaling if this flag is set to false
41  */
42  TimeScale(std::string file_name = "", bool error_if_file_not_given = false);
43 
44  /**
45  * @brief TimeScale constructor
46  *
47  * @param file_name Path to input CSV data file
48  * @param delimiter Character which is used to separate the data in a csv row,
49  * by default it is ','
50  * @param error_if_file_not_given If file name is not provided, the
51  * constructor will throw an error if this flag is set to true or throw a
52  * warning and use linear scaling if this flag is set to false
53  */
54  TimeScale(std::string file_name, std::string delimiter,
55  bool error_if_file_not_given = false);
56 
57  /**
58  * @brief Get scaling at a given time
59  *
60  * @param time
61  * @return double
62  */
63  double getScale(const double time);
64 
65 private:
66  MoFEMErrorCode timeData(std::string fileName, std::string delimiter);
67 
68  /**
69  * @brief Get scaling at a given time when the scalar values have been
70  * provided. Uses linear interpolation on the nearest time range to calculate
71  * scaling if the provided time is not present in the data.
72  * @return double
73  */
74  double getScaleFromData(const double time);
75 
76  /**
77  * @brief Returns the value of time.
78  * @return double
79  */
80  double getLinearScale(const double time);
81 
82  std::map<double, double> tSeries;
83  std::string fileName = "";
84  std::string fileNameFlag = "-time_scalar_file";
85 
86  static const std::string
87  defaultDelimiter; // "(\\s*,\\s*|\\s+)";
88 
90  std::function<double(double)> scalingMethod = [](double time) {
91  return time;
92  };
93 };
94 
95 /** \brief Force scale operator for reading four columns (time and vector)
96  */
97 template <int SPACE_DIM> struct TimeScaleVector : public ScalingMethod {
98 
99  TimeScaleVector(std::string name = "-time_vector_file",
100  bool error_if_file_not_given = false);
101 
102  TimeScaleVector(std::string name, int ms_id,
103  bool error_if_file_not_given = false);
104 
105  virtual FTensor::Tensor1<double, SPACE_DIM> getVector(const double time);
107  getVectorFromData(const double time);
108 
109 private:
111 
112  std::map<double, FTensor::Tensor1<double, 3>> tSeries;
114  string nAme;
116 
117  PetscBool fLg;
118  std::function<FTensor::Tensor1<double, SPACE_DIM>(double)> scalingMethod =
119  [this](double time) {
122  s(i) = time;
123  return s;
124  };
125 };
128 
129 } // namespace MoFEM
130 
131 #endif //_TIME_SCALING_HPP_
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
MoFEM::TimeScaleVector::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: ScalingMethod.hpp:115
MoFEM::TimeScaleVector::fLg
PetscBool fLg
Definition: ScalingMethod.hpp:117
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::TimeScaleVector::getVectorFromData
virtual FTensor::Tensor1< double, SPACE_DIM > getVectorFromData(const double time)
Definition: ScalingMethod.cpp:226
MoFEM::TimeScaleVector::debug
int debug
Definition: ScalingMethod.hpp:113
MoFEM::TimeScaleVector::scalingMethod
std::function< FTensor::Tensor1< double, SPACE_DIM >double)> scalingMethod
Definition: ScalingMethod.hpp:118
MoFEM::TimeScaleVector::timeData
MoFEMErrorCode timeData()
Definition: ScalingMethod.cpp:154
MoFEM::ScalingMethod::~ScalingMethod
virtual ~ScalingMethod()=default
MoFEM::ScalingMethod::ScalingMethod
ScalingMethod()=default
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::TimeScale::TimeScale
TimeScale(std::string file_name="", bool error_if_file_not_given=false)
TimeScale constructor.
Definition: ScalingMethod.cpp:22
MoFEM::TimeScaleVector::readFile
int readFile
Definition: ScalingMethod.hpp:113
double
MoFEM::TimeScale
Force scale operator for reading two columns.
Definition: ScalingMethod.hpp:32
MoFEM::ScalingMethod
Definition: ScalingMethod.hpp:16
MoFEM::TimeScale::tSeries
std::map< double, double > tSeries
Definition: ScalingMethod.hpp:82
MoFEM::TimeScale::fileName
std::string fileName
Definition: ScalingMethod.hpp:83
MoFEM::TimeScale::timeData
MoFEMErrorCode timeData(std::string fileName, std::string delimiter)
Definition: ScalingMethod.cpp:32
MoFEM::TimeScaleVector
Force scale operator for reading four columns (time and vector)
Definition: ScalingMethod.hpp:97
MoFEM::TimeScaleVector::TimeScaleVector
TimeScaleVector(std::string name="-time_vector_file", bool error_if_file_not_given=false)
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
MoFEM::TimeScale::getScale
double getScale(const double time)
Get scaling at a given time.
Definition: ScalingMethod.cpp:133
FTensor::Index< 'i', SPACE_DIM >
MoFEM::TimeScale::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: ScalingMethod.hpp:89
MoFEM::TimeScale::defaultDelimiter
static const std::string defaultDelimiter
comma or space
Definition: ScalingMethod.hpp:87
MoFEM::TimeScale::fileNameFlag
std::string fileNameFlag
Definition: ScalingMethod.hpp:84
MoFEM::TimeScaleVector::nAme
string nAme
Definition: ScalingMethod.hpp:114
MoFEM::TimeScale::scalingMethod
std::function< double(double)> scalingMethod
Definition: ScalingMethod.hpp:90
MoFEM::ScalingMethod::getScale
virtual double getScale(const double time)
Get scaling at given time.
Definition: ScalingMethod.cpp:15
MoFEM::TimeScale::getScaleFromData
double getScaleFromData(const double time)
Get scaling at a given time when the scalar values have been provided. Uses linear interpolation on t...
Definition: ScalingMethod.cpp:105
MoFEM::TimeScale::getLinearScale
double getLinearScale(const double time)
Returns the value of time.
Definition: ScalingMethod.cpp:103
MoFEM::TimeScaleVector::tSeries
std::map< double, FTensor::Tensor1< double, 3 > > tSeries
Definition: ScalingMethod.hpp:112
MoFEM::TimeScaleVector::getVector
virtual FTensor::Tensor1< double, SPACE_DIM > getVector(const double time)
Definition: ScalingMethod.cpp:220