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  using ScalingFun = std::function<double(double)>;
35 
36  /**
37  * @brief TimeScale constructor
38  *
39  * @param file_name Path to input CSV data file
40  * @param error_if_file_not_given If file name is not provided, the
41  * constructor will throw an error if this flag is set to true or throw a
42  * warning and use linear scaling if this flag is set to false
43  */
44  TimeScale(
45  std::string file_name = "", bool error_if_file_not_given = false,
46  ScalingFun def_scaling_fun = [](double time) { return time; });
47 
48  /**
49  * @brief TimeScale constructor
50  *
51  * @param file_name Path to input CSV data file
52  * @param delimiter Character which is used to separate the data in a csv row,
53  * by default it is ','
54  * @param error_if_file_not_given If file name is not provided, the
55  * constructor will throw an error if this flag is set to true or throw a
56  * warning and use linear scaling if this flag is set to false
57  */
58  TimeScale(
59  std::string file_name, std::string delimiter,
60  bool error_if_file_not_given = false,
61  ScalingFun def_scaling_fun = [](double time) { return time; });
62 
63  /**
64  * @brief Get scaling at a given time
65  *
66  * @param time
67  * @return double
68  */
69  double getScale(const double time);
70 
71  std::string fileName = ""; //< file CSV data file
72  PetscBool argFileScale = PETSC_FALSE; //< get file name from command line
73 
74 private:
75  MoFEMErrorCode timeData(std::string fileName, std::string delimiter);
76 
77  /**
78  * @brief Get scaling at a given time when the scalar values have been
79  * provided. Uses linear interpolation on the nearest time range to calculate
80  * scaling if the provided time is not present in the data.
81  * @return double
82  */
83  double getScaleFromData(const double time);
84 
85  /**
86  * @brief Returns the value of time.
87  * @return double
88  */
89  double getLinearScale(const double time);
90 
91  std::map<double, double> tSeries;
92  std::string fileNameFlag = "-time_scalar_file";
93 
94  static const std::string
95  defaultDelimiter; // "(\\s*,\\s*|\\s+)";
96 
98  ScalingFun defScalingMethod = [](double time) { return time; };
100 };
101 
102 /** \brief Force scale operator for reading four columns (time and vector)
103  */
104 template <int SPACE_DIM> struct TimeScaleVector : public ScalingMethod {
105 
106  TimeScaleVector(std::string name = "-time_vector_file",
107  bool error_if_file_not_given = false);
108 
109  TimeScaleVector(std::string name, int ms_id,
110  bool error_if_file_not_given = false);
111 
112  virtual FTensor::Tensor1<double, SPACE_DIM> getVector(const double time);
114  getVectorFromData(const double time);
115 
116 private:
118 
119  std::map<double, FTensor::Tensor1<double, 3>> tSeries;
121  string nAme;
123 
124  PetscBool fLg;
125  std::function<FTensor::Tensor1<double, SPACE_DIM>(double)> scalingMethod =
126  [this](double time) {
129  s(i) = time;
130  return s;
131  };
132 };
135 
136 } // namespace MoFEM
137 
138 #endif //_TIME_SCALING_HPP_
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
MoFEM::TimeScale::TimeScale
TimeScale(std::string file_name="", bool error_if_file_not_given=false, ScalingFun def_scaling_fun=[](double time) { return time;})
TimeScale constructor.
Definition: ScalingMethod.cpp:22
MoFEM::TimeScaleVector::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: ScalingMethod.hpp:122
MoFEM::TimeScaleVector::fLg
PetscBool fLg
Definition: ScalingMethod.hpp:124
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:230
MoFEM::TimeScaleVector::debug
int debug
Definition: ScalingMethod.hpp:120
MoFEM::TimeScaleVector::scalingMethod
std::function< FTensor::Tensor1< double, SPACE_DIM >double)> scalingMethod
Definition: ScalingMethod.hpp:125
MoFEM::TimeScaleVector::timeData
MoFEMErrorCode timeData()
Definition: ScalingMethod.cpp:158
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::scalingMethod
ScalingFun scalingMethod
Definition: ScalingMethod.hpp:99
MoFEM::TimeScaleVector::readFile
int readFile
Definition: ScalingMethod.hpp:120
MoFEM::TimeScale::ScalingFun
std::function< double(double)> ScalingFun
Definition: ScalingMethod.hpp:34
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:91
MoFEM::TimeScale::fileName
std::string fileName
Definition: ScalingMethod.hpp:71
MoFEM::TimeScale::timeData
MoFEMErrorCode timeData(std::string fileName, std::string delimiter)
Definition: ScalingMethod.cpp:35
MoFEM::TimeScaleVector
Force scale operator for reading four columns (time and vector)
Definition: ScalingMethod.hpp:104
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:137
FTensor::Index< 'i', SPACE_DIM >
MoFEM::TimeScale::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: ScalingMethod.hpp:97
MoFEM::TimeScale::defScalingMethod
ScalingFun defScalingMethod
Definition: ScalingMethod.hpp:98
MoFEM::TimeScale::defaultDelimiter
static const std::string defaultDelimiter
comma or space
Definition: ScalingMethod.hpp:95
MoFEM::TimeScale::fileNameFlag
std::string fileNameFlag
Definition: ScalingMethod.hpp:92
MoFEM::TimeScale::argFileScale
PetscBool argFileScale
Definition: ScalingMethod.hpp:72
MoFEM::TimeScaleVector::nAme
string nAme
Definition: ScalingMethod.hpp:121
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:109
MoFEM::TimeScale::getLinearScale
double getLinearScale(const double time)
Returns the value of time.
MoFEM::TimeScaleVector::tSeries
std::map< double, FTensor::Tensor1< double, 3 > > tSeries
Definition: ScalingMethod.hpp:119
MoFEM::TimeScaleVector::getVector
virtual FTensor::Tensor1< double, SPACE_DIM > getVector(const double time)
Definition: ScalingMethod.cpp:224