v0.14.0
Public Member Functions | Public Attributes | List of all members
TimeForceScale Struct Reference

Force scale operator for reading two columns. More...

#include <tutorials/src/TimeForceScale.hpp>

Inheritance diagram for TimeForceScale:
[legend]
Collaboration diagram for TimeForceScale:
[legend]

Public Member Functions

 TimeForceScale (string name="-my_time_data_file", bool error_if_file_not_given=false)
 
MoFEMErrorCode timeData ()
 
MoFEMErrorCode getForceScale (const double ts_t, double &scale)
 
MoFEMErrorCode scaleNf (const FEMethod *fe, VectorDouble &Nf)
 Scale force the right hand vector. More...
 
 TimeForceScale (string name="-my_time_data_file", bool error_if_file_not_given=false)
 
MoFEMErrorCode timeData ()
 
MoFEMErrorCode getForceScale (const double ts_t, double &scale)
 
MoFEMErrorCode scaleNf (const FEMethod *fe, VectorDouble &Nf)
 Scale force the right hand vector. More...
 
- Public Member Functions inherited from MethodForForceScaling
virtual ~MethodForForceScaling ()
 
virtual ~MethodForForceScaling ()
 

Public Attributes

std::map< double, doubletSeries
 
int readFile
 
int debug
 
string nAme
 
bool errorIfFileNotGiven
 
PetscBool fLg
 

Additional Inherited Members

- Static Public Member Functions inherited from MethodForForceScaling
static MoFEMErrorCode applyScale (const FEMethod *fe, boost::ptr_vector< MethodForForceScaling > &methods_op, VectorDouble &nf)
 
static MoFEMErrorCode applyScale (const FEMethod *fe, boost::shared_ptr< MethodForForceScaling > method_op, VectorDouble &nf)
 
static MoFEMErrorCode applyScale (const FEMethod *fe, boost::ptr_vector< MethodForForceScaling > &methods_op, VectorDouble &nf)
 
static MoFEMErrorCode applyScale (const FEMethod *fe, boost::shared_ptr< MethodForForceScaling > method_op, VectorDouble &nf)
 

Detailed Description

Force scale operator for reading two columns.

Examples
bone_adaptation.cpp, nonlinear_dynamics.cpp, Remodeling.cpp, and UnsaturatedFlow.hpp.

Definition at line 18 of file TimeForceScale.hpp.

Constructor & Destructor Documentation

◆ TimeForceScale() [1/2]

TimeForceScale::TimeForceScale ( string  name = "-my_time_data_file",
bool  error_if_file_not_given = false 
)
inline

Definition at line 25 of file TimeForceScale.hpp.

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  }

◆ TimeForceScale() [2/2]

TimeForceScale::TimeForceScale ( string  name = "-my_time_data_file",
bool  error_if_file_not_given = false 
)
inline

Definition at line 25 of file TimeForceScale.hpp.

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  }

Member Function Documentation

◆ getForceScale() [1/2]

MoFEMErrorCode TimeForceScale::getForceScale ( const double  ts_t,
double scale 
)
inlinevirtual

Reimplemented from MethodForForceScaling.

Definition at line 89 of file TimeForceScale.hpp.

89  {
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  }

◆ getForceScale() [2/2]

MoFEMErrorCode TimeForceScale::getForceScale ( const double  ts_t,
double scale 
)
inlinevirtual

Reimplemented from MethodForForceScaling.

Definition at line 89 of file TimeForceScale.hpp.

89  {
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  }

◆ scaleNf() [1/2]

MoFEMErrorCode TimeForceScale::scaleNf ( const FEMethod fe,
VectorDouble &  Nf 
)
inlinevirtual

Scale force the right hand vector.

Parameters
fe
Nf
Returns
MoFEMErrorCode

Implements MethodForForceScaling.

Definition at line 123 of file TimeForceScale.hpp.

123  {
125  double scale;
126  const double ts_t = fe->ts_t;
127  CHKERR getForceScale(ts_t, scale);
128  Nf *= scale;
130  }

◆ scaleNf() [2/2]

MoFEMErrorCode TimeForceScale::scaleNf ( const FEMethod fe,
VectorDouble &  Nf 
)
inlinevirtual

Scale force the right hand vector.

Parameters
fe
Nf
Returns
MoFEMErrorCode

Implements MethodForForceScaling.

Definition at line 123 of file TimeForceScale.hpp.

123  {
125  double scale;
126  const double ts_t = fe->ts_t;
127  CHKERR getForceScale(ts_t, scale);
128  Nf *= scale;
130  }

◆ timeData() [1/2]

MoFEMErrorCode TimeForceScale::timeData ( )
inline

Definition at line 36 of file TimeForceScale.hpp.

36  {
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  }

◆ timeData() [2/2]

MoFEMErrorCode TimeForceScale::timeData ( )
inline

Definition at line 36 of file TimeForceScale.hpp.

36  {
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  }

Member Data Documentation

◆ debug

int TimeForceScale::debug

Definition at line 21 of file TimeForceScale.hpp.

◆ errorIfFileNotGiven

bool TimeForceScale::errorIfFileNotGiven

Definition at line 23 of file TimeForceScale.hpp.

◆ fLg

PetscBool TimeForceScale::fLg

Definition at line 34 of file TimeForceScale.hpp.

◆ nAme

string TimeForceScale::nAme

Definition at line 22 of file TimeForceScale.hpp.

◆ readFile

int TimeForceScale::readFile

Definition at line 21 of file TimeForceScale.hpp.

◆ tSeries

std::map< double, double > TimeForceScale::tSeries

Definition at line 20 of file TimeForceScale.hpp.


The documentation for this struct was generated from the following file:
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
scale
double scale
Definition: plastic.cpp:119
sdf.r
int r
Definition: sdf.py:8
TimeForceScale::debug
int debug
Definition: TimeForceScale.hpp:21
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
TimeForceScale::timeData
MoFEMErrorCode timeData()
Definition: TimeForceScale.hpp:36
TimeForceScale::tSeries
std::map< double, double > tSeries
Definition: TimeForceScale.hpp:20
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
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
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
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
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