FEDEM Solver  R8.0
Source code of the dynamics solver
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
FiASCFile Class Reference

Class representing external device functions based on ASCII files. More...

#include <FiASCFile.H>

Inheritance diagram for FiASCFile:
Inheritance graph
[legend]
Collaboration diagram for FiASCFile:
Collaboration graph
[legend]

Public Member Functions

 FiASCFile (const char *fname=NULL, int nchan=1)
 Default constructor. More...
 
virtual ~FiASCFile ()
 Empty destructor. More...
 
virtual size_t getValueCount () const
 Returns the number of (x,y) pairs of the function. More...
 
virtual double getValue (double x, int channel, bool zeroAdjust, double vertShift, double scaleFac)
 Evaluates the function for a given x value. More...
 
virtual bool getValues (double x0, double x1, Doubles &x, Doubles &y, int channel, bool zeroAdj, double shift, double scale)
 Evaluates the function at all points within specified interval. More...
 
virtual void getRawData (Doubles &x, Doubles &y, double minX, double maxX, int channel)
 Extracts all function data point values within specified interval. More...
 
virtual void getData (Doubles &x, Doubles &y, const std::string &channel, double minX, double maxX)
 Extracts all function data point values within specified interval. More...
 
virtual void setValue (double x, double y)
 Assigns a function value for a single-channel function. More...
 
virtual bool setData (const Doubles &x, const Doubles &y)
 Adds a channel to current file by interpolation. More...
 
virtual void setDescription (const std::string &desc)
 Assigns a name to the (last) channel in file. More...
 
virtual void setEmptyChannel (const std::string &desc)
 Adds an empty channel to the file. More...
 
virtual void setPrecision (int type)
 Defines the output precision. More...
 
virtual bool getChannelList (Strings &list)
 Extracts the list of channel names (file column labels). More...
 
virtual int isChannelPresentInFile (const std::string &channel)
 Returns the column index of the named channel. More...
 
virtual bool isChannelPresentInFile (int channel)
 Returns true if channel is a valid column index. More...
 
- Public Member Functions inherited from FiDeviceFunctionBase
virtual ~FiDeviceFunctionBase ()
 
bool open (const char *devicename, FileStatus status=Read_Only)
 
bool open (FileStatus status=Read_Only)
 
bool close (bool noHeader=false)
 
const std::string & getDevicename () const
 
void setExtrapolationPolicy (InterpolationPolicy policy=Constant)
 
void setInterpolationPolicy (InterpolationPolicy policy=Linear)
 
virtual void getValueRange (double &mn, double &mx) const
 
virtual double getXAxisOrigin () const
 
virtual bool getChannelList (std::vector< std::string > &)
 
virtual void setTimeSpan (double)
 
double integrate (double x, int order=1, int channel=0, double vertShift=0.0, double scaleFac=1.0)
 
int getRefCount () const
 
int ref ()
 
int unref ()
 
double getStep () const
 
double getFrequency () const
 
void setStep (double aStep)
 
void setFrequency (double aFreqency)
 
void setParent (const std::string &modelfile)
 
bool isReadOnly () const
 
FileStatus getFileStatus () const
 
void getAxisUnit (int axis, char *unitText, size_t n) const
 
void getAxisTitle (int axis, char *titleText, size_t n) const
 
void setAxisUnit (int axis, const char *unitText)
 
void setAxisTitle (int axis, const char *titleText)
 

Static Public Member Functions

static int getNoChannels (const char *fname)
 Counts the number of channels (number of columns minus one). More...
 
static bool isMultiChannel (FT_FILE fd, const char *fname=NULL, bool rewind=false)
 Checks if the specified file consists of two or more columns. More...
 
static int readHeader (FT_FILE fd, Strings &header)
 Reads the header section of a specified file. More...
 
static bool readNext (FT_FILE fd, const std::vector< int > &columns, Doubles &values)
 Reads the next line of data from specified file. More...
 

