v0.14.0
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 104 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 }

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::BasicBCVectorScale, and BasicBoundaryConditionsInterface::BasicBCVectorConst.

Definition at line 224 of file ScalingMethod.cpp.

224  {
225  return scalingMethod(time);
226 }

◆ 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 }

◆ 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_NULL, PETSC_NULL, nAme.c_str(),
165  time_file_name, 255, &flg);
166 
167  if (!flg) {
169  SETERRQ1(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  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
177  "*** ERROR data file < %s > open unsuccessful", time_file_name);
178  }
179  double no1 = 0.0;
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  SETERRQ1(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 }

Member Data Documentation

◆ debug

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

Definition at line 120 of file ScalingMethod.hpp.

◆ errorIfFileNotGiven

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

Definition at line 122 of file ScalingMethod.hpp.

◆ fLg

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

Definition at line 124 of file ScalingMethod.hpp.

◆ nAme

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

Definition at line 121 of file ScalingMethod.hpp.

◆ readFile

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

Definition at line 120 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 125 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 119 of file ScalingMethod.hpp.


The documentation for this struct was generated from the following files:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
MoFEM::TimeScaleVector::errorIfFileNotGiven
bool errorIfFileNotGiven
Definition: ScalingMethod.hpp:122
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:609
MoFEM::TimeScaleVector::getVectorFromData
virtual FTensor::Tensor1< double, SPACE_DIM > getVectorFromData(const double time)
Definition: ScalingMethod.cpp:230
MoFEM::TimeScaleVector::debug
int debug
Definition: ScalingMethod.hpp:120
sdf.r
int r
Definition: sdf.py:8
I
constexpr IntegrationType I
Definition: operators_tests.cpp:31
MoFEM::TimeScaleVector::scalingMethod
std::function< FTensor::Tensor1< double, SPACE_DIM >double)> scalingMethod
Definition: ScalingMethod.hpp:125
MoFEM::TimeScaleVector::timeData
MoFEMErrorCode timeData()
Definition: ScalingMethod.cpp:158
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::TimeScaleVector::readFile
int readFile
Definition: ScalingMethod.hpp:120
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Index
Definition: Index.hpp:23
convert.n
n
Definition: convert.py:82
MOFEM_TAG_AND_LOG_C
#define MOFEM_TAG_AND_LOG_C(channel, severity, tag, format,...)
Tag and log in channel.
Definition: LogManager.hpp:370
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::TimeScaleVector::nAme
string nAme
Definition: ScalingMethod.hpp:121
dt
double dt
Definition: heat_method.cpp:26
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEM::TimeScaleVector::tSeries
std::map< double, FTensor::Tensor1< double, 3 > > tSeries
Definition: ScalingMethod.hpp:119
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36