v0.14.0
Loading...
Searching...
No Matches
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
36 MoFEMErrorCode timeData() {
38 char time_file_name[255];
39 ierr = PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
40 time_file_name, 255, &fLg);
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 */
123 MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf) {
125 double scale;
126 const double ts_t = fe->ts_t;
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
146 MoFEMErrorCode timeData() {
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
196 MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf) {
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__
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
static PetscErrorCode ierr
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
FTensor::Index< 'n', SPACE_DIM > n
double dt
Definition: heat_method.cpp:26
double scale
Definition: plastic.cpp:163
Class used to scale loads, f.e. in arc-length control.
std::map< double, VectorDouble > tSeries
TimeAccelerogram(string name="-my_accelerogram")
MoFEMErrorCode timeData()
MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf)
Force scale operator for reading two columns.
TimeForceScale(string name="-my_time_data_file", bool error_if_file_not_given=false)
std::map< double, double > tSeries
MoFEMErrorCode scaleNf(const FEMethod *fe, VectorDouble &Nf)
Scale force the right hand vector.
MoFEMErrorCode timeData()
MoFEMErrorCode getForceScale(const double ts_t, double &scale)