FEDEM Solver  R8.0
Source code of the dynamics solver
FiDeviceFunctionFactory.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 
13 #ifndef FI_DEVICE_FUNCTION_FACTORY_H
14 #define FI_DEVICE_FUNCTION_FACTORY_H
15 
17 #include "FFaLib/FFaOS/FFaIO.H"
18 #include <string>
19 #include <vector>
20 #include <map>
21 
23 
24 
26 enum FiStatus {
27  IO_READ = 1,
28  IO_WRITE = 2
29 };
30 
33  NON_EXISTING = -1,
39  EXT_FUNC
40 };
41 
42 
47 class FiDeviceFunctionFactory : public FFaSingelton<FiDeviceFunctionFactory>
48 {
49 protected:
53  virtual ~FiDeviceFunctionFactory();
54 
55 public:
63  int open(const std::string& fileName, FiDevFormat format = UNKNOWN_FILE,
64  FiStatus status = IO_READ, int inputChannel = 0,
65  bool littleEndian = false);
66 
68  void close(const std::string& fileName);
70  void close(int fileIndex);
71 
81  double getValue(int fileIndex, double arg, int& stat, int channel = 0,
82  int zeroAd = 0, double shift = 0.0, double scale = 1.0) const;
93  bool getValues(int fileIndex, double x0, double x1,
94  std::vector<double>& x, std::vector<double>& y,
95  int channel = 0, int zeroAdjust = 0,
96  double shift = 0.0, double scale = 1.0) const;
97 
99  double getStep(int fileIndex) const;
101  double getFrequency(int fileIndex) const;
102 
104  void getAxisTitle(int fileIndex, int axis, char* axisText, size_t n) const;
106  void getAxisUnit(int fileIndex, int axis, char* unitText, size_t n) const;
107 
109  bool setValue(int fileIndex, double xVal, double yVal);
110 
112  void setStep(int fileIndex, double step) const;
114  void setFrequency(int fileIndex, double freq) const;
115 
117  void setAxisTitle(int fileIndex, int axis, const char* axisText) const;
119  void setAxisUnit(int fileIndex, int axis, const char* unitText) const;
120 
122  int channelIndex(int fileIndex, const std::string& channel) const;
124  bool getChannelList(int fileIndex, std::vector<std::string>& ch) const;
125 
127  static bool getChannelList(const std::string& fileName,
128  std::vector<std::string>& channels);
129 
131  static FiDevFormat identify(const std::string& fileName,
132  const std::string& path = "",
133  FiStatus status = IO_READ);
134 
136  void dump() const;
137 
141  bool initExtFuncFromFile(const std::string& fileName,
142  const std::string& labels = "");
145  bool updateExtFuncFromFile(int nstep = 1);
150  double getExtFunc(int idx, int stat = 0) const
151  {
152  return this->getValue(0,0.0,stat,idx);
153  }
154 
161  void storeExtFuncValues(double* data, unsigned int ndat, int iop, int& offs);
162 
163 protected:
171  int create(const std::string& fileName, int inputChannel,
172  FiDevFormat format, FiStatus status, bool useLittleEndian);
173 
175  FiDeviceFunctionBase* getDevice(size_t fileIndex) const;
176 
177 public:
178  static int myNumExtFun;
179 
180 private:
182  typedef std::map<std::string,size_t> FileMap;
184  typedef std::pair<std::string,int> FileChannel;
186  typedef std::map<FileChannel,size_t> FileChnMap;
187 
188  std::vector<FiDeviceFunctionBase*> myDevices;
189 
192 
193  std::vector<double> myExtValues;
194  std::vector<int> myExtIndex;
196 
198 };
199 
200 #endif
Functions and data type for direct access of large binary files.
#define FT_FILE
File pointer.
Definition: FFaIO.H:136
FiStatus
Enum for file opening modes.
Definition: FiDeviceFunctionFactory.H:26
@ IO_WRITE
Write access.
Definition: FiDeviceFunctionFactory.H:28
@ IO_READ
Read only access.
Definition: FiDeviceFunctionFactory.H:27
FiDevFormat
Enum for file formats.
Definition: FiDeviceFunctionFactory.H:32
@ EXT_FUNC
External function (no file)
Definition: FiDeviceFunctionFactory.H:39
@ RPC_TH_FILE
RPC time history fomrat (MTS binary format)
Definition: FiDeviceFunctionFactory.H:38
@ DAC_FILE
DAC file (nCode binary format)
Definition: FiDeviceFunctionFactory.H:35
@ UNKNOWN_FILE
Unknown or undefined file format.
Definition: FiDeviceFunctionFactory.H:34
@ ASC_MC_FILE
Multi-column ASCII format.
Definition: FiDeviceFunctionFactory.H:37
@ ASC_FILE
Two-column ASCII format.
Definition: FiDeviceFunctionFactory.H:36
@ NON_EXISTING
Non-existing file.
Definition: FiDeviceFunctionFactory.H:33
Template class for singleton classes.
Definition: FFaSingelton.H:20
Definition: FiDeviceFunctionBase.H:19
Singleton class for external device functions (functions from file).
Definition: FiDeviceFunctionFactory.H:48
FileChnMap myFileChannelMap
File name/channel to device index mapping.
Definition: FiDeviceFunctionFactory.H:191
std::vector< double > myExtValues
Function values for external functions.
Definition: FiDeviceFunctionFactory.H:193
int create(const std::string &fileName, int inputChannel, FiDevFormat format, FiStatus status, bool useLittleEndian)
Opens the named file, not already opened.
Definition: FiDeviceFunctionFactory.C:108
double getFrequency(int fileIndex) const
Returns (constant) sampling frequency of the indexed function.
Definition: FiDeviceFunctionFactory.C:378
FiDeviceFunctionFactory()
Default constructor.
Definition: FiDeviceFunctionFactory.H:51
void getAxisUnit(int fileIndex, int axis, char *unitText, size_t n) const
Returns the axis unit of the indexed function.
Definition: FiDeviceFunctionFactory.C:340
virtual ~FiDeviceFunctionFactory()
The destructor closes all opened files.
Definition: FiDeviceFunctionFactory.C:27
void setAxisTitle(int fileIndex, int axis, const char *axisText) const
Sets the axis title of the indexed function.
Definition: FiDeviceFunctionFactory.C:315
std::pair< std::string, int > FileChannel
File name and column index pair.
Definition: FiDeviceFunctionFactory.H:184
static FiDevFormat identify(const std::string &fileName, const std::string &path="", FiStatus status=IO_READ)
Returns the file format of a named function file.
Definition: FiDeviceFunctionFactory.C:180
std::vector< FiDeviceFunctionBase * > myDevices
Device function container.
Definition: FiDeviceFunctionFactory.H:188
void getAxisTitle(int fileIndex, int axis, char *axisText, size_t n) const
Returns the axis title of the indexed function.
Definition: FiDeviceFunctionFactory.C:332
bool initExtFuncFromFile(const std::string &fileName, const std::string &labels="")
Opens a file to read external function values from.
Definition: FiDeviceFunctionFactory.C:471
bool getValues(int fileIndex, double x0, double x1, std::vector< double > &x, std::vector< double > &y, int channel=0, int zeroAdjust=0, double shift=0.0, double scale=1.0) const
Evaluate the indexed function for the specified argument range.
Definition: FiDeviceFunctionFactory.C:258
bool getChannelList(int fileIndex, std::vector< std::string > &ch) const
Returns the list of channel labels for the indexed function.
Definition: FiDeviceFunctionFactory.C:395
bool setValue(int fileIndex, double xVal, double yVal)
Sets an argument/value pair for an indexed function.
Definition: FiDeviceFunctionFactory.C:276
FT_FILE myExtFnFile
External function value file handle.
Definition: FiDeviceFunctionFactory.H:195
double getStep(int fileIndex) const
Returns (constant) argument increment of the indexed function.
Definition: FiDeviceFunctionFactory.C:372
double getValue(int fileIndex, double arg, int &stat, int channel=0, int zeroAd=0, double shift=0.0, double scale=1.0) const
Evaluates the indexed function for the specified argument value.
Definition: FiDeviceFunctionFactory.C:227
std::map< std::string, size_t > FileMap
File name to device index mapping.
Definition: FiDeviceFunctionFactory.H:182
void setFrequency(int fileIndex, double freq) const
Sets the constant sampling frequency of the indexed function.
Definition: FiDeviceFunctionFactory.C:353
void dump() const
Prints a summary of the currently open files to std::cout.
Definition: FiDeviceFunctionFactory.C:438
int channelIndex(int fileIndex, const std::string &channel) const
Returns the index of a named channel of the indexed function.
Definition: FiDeviceFunctionFactory.C:387
void setAxisUnit(int fileIndex, int axis, const char *unitText) const
Sets the axis unit of the indexed function.
Definition: FiDeviceFunctionFactory.C:323
std::map< FileChannel, size_t > FileChnMap
File name and column to device index mapping.
Definition: FiDeviceFunctionFactory.H:186
FileMap myFileToIndexMap
File name to device index mapping.
Definition: FiDeviceFunctionFactory.H:190
void setStep(int fileIndex, double step) const
Sets the constant argument increment of the indexed function.
Definition: FiDeviceFunctionFactory.C:360
double getExtFunc(int idx, int stat=0) const
Evaluates an indexed external function.
Definition: FiDeviceFunctionFactory.H:150
int open(const std::string &fileName, FiDevFormat format=UNKNOWN_FILE, FiStatus status=IO_READ, int inputChannel=0, bool littleEndian=false)
Opens the named file.
Definition: FiDeviceFunctionFactory.C:35
std::vector< int > myExtIndex
Associated file column indices.
Definition: FiDeviceFunctionFactory.H:194
FiDeviceFunctionBase * getDevice(size_t fileIndex) const
Returns the device object for the indexed function.
Definition: FiDeviceFunctionFactory.C:450
void close(const std::string &fileName)
Closes the named file.
Definition: FiDeviceFunctionFactory.C:96
void storeExtFuncValues(double *data, unsigned int ndat, int iop, int &offs)
Stores/extracts external function values from in-core array.
Definition: FiDeviceFunctionFactory.C:545
bool updateExtFuncFromFile(int nstep=1)
Updates the external function values from file.
Definition: FiDeviceFunctionFactory.C:532
static int myNumExtFun
Number of external functions in current model.
Definition: FiDeviceFunctionFactory.H:178
integer(ptr), save, private x
Definition: extCtrlSysRoutinesModule.f90:16
integer channel
Column index for data file.
Definition: initiateFunctionTypeModule.f90:26
integer, save nstep
Definition: saveVTFModule.f90:25
static int iop
Internal operation status variable.
Definition: solverInterface.C:49
subroutine scale(vec, a)
Definition: windTurbineRoutinesModule.f90:510