GemaCoreLib
The GeMA Core library
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
GmGhostNodeAccessor Class Reference

A proxy class that receives as parameters two accessors for the same data, one for the common node data and the other for ghost node data, reimplementing the interface defined by GmValueAccessor to use one accessor or the other depending on the given node index. More...

#include <gmGhostNodeAccessor.h>

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

Public Member Functions

 GmGhostNodeAccessor (GmValueAccessor *commonAc, GmValueAccessor *ghostAc)
 Constructor receiving as parameters the wrapped accessors. More...
 
virtual ~GmGhostNodeAccessor ()
 Virtual destructor.
 
virtual int size () const
 Returns the number of values in the set refered to by the accessor, meaning that valid indices will fall in the range [0..size()-1].
 
int nodeSize () const
 Returns the number of 'common' (geometric) nodes in this accessor.
 
int ghostSize () const
 Returns the number of 'ghost' nodes in this accessor.
 
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 into -1 if the given index is out of range. More...
 
virtual int adjustLinearIndex (int index, int firstGhostIndex)
 Simmilar to adjustLinearIndex(int, const GmMesh*), this function overload gets as second parameter the index of the first ghost node in the mesh (equal to mesh->numNodes()).
 
virtual GmValueInfoinfo () const
 Returns the information object describing the values returned by this accessor.
 
virtual bool isDefValue (int index) const
 Returns true if the value at the specified index is equal to the default value defined by info()->defValue()
 
virtual Unit unit () const
 Returns the unit in which data returned/received by the accessor is expressed. More...
 
virtual bool hasUnitConversion () const
 Returns true if this accessor perfroms unit conversions, false if not.
 
virtual const double * valueAt (int index, const GmVector *coord) const
 Returns the value associated with the "index" position of the data set, evaluated at the requested position (when necessary). More...
 
virtual double scalarValueAt (int index, const GmVector *coord) const
 Similar to valueAt() but returning a single double. Must be used for scalar data sets only.
 
virtual bool setValue (int index, const double *value)
 Allows for altering the value associated with entry "index" in the value set. This version of the function works for scalar, vector or matrix values. Values are copied to the data set. Matrix values should be organized in COLUMN MAJOR ORDER. More...
 
virtual bool setScalarValue (int index, double value)
 Similar to setValue() but passing a single double. Must be used for scalar data sets only.
 
virtual bool setValueAsDef (int index)
 Similar to setValue(), filling the index entry with the default value.
 
virtual bool setFunctionValue (int index, GmUserFunction *functionDef)
 Overload of setValue() storing a user function definition. More...
 
virtual bool setFunctionValue (int index, GmUserFunctionEvaluator *functionEval)
 Overload of setValue() storing a user function evaluation context. More...
 
virtual QString valueStr (int index, bool evalFunctions, bool printDefAsNil, int fieldWidth=0, char format='g', int precision=-1, const GmVector *coord=NULL) const
 Auxiliary function to return the value of an accessor converted to a string. Works for scalars, vectors and matrices. More...
 
virtual bool setFunctionFromName (int index, QString userFunctionId, QString &err)
 Sets a function value from the function name. More...
 
virtual bool setValueFromVariant (int index, const QVariant &v, bool acceptMissingDimension, QString &err)
 Sets a value with data read from a QVariant. More...
 
virtual bool isFunction (int index) const
 Returns true if the data in index is a reference to a function (in C or Lua). Used by valueStr() to mark function results.
 
virtual QString functionId (int index) const
 Returns a function id name for a function reference at the index or an empty string for non function indices. Used by valueStr().
 
virtual void setEvalContext (GmValueSetEvalContext *context, bool ownsContext)
 Sets the EvalContext object that will be used to translate function names / objects into function evaluators to allow for evaluating user functions.
 
virtual GmValueSetEvalContextevalContext () const
 Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dump functions.
 
- Public Member Functions inherited from GmValueAccessor
virtual ~GmValueAccessor ()
 Virtual destructor.
 
bool isScalar () const
 Returns true if the accessor returns scalar values (can be false even if valueSize() == 1 – think about a 1x1 matrix)
 