Static Public Attributes

static size_t bufferSize = 0
 Buffer size for ASCII output in KBytes. More...
 

Protected Member Functions

virtual bool concludingDeviceWrite (bool noHeader)
 Writes all function data to file. More...
 
virtual bool initialDeviceRead ()
 Reads the file and loads the first channel into core. More...
 
virtual bool preliminaryDeviceWrite ()
 Dummy method doing nothing. More...
 
- Protected Member Functions inherited from FiDeviceFunctionBase
 FiDeviceFunctionBase (const char *devicename=NULL)
 
 FiDeviceFunctionBase (const FiDeviceFunctionBase &)=delete
 
FiDeviceFunctionBaseoperator= (const FiDeviceFunctionBase &)=delete
 
double interpolate (double x, double x0, double f0, double x1, double f1) const
 
double extrapolate (double x, double x0, double f0, double x1, double f1) const
 
bool writeString (const char *str)
 
bool writeString (const char *lab, const std::string &val)
 

Private Types

typedef std::vector< double > Doubles
 Convenience type definition. More...
 
typedef std::vector< std::string > Strings
 Convenience type definition. More...
 
typedef std::map< double, DoublesValuesMap
 Mapping from x-value (time) to channel values. More...
 
typedef ValuesMap::iterator ValuesIter
 Convenience type definition. More...
 

Private Member Functions

int readChannel (int channel)
 Reads the specified channel into core. More...
 

Static Private Member Functions

static char * readLine (FT_FILE fd, bool commentsOnly=false)
 Reads one line of data from specified file. More...
 
static int countColumns (FT_FILE fd)
 Returns the number of columns in the file fd. More...
 

Private Attributes

Strings chn
 Channel names (columns labels) More...
 
ValuesMap myValues
 Curve data, either for all or one channel. More...
 
ValuesIter vit0
 Start iterator of last evaluation interval. More...
 
ValuesIter vit1
 End iterator of last evaluation interval. More...
 
int myChannel
 Channel (column index) that currently resides in core. More...
 
int myNumChannels
 Number of columns minus 1 (column 1 is the X-values) More...
 
int outputFormat
 0: 4-digits, 1: 8 digits, 2: 16-digits More...
 
bool isCSVt
 If true, this file has microsec as first column. More...
 

Additional Inherited Members

- Public Types inherited from FiDeviceFunctionBase
enum  Axis { X =0 , Y =1 }
 
enum  Endianness { LittleEndian , BigEndian }
 
enum  FileFormat { ascii , binary }
 
enum  FileStatus { Not_Loaded =-1 , Not_Open =0 , Read_Only =1 , Write_Only =2 }
 
enum  InterpolationPolicy { Constant , Linear , Previous_Value , Next_Value }
 
- Protected Attributes inherited from FiDeviceFunctionBase
FT_FILE myFile
 
std::string myParent
 
std::string myDatasetDevice
 
Endianness myOutputEndian
 
Endianness myInputEndian
 
double myStep
 
std::map< int, axisInfomyAxisInfo
 
- Static Protected Attributes inherited from FiDeviceFunctionBase
static Endianness myMachineEndian
 

Detailed Description

Class representing external device functions based on ASCII files.

This class is used to represent a polyline (or piece-wise linear) function defined through a sequence of (x,y) points, where the x- and y-values are stored as two columns of a multi-column ASCII file (the file itself may contain two or more columns of data). The first column of the file is always the x-values, which need to be monotonically increasing, i.e., xi-1 ≤ xi ≤ xi+1 for all i.

Member Typedef Documentation

◆ Doubles

typedef std::vector<double> FiASCFile::Doubles
private

Convenience type definition.

◆ Strings

typedef std::vector<std::string> FiASCFile::Strings
private

Convenience type definition.

◆ ValuesIter

typedef ValuesMap::iterator FiASCFile::ValuesIter
private

Convenience type definition.

◆ ValuesMap

