GemaCoreLib
The GeMA Core library
gmCellAccessor.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMA_CELL_ACCESSOR_H_
25 #define _GEMA_CELL_ACCESSOR_H_
26 
27 #include "gmAccessorProxy.h"
28 
29 #include "gmCell.h"
30 #include "gmValueSetEvalContext.h"
31 
32 #include <assert.h>
33 
34 
37 {
38 public:
41 
42 protected:
50  void saveCellInContext(const GmCell* c, int ip) const
51  {
52  GmValueSetEvalContext* context = _ac->evalContext();
53  if(context)
54  context->setCell(c, ip);
55  }
56 };
57 
67 {
68 public:
71 
72  // Wrapped functions. For descriptions, see GmValueAccessor documentation
73  const double* valueAt(const GmCell* c, const GmVector* coord, int ip=-1) const
74  {
75  saveCellInContext(c, ip);
76  return _ac->valueAt(queryIndex(c), coord);
77  }
78 
79  double scalarValueAt(const GmCell* c, const GmVector* coord, int ip = -1) const
80  {
81  saveCellInContext(c, ip);
82  return _ac->scalarValueAt(queryIndex(c), coord);
83  }
84 
85  void matrixValueAt(const GmCell* c, const GmVector* coord, GmCRMatrix& mat, int ip = -1) const
86  {
87  saveCellInContext(c, ip);
88  _ac->matrixValueAt(queryIndex(c), coord, mat);
89  }
90 
91  void vectorValueAt(const GmCell* c, const GmVector* coord, GmCRVector& vec, int ip = -1) const
92  {
93  saveCellInContext(c, ip);
94  _ac->vectorValueAt(queryIndex(c), coord, vec);
95  }
96 
97  bool setValue (const GmCell* c, const double* value) { return _ac->setValue(queryIndex(c), value); }
98  bool setScalarValue (const GmCell* c, double value) { return _ac->setScalarValue(queryIndex(c), value); }
99  bool setScalarValueAtDim(const GmCell* c, int dim, double value) { return _ac->setScalarValueAtDim(queryIndex(c), dim, value); }
100  bool setValueAsDef (const GmCell* c) { return _ac->setValueAsDef(queryIndex(c)); }
101  bool setFunctionValue (const GmCell* c, GmUserFunction* functionDef) { return _ac->setFunctionValue(queryIndex(c), functionDef); }
102  bool setFunctionValue (const GmCell* c, GmUserFunctionEvaluator* functionEval) { return _ac->setFunctionValue(queryIndex(c), functionEval); }
103 
104  QString valueStr(const GmCell* c, bool evalFunctions, bool printDefAsNil,
105  int fieldWidth = 0, char format = 'g', int precision = -1,
106  const GmVector* coord = NULL, int ip = -1) const
107  {
108  saveCellInContext(c, ip);
109  return _ac->valueStr(queryIndex(c), evalFunctions, printDefAsNil, fieldWidth, format, precision, coord);
110  }
111 
112  bool setFunctionFromName(const GmCell* c, QString userFunctionId, QString& err)
113  {
114  return _ac->setFunctionFromName(queryIndex(c), userFunctionId, err);
115  }
116 
117  bool setValueFromVariant(const GmCell* c, const QVariant& v, bool acceptMissingDimension, QString& err)
118  {
119  return _ac->setValueFromVariant(queryIndex(c), v, acceptMissingDimension, err);
120  }
121 
122  bool isDefValue(const GmCell* c) const { return _ac->isDefValue(queryIndex(c)); }
123  bool isFunction(const GmCell* c) const { return _ac->isFunction(queryIndex(c)); }
124  QString functionId(const GmCell* c) const { return _ac->functionId(queryIndex(c)); }
125 
126 protected:
128  virtual int queryIndex(const GmCell* c) const = 0;
129 };
130 
133 {
134 public:
137 
138 protected:
140  virtual int queryIndex(const GmCell* c) const { assert(c); return c->cellId(); }
141 };
142 
145 {
146 public:
148  GmPropertyCellAccessor(GmValueAccessor* ac, int psetIndex) : GmCellAccessor(ac), _pset(psetIndex) {}
149 
150 protected:
152  virtual int queryIndex(const GmCell* c) const { assert(c); return c->propertyIndex(_pset); }
153 
154 private:
155  int _pset;
156 };
157 
158 
159 #endif
160 
GmCellAccessorProxy(GmValueAccessor *ac)
Constructor. Takes ownership of the accessor.
Definition: gmCellAccessor.h:40
Class responsible for evaluating a UserFunction over a node / cell.
Definition: gmUserFunction.h:148
void setCell(const GmCell *cell, int ip)
Sets the cell / integration point over which values will be calculated.
Definition: gmValueSetEvalContext.h:78
Base interface for mesh cells.
Definition: gmCell.h:81
virtual int propertyIndex(int propertySet) const =0
Given a property set number, returns the line of the property set that contains property values for t...
Extends GmCellAccessor to handle attribute accessors.
Definition: gmCellAccessor.h:132
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
virtual int cellId() const =0
Returns a number identifying the cell. It should be possible to use this id as an index to GmCellMesh...
GmPropertyCellAccessor(GmValueAccessor *ac, int psetIndex)
Constructor. Takes ownership of the accessor.
Definition: gmCellAccessor.h:148
virtual int queryIndex(const GmCell *c) const
A virtual function that given a cell returns the index that should be accessed.
Definition: gmCellAccessor.h:140
GmAttributeCellAccessor(GmValueAccessor *ac)
Constructor. Takes ownership of the accessor.
Definition: gmCellAccessor.h:136
void saveCellInContext(const GmCell *c, int ip) const
A function that given a cell, saves it in the context. The ip parameter should store the integration ...
Definition: gmCellAccessor.h:50
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition: gmCellAccessor.h:66
virtual int queryIndex(const GmCell *c) const
A virtual function that given a cell returns the index that should be accessed.
Definition: gmCellAccessor.h:152
Declaration of the GmValueSetEvalContext class.
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
An auxiliary vector WRAPPER that binds the vector to a CONST memory area with data already initialize...
Definition: gmVector.h:69
GmCellAccessor(GmValueAccessor *ac)
Constructor. Takes ownership of the accessor.
Definition: gmCellAccessor.h:70
Extends GmCellAccessor to handle property accessors.
Definition: gmCellAccessor.h:144
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition: gmValueSetEvalContext.h:45
Declaration of the GmCell class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
An auxiliary matrix WRAPPER that binds the matrix to a CONST memory area with data already inicialize...
Definition: gmMatrix.h:100
Class used to store the definition of a user function and its parameters.
Definition: gmUserFunction.h:78
Implementation of the GmAccessorProxy class Moved from gmCellAccessor.h.
Helper class with common code for several classes that wrap a value accessor, provinding a slitly dif...
Definition: gmAccessorProxy.h:38
An accessor proxy + method for saving a cell in the context.
Definition: gmCellAccessor.h:36