v0.13.2
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, SPACE_DIM > > 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 133 of file ScalingMethod.cpp.

134 : readFile(0), debug(0),
135 errorIfFileNotGiven(error_if_file_not_given) {
136 nAme = name + std::to_string(ms_id);
137 CHK_THROW_MESSAGE(timeData(), "Error in reading time data");
138}
#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 208 of file ScalingMethod.cpp.

208 {
209 return scalingMethod(time);
210}
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 214 of file ScalingMethod.cpp.

214 {
215
216 // if (readFile == 0) {
217 // CHK_THROW_MESSAGE(MOFEM_OPERATION_UNSUCCESSFUL, "Data file not read");
218 // }
219
221 FTensor::Tensor1<double, SPACE_DIM> acc0 = tSeries.begin()->second;
224
225 double t0 = 0, t1, dt;
226 for (auto &[ts, vec] : tSeries) {
227 if (ts > time) {
228 t1 = ts;
229 dt = time - t0;
230 acc(i) = acc0(i) + ((vec(i) - acc0(i)) / (t1 - t0)) * dt;
231 break;
232 }
233 t0 = ts;
234 acc0 = vec;
235 acc = acc0;
236 }
237 Nf(i) = acc(i);
238 return Nf;
239}
FTensor::Index< 'i', SPACE_DIM > i
double dt
Definition: heat_method.cpp:26
std::map< double, FTensor::Tensor1< double, SPACE_DIM > > tSeries

◆ timeData()

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

Definition at line 141 of file ScalingMethod.cpp.

141 {
142
144
145 char time_file_name[255];
146 PetscBool flg = PETSC_FALSE;
147 if (!nAme.empty())
148 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, nAme.c_str(),
149 time_file_name, 255, &flg);
150
151 if (!flg) {
153 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
154 "*** ERROR %s (time_data FILE NEEDED)", nAme.c_str());
156 }
157
158 FILE *time_data = fopen(time_file_name, "r");
159 if (time_data == NULL) {
160 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
161 "*** ERROR data file < %s > open unsuccessful", time_file_name);
162 }
163 double no1 = 0.0;
166 no2(i) = 0.;
167 tSeries[no1] = no2;
168 while (!feof(time_data)) {
169 int n =
170 fscanf(time_data, "%lf %lf %lf %lf", &no1, &no2(0), &no2(1), &no2(2));
171 if (n < 0) {
172 fgetc(time_data);
173 continue;
174 }
175 if (n != 4) {
176 SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
177 "*** ERROR read data file error (check input time data file) "
178 "{ n = %d }",
179 n);
180 }
181 tSeries[no1] = no2;
182 }
183 int r = fclose(time_data);
184 if (debug) {
185
186 for (auto &[ts, vec] : tSeries) {
187 PetscPrintf(PETSC_COMM_WORLD,
188 "** read vector %3.2e time %3.2e %3.2e %3.2e\n",
189 ts, vec(0), vec(1), vec(2));
190 }
191 }
192 if (r != 0) {
193 SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR file close unsuccessful");
194 }
195 readFile = 1;
196
197 if (readFile == 1)
198 scalingMethod = [this](double time) {
199 return this->getVectorFromData(time);
200 };
201
203}
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
#define CHKERR
Inline error check.
Definition: definitions.h:535
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
FTensor::Index< 'n', SPACE_DIM > n
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
int r
Definition: sdf.py:5
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, SPACE_DIM> > 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: