v0.14.0
TimeForceScale.hpp
Go to the documentation of this file.
1 /* \brief TimeForceScale.hpp
2  *
3  * Edited and modified by Hassan.
4  *
5  * This is not exactly procedure for linear elastic dynamics, since jacobian is
6  * evaluated at every time step and SNES procedure is involved. However it is
7  * implemented like that, to test methodology for general nonlinear problem.
8  *
9  */
10 
11 
12 
13 #ifndef __TIMEFORCESCALE_HPP__
14 #define __TIMEFORCESCALE_HPP__
15 
16 /** \brief Force scale operator for reading two columns
17  */
19 
20  std::map<double, double> tSeries;
22  string nAme;
24 
25  TimeForceScale(string name = "-my_time_data_file",
26  bool error_if_file_not_given = false)
27  : readFile(0), debug(0), nAme(name),
28  errorIfFileNotGiven(error_if_file_not_given) {
29 
30  ierr = timeData();
31  CHKERRABORT(PETSC_COMM_WORLD, ierr);
32  }
33 
34  PetscBool fLg;
35 
38  char time_file_name[255];
39  ierr = PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
40  time_file_name, 255, &fLg);
41  CHKERRG(ierr);
42  if (!fLg && errorIfFileNotGiven) {
43  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
44  "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
45  }
46  if (!fLg) {
47  MOFEM_LOG_C("WORLD", Sev::warning,
48  "The %s file not provided. Loading scaled with time.",
49  nAme.c_str());
51  }
52  FILE *time_data = fopen(time_file_name, "r");
53  if (time_data == NULL) {
54  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
55  "*** ERROR data file < %s > open unsuccessful", time_file_name);
56  }
57  double no1 = 0.0, no2 = 0.0;
58  tSeries[no1] = no2;
59  while (!feof(time_data)) {
60  int n = fscanf(time_data, "%lf %lf", &no1, &no2);
61  if ((n <= 0) || ((no1 == 0) && (no2 == 0))) {
62  fgetc(time_data);
63  continue;
64  }
65  if (n != 2) {
66  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
67  "*** ERROR read data file error (check input time data file) "
68  "{ n = %d }",
69  n);
70  }
71  tSeries[no1] = no2;
72  }
73  int r = fclose(time_data);
74  if (debug) {
75  std::map<double, double>::iterator tit = tSeries.begin();
76  for (; tit != tSeries.end(); tit++) {
77  PetscPrintf(PETSC_COMM_WORLD, "** read time series %3.2e time %3.2e\n",
78  tit->first, tit->second);
79  }
80  }
81  if (r != 0) {
82  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
83  "*** ERROR file close unsuccessful");
84  }
85  readFile = 1;
87  }
88 
89  MoFEMErrorCode getForceScale(const double ts_t, double &scale) {
91  if (!fLg) {
92  scale = ts_t; // scale with time, by default
94  }
95  if (readFile == 0) {
96  SETERRQ(PETSC_COMM_SELF, 1, "data file not read");
97  }
98  scale = 0;
99  double t0 = 0, t1, s0 = tSeries[0], s1, dt;
100  std::map<double, double>::iterator tit = tSeries.begin();
101  for (; tit != tSeries.end(); tit++) {
102  if (tit->first > ts_t) {
103  t1 = tit->first;
104  s1 = tit->second;
105  dt = ts_t - t0;
106  scale = s0 + ((s1 - s0) / (t1 - t0)) * dt;
107  break;
108  }
109  t0 = tit->first;
110  s0 = tit->second;
111  scale = s0;
112  }
114  }
115 
116  /**
117  * @brief Scale force the right hand vector
118  *
119  * @param fe
120  * @param Nf
121  * @return MoFEMErrorCode
122  */
125  double scale;
126  const double ts_t = fe->ts_t;
127  CHKERR getForceScale(ts_t, scale);
128  Nf *= scale;
130  }
131 };
132 
134 
135  std::map<double, VectorDouble> tSeries;
137  string nAme;
138 
139  TimeAccelerogram(string name = "-my_accelerogram")
140  : readFile(0), debug(0), nAme(name) {
141 
142  ierr = timeData();
143  CHKERRABORT(PETSC_COMM_WORLD, ierr);
144  }
145 
148  char time_file_name[255];
149  PetscBool flg = PETSC_TRUE;
150  ierr = PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
151  time_file_name, 255, &flg);
152  CHKERRG(ierr);
153  if (flg != PETSC_TRUE) {
154  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
155  "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
156  }
157  FILE *time_data = fopen(time_file_name, "r");
158  if (time_data == NULL) {
159  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
160  "*** ERROR data file < %s > open unsuccessful", time_file_name);
161  }
162  double no1 = 0.0;
163  VectorDouble no2(3);
164  tSeries[no1] = no2;
165  while (!feof(time_data)) {
166  int n =
167  fscanf(time_data, "%lf %lf %lf %lf", &no1, &no2[0], &no2[1], &no2[2]);
168  if (n < 0) {
169  fgetc(time_data);
170  continue;
171  }
172  if (n != 4) {
173  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
174  "*** ERROR read data file error (check input time data file) "
175  "{ n = %d }",
176  n);
177  }
178  tSeries[no1] = no2;
179  }
180  int r = fclose(time_data);
181  if (debug) {
182  std::map<double, VectorDouble>::iterator tit = tSeries.begin();
183  for (; tit != tSeries.end(); tit++) {
184  PetscPrintf(PETSC_COMM_WORLD,
185  "** read accelerogram %3.2e time %3.2e %3.2e %3.2e\n",
186  tit->first, tit->second[0], tit->second[1], tit->second[2]);
187  }
188  }
189  if (r != 0) {
190  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR file close unsuccessful");
191  }
192  readFile = 1;
194  }
195 
198  if (readFile == 0) {
199  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "data file not read");
200  }
201  double ts_t = fe->ts_t;
202  VectorDouble acc(3);
203  VectorDouble acc0 = tSeries[0], acc1(3);
204  double t0 = 0, t1, dt;
205  std::map<double, VectorDouble>::iterator tit = tSeries.begin();
206  for (; tit != tSeries.end(); tit++) {
207  if (tit->first > ts_t) {
208  t1 = tit->first;
209  acc1 = tit->second;
210  dt = ts_t - t0;
211  acc = acc0 + ((acc1 - acc0) / (t1 - t0)) * dt;
212  break;
213  }
214  t0 = tit->first;
215  acc0 = tit->second;
216  acc = acc0;
217  }
218  Nf += acc;
220  }
221 };
222 
223 #endif // __TIMEFORCESCALE_HPP__
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
TimeAccelerogram::timeData
MoFEMErrorCode timeData()
Definition: TimeForceScale.hpp:146
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
TimeAccelerogram::readFile
int readFile
Definition: TimeForceScale.hpp:136
scale
double scale
Definition: plastic.cpp:119
sdf.r
int r
Definition: sdf.py:8
TimeForceScale::TimeForceScale
TimeForceScale(string name="-my_time_data_file", bool error_if_file_not_given=false)
Definition: TimeForceScale.hpp:25
TimeAccelerogram::debug
int debug
Definition: TimeForceScale.hpp:136
TimeForceScale::debug
int debug
Definition: TimeForceScale.hpp:21
FEMethod
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
TimeForceScale
Force scale operator for reading two columns.
Definition: TimeForceScale.hpp:18
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
MethodForForceScaling
Class used to scale loads, f.e. in arc-length control.
Definition: MethodForForceScaling.hpp:11
TimeForceScale::timeData
MoFEMErrorCode timeData()
Definition: TimeForceScale.hpp:36
TimeForceScale::tSeries
std::map< double, double > tSeries
Definition: TimeForceScale.hpp:20
TimeAccelerogram::TimeAccelerogram
TimeAccelerogram(string name="-my_accelerogram")
Definition: TimeForceScale.hpp:139
convert.n
n
Definition: convert.py:82
TimeForceScale::getForceScale
MoFEMErrorCode getForceScale(const double ts_t, double &scale)
Definition: TimeForceScale.hpp:89
TimeForceScale::fLg
PetscBool fLg
Definition: TimeForceScale.hpp:34
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
TimeForceScale::scaleNf
MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf)
Scale force the right hand vector.
Definition: TimeForceScale.hpp:123
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
TimeForceScale::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: TimeForceScale.hpp:23
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
TimeAccelerogram::scaleNf
MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf)
Definition: TimeForceScale.hpp:196
TimeForceScale::readFile
int readFile
Definition: TimeForceScale.hpp:21
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
dt
double dt
Definition: heat_method.cpp:26
TimeAccelerogram::nAme
string nAme
Definition: TimeForceScale.hpp:137
TimeForceScale::nAme
string nAme
Definition: TimeForceScale.hpp:22
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
TimeAccelerogram
Definition: TimeForceScale.hpp:133
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
TimeAccelerogram::tSeries
std::map< double, VectorDouble > tSeries
Definition: TimeForceScale.hpp:135