virtual const double * defValue () const
 Returns the default value for the data converted to the accessor unit. The returned array contents is valid only UNTIL a new call to the accessor is done. Meaningfull only when the default value is NOT a function.
 
int valueSize () const
 Returns the size of the array returned by value(), i.e. 1 for scalar values and nlin * ncol for vector or matrix values.
 
const double * value (int index) const
 Similar to valueAt(), passing NULL as coordinates.
 
double scalarValue (int index) const
 Similar to scalarValueAt(), passing NULL as coordinates.
 
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 matrix is valid only UNTIL the next call to the accessor.
 
void matrixValue (int index, GmCRMatrix &mat) const
 Similar to matrixValueAt(), passing NULL as coordinates.
 
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 vector is valid only UNTIL the next call to the accessor.
 
void vectorValue (int index, GmCRVector &vec) const
 Similar to vectorValueAt(), passing NULL as coordinates.
 
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, vector and matrix sets. For matrices, dim refers to the position in the linearized vector data in COLUMN MAJOR FORMAT. Should be used only if the current value is NOT a function.
 
bool setMatrixValue (int index, const GmMatrix &mat)
 Similar to setValue() but receiving the data as a matrix.
 
bool setVectorValue (int index, const GmVector &vec)
 Similar to setValue() but receiving the data as a vector.
 
bool addScalarToValue (int index, double value)
 Convenience function equivalent to calling setScalarValue(index, scalarValue(index) + value)
 
bool addToValue (int index, const double *val)
 Convenience function logically equivalent to calling setValue(index, value(index) + val) operating over the full vector. Should be used only if the current value is NOT a function.
 

Protected Member Functions

virtual double convertToAccessorUnit (double val) const
 An utility function that given a value, converts it to the accessor unit. If no conversion is needed, returns val.
 
virtual const double * convertToAccessorUnit (const double *p) const
 An utility function that given a pointer to the stored data, converts the value to the accessor unit and returns a pointer to the internal buffer used to store the converted value. If no conversion is needed, returns p.
 
virtual void convertFromAccessorUnit (double val, double *dst) const
 Copies the values given by val into the area pointed to by dst, converting units if needed.
 
virtual void convertFromAccessorUnit (const double *val, double *dst) const
 Copies the values given by val into the area pointed to by dst, converting units if needed.
 

Private Member Functions

const GmValueAccessort (int *index) const
 Given an index, returns the accessor that should be called and also changes the value of the given index when needed. More...
 
GmValueAccessort (int *index)
 Non const version of the homonimous function.
 

Private Attributes

GmValueAccessor_cAc
 The accessor for the data tied to the common, "geometric", nodes.
 
GmValueAccessor_gAc
 The accessor for the data tied to ghost nodes.
 

Friends

class GmStateDump
 

Detailed Description

A proxy class that receives as parameters two accessors for the same data, one for the common node data and the other for ghost node data, reimplementing the interface defined by GmValueAccessor to use one accessor or the other depending on the given node index.

Indexes passed to the accessor methods can be either a 'ghost index', i.e., a value with the highest bit set, (as described by GmMesh::isGhostNode()) or a 'linear' index, a value between 0 and GmMesh::totalNumNodes()-1 for nodeStorage == GM_BOTH and a value between 0 and GmMesh::numGhostNodes()-1 for nodeStorage == GM_GHOST_NODE.

In that way, querying all node values can be easily done in several use cases:

GmValueAccessor* ac = mesh->nodeCoordAccessor("", logger);
// Continuous indexing. Will access first regular geometric nodes (i < mesh->numNodes())
// and then ghost nodes (i >= mesh->numNodes())
for(int i = 0; i< mesh->totalNumNodes(); i++)
{
const double* coord = ac->value(i);
}
// Indexing nodes in a cell. Regular nodes have an index between 0 and mesh->numNodes()
// while ghost nodes have a value between 0 and mesh->numGhostNodes with the highest bit set
GmCell* c = mesh->cell(cellId);
for(int i=0; i<cell->totalNumNodes(); i++)
{
const double* coord = ac->value(cell->nodeIndex(i));
}

When dealing with ghost only accessors in a general setting, where a loop traverses all available linear node indices, the indexing rule can cause surprises since the global linear index can not be used to access the ghost only accessor directly. Allowing that is possible but is probably worse than the current behaviour since it would break the strong assumption that an accessor index is valid if it is >= 0 and < ac->size() and in that case the accessor would be indexable only between GmMesh::numNodes() and ac->size(). (To accomplish that, the ghost accessor must have access to the number of regular nodes in the mesh. The best way would be to pass as second accessor a coordinate accessor instead of NULL. Passing the number of nodes is no good since accessors should remain valid when the number of nodes change.)

In general when working with a single known accessor this is a no issue, but generic code like the assembler or code for printing node values must work with a set of accessor with mixed node storage types. To help in this settings, use the ac->adjustLinearIndex() function.

Constructor & Destructor Documentation

◆ GmGhostNodeAccessor()

GmGhostNodeAccessor::GmGhostNodeAccessor ( GmValueAccessor commonAc,
GmValueAccessor ghostAc 
)
inline

Constructor receiving as parameters the wrapped accessors.

The common accessor can be a NULL pointer. This usage pattern allows us to reuse this class for implementing the needed index translation for ghost nodes only data.

The constructed object takes ownership of the supplied accessors.

Member Function Documentation

◆ adjustLinearIndex()

virtual int GmGhostNodeAccessor::adjustLinearIndex ( int  index,
const GmMesh m 
)
inlinevirtual

Translates a linear index (from 0 to mesh->totalNumNodes()-1) into a valid index for this accessor or into -1 if the given index is out of range.

When dealing with ghost nodes in a general setting, where a loop traverses all available linear node indices, we might have to adjust the linear index since an accessor might be able to honor only the geometry or the ghost part of the data. Also, for ghost only accessors, the indexing rule that says that valid indices fall in the range [0..size()-1] can cause surprises since the global linear index can not be used to access the ghost only accessor directly. A zero based index should be used instead.

This function adjusts the given index to both scenarios, converting indices for ghost only accessors and returning -1 if the linear index is out of the accessor range (a ghost index for a geometry only accessor or a geometry index for a ghost only accessor).

It receives as a second parameter the associated mesh, used to get access to the number of geometric nodes in the mesh.

Reimplemented from GmValueAccessor.

◆ setFunctionFromName()

virtual bool GmGhostNodeAccessor::setFunctionFromName ( int  index,
QString  userFunctionId,
QString err 
)
inlinevirtual

Sets a function value from the function name.

On errors, returns false and fills err with a description of the problem (errors in this case are not logged through the accessor logger).

Implements GmValueAccessor.

◆ setFunctionValue() [1/2]

virtual bool GmGhostNodeAccessor::setFunctionValue ( int  index,
GmUserFunction functionDef 
)
inlinevirtual

Overload of setValue() storing a user function definition.

This is the intended way to store a user function if the value set corresponding to this accessor is NOT directly tied to a mesh

(its a property set ValueSet, for example)

Implements GmValueAccessor.

◆ setFunctionValue() [2/2]

virtual bool GmGhostNodeAccessor::setFunctionValue ( int  index,
GmUserFunctionEvaluator functionEval 
)
inlinevirtual

Overload of setValue() storing a user function evaluation context.

This is the intended way to store a user function if the value set corresponding to this accessor is directly tied to a mesh (a node or cell attribute, for example). Storing an evaluator is more efficient than a function definition, but can only be done if the value set is not shared between several meshes.

Implements GmValueAccessor.

◆ setValue()

virtual bool GmGhostNodeAccessor::setValue ( int  index,
const double *  value 
)
inlinevirtual

Allows for altering the value associated with entry "index" in the value set. This version of the function works for scalar, vector or matrix values. Values are copied to the data set. Matrix values should be organized in COLUMN MAJOR ORDER.

Returns false if the data could not be set due to allocation or permission problems and an error message will be logged.

