v0.15.0
Loading...
Searching...
No Matches
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.
 
 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 144 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 151 of file ScalingMethod.cpp.

153 : readFile(0), debug(0), errorIfFileNotGiven(error_if_file_not_given) {
154 nAme = name + std::to_string(ms_id);
155 CHK_THROW_MESSAGE(timeData(), "Error in reading time data");
156}
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
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 224 of file ScalingMethod.cpp.

224 {
225 return scalingMethod(time);
226}
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 230 of file ScalingMethod.cpp.

230 {
231
234 FTensor::Tensor1<double, 3> acc0 = tSeries.begin()->second;
235
238
239 double t0 = 0, t1, dt;
240 for (auto &[ts, vec] : tSeries) {
241 if (ts > time) {
242 t1 = ts;
243 dt = time - t0;
244 acc(I) = acc0(I) + ((vec(I) - acc0(I)) / (t1 - t0)) * dt;
245 break;
246 }
247 t0 = ts;
248 acc0 = vec;
249 acc = acc0;
250 }
251 Nf(i) = acc(i);
252 return Nf;
253}
constexpr int SPACE_DIM
FTensor::Index< 'i', SPACE_DIM > i
double dt
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 158 of file ScalingMethod.cpp.

158 {
160
161 char time_file_name[255];
162 PetscBool flg = PETSC_FALSE;
163 if (!nAme.empty())
164 CHKERR PetscOptionsGetString(PETSC_NULLPTR, PETSC_NULLPTR, nAme.c_str(),
165 time_file_name, 255, &flg);
166
167 if (!flg) {
169 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
170 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
172 }
173
174 FILE *time_data = fopen(time_file_name, "r");
175 if (time_data == NULL) {
176 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
177 "*** ERROR data file < %s > open unsuccessful", time_file_name);
178 }
179 double no1 = 0.0;
180 FTensor::Index<'i', 3> i;
181 (tSeries[no1])(i) = 0.;
182 while (!feof(time_data)) {
183 FTensor::Tensor1<double, 3> no2{0., 0., 0.};
184 int n =
185 fscanf(time_data, "%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
186 if (n < 0) {
187 fgetc(time_data);
188 continue;
189 }
190 if (n != 4) {
191 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
192 "*** ERROR read data file error (check input time data file) "
193 "{ n = %d }",
194 n);
195 }
196 (tSeries[no1])(i) = no2(i);
197 }
198 int r = fclose(time_data);
199
200 MOFEM_LOG_CHANNEL("WORLD");
201 for (auto &[ts, vec] : tSeries) {
202 MOFEM_TAG_AND_LOG_C("WORLD", Sev::verbose, "TimeScaleVector",
203 "** read vector %3.2e time %3.2e %3.2e %3.2e", ts,
204 vec(0), vec(1), vec(2));
205 }
206 MOFEM_LOG_CHANNEL("WORLD");
207
208 if (r != 0) {
209 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
210 "*** ERROR file close unsuccessful");
211 }
212 readFile = 1;
213
214 if (readFile == 1)
215 scalingMethod = [this](double time) {
216 return this->getVectorFromData(time);
217 };
218
220}
#define MOFEM_TAG_AND_LOG_C(channel, severity, tag, format,...)
Tag and log in channel.
#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
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()
#define CHKERR
Inline error check.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
const double n
refractive index of diffusive medium
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 160 of file ScalingMethod.hpp.

◆ errorIfFileNotGiven

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

Definition at line 162 of file ScalingMethod.hpp.

◆ fLg

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

Definition at line 164 of file ScalingMethod.hpp.

◆ nAme

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

Definition at line 161 of file ScalingMethod.hpp.

◆ readFile

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

Definition at line 160 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 165 of file ScalingMethod.hpp.

166 {
169 s(i) = time;
170 return s;
171 };

◆ tSeries

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

Definition at line 159 of file ScalingMethod.hpp.


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