v0.14.0
Loading...
Searching...
No Matches
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
14namespace MoFEM {
15
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 */
32struct 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
65private:
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 */
97template <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
109private:
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_
constexpr int SPACE_DIM
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
virtual double getScale(const double time)
Get scaling at given time.
virtual ~ScalingMethod()=default
Force scale operator for reading two columns.
std::string fileName
double getLinearScale(const double time)
Returns the value of time.
double getScale(const double time)
Get scaling at a given time.
double getScaleFromData(const double time)
Get scaling at a given time when the scalar values have been provided. Uses linear interpolation on t...
TimeScale(std::string file_name="", bool error_if_file_not_given=false)
TimeScale constructor.
std::string fileNameFlag
static const std::string defaultDelimiter
comma or space
std::function< double(double)> scalingMethod
MoFEMErrorCode timeData(std::string fileName, std::string delimiter)
std::map< double, double > tSeries
Force scale operator for reading four columns (time and vector)
std::map< double, FTensor::Tensor1< double, 3 > > tSeries
TimeScaleVector(std::string name="-time_vector_file", bool error_if_file_not_given=false)
std::function< FTensor::Tensor1< double, SPACE_DIM >(double)> scalingMethod
MoFEMErrorCode timeData()
virtual FTensor::Tensor1< double, SPACE_DIM > getVector(const double time)
virtual FTensor::Tensor1< double, SPACE_DIM > getVectorFromData(const double time)