v0.14.0
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MoFEM::TimeScaleVector< SPACE_DIM > Struct Template Reference

Force scale operator for reading four columns (time and vector) More...

#include <src/boundary_conditions/ScalingMethod.hpp>

Inheritance diagram for MoFEM::TimeScaleVector< SPACE_DIM >:
[legend]
Collaboration diagram for MoFEM::TimeScaleVector< SPACE_DIM >:
[legend]

Public Member Functions

 TimeScaleVector (std::string name="-time_vector_file", bool error_if_file_not_given=false)
 
 TimeScaleVector (std::string name, int ms_id, bool error_if_file_not_given=false)
 
virtual FTensor::Tensor1< double, SPACE_DIMgetVector (const double time)
 
virtual FTensor::Tensor1< double, SPACE_DIMgetVectorFromData (const double time)
 
- Public Member Functions inherited from MoFEM::ScalingMethod
virtual double getScale (const double time)
 Get scaling at given time. More...
 
 ScalingMethod ()=default
 
virtual ~ScalingMethod ()=default
 

Private Member Functions

MoFEMErrorCode timeData ()
 

Private Attributes

std::map< double, FTensor::Tensor1< double, 3 > > tSeries
 
int readFile
 
int debug
 
string nAme
 
bool errorIfFileNotGiven
 
PetscBool fLg
 
std::function< FTensor::Tensor1< double, SPACE_DIM >(double)> scalingMethod
 

Detailed Description

template<int SPACE_DIM>
struct MoFEM::TimeScaleVector< SPACE_DIM >

Force scale operator for reading four columns (time and vector)

Definition at line 97 of file ScalingMethod.hpp.

Constructor & Destructor Documentation

◆ TimeScaleVector() [1/2]

template<int SPACE_DIM>
MoFEM::TimeScaleVector< SPACE_DIM >::TimeScaleVector ( std::string  name = "-time_vector_file",
bool  error_if_file_not_given = false 
)

◆ TimeScaleVector() [2/2]

template<int SPACE_DIM>
MoFEM::TimeScaleVector< SPACE_DIM >::TimeScaleVector ( std::string  name,
int  ms_id,
bool  error_if_file_not_given = false 
)

Definition at line 147 of file ScalingMethod.cpp.

149 : readFile(0), debug(0), errorIfFileNotGiven(error_if_file_not_given) {
150 nAme = name + std::to_string(ms_id);
151 CHK_THROW_MESSAGE(timeData(), "Error in reading time data");
152}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:595
MoFEMErrorCode timeData()

Member Function Documentation

◆ getVector()

template<int SPACE_DIM>
FTensor::Tensor1< double, SPACE_DIM > MoFEM::TimeScaleVector< SPACE_DIM >::getVector ( const double  time)
virtual

Reimplemented in BasicBoundaryConditionsInterface::BasicBCVectorConst, and BasicBoundaryConditionsInterface::BasicBCVectorScale.

Definition at line 220 of file ScalingMethod.cpp.

220 {
221 return scalingMethod(time);
222}
std::function< FTensor::Tensor1< double, SPACE_DIM >(double)> scalingMethod

◆ getVectorFromData()

template<int SPACE_DIM>
FTensor::Tensor1< double, SPACE_DIM > MoFEM::TimeScaleVector< SPACE_DIM >::getVectorFromData ( const double  time)
virtual

Definition at line 226 of file ScalingMethod.cpp.

226 {
227
230 FTensor::Tensor1<double, 3> acc0 = tSeries.begin()->second;
231
234
235 double t0 = 0, t1, dt;
236 for (auto &[ts, vec] : tSeries) {
237 if (ts > time) {
238 t1 = ts;
239 dt = time - t0;
240 acc(I) = acc0(I) + ((vec(I) - acc0(I)) / (t1 - t0)) * dt;
241 break;
242 }
243 t0 = ts;
244 acc0 = vec;
245 acc = acc0;
246 }
247 Nf(i) = acc(i);
248 return Nf;
249}
FTensor::Index< 'i', SPACE_DIM > i
double dt
Definition: heat_method.cpp:26
constexpr IntegrationType I
std::map< double, FTensor::Tensor1< double, 3 > > tSeries

