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) {
34 PetscBool arg_found = PETSC_FALSE;
35 char time_file_name[255] = {
'\0'};
37 time_file_name, 255, &arg_found);
39 fileName = std::string(time_file_name);
43 "*** ERROR %s (time_data FILE NEEDED)",
fileName.c_str());
46 "The %s file not provided. Loading scaled with time.",
52 std::ifstream in_file_stream(
fileName);
55 "*** ERROR data file < %s > open unsuccessful",
fileName.c_str());
58 <<
"*** Warning data file " <<
fileName
59 <<
" open unsuccessful. Using linear time scaling.";
64 in_file_stream.seekg(0);
66 double time = 0.0, value = 0.0;
69 std::regex rgx(delimiter.c_str());
70 std::sregex_token_iterator end;
71 while (std::getline(in_file_stream, line)) {
72 std::sregex_token_iterator iter(line.begin(), line.end(), rgx, -1);
74 auto value_str = ++iter;
75 if (time_str == end || value_str == end) {
77 "*** ERROR read data file error (check input time data file) ");
79 time = std::stod(time_str->str());
80 value = std::stod(value_str->str());
83 in_file_stream.close();
85 if (in_file_stream.is_open()) {
87 "*** ERROR file close unsuccessful");
102 auto it =
tSeries.lower_bound(time);
104 return (--it)->second;
115 double t = (time - lower.first) / (upper.first - lower.first);
116 double scale1 = upper.second;
117 double scale0 = lower.second;
118 return scale0 +
t * (scale1 - scale0);
127template <
int SPACE_DIM>
129 bool error_if_file_not_given)
130 : readFile(0),
debug(0), nAme(name),
131 errorIfFileNotGiven(error_if_file_not_given) {
135template <
int SPACE_DIM>
137 bool error_if_file_not_given)
138 : readFile(0),
debug(0), errorIfFileNotGiven(error_if_file_not_given) {
139 nAme = name + std::to_string(ms_id);
146 char time_file_name[255];
147 PetscBool flg = PETSC_FALSE;
150 time_file_name, 255, &flg);
153 if (errorIfFileNotGiven)
155 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
159 FILE *time_data = fopen(time_file_name,
"r");
160 if (time_data == NULL) {
162 "*** ERROR data file < %s > open unsuccessful", time_file_name);
166 (tSeries[no1])(
i) = 0.;
167 while (!feof(time_data)) {
170 fscanf(time_data,
"%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
177 "*** ERROR read data file error (check input time data file) "
181 (tSeries[no1])(
i) = no2(
i);
183 int r = fclose(time_data);
186 for (
auto &[ts, vec] : tSeries) {
188 "** read vector %3.2e time %3.2e %3.2e %3.2e", ts,
189 vec(0), vec(1), vec(2));
195 "*** ERROR file close unsuccessful");
200 scalingMethod = [
this](
double time) {
201 return this->getVectorFromData(time);
207template <
int SPACE_DIM>
210 return scalingMethod(time);
213template <
int SPACE_DIM>
224 double t0 = 0, t1,
dt;
225 for (
auto &[ts, vec] : tSeries) {
229 acc(
I) = acc0(
I) + ((vec(
I) - acc0(
I)) / (t1 - t0)) *
dt;
#define MOFEM_TAG_AND_LOG_C(channel, severity, tag, format,...)
Tag and log in channel.
#define MOFEM_LOG_C(channel, severity, format,...)
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
FTensor::Index< 'n', SPACE_DIM > n
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
constexpr IntegrationType I
constexpr double t
plate stiffness
virtual double getScale(const double time)
Get scaling at given time.
Force scale operator for reading two columns.
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.
static const std::string defaultDelimiter
comma or space
std::function< double(double)> scalingMethod
MoFEMErrorCode timeData(std::string delimiter)
std::map< double, double > tSeries
Force scale operator for reading four columns (time and vector)
TimeScaleVector(std::string name="-time_vector_file", bool error_if_file_not_given=false)
MoFEMErrorCode timeData()
virtual FTensor::Tensor1< double, SPACE_DIM > getVector(const double time)
virtual FTensor::Tensor1< double, SPACE_DIM > getVectorFromData(const double time)