24 :
TimeScale(file_name, defaultDelimiter, error_if_file_not_given,
28 bool error_if_file_not_given,
ScalingFun def_scaling_fun)
29 : fileName(file_name), errorIfFileNotGiven(error_if_file_not_given),
30 defScalingMethod(def_scaling_fun) {
32 "Error in reading time data");
36 std::string delimiter) {
40 char time_file_name[255] = {
'\0'};
47 fileName = std::string(time_file_name);
56 "*** ERROR %s (time_data FILE NEEDED)",
fileName.c_str());
59 "The %s file not provided. Loading scaled with time.",
67 std::ifstream in_file_stream(
fileName);
70 "*** ERROR data file < %s > open unsuccessful",
fileName.c_str());
73 <<
"*** Warning data file " <<
fileName
74 <<
" open unsuccessful. Using default time scaling.";
81 in_file_stream.seekg(0);
83 double time = 0.0, value = 0.0;
86 std::regex rgx(delimiter.c_str());
87 std::sregex_token_iterator end;
88 while (std::getline(in_file_stream, line)) {
89 std::sregex_token_iterator iter(line.begin(), line.end(), rgx, -1);
91 auto value_str = ++iter;
92 if (time_str == end || value_str == end) {
94 "*** ERROR read data file error (check input time data file) ");
96 time = std::stod(time_str->str());
97 value = std::stod(value_str->str());
100 in_file_stream.close();
102 if (in_file_stream.is_open()) {
104 "*** ERROR file close unsuccessful");
117 auto it =
tSeries.lower_bound(time);
119 return (--it)->second;
130 double t = (time - lower.first) / (upper.first - lower.first);
131 double scale1 = upper.second;
132 double scale0 = lower.second;
133 return scale0 +
t * (scale1 - scale0);
142 template <
int SPACE_DIM>
144 bool error_if_file_not_given)
145 : readFile(0),
debug(0), nAme(name),
146 errorIfFileNotGiven(error_if_file_not_given) {
150 template <
int SPACE_DIM>
152 bool error_if_file_not_given)
153 : readFile(0),
debug(0), errorIfFileNotGiven(error_if_file_not_given) {
154 nAme = name + std::to_string(ms_id);
161 char time_file_name[255];
162 PetscBool flg = PETSC_FALSE;
165 time_file_name, 255, &flg);
168 if (errorIfFileNotGiven)
170 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
174 FILE *time_data = fopen(time_file_name,
"r");
175 if (time_data == NULL) {
177 "*** ERROR data file < %s > open unsuccessful", time_file_name);
181 (tSeries[no1])(
i) = 0.;
182 while (!feof(time_data)) {
185 fscanf(time_data,
"%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
192 "*** ERROR read data file error (check input time data file) "
196 (tSeries[no1])(
i) = no2(
i);
198 int r = fclose(time_data);
201 for (
auto &[ts, vec] : tSeries) {
203 "** read vector %3.2e time %3.2e %3.2e %3.2e", ts,
204 vec(0), vec(1), vec(2));
210 "*** ERROR file close unsuccessful");
215 scalingMethod = [
this](
double time) {
216 return this->getVectorFromData(time);
222 template <
int SPACE_DIM>
225 return scalingMethod(time);
228 template <
int SPACE_DIM>
239 double t0 = 0, t1,
dt;
240 for (
auto &[ts, vec] : tSeries) {
244 acc(
I) = acc0(
I) + ((vec(
I) - acc0(
I)) / (t1 - t0)) *
dt;