Assumes that values are expressed in the REQUESTED desired unit if that was given when the accessor was created. If that unit exists and is different from the data base unit, values are converted to the data unit before beeing stored.

Implements GmValueAccessor.

◆ setValueFromVariant()

virtual bool GmGhostNodeAccessor::setValueFromVariant ( int  index,
const QVariant v,
bool  acceptMissingDimension,
QString err 
)
inlinevirtual

Sets a value with data read from a QVariant.

The variant v can contain a double, a Lua table with a set of doubles or a string referencing an user function, according to the accessor dimension and possibility of having functions.

Matrix values can be provided either by a Lua table with values organized per column or by a table of tables.

If v is a null object, nothing is done. If a component is missing for a multidimensional object (vector or matrix), an error is reported if acceptMissingDimension is false. Otherwise, the missing data is filled with the corresponding value from the default value.

On errors, returns false and fills err with a description of the problem (errors in this case are not logged through the accessor logger).

Implements GmValueAccessor.

◆ t()

const GmValueAccessor* GmGhostNodeAccessor::t ( int *  index) const
inlineprivate

Given an index, returns the accessor that should be called and also changes the value of the given index when needed.

Possible cases: 1) _cAc == NULL & index is a ghost index: Returns _gAc and removes the "ghost bit" from index 2) _cAc == NULL & index is a normal value: Returns _gAc and does no changes to index 3) _cAc != NULL & index is a ghost index: Returns _gAc and removes the "ghost bit" from index

4) _cAc != NULL & index is normal index in the cAc range: Returns _cAc and does no changes to index 5) _cAc != NULL & index is normal index outside the cAc range: Returns _gAc and subtracts _cAc->size() from the index

◆ unit()

virtual Unit GmGhostNodeAccessor::unit ( ) const
inlinevirtual

Returns the unit in which data returned/received by the accessor is expressed.

Keep in mind that this unit can be different from info()->unit() if the accessor was created with a different unit than the original data unit.

Implements GmValueAccessor.

◆ valueAt()

virtual const double* GmGhostNodeAccessor::valueAt ( int  index,
const GmVector coord 
) const
inlinevirtual

Returns the value associated with the "index" position of the data set, evaluated at the requested position (when necessary).

If the data is a function reference, the function will be called and the result returned. Also, the results will be converted to the requested desired unit.

The function returns the address of an array (possibly internal to the accessor), storing the requested data, which can be a scalar, a vector or a matrix, linearized using COLUMN MAJOR ORDER. This array contents is valid only UNTIL a new call to the accessor is done. This restriction allows for the accessor implementation to be free to return a pointer to the data when no unit conversion is needed or a pointer to a static internal buffer when converting values.

If an error happens while evaluating a function, the result will be the (converted) default value for the data set and an error message will be logged (if the default value is itself a function, the function will return a vector filled with zeros, converted to the desired unit if needed).

The set of coordinates is used only for the evaluation of user functions over cell attributes / properties. A NULL pointer can be passed if the accessor context doesn't needs this information (and that's why this parameter is a GmVector* and not a GmVector&).

The coordinate values depends on the type of cell. For 'plain' cells, it should be cartesian coordinates in the same unit as coordinates are expressed in the mesh.

For element cells, it should be natural coordinates.

Implements GmValueAccessor.

◆ valueStr()

virtual QString GmGhostNodeAccessor::valueStr ( int  index,
bool  evalFunctions,
bool  printDefAsNil,
int  fieldWidth = 0,
char  format = 'g',
int  precision = -1,
const GmVector coord = NULL 
) const
inlinevirtual

Auxiliary function to return the value of an accessor converted to a string. Works for scalars, vectors and matrices.

The evalFunctions parameter defines whether function based values will be evaluated or not. If printDefAsNil == true, default values will be printed as the 'nil' string.

The formatted value conforms to the standard QString::arg() parameters. Scalars are presented as simple formatted numbers. Vectors and matrices are surrounded by [...]. Matrix values are listed in COLUMN MAJOR ORDER. Values returned by function calls are surrounded by (), which means that a vector returned by a function call will be represented as ([...]).

Implements GmValueAccessor.


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