v0.13.2
Loading...
Searching...
No Matches
ScalingMethod.hpp
Go to the documentation of this file.
1/**
2 * @file TimeScaling.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 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} // namespace MoFEM
95
96#endif //_TIME_SCALING_HPP_
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
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...
std::string fileNameFlag
static const std::string defaultDelimiter
comma or space
std::function< double(double)> scalingMethod
MoFEMErrorCode timeData(std::string delimiter)
std::map< double, double > tSeries