FEDEM Solver  R8.0
Source code of the dynamics solver
FiDeviceFunctionBase.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FI_DEVICE_FUNCTION_BASE_H
9 #define FI_DEVICE_FUNCTION_BASE_H
10 
11 #include <string>
12 #include <vector>
13 #include <map>
14 
15 #include "FFaLib/FFaOS/FFaIO.H"
16 
17 
19 {
20 protected:
21  FiDeviceFunctionBase(const char* devicename = NULL);
24 
25 public:
26  virtual ~FiDeviceFunctionBase() { this->close(); }
27 
28  enum Axis {X=0, Y=1};
33 
34  bool open(const char* devicename, FileStatus status = Read_Only);
35  bool open(FileStatus status = Read_Only) { return this->open(NULL,status); }
36 
37  bool close(bool noHeader = false);
38 
39  const std::string& getDevicename() const { return myDatasetDevice; }
40 
42  { myExtrapolationPolicy = policy; }
44  { myInterpolationPolicy = policy; }
45 
46  virtual size_t getValueCount() const = 0;
47  virtual void getValueRange(double& mn, double& mx) const { mn = mx = 0.0; }
48  virtual double getXAxisOrigin() const { return 0.0; }
49 
50  virtual bool getChannelList(std::vector<std::string>&) { return true; }
51  virtual bool isChannelPresentInFile(int) { return true; }
52  virtual int isChannelPresentInFile(const std::string&) { return 1; }
53  virtual void setTimeSpan(double) {}
54  virtual void setPrecision(int) {}
55 
56  virtual double getValue(double x, int channel = 0,
57  bool zeroAdjust = false, double vertShift = 0.0,
58  double scaleFac = 1.0) = 0;
59 
60  virtual bool getValues(double x0, double x1,
61  std::vector<double>& x, std::vector<double>& y,
62  int channel, bool zeroAdjust = false,
63  double shift = 0.0, double scale = 1.0) = 0;
64 
65  virtual void getRawData(std::vector<double>& x, std::vector<double>& y,
66  double minX, double maxX, int channel = 0) = 0;
67 
68  virtual void getData(std::vector<double>& x, std::vector<double>& y,
69  const std::string&, double minX = 0.0, double maxX = -1.0)
70  { this->getRawData(x,y,minX,maxX); }
71 
72  virtual void setValue(double x, double y) = 0;
73  virtual bool setData(const std::vector<double>& x, const std::vector<double>& y) = 0;
74 
75  double integrate(double x, int order = 1, int channel = 0,
76  double vertShift = 0.0, double scaleFac = 1.0);
77 
78  // reference counting (if user cares...)
79  int getRefCount() const { return myRefCount; }
80  int ref() { return ++myRefCount; }
81  int unref();
82 
83  double getStep() const { return myStep; }
84  double getFrequency() const { return 1.0/myStep; }
85 
86  void setStep(double aStep) { myStep = aStep; }
87  void setFrequency(double aFreqency) { myStep = 1.0/aFreqency; }
88 
89  virtual void setDescription(const std::string&) {}
90  virtual void setEmptyChannel(const std::string&) {}
91  void setParent(const std::string& modelfile) { myParent = modelfile; }
92 
93  bool isReadOnly() const { return myFileStatus == Read_Only; }
95 
96  void getAxisUnit(int axis, char* unitText, size_t n) const;
97  void getAxisTitle(int axis, char* titleText, size_t n) const;
98 
99  void setAxisUnit(int axis, const char* unitText);
100  void setAxisTitle(int axis, const char* titleText);
101 
102 protected:
103  // TODO: Use an iterator on the data set instead of x0 etc...
104  // This enables spline, quadratic or any other
105  // interpolation/extrapolation policy
106 
107  double interpolate(double x,
108  double x0, double f0,
109  double x1, double f1) const;
110 
111  double extrapolate(double x,
112  double x0, double f0,
113  double x1, double f1) const;
114 
115  // Convenience methods for writing text headers, etc.
116  bool writeString(const char* str);
117  bool writeString(const char* lab, const std::string& val);
118 
119  virtual bool initialDeviceRead() = 0;
120  virtual bool preliminaryDeviceWrite() = 0;
121  virtual bool concludingDeviceWrite(bool noHeader = false) = 0;
122 
123  // file data
125  std::string myParent;
126  std::string myDatasetDevice;
127 
131 
132  // time series information
133  double myStep;
134 
135  struct axisInfo
136  {
137  std::string unit;
138  std::string title;
139  };
140 
141  std::map<int,axisInfo> myAxisInfo;
142 
143 private:
147 
148  // used for integration
149  std::vector<double> Xval;
150  std::vector<double> Yval;
151 
152  // reference counting
154 };
155 
156 #endif
Functions and data type for direct access of large binary files.
#define FT_FILE
File pointer.
Definition: FFaIO.H:136
Definition: FiDeviceFunctionBase.H:19
virtual bool initialDeviceRead()=0
virtual double getValue(double x, int channel=0, bool zeroAdjust=false, double vertShift=0.0, double scaleFac=1.0)=0
double myStep
Definition: FiDeviceFunctionBase.H:133
FileStatus myFileStatus
Definition: FiDeviceFunctionBase.H:144
Endianness myInputEndian
Definition: FiDeviceFunctionBase.H:130
virtual void setPrecision(int)
Definition: FiDeviceFunctionBase.H:54
void getAxisTitle(int axis, char *titleText, size_t n) const
Definition: FiDeviceFunctionBase.C:94
Endianness
Definition: FiDeviceFunctionBase.H:29
@ BigEndian
Definition: FiDeviceFunctionBase.H:29
@ LittleEndian
Definition: FiDeviceFunctionBase.H:29
bool open(FileStatus status=Read_Only)
Definition: FiDeviceFunctionBase.H:35
InterpolationPolicy myExtrapolationPolicy
Definition: FiDeviceFunctionBase.H:146
Endianness myOutputEndian
Definition: FiDeviceFunctionBase.H:129
int getRefCount() const
Definition: FiDeviceFunctionBase.H:79
virtual bool preliminaryDeviceWrite()=0
virtual bool getValues(double x0, double x1, std::vector< double > &x, std::vector< double > &y, int channel, bool zeroAdjust=false, double shift=0.0, double scale=1.0)=0
virtual int isChannelPresentInFile(const std::string &)
Definition: FiDeviceFunctionBase.H:52
Axis
Definition: FiDeviceFunctionBase.H:28
@ X
Definition: FiDeviceFunctionBase.H:28
@ Y
Definition: FiDeviceFunctionBase.H:28
virtual void setEmptyChannel(const std::string &)
Definition: FiDeviceFunctionBase.H:90
virtual void getRawData(std::vector< double > &x, std::vector< double > &y, double minX, double maxX, int channel=0)=0
std::vector< double > Xval
Definition: FiDeviceFunctionBase.H:149
FiDeviceFunctionBase & operator=(const FiDeviceFunctionBase &)=delete
virtual bool isChannelPresentInFile(int)
Definition: FiDeviceFunctionBase.H:51
double integrate(double x, int order=1, int channel=0, double vertShift=0.0, double scaleFac=1.0)
Definition: FiDeviceFunctionBase.C:174
virtual void setTimeSpan(double)
Definition: FiDeviceFunctionBase.H:53
void setParent(const std::string &modelfile)
Definition: FiDeviceFunctionBase.H:91
virtual double getXAxisOrigin() const
Definition: FiDeviceFunctionBase.H:48
bool open(const char *devicename, FileStatus status=Read_Only)
Definition: FiDeviceFunctionBase.C:48
bool writeString(const char *str)
Definition: FiDeviceFunctionBase.C:115
int myRefCount
Definition: FiDeviceFunctionBase.H:153
void setFrequency(double aFreqency)
Definition: FiDeviceFunctionBase.H:87
virtual void getData(std::vector< double > &x, std::vector< double > &y, const std::string &, double minX=0.0, double maxX=-1.0)
Definition: FiDeviceFunctionBase.H:68
double getFrequency() const
Definition: FiDeviceFunctionBase.H:84
virtual bool setData(const std::vector< double > &x, const std::vector< double > &y)=0
virtual void getValueRange(double &mn, double &mx) const
Definition: FiDeviceFunctionBase.H:47
void getAxisUnit(int axis, char *unitText, size_t n) const
Definition: FiDeviceFunctionBase.C:85
void setAxisTitle(int axis, const char *titleText)
Definition: FiDeviceFunctionBase.C:109
InterpolationPolicy myInterpolationPolicy
Definition: FiDeviceFunctionBase.H:145
FiDeviceFunctionBase(const char *devicename=NULL)
Definition: FiDeviceFunctionBase.C:25
FT_FILE myFile
Definition: FiDeviceFunctionBase.H:124
void setStep(double aStep)
Definition: FiDeviceFunctionBase.H:86
double extrapolate(double x, double x0, double f0, double x1, double f1) const
Definition: FiDeviceFunctionBase.C:159
virtual ~FiDeviceFunctionBase()
Definition: FiDeviceFunctionBase.H:26
void setInterpolationPolicy(InterpolationPolicy policy=Linear)
Definition: FiDeviceFunctionBase.H:43
std::string myDatasetDevice
Definition: FiDeviceFunctionBase.H:126
void setExtrapolationPolicy(InterpolationPolicy policy=Constant)
Definition: FiDeviceFunctionBase.H:41
virtual bool concludingDeviceWrite(bool noHeader=false)=0
void setAxisUnit(int axis, const char *unitText)
Definition: FiDeviceFunctionBase.C:104
FileFormat
Definition: FiDeviceFunctionBase.H:30
@ ascii
Definition: FiDeviceFunctionBase.H:30
@ binary
Definition: FiDeviceFunctionBase.H:30
FileStatus getFileStatus() const
Definition: FiDeviceFunctionBase.H:94
bool close(bool noHeader=false)
Definition: FiDeviceFunctionBase.C:127
virtual bool getChannelList(std::vector< std::string > &)
Definition: FiDeviceFunctionBase.H:50
double interpolate(double x, double x0, double f0, double x1, double f1) const
Definition: FiDeviceFunctionBase.C:142
const std::string & getDevicename() const
Definition: FiDeviceFunctionBase.H:39
static Endianness myMachineEndian
Definition: FiDeviceFunctionBase.H:128
InterpolationPolicy
Definition: FiDeviceFunctionBase.H:32
@ Next_Value
Definition: FiDeviceFunctionBase.H:32
@ Constant
Definition: FiDeviceFunctionBase.H:32
@ Linear
Definition: FiDeviceFunctionBase.H:32
@ Previous_Value
Definition: FiDeviceFunctionBase.H:32
FiDeviceFunctionBase(const FiDeviceFunctionBase &)=delete
std::vector< double > Yval
Definition: FiDeviceFunctionBase.H:150
virtual void setValue(double x, double y)=0
int unref()
Definition: FiDeviceFunctionBase.C:38
virtual void setDescription(const std::string &)
Definition: FiDeviceFunctionBase.H:89
bool isReadOnly() const
Definition: FiDeviceFunctionBase.H:93
FileStatus
Definition: FiDeviceFunctionBase.H:31
@ Write_Only
Definition: FiDeviceFunctionBase.H:31
@ Read_Only
Definition: FiDeviceFunctionBase.H:31
@ Not_Loaded
Definition: FiDeviceFunctionBase.H:31
@ Not_Open
Definition: FiDeviceFunctionBase.H:31
std::string myParent
Definition: FiDeviceFunctionBase.H:125
int ref()
Definition: FiDeviceFunctionBase.H:80
virtual size_t getValueCount() const =0
std::map< int, axisInfo > myAxisInfo
Definition: FiDeviceFunctionBase.H:141
double getStep() const
Definition: FiDeviceFunctionBase.H:83
integer(ptr), save, private x
Definition: extCtrlSysRoutinesModule.f90:16
integer channel
Column index for data file.
Definition: initiateFunctionTypeModule.f90:26
character(lfnam_p) modelfile
Model file name.
Definition: headingNamelistModule.f90:21
Definition: FiDeviceFunctionBase.H:136
std::string unit
Definition: FiDeviceFunctionBase.H:137
std::string title
Definition: FiDeviceFunctionBase.H:138
subroutine scale(vec, a)
Definition: windTurbineRoutinesModule.f90:510