typedef std::map<double,Doubles> FiASCFile::ValuesMap
private

Mapping from x-value (time) to channel values.

Constructor & Destructor Documentation

◆ FiASCFile()

FiASCFile::FiASCFile ( const char *  fname = NULL,
int  nchan = 1 
)

Default constructor.

Parameters
[in]fnameName of file containing the function data.
[in]nchanNumber of channels in file (used when writing the file)

◆ ~FiASCFile()

virtual FiASCFile::~FiASCFile ( )
inlinevirtual

Empty destructor.

Member Function Documentation

◆ concludingDeviceWrite()

bool FiASCFile::concludingDeviceWrite ( bool  noHeader)
protectedvirtual

Writes all function data to file.

Implements FiDeviceFunctionBase.

◆ countColumns()

int FiASCFile::countColumns ( FT_FILE  fd)
staticprivate

Returns the number of columns in the file fd.

◆ getChannelList()

bool FiASCFile::getChannelList ( Strings list)
virtual

Extracts the list of channel names (file column labels).

◆ getData()

void FiASCFile::getData ( Doubles x,
Doubles y,
const std::string &  channel,
double  minX,
double  maxX 
)
virtual

Extracts all function data point values within specified interval.

Parameters
[out]xX-values (argument values) of all points within the interval
[out]yY-values (function values) of all points within the interval
[in]channelChannel name identifying the function values to use
[in]minXLower bound of function argument interval
[in]maxXUpper bound of function argument interval

Reimplemented from FiDeviceFunctionBase.

◆ getNoChannels()

int FiASCFile::getNoChannels ( const char *  fname)
static

Counts the number of channels (number of columns minus one).

◆ getRawData()

void FiASCFile::getRawData ( Doubles x,
Doubles y,
double  minX,
double  maxX,
int  channel 
)
virtual

Extracts all function data point values within specified interval.

Parameters
[out]xX-values (argument values) of all points within the interval
[out]yY-values (function values) of all points within the interval
[in]minXLower bound of function argument interval
[in]maxXUpper bound of function argument interval
[in]channelColumn index identifying the function values to use

Implements FiDeviceFunctionBase.

◆ getValue()

double FiASCFile::getValue ( double  x,
int  channel,
bool  zeroAdjust,
double  vertShift,
double  scaleFac 
)
virtual

Evaluates the function for a given x value.

Parameters
[in]xThe function argument to evaluate for
[in]channelColumn index identifying the function values to use
[in]zeroAdjustIf true, the function values are shifted such that it evaluates to zero (or vertShift) at its first point value
[in]vertShiftAdditional function-value shift
[in]scaleFacFunction-value scaling factor

Implements FiDeviceFunctionBase.

◆ getValueCount()

virtual size_t FiASCFile::getValueCount ( ) const
inlinevirtual

Returns the number of (x,y) pairs of the function.

Implements FiDeviceFunctionBase.

◆ getValues()

bool FiASCFile::getValues ( double  x0,
double  x1,
Doubles x,
Doubles y,
int  channel,
bool  zeroAdj,
double  shift,
double  scale 
)
virtual

Evaluates the function at all points within specified interval.

Parameters
[in]x0Lower bound of function argument interval
[in]x1Upper bound of function argument interval
[out]xX-values (argument values) of all points within the interval
[out]yY-values (function values) of all points within the interval
[in]channelColumn index identifying the function values to use
[in]zeroAdjIf true, the function values are shifted such that it evaluates to zero (or shift) at its first point value
[in]shiftAdditional function-value shift
[in]scaleFunction-value scaling factor

This method is equivalent to the getRawData() method if invoked with zeroAdj = false, shift = 0.0 and scale = 1.0, however, the former method will be more efficient in that case.

Implements FiDeviceFunctionBase.

◆ initialDeviceRead()

bool FiASCFile::initialDeviceRead ( )
protectedvirtual

Reads the file and loads the first channel into core.

Implements FiDeviceFunctionBase.

