23 :
TimeScale(file_name, defaultDelimiter, error_if_file_not_given) {}
26 bool error_if_file_not_given)
27 : fileName(file_name), errorIfFileNotGiven(error_if_file_not_given) {
29 "Error in reading time data");
33 std::string delimiter) {
37 PetscBool arg_found = PETSC_FALSE;
38 char time_file_name[255] = {
'\0'};
43 time_file_name, 255, &arg_found);
45 fileName = std::string(time_file_name);
50 arg_found = PETSC_TRUE;
54 "*** ERROR %s (time_data FILE NEEDED)",
fileName.c_str());
57 "The %s file not provided. Loading scaled with time.",
63 std::ifstream in_file_stream(
fileName);
66 "*** ERROR data file < %s > open unsuccessful",
fileName.c_str());
69 <<
"*** Warning data file " <<
fileName
70 <<
" open unsuccessful. Using linear time scaling.";
75 in_file_stream.seekg(0);
77 double time = 0.0, value = 0.0;
80 std::regex rgx(delimiter.c_str());
81 std::sregex_token_iterator end;
82 while (std::getline(in_file_stream, line)) {
83 std::sregex_token_iterator iter(line.begin(), line.end(), rgx, -1);
85 auto value_str = ++iter;
86 if (time_str == end || value_str == end) {
88 "*** ERROR read data file error (check input time data file) ");
90 time = std::stod(time_str->str());
91 value = std::stod(value_str->str());
94 in_file_stream.close();
96 if (in_file_stream.is_open()) {
98 "*** ERROR file close unsuccessful");
113 auto it =
tSeries.lower_bound(time);
115 return (--it)->second;
126 double t = (time - lower.first) / (upper.first - lower.first);
127 double scale1 = upper.second;
128 double scale0 = lower.second;
129 return scale0 +
t * (scale1 - scale0);
138 template <
int SPACE_DIM>
140 bool error_if_file_not_given)
141 : readFile(0),
debug(0), nAme(name),
142 errorIfFileNotGiven(error_if_file_not_given) {
146 template <
int SPACE_DIM>
148 bool error_if_file_not_given)
149 : readFile(0),
debug(0), errorIfFileNotGiven(error_if_file_not_given) {
150 nAme = name + std::to_string(ms_id);
157 char time_file_name[255];
158 PetscBool flg = PETSC_FALSE;
161 time_file_name, 255, &flg);
164 if (errorIfFileNotGiven)
166 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
170 FILE *time_data = fopen(time_file_name,
"r");
171 if (time_data == NULL) {
173 "*** ERROR data file < %s > open unsuccessful", time_file_name);
177 (tSeries[no1])(
i) = 0.;
178 while (!feof(time_data)) {
181 fscanf(time_data,
"%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
188 "*** ERROR read data file error (check input time data file) "
192 (tSeries[no1])(
i) = no2(
i);
194 int r = fclose(time_data);
197 for (
auto &[ts, vec] : tSeries) {
199 "** read vector %3.2e time %3.2e %3.2e %3.2e", ts,
200 vec(0), vec(1), vec(2));
206 "*** ERROR file close unsuccessful");
211 scalingMethod = [
this](
double time) {
212 return this->getVectorFromData(time);
218 template <
int SPACE_DIM>
221 return scalingMethod(time);
224 template <
int SPACE_DIM>
235 double t0 = 0, t1,
dt;
236 for (
auto &[ts, vec] : tSeries) {
240 acc(
I) = acc0(
I) + ((vec(
I) - acc0(
I)) / (t1 - t0)) *
dt;