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

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

#include <users_modules/basic_finite_elements/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...
 
- Public Member Functions inherited from MethodForForceScaling
virtual ~MethodForForceScaling ()
 

Public Attributes

std::map< double, double > tSeries
 
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)
 

Detailed Description

Force scale operator for reading two columns.

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

Definition at line 30 of file TimeForceScale.hpp.

Constructor & Destructor Documentation

◆ TimeForceScale()

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

Definition at line 37 of file TimeForceScale.hpp.

39  : readFile(0), debug(0), nAme(name),
40  errorIfFileNotGiven(error_if_file_not_given) {
41 
42  ierr = timeData();
43  CHKERRABORT(PETSC_COMM_WORLD, ierr);
44  }
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87
MoFEMErrorCode timeData()

Member Function Documentation

◆ getForceScale()

MoFEMErrorCode TimeForceScale::getForceScale ( const double  ts_t,
double &  scale 
)
virtual

Reimplemented from MethodForForceScaling.

Definition at line 101 of file TimeForceScale.hpp.

101  {
103  if (!fLg) {
104  scale = ts_t; // scale with time, by default
106  }
107  if (readFile == 0) {
108  SETERRQ(PETSC_COMM_SELF, 1, "data file not read");
109  }
110  scale = 0;
111  double t0 = 0, t1, s0 = tSeries[0], s1, dt;
112  std::map<double, double>::iterator tit = tSeries.begin();
113  for (; tit != tSeries.end(); tit++) {
114  if (tit->first > ts_t) {
115  t1 = tit->first;
116  s1 = tit->second;
117  dt = ts_t - t0;
118  scale = s0 + ((s1 - s0) / (t1 - t0)) * dt;
119  break;
120  }
121  t0 = tit->first;
122  s0 = tit->second;
123  scale = s0;
124  }
126  }
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
double dt
Definition: heat_method.cpp:40
double scale
Definition: plastic.cpp:103
std::map< double, double > tSeries

◆ scaleNf()

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

Scale force the right hand vector.

Parameters
fe
Nf
Returns
MoFEMErrorCode

Implements MethodForForceScaling.

Definition at line 135 of file TimeForceScale.hpp.

135  {
137  double scale;
138  const double ts_t = fe->ts_t;
139  CHKERR getForceScale(ts_t, scale);
140  Nf *= scale;
142  }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEMErrorCode getForceScale(const double ts_t, double &scale)

◆ timeData()

MoFEMErrorCode TimeForceScale::timeData ( )

Definition at line 48 of file TimeForceScale.hpp.

48  {
50  char time_file_name[255];
51  ierr = PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
52  time_file_name, 255, &fLg);
53  CHKERRG(ierr);
54  if (!fLg && errorIfFileNotGiven) {
55  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
56  "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
57  }
58  if (!fLg) {
59  MOFEM_LOG_C("WORLD", Sev::warning,
60  "The %s file not provided. Loading scaled with time.",
61  nAme.c_str());
63  }
64  FILE *time_data = fopen(time_file_name, "r");
65  if (time_data == NULL) {
66  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
67  "*** ERROR data file < %s > open unsuccessful", time_file_name);
68  }
69  double no1 = 0.0, no2 = 0.0;
70  tSeries[no1] = no2;
71  while (!feof(time_data)) {
72  int n = fscanf(time_data, "%lf %lf", &no1, &no2);
73  if ((n <= 0) || ((no1 == 0) && (no2 == 0))) {
74  fgetc(time_data);
75  continue;
76  }
77  if (n != 2) {
78  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
79  "*** ERROR read data file error (check input time data file) "
80  "{ n = %d }",
81  n);
82  }
83  tSeries[no1] = no2;
84  }
85  int r = fclose(time_data);
86  if (debug) {
87  std::map<double, double>::iterator tit = tSeries.begin();
88  for (; tit != tSeries.end(); tit++) {
89  PetscPrintf(PETSC_COMM_WORLD, "** read time series %3.2e time %3.2e\n",
90  tit->first, tit->second);
91  }
92  }
93  if (r != 0) {
94  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
95  "*** ERROR file close unsuccessful");
96  }
97  readFile = 1;
99  }
static Index< 'n', 3 > n
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:314
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
const double r
rate factor

Member Data Documentation

◆ debug

int TimeForceScale::debug

Definition at line 33 of file TimeForceScale.hpp.

◆ errorIfFileNotGiven

bool TimeForceScale::errorIfFileNotGiven

Definition at line 35 of file TimeForceScale.hpp.

◆ fLg

PetscBool TimeForceScale::fLg

Definition at line 46 of file TimeForceScale.hpp.

◆ nAme

string TimeForceScale::nAme

Definition at line 34 of file TimeForceScale.hpp.

◆ readFile

int TimeForceScale::readFile

Definition at line 33 of file TimeForceScale.hpp.

◆ tSeries

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

Definition at line 32 of file TimeForceScale.hpp.


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