◆ isChannelPresentInFile() [1/2]

int FiASCFile::isChannelPresentInFile ( const std::string &  channel)
virtual

Returns the column index of the named channel.

Reimplemented from FiDeviceFunctionBase.

◆ isChannelPresentInFile() [2/2]

bool FiASCFile::isChannelPresentInFile ( int  channel)
virtual

Returns true if channel is a valid column index.

Reimplemented from FiDeviceFunctionBase.

◆ isMultiChannel()

bool FiASCFile::isMultiChannel ( FT_FILE  fd,
const char *  fname = NULL,
bool  rewind = false 
)
static

Checks if the specified file consists of two or more columns.

◆ preliminaryDeviceWrite()

virtual bool FiASCFile::preliminaryDeviceWrite ( )
inlineprotectedvirtual

Dummy method doing nothing.

Implements FiDeviceFunctionBase.

◆ readChannel()

int FiASCFile::readChannel ( int  channel)
private

Reads the specified channel into core.

◆ readHeader()

int FiASCFile::readHeader ( FT_FILE  fd,
Strings header 
)
static

Reads the header section of a specified file.

Parameters
[in]fdFile descriptor to read from
[out]headerArray of channel names (column labels) of the file
Returns
Number of (non-blank) column names, negative if no header

◆ readLine()

char * FiASCFile::readLine ( FT_FILE  fd,
bool  commentsOnly = false 
)
staticprivate

Reads one line of data from specified file.

Parameters
[in]fdFile descriptor to read from
[in]commentsOnlyIf true, only read comment lines
Returns
Pointer to a static buffer containing the last read line

◆ readNext()

bool FiASCFile::readNext ( FT_FILE  fd,
const std::vector< int > &  columns,
Doubles values 
)
static

Reads the next line of data from specified file.

Parameters
[in]fdFile descriptor to read from
[in]columnsColumn indices of the channels to read
[out]valuesArray of channel values
Returns
Always true, unless end of file is reached

◆ setData()

bool FiASCFile::setData ( const Doubles x,
const Doubles y 
)
virtual

Adds a channel to current file by interpolation.

Implements FiDeviceFunctionBase.

◆ setDescription()

void FiASCFile::setDescription ( const std::string &  desc)
virtual

Assigns a name to the (last) channel in file.

Reimplemented from FiDeviceFunctionBase.

◆ setEmptyChannel()

void FiASCFile::setEmptyChannel ( const std::string &  desc)
virtual

Adds an empty channel to the file.

Reimplemented from FiDeviceFunctionBase.

◆ setPrecision()

virtual void FiASCFile::setPrecision ( int  type)
inlinevirtual

Defines the output precision.

Reimplemented from FiDeviceFunctionBase.

◆ setValue()

void FiASCFile::setValue ( double  x,
double  y 
)
virtual

Assigns a function value for a single-channel function.

Implements FiDeviceFunctionBase.

Member Data Documentation

◆ bufferSize

size_t FiASCFile::bufferSize = 0
static

Buffer size for ASCII output in KBytes.

◆ chn

Strings FiASCFile::chn
private

Channel names (columns labels)

◆ isCSVt

bool FiASCFile::isCSVt
private

If true, this file has microsec as first column.

◆ myChannel

int FiASCFile::myChannel
private

Channel (column index) that currently resides in core.

◆ myNumChannels

int FiASCFile::myNumChannels
private

Number of columns minus 1 (column 1 is the X-values)

◆ myValues

ValuesMap FiASCFile::myValues
private

Curve data, either for all or one channel.

◆ outputFormat

int FiASCFile::outputFormat
private

0: 4-digits, 1: 8 digits, 2: 16-digits

◆ vit0

ValuesIter FiASCFile::vit0
private

Start iterator of last evaluation interval.

◆ vit1

ValuesIter FiASCFile::vit1
private

End iterator of last evaluation interval.


The documentation for this class was generated from the following files: