GemaCoreLib
The GeMA Core library
gmGhostNodeAccessor.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 
23 #ifndef _GEMA_GHOSTNODE_ACCESSOR_H_
24 #define _GEMA_GHOSTNODE_ACCESSOR_H_
25 
26 #include "gmMesh.h"
27 #include "gmValueAccessor.h"
28 #include "gmValueSetEvalContext.h"
29 
76 {
77 public:
86  {
87  assert(ghostAc);
88  _cAc = commonAc;
89  _gAc = ghostAc;
90 
91  // Mark in the evaluation context that this is an accessor to the ghost part of the data
92  if(_gAc->evalContext())
93  _gAc->evalContext()->setGhostData(true);
94  }
95 
98  {
99  delete _cAc;
100  delete _gAc;
101  }
102 
103  // See comments on the base class
104  virtual int size() const { return _gAc->size() + (_cAc ? _cAc->size() : 0); }
105 
107  int nodeSize() const { return _cAc ? _cAc->size() : 0; }
108 
110  int ghostSize() const { return _gAc->size(); }
111 
112  // See comments on the base class
113  virtual int adjustLinearIndex(int index, const GmMesh* m)
114  {
115  if(!_cAc)
116  index = m->toLocalGhostIndex(index);
117  return (index >= 0 && index < size()) ? index : -1;
118  }
119 
120  // See comments on the base class
121  virtual int adjustLinearIndex(int index, int firstGhostIndex)
122  {
123  if(!_cAc)
124  index -= firstGhostIndex;
125  return (index >= 0 && index < size()) ? index : -1;
126  }
127 
128  // See comments on the base class
129  virtual GmValueInfo* info() const { return _gAc->info(); }
130 
131  // See comments on the base class
132  virtual bool isDefValue(int index) const { return t(&index)->isDefValue(index); }
133 
134  // See comments on the base class
135  virtual Unit unit() const { return _gAc->unit(); }
136 
137  // See comments on the base class
138  virtual bool hasUnitConversion() const { return _gAc->hasUnitConversion(); }
139 
140  // See comments on the base class
141  virtual const double* valueAt(int index, const GmVector* coord) const { return t(&index)->valueAt(index, coord); }
142 
143  // See comments on the base class
144  virtual double scalarValueAt(int index, const GmVector* coord) const { return t(&index)->scalarValueAt(index, coord); }
145 
146  // See comments on the base class
147  virtual bool setValue(int index, const double* value) { return t(&index)->setValue(index, value); }
148 
149  // See comments on the base class
150  virtual bool setScalarValue(int index, double value) { return t(&index)->setScalarValue(index, value); }
151 
152  // See comments on the base class
153  virtual bool setValueAsDef(int index) { return t(&index)->setValueAsDef(index); }
154 
155  // See comments on the base class
156  virtual bool setFunctionValue(int index, GmUserFunction* functionDef) { return t(&index)->setFunctionValue(index, functionDef); }
157 
158  // See comments on the base class
159  virtual bool setFunctionValue(int index, GmUserFunctionEvaluator* functionEval) { return t(&index)->setFunctionValue(index, functionEval); }
160 
161  // See comments on the base class
162  virtual QString valueStr(int index, bool evalFunctions, bool printDefAsNil,
163  int fieldWidth = 0, char format = 'g', int precision = -1,
164  const GmVector* coord = NULL) const
165  {
166  return t(&index)->valueStr(index, evalFunctions, printDefAsNil, fieldWidth, format, precision, coord);
167  }
168 
169  // See comments on the base class
170  virtual bool setFunctionFromName(int index, QString userFunctionId, QString& err) { return t(&index)->setFunctionFromName(index, userFunctionId, err); }
171 
172  // See comments on the base class
173  virtual bool setValueFromVariant(int index, const QVariant& v, bool acceptMissingDimension, QString& err) { return t(&index)->setValueFromVariant(index, v, acceptMissingDimension, err); }
174 
175  // See comments on the base class
176  virtual bool isFunction(int index) const { return t(&index)->isFunction(index); }
177 
178  // See comments on the base class
179  virtual QString functionId(int index) const { return t(&index)->functionId(index); }
180 
181  // See comments on the base class
182  virtual void setEvalContext(GmValueSetEvalContext* context, bool ownsContext)
183  {
184  // From the current accessor work flow, this function should be never called
185  // for a ghost accessor (it is called for the base accessors stored on _cAc and _gAc).
186  // If this changes in the future, the implementation must be sure to add different
187  // contexts to the _cAC and _gAc accessors since the ghost offset should be
188  // different from zero in _gAc only. To do this, we will probably need to change
189  // the function signature to include a mesh parameter (?!? - unchecked)
190  assert(0); Q_UNUSED(context); Q_UNUSED(ownsContext);
191 
192  //if(_cAc)
193  // _cAc->setEvalContext(context, false);
194  //_gAc->setEvalContext(context, ownsContext);
195  }
196 
197  // See comments on the base class
199  {
200  // Which context should we return? When _cAc exists, its context is different
201  // from _gAc context. In the current workflow, this function is never called
202  // for a ghost accessor. If this ever changes we must decide what to do!
203  // See also the coments on the setEvalContext() implementation.
204  assert(0);
205  return NULL;
206  //return _gAc->evalContext();
207  }
208 
209 protected:
210 
211  // See comments on the base class
212  virtual double convertToAccessorUnit(double val) const { return _gAc->convertToAccessorUnit(val); }
213 
214  // See comments on the base class
215  virtual const double* convertToAccessorUnit(const double* p) const { return _gAc->convertToAccessorUnit(p); }
216 
217  // See comments on the base class
218  virtual void convertFromAccessorUnit(double val, double* dst) const { return _gAc->convertFromAccessorUnit(val, dst); }
219 
220  // See comments on the base class
221  virtual void convertFromAccessorUnit(const double* val, double* dst) const { return _gAc->convertFromAccessorUnit(val, dst); }
222 
223 private:
234  const GmValueAccessor* t(int* index) const
235  {
236  if(!_cAc || GmMesh::isGhostNode(*index))
237  {
238  *index = GmMesh::clearGhostFlag(*index);
239  return _gAc;
240  }
241  return (*index < _cAc->size()) ? _cAc : (*index -= _cAc->size(), _gAc);
242  }
243 
245  GmValueAccessor* t(int* index)
246  {
247  if(!_cAc || GmMesh::isGhostNode(*index))
248  {
249  *index = GmMesh::clearGhostFlag(*index);
250  return _gAc;
251  }
252  return (*index < _cAc->size()) ? _cAc : (*index -= _cAc->size(), _gAc);
253  }
254 
255  friend class GmStateDump; // State dump interface needs to get the base value accessor
256 
259 };
260 
261 
262 
263 
264 #endif
265 
266 
virtual bool hasUnitConversion() const =0
Returns true if this accessor perfroms unit conversions, false if not.
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.
Definition: gmGhostNodeAccessor.h:144
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition: gmValueInfo.h:126
virtual bool setValueAsDef(int index)
Similar to setValue(), filling the index entry with the default value.
Definition: gmGhostNodeAccessor.h:153
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 m...
Definition: gmGhostNodeAccessor.h:176
virtual int adjustLinearIndex(int index, int firstGhostIndex)
Simmilar to adjustLinearIndex(int, const GmMesh*), this function overload gets as second parameter th...
Definition: gmGhostNodeAccessor.h:121
virtual GmValueInfo * info() const
Returns the information object describing the values returned by this accessor.
Definition: gmGhostNodeAccessor.h:129
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.
Definition: gmGhostNodeAccessor.h:218
int ghostSize() const
Returns the number of 'ghost' nodes in this accessor.
Definition: gmGhostNodeAccessor.h:110
virtual GmValueSetEvalContext * evalContext() const
Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dum...
Definition: gmGhostNodeAccessor.h:198
virtual bool setScalarValue(int index, double value)=0
Similar to setValue() but passing a single double. Must be used for scalar data sets only.
The GmStateDump class presents a higher level of abstraction over GmMemoryDump, storing accessor data...
Definition: gmStateDump.h:52
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 bool setValue(int index, const double *value)
Allows for altering the value associated with entry "index" in the value set. This version of the fun...
Definition: gmGhostNodeAccessor.h:147
Class responsible for evaluating a UserFunction over a node / cell.
Definition: gmUserFunction.h:148
GmValueAccessor * _cAc
The accessor for the data tied to the common, "geometric", nodes.
Definition: gmGhostNodeAccessor.h:257
int nodeSize() const
Returns the number of 'common' (geometric) nodes in this accessor.
Definition: gmGhostNodeAccessor.h:107
virtual bool setValueAsDef(int index)=0
Similar to setValue(), filling the index entry with the default value.
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: gmGhostNodeAccessor.h:113
const double * value(int index) const
Similar to valueAt(), passing NULL as coordinates.
Definition: gmValueAccessor.h:158
virtual bool setValueFromVariant(int index, const QVariant &v, bool acceptMissingDimension, QString &err)
Sets a value with data read from a QVariant.
Definition: gmGhostNodeAccessor.h:173
virtual double convertToAccessorUnit(double val) const
An utility function that given a value, converts it to the accessor unit. If no conversion is needed,...
Definition: gmGhostNodeAccessor.h:212
virtual Unit unit() const
Returns the unit in which data returned/received by the accessor is expressed.
Definition: gmGhostNodeAccessor.h:135
GmValueAccessor * t(int *index)
Non const version of the homonimous function.
Definition: gmGhostNodeAccessor.h:245
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
virtual bool isDefValue(int index) const
Returns true if the value at the specified index is equal to the default value defined by info()->def...
Definition: gmGhostNodeAccessor.h:132
int toLocalGhostIndex(int nodeIndex) const
Given a global ghost index (a value >= numNodes() and < totalNumNodes()), returns a zero based versio...
Definition: gmMesh.h:126
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.
static bool isGhostNode(int nodeIndex)
Returns true if the given index is a ghost node index, false if not.
Definition: gmMesh.h:109
virtual bool setFunctionFromName(int index, QString userFunctionId, QString &err)=0
Sets a function value from the function name.
static int clearGhostFlag(int nodeIndex)
Returns the given index with the ghost node bit cleared.
Definition: gmMesh.h:115
Declaration of the GmMesh interface class.
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 ...
Definition: gmGhostNodeAccessor.h:179
void setGhostData(bool mode)
Changes the flag that states if this context is tied to a ghost value set or not.
Definition: gmValueSetEvalContext.h:84
virtual int size() const =0
Returns the number of values in the set refered to by the accessor, meaning that valid indices will f...
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...
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.
virtual bool setScalarValue(int index, double value)
Similar to setValue() but passing a single double. Must be used for scalar data sets only.
Definition: gmGhostNodeAccessor.h:150
virtual GmValueSetEvalContext * evalContext() const =0
Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dum...
Declaration of the GmValueSetEvalContext class.
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 Unit unit() const =0
Returns the unit in which data returned/received by the accessor is expressed.
virtual int size() const
Returns the number of values in the set refered to by the accessor, meaning that valid indices will f...
Definition: gmGhostNodeAccessor.h:104
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.
Definition: gmGhostNodeAccessor.h:221
Declaration of the GmValueAccessor interface and GmValueAccessorBase class.
Auxiliar class used to store the needed information to translate an user function id / user function ...
Definition: gmValueSetEvalContext.h:45
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 bool setFunctionValue(int index, GmUserFunctionEvaluator *functionEval)
Overload of setValue() storing a user function evaluation context.
Definition: gmGhostNodeAccessor.h:159
A proxy class that receives as parameters two accessors for the same data, one for the common node da...
Definition: gmGhostNodeAccessor.h:75
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 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,...
Definition: gmGhostNodeAccessor.h:162
virtual bool setFunctionFromName(int index, QString userFunctionId, QString &err)
Sets a function value from the function name.
Definition: gmGhostNodeAccessor.h:170
GmGhostNodeAccessor(GmValueAccessor *commonAc, GmValueAccessor *ghostAc)
Constructor receiving as parameters the wrapped accessors.
Definition: gmGhostNodeAccessor.h:85
const GmValueAccessor * t(int *index) const
Given an index, returns the accessor that should be called and also changes the value of the given in...
Definition: gmGhostNodeAccessor.h:234
virtual GmValueInfo * info() const =0
Returns the information object describing the values returned by this accessor.
virtual void setEvalContext(GmValueSetEvalContext *context, bool ownsContext)
Sets the EvalContext object that will be used to translate function names / objects into function eva...
Definition: gmGhostNodeAccessor.h:182
virtual ~GmGhostNodeAccessor()
Virtual destructor.
Definition: gmGhostNodeAccessor.h:97
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 * valueAt(int index, const GmVector *coord) const
Returns the value associated with the "index" position of the data set, evaluated at the requested po...
Definition: gmGhostNodeAccessor.h:141
virtual bool setValueFromVariant(int index, const QVariant &v, bool acceptMissingDimension, QString &err)=0
Sets a value with data read from a QVariant.
virtual bool setFunctionValue(int index, GmUserFunction *functionDef)=0
Overload of setValue() storing a user function definition.
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 ...
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44
Class used to store the definition of a user function and its parameters.
Definition: gmUserFunction.h:78
virtual bool setFunctionValue(int index, GmUserFunction *functionDef)
Overload of setValue() storing a user function definition.
Definition: gmGhostNodeAccessor.h:156
virtual bool hasUnitConversion() const
Returns true if this accessor perfroms unit conversions, false if not.
Definition: gmGhostNodeAccessor.h:138
GmValueAccessor * _gAc
The accessor for the data tied to ghost nodes.
Definition: gmGhostNodeAccessor.h:258
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 ...
Definition: gmGhostNodeAccessor.h:215