23#ifndef _GEMA_VALUE_ACCESSOR_H_
24#define _GEMA_VALUE_ACCESSOR_H_
68 virtual int size()
const = 0;
76 bool isScalar()
const {
return info()->isScalar(); }
87 virtual const double*
defValue()
const {
return convertToAccessorUnit(info()->
defValue()); }
127 Q_UNUSED(firstGhostIndex);
return (index < size()) ? index : -1;
160 const double*
value(
int index)
const {
return valueAt(index, NULL); }
166 double scalarValue(
int index)
const {
return scalarValueAt(index, NULL); }
173 mat.
setMemory(valueAt(index, coord), info()->nlin(), info()->ncol());
184 vec.
setMemory(valueAt(index, coord), info()->size());
202 virtual bool setValue(
int index,
const double* value) = 0;
215 assert(dim >= 0 && dim < n);
217 memcpy(data.
data(), value(index), n *
sizeof(
double));
219 return setValue(index, data.
data());
228 assert(info()->dimType() ==
GM_MATRIX_VALUE && info()->nlin() == (
int)mat.n_rows && info()->ncol() == (
int)mat.n_cols);
229 return setValue(index, mat.memptr());
235 assert(info()->dimType() !=
GM_MATRIX_VALUE && info()->nlin() == (
int)vec.n_rows);
236 return setValue(index, vec.memptr());
242 return setScalarValue(index, scalarValue(index) + value);
253 const double* v = value(index);
254 for(
int i = 0; i<n; i++)
255 data[i] = v[i] + val[i];
256 return setValue(index, data.
data());
291 int fieldWidth = 0,
char format =
'g',
int precision = -1,
292 const GmVector* coord = NULL)
const = 0;
382 virtual QString valueStr(
int index,
bool evalFunctions,
bool printDefAsNil,
383 int fieldWidth = 0,
char format =
'g',
int precision = -1,
384 const GmVector* coord = NULL)
const;
386 virtual bool setFunctionFromName(
int index,
QString userFunctionId,
QString& err);
387 virtual bool setValueFromVariant(
int index,
const QVariant& v,
bool acceptMissingDimension,
QString& err);
392 static bool fillMatrixFromLuaTable(
double* m,
int nlin,
int ncol,
LuaTable& t,
const GmValueInfo* info,
const double* defVal,
QString& err);
399 const double* evalDefValue(
int index,
const GmVector* coord)
const;
401 virtual double convertToAccessorUnit(
double val)
const;
402 virtual const double* convertToAccessorUnit(
const double* p)
const;
403 virtual void convertFromAccessorUnit(
double val,
double* dst)
const;
404 virtual void convertFromAccessorUnit(
const double* val,
double* dst)
const;
406 double* convData()
const { assert(_convData);
return _convData->localBuffer(); }
421 bool _ownsEvalContext;
Helper class with common code for several classes that wrap a value accessor, provinding a slitly dif...
Definition gmAccessorProxy.h:39
An auxiliary matrix WRAPPER that binds the matrix to a CONST memory area with data already inicialize...
Definition gmMatrix.h:102
void setMemory(const double *data, int nlin, int ncol)
Exchanges the memory area used by the matrix. Same caveats explained in the class documentation apply...
Definition gmMatrix.h:132
An auxiliary vector WRAPPER that binds the vector to a CONST memory area with data already initialize...
Definition gmVector.h:72
void setMemory(const double *data, int nlin)
Exchanges the memory area used by the vector. Same caveats explained in the class documentation apply...
Definition gmVector.h:102
The GmDiscontinuityAccessor class is a proxy object to a value accesor implementing a more convenient...
Definition gmDiscontinuityAccessor.h:48
A proxy class that receives as parameters two accessors for the same data, one for the common node da...
Definition gmGhostNodeAccessor.h:76
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
A class similar to GmTLS that creates a buffer for each possible thread in the GmThreadManager,...
Definition gmThreadLocalBuffer.h:106
Class responsible for evaluating a UserFunction over a node / cell.
Definition gmUserFunction.h:160
Class used to store the definition of a user function and its parameters.
Definition gmUserFunction.h:82
An implementation of basic attributes and functions that should be common for most value accessor imp...
Definition gmValueAccessor.h:367
UnitConverter * _rconv
Unit converter in the reverse direction: from desired unit to data unit.
Definition gmValueAccessor.h:414
virtual bool hasUnitConversion() const
Returns true if this accessor performs unit conversions, false if not.
Definition gmValueAccessor.h:380
UnitConverter * _conv
Unit converter.
Definition gmValueAccessor.h:413
virtual Unit unit() const
Returns the unit in which data returned/received by the accessor is expressed.
Definition gmValueAccessor.h:377
virtual GmValueSetEvalContext * evalContext() const
Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dum...
Definition gmValueAccessor.h:390
GmTLBuffer< double, true > * _convData
Per thread local buffer used to store converted data. Null if _conv == NULL.
Definition gmValueAccessor.h:411
virtual GmValueInfo * info() const
Returns the information object describing the values returned by this accessor.
Definition gmValueAccessor.h:374
GmValueInfo * _info
The metadata describing the values returned by this accessor.
Definition gmValueAccessor.h:408
const GmLogCategory & _logger
The logger object used to report errors while accessing or setting data.
Definition gmValueAccessor.h:409
QString _unit
The unit in which data will be returned. Needed for the case when _conv = NULL and _info->unit() is e...
Definition gmValueAccessor.h:415
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
int valueSize() const
Returns the size of the array returned by value(), i.e. 1 for scalar values and nlin * ncol for vecto...
Definition gmValueAccessor.h:102
virtual bool isDefValue(int index) const =0
Returns true if the value at the specified index is equal to the default value defined by info()->def...
virtual const double * convertToAccessorUnit(const double *p) const =0
An utility function that given a pointer to the stored data, converts the value to the accessor unit ...
virtual Unit unit() const =0
Returns the unit in which data returned/received by the accessor is expressed.
bool setVectorValue(int index, const GmVector &vec)
Similar to setValue() but receiving the data as a vector.
Definition gmValueAccessor.h:233
void matrixValue(int index, GmCRMatrix &mat) const
Similar to matrixValueAt(), passing NULL as coordinates.
Definition gmValueAccessor.h:177
virtual ~GmValueAccessor()
Virtual destructor.
Definition gmValueAccessor.h:63
const double * value(int index) const
Similar to valueAt(), passing NULL as coordinates.
Definition gmValueAccessor.h:160
bool isScalar() const
Returns true if the accessor returns scalar values (can be false even if valueSize() == 1 – think abo...
Definition gmValueAccessor.h:76
void vectorValue(int index, GmCRVector &vec) const
Similar to vectorValueAt(), passing NULL as coordinates.
Definition gmValueAccessor.h:188
virtual GmValueSetEvalContext * evalContext() const =0
Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dum...
virtual bool setFunctionValue(int index, GmUserFunction *functionDef)=0
Overload of setValue() storing a user function definition.
virtual double convertToAccessorUnit(double val) const =0
An utility function that given a value, converts it to the accessor unit. If no conversion is needed,...
virtual QString valueStr(int index, bool evalFunctions, bool printDefAsNil, int fieldWidth=0, char format='g', int precision=-1, const GmVector *coord=NULL) const =0
Auxiliary function to return the value of an accessor converted to a string. Works for scalars,...
virtual void convertFromAccessorUnit(const double *val, double *dst) const =0
Copies the values given by val into the area pointed to by dst, converting units if needed.
virtual const double * valueAt(int index, const GmVector *coord) const =0
Returns the value associated with the "index" position of the data set, evaluated at the requested po...
virtual QString functionId(int index) const =0
Returns a function id name for a function reference at the index or an empty string for non function ...
virtual int adjustLinearIndex(int index, int firstGhostIndex)
Similar to adjustLinearIndex(int, const GmMesh*), this function overload gets as second parameter the...
Definition gmValueAccessor.h:126
virtual bool setValueFromVariant(int index, const QVariant &v, bool acceptMissingDimension, QString &err)=0
Sets a value with data read from a QVariant.
virtual int adjustLinearIndex(int index, const GmMesh *m)
Translates a linear index (from 0 to mesh->totalNumNodes()-1) into a valid index for this accessor or...
Definition gmValueAccessor.h:121
virtual bool setFunctionValue(int index, GmUserFunctionEvaluator *functionEval)=0
Overload of setValue() storing a user function evaluation context.
virtual bool setScalarValueAtDim(int index, int dim, double val)
Similar to setValue() but changing only the value at the given dimension. Can be used over scalar,...
Definition gmValueAccessor.h:212
virtual void setEvalContext(GmValueSetEvalContext *context, bool ownsContext)=0
Sets the EvalContext object that will be used to translate function names / objects into function eva...
virtual bool hasUnitConversion() const =0
Returns true if this accessor performs unit conversions, false if not.
virtual bool setScalarValue(int index, double value)=0
Similar to setValue() but passing a single double. Must be used for scalar data sets only.
virtual int size() const =0
Returns the number of values in the set referred to by the accessor, meaning that valid indices will ...
virtual const double * defValue() const
Returns the default value for the data converted to the accessor unit. The returned array contents is...
Definition gmValueAccessor.h:87
void matrixValueAt(int index, const GmVector *coord, GmCRMatrix &mat) const
Similar to valueAt(), but returning the result as a CONST matrix. Bear in mind that the resulting mat...
Definition gmValueAccessor.h:171
virtual void convertFromAccessorUnit(double val, double *dst) const =0
Copies the values given by val into the area pointed to by dst, converting units if needed.
void vectorValueAt(int index, const GmVector *coord, GmCRVector &vec) const
Similar to valueAt(), but returning the result as a CONST vector. Bear in mind that the resulting vec...
Definition gmValueAccessor.h:182
virtual bool setValue(int index, const double *value)=0
Allows for altering the value associated with entry "index" in the value set. This version of the fun...
virtual bool isFunction(int index) const =0
Returns true if the data in index is a reference to a function (in C or Lua). Used by valueStr() to m...
bool setMatrixValue(int index, const GmMatrix &mat)
Similar to setValue() but receiving the data as a matrix.
Definition gmValueAccessor.h:226
virtual GmValueInfo * info() const =0
Returns the information object describing the values returned by this accessor.
bool addScalarToValue(int index, double value)
Convenience function equivalent to calling setScalarValue(index, scalarValue(index) + value)
Definition gmValueAccessor.h:240
double scalarValue(int index) const
Similar to scalarValueAt(), passing NULL as coordinates.
Definition gmValueAccessor.h:166
virtual bool setFunctionFromName(int index, QString userFunctionId, QString &err)=0
Sets a function value from the function name.
virtual double scalarValueAt(int index, const GmVector *coord) const =0
Similar to valueAt() but returning a single double. Must be used for scalar data sets only.
bool addToValue(int index, const double *val)
Convenience function logically equivalent to calling setValue(index, value(index) + val) operating ov...
Definition gmValueAccessor.h:249
virtual bool setValueAsDef(int index)=0
Similar to setValue(), filling the index entry with the default value.
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition gmValueInfo.h:132
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition gmValueSetEvalContext.h:46
Declaration of useful configuration definitions for the Core library.
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of the GmMatrix class.
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
Declaration of the GmTLBuffer class.
Declaration of the GmValueInfo class.
@ GM_MATRIX_VALUE
Means that the value is a 2D matrix of numbers.
Definition gmValueInfo.h:75
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34