44 #define PiecewiseLinFunction_PRECISION 1.e-12 57 double xa, xb, ya, yb;
64 if ( fabs(this->
dates.
at(i) - time) < precision ) {
66 }
else if ( this->
dates.
at(i) > time ) {
68 OOFEM_WARNING(
"computational time %f is out of given time %f, using closest value", time,
dates.
at(i) );
77 return ya + ( time - xa ) * ( yb - ya ) / ( xb - xa );
81 OOFEM_WARNING(
"computational time %f is out of given time, using closest value", time );
91 double xa, xb, ya, yb;
98 if ( fabs(
dates.
at(i) - time) < precision ) {
104 }
else if (
dates.
at(i) > time ) {
114 return ( yb - ya ) / ( xb - xa );
128 std :: list< double >t, ft;
133 std :: ifstream file(fname.c_str(), std :: ios :: in);
134 if ( !file.is_open() ) {
135 OOFEM_ERROR(
"Failed to open data file: %s\n", fname.c_str());
138 double temp_t, temp_ft;
139 std :: string sLine =
"";
140 while ( !file.eof() ) {
141 getline(file, sLine);
142 if ( sLine [ 0 ] ==
'#' ) {
145 std :: stringstream ss1(sLine);
146 ss1 >> temp_t >> temp_ft;
148 ft.push_back(temp_ft);
154 std :: list< double > :: iterator it_t = t.begin(), it_ft = ft.begin();
155 for (
int i = 1; i <= ( int ) t.size(); ++i, ++it_t, ++it_ft ) {
#define PiecewiseLinFunction_PRECISION
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
contextIOResultType storeYourself(DataStream &stream) const
double & at(int i)
Coefficient access function.
PiecewiseLinFunction(int i, Domain *d)
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
#define _IFT_PiecewiseLinFunction_ft
REGISTER_Function(CalculatorFunction)
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
#define _IFT_PiecewiseLinFunction_t
virtual contextIOResultType restoreContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Restores the receiver state previously written in stream.
contextIOResultType restoreYourself(DataStream &stream)
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Abstract base class representing a function with vector input and output.
virtual double evaluateVelocityAtTime(double t)
Returns the first time derivative of the function at given time.
IRResultType
Type defining the return values of InputRecord reading operations.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
long ContextMode
Context mode (mask), defining the type of information written/read to/from context.
int giveSize() const
Returns the size of receiver.
virtual double evaluateAtTime(double t)
Returns the value of the function at given time.
the oofem namespace is to define a context or scope in which all oofem names are defined.
#define _IFT_PiecewiseLinFunction_dataFile
#define OOFEM_WARNING(...)
virtual contextIOResultType saveContext(DataStream &stream, ContextMode mode, void *obj=NULL)
Stores receiver state to output stream.
void resize(int s)
Resizes receiver towards requested size.