◆ timeData()

template<int SPACE_DIM>
MoFEMErrorCode MoFEM::TimeScaleVector< SPACE_DIM >::timeData
private

Definition at line 154 of file ScalingMethod.cpp.

154 {
156
157 char time_file_name[255];
158 PetscBool flg = PETSC_FALSE;
159 if (!nAme.empty())
160 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
161 time_file_name, 255, &flg);
162
163 if (!flg) {
165 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
166 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
168 }
169
170 FILE *time_data = fopen(time_file_name, "r");
171 if (time_data == NULL) {
172 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
173 "*** ERROR data file < %s > open unsuccessful", time_file_name);
174 }
175 double no1 = 0.0;
177 (tSeries[no1])(i) = 0.;
178 while (!feof(time_data)) {
179 FTensor::Tensor1<double, 3> no2{0., 0., 0.};
180 int n =
181 fscanf(time_data, "%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
182 if (n < 0) {
183 fgetc(time_data);
184 continue;
185 }
186 if (n != 4) {
187 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
188 "*** ERROR read data file error (check input time data file) "
189 "{ n = %d }",
190 n);
191 }
192 (tSeries[no1])(i) = no2(i);
193 }
194 int r = fclose(time_data);
195
196 MOFEM_LOG_CHANNEL("WORLD");
197 for (auto &[ts, vec] : tSeries) {
198 MOFEM_TAG_AND_LOG_C("WORLD", Sev::verbose, "TimeScaleVector",
199 "** read vector %3.2e time %3.2e %3.2e %3.2e", ts,
200 vec(0), vec(1), vec(2));
201 }
202 MOFEM_LOG_CHANNEL("WORLD");
203
204 if (r != 0) {
205 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
206 "*** ERROR file close unsuccessful");
207 }
208 readFile = 1;
209
210 if (readFile == 1)
211 scalingMethod = [this](double time) {
212 return this->getVectorFromData(time);
213 };
214
216}
#define MOFEM_TAG_AND_LOG_C(channel, severity, tag, format,...)
Tag and log in channel.
Definition: LogManager.hpp:370
#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
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
#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
FTensor::Index< 'n', SPACE_DIM > n
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
int r
Definition: sdf.py:8
virtual FTensor::Tensor1< double, SPACE_DIM > getVectorFromData(const double time)

Member Data Documentation

◆ debug

template<int SPACE_DIM>
int MoFEM::TimeScaleVector< SPACE_DIM >::debug
private

Definition at line 113 of file ScalingMethod.hpp.

◆ errorIfFileNotGiven

template<int SPACE_DIM>
bool MoFEM::TimeScaleVector< SPACE_DIM >::errorIfFileNotGiven
private

Definition at line 115 of file ScalingMethod.hpp.

◆ fLg

template<int SPACE_DIM>
PetscBool MoFEM::TimeScaleVector< SPACE_DIM >::fLg
private

Definition at line 117 of file ScalingMethod.hpp.

◆ nAme

template<int SPACE_DIM>
string MoFEM::TimeScaleVector< SPACE_DIM >::nAme
private

Definition at line 114 of file ScalingMethod.hpp.

◆ readFile

template<int SPACE_DIM>
int MoFEM::TimeScaleVector< SPACE_DIM >::readFile
private

Definition at line 113 of file ScalingMethod.hpp.

◆ scalingMethod

template<int SPACE_DIM>
std::function<FTensor::Tensor1<double, SPACE_DIM>(double)> MoFEM::TimeScaleVector< SPACE_DIM >::scalingMethod
private
Initial value:
=
[this](double time) {
s(i) = time;
return s;
}

Definition at line 118 of file ScalingMethod.hpp.

◆ tSeries

template<int SPACE_DIM>
std::map<double, FTensor::Tensor1<double, 3> > MoFEM::TimeScaleVector< SPACE_DIM >::tSeries
private

Definition at line 112 of file ScalingMethod.hpp.


The documentation for this struct was generated from the following files: