GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
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"
29
76{
77public:
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())
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
113 GmValueAccessor* geomAc() const { return _cAc; }
114
116 GmValueAccessor* ghostAc() const { return _gAc; }
117
118 // See comments on the base class
119 virtual int adjustLinearIndex(int index, const GmMesh* m)
120 {
121 if(!_cAc)
122 index = m->toLocalGhostIndex(index);
123 return (index >= 0 && index < size()) ? index : -1;
124 }
125
126 // See comments on the base class
127 virtual int adjustLinearIndex(int index, int firstGhostIndex)
128 {
129 if(!_cAc)
130 index -= firstGhostIndex;
131 return (index >= 0 && index < size()) ? index : -1;
132 }
133
134 // See comments on the base class
135 virtual GmValueInfo* info() const { return _gAc->info(); }
136
137 // See comments on the base class
138 virtual bool isDefValue(int index) const { return t(&index)->isDefValue(index); }
139
140 // See comments on the base class
141 virtual Unit unit() const { return _gAc->unit(); }
142
143 // See comments on the base class
144 virtual bool hasUnitConversion() const { return _gAc->hasUnitConversion(); }
145
146 // See comments on the base class
147 virtual const double* valueAt(int index, const GmVector* coord) const { return t(&index)->valueAt(index, coord); }
148
149 // See comments on the base class
150 virtual double scalarValueAt(int index, const GmVector* coord) const { return t(&index)->scalarValueAt(index, coord); }
151
152 // See comments on the base class
153 virtual bool setValue(int index, const double* value) { return t(&index)->setValue(index, value); }
154
155 // See comments on the base class
156 virtual bool setScalarValue(int index, double value) { return t(&index)->setScalarValue(index, value); }
157
158 // See comments on the base class
159 virtual bool setValueAsDef(int index) { return t(&index)->setValueAsDef(index); }
160
161 // See comments on the base class
162 virtual bool setFunctionValue(int index, GmUserFunction* functionDef) { return t(&index)->setFunctionValue(index, functionDef); }
163
164 // See comments on the base class
165 virtual bool setFunctionValue(int index, GmUserFunctionEvaluator* functionEval) { return t(&index)->setFunctionValue(index, functionEval); }
166
167 // See comments on the base class
168 virtual QString valueStr(int index, bool evalFunctions, bool printDefAsNil,
169 int fieldWidth = 0, char format = 'g', int precision = -1,
170 const GmVector* coord = NULL) const
171 {
172 return t(&index)->valueStr(index, evalFunctions, printDefAsNil, fieldWidth, format, precision, coord);
173 }
174
175 // See comments on the base class
176 virtual bool setFunctionFromName(int index, QString userFunctionId, QString& err) { return t(&index)->setFunctionFromName(index, userFunctionId, err); }
177
178 // See comments on the base class
179 virtual bool setValueFromVariant(int index, const QVariant& v, bool acceptMissingDimension, QString& err) { return t(&index)->setValueFromVariant(index, v, acceptMissingDimension, err); }
180
181 // See comments on the base class
182 virtual bool isFunction(int index) const { return t(&index)->isFunction(index); }
183
184 // See comments on the base class
185 virtual QString functionId(int index) const { return t(&index)->functionId(index); }
186
187 // See comments on the base class
188 virtual void setEvalContext(GmValueSetEvalContext* context, bool ownsContext)
189 {
190 // From the current accessor work flow, this function should be never called
191 // for a ghost accessor (it is called for the base accessors stored on _cAc and _gAc).
192 // If this changes in the future, the implementation must be sure to add different
193 // contexts to the _cAC and _gAc accessors since the ghost offset should be
194 // different from zero in _gAc only. To do this, we will probably need to change
195 // the function signature to include a mesh parameter (?!? - unchecked)
196 assert(0); Q_UNUSED(context); Q_UNUSED(ownsContext);
197
198 //if(_cAc)
199 // _cAc->setEvalContext(context, false);
200 //_gAc->setEvalContext(context, ownsContext);
201 }
202
203 // See comments on the base class
205 {
206 // Which context should we return? When _cAc exists, its context is different
207 // from _gAc context. In the current workflow, this function is never called
208 // for a ghost accessor. If this ever changes we must decide what to do!
209 // See also the coments on the setEvalContext() implementation.
210 assert(0);
211 return NULL;
212 //return _gAc->evalContext();
213 }
214
215protected:
216
217 // See comments on the base class
218 virtual double convertToAccessorUnit(double val) const { return _gAc->convertToAccessorUnit(val); }
219
220 // See comments on the base class
221 virtual const double* convertToAccessorUnit(const double* p) const { return _gAc->convertToAccessorUnit(p); }
222
223 // See comments on the base class
224 virtual void convertFromAccessorUnit(double val, double* dst) const { return _gAc->convertFromAccessorUnit(val, dst); }
225
226 // See comments on the base class
227 virtual void convertFromAccessorUnit(const double* val, double* dst) const { return _gAc->convertFromAccessorUnit(val, dst); }
228
229private:
240 const GmValueAccessor* t(int* index) const
241 {
242 if(!_cAc || GmMesh::isGhostNode(*index))
243 {
244 *index = GmMesh::clearGhostFlag(*index);
245 return _gAc;
246 }
247 return (*index < _cAc->size()) ? _cAc : (*index -= _cAc->size(), _gAc);
248 }
249
251 GmValueAccessor* t(int* index)
252 {
253 if(!_cAc || GmMesh::isGhostNode(*index))
254 {
255 *index = GmMesh::clearGhostFlag(*index);
256 return _gAc;
257 }
258 return (*index < _cAc->size()) ? _cAc : (*index -= _cAc->size(), _gAc);
259 }
260
263};
264
265
266
267
268#endif
269
270
A proxy class that receives as parameters two accessors for the same data, one for the common node da...
Definition gmGhostNodeAccessor.h:76
virtual Unit unit() const
Returns the unit in which data returned/received by the accessor is expressed.
Definition gmGhostNodeAccessor.h:141
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:150
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:153
GmValueAccessor * ghostAc() const
Returns the stored accessor for the ghost part of the data.
Definition gmGhostNodeAccessor.h:116
GmValueAccessor * t(int *index)
Non const version of the homonimous function.
Definition gmGhostNodeAccessor.h:251
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:156
GmGhostNodeAccessor(GmValueAccessor *commonAc, GmValueAccessor *ghostAc)
Constructor receiving as parameters the wrapped accessors.
Definition gmGhostNodeAccessor.h:85
virtual GmValueSetEvalContext * evalContext() const
Returns the internal evaluation context. Needed by GmCellAccessorProxy, GmBcAccessorProxy & state dum...
Definition gmGhostNodeAccessor.h:204
GmValueAccessor * geomAc() const
Returns the stored accessor for the geometry part of the data.
Definition gmGhostNodeAccessor.h:113
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:138
int nodeSize() const
Returns the number of 'common' (geometric) nodes in this accessor.
Definition gmGhostNodeAccessor.h:107
virtual GmValueInfo * info() const
Returns the information object describing the values returned by this accessor.
Definition gmGhostNodeAccessor.h:135
GmValueAccessor * _cAc
The accessor for the data tied to the common, "geometric", nodes.
Definition gmGhostNodeAccessor.h:261
virtual bool setFunctionValue(int index, GmUserFunction *functionDef)
Overload of setValue() storing a user function definition.
Definition gmGhostNodeAccessor.h:162
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:218
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:168
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:188
virtual bool setFunctionFromName(int index, QString userFunctionId, QString &err)
Sets a function value from the function name.
Definition gmGhostNodeAccessor.h:176
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:182
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:221
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:240
GmValueAccessor * _gAc
The accessor for the data tied to ghost nodes.
Definition gmGhostNodeAccessor.h:262
virtual bool hasUnitConversion() const
Returns true if this accessor performs unit conversions, false if not.
Definition gmGhostNodeAccessor.h:144
virtual int size() const
Returns the number of values in the set referred to by the accessor, meaning that valid indices will ...
Definition gmGhostNodeAccessor.h:104
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:119
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:147
virtual ~GmGhostNodeAccessor()
Virtual destructor.
Definition gmGhostNodeAccessor.h:97
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:224
virtual bool setFunctionValue(int index, GmUserFunctionEvaluator *functionEval)
Overload of setValue() storing a user function evaluation context.
Definition gmGhostNodeAccessor.h:165
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:185
virtual bool setValueFromVariant(int index, const QVariant &v, bool acceptMissingDimension, QString &err)
Sets a value with data read from a QVariant.
Definition gmGhostNodeAccessor.h:179
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:227
virtual bool setValueAsDef(int index)
Similar to setValue(), filling the index entry with the default value.
Definition gmGhostNodeAccessor.h:159
int ghostSize() const
Returns the number of 'ghost' nodes in this accessor.
Definition gmGhostNodeAccessor.h:110
virtual int adjustLinearIndex(int index, int firstGhostIndex)
Similar to adjustLinearIndex(int, const GmMesh*), this function overload gets as second parameter the...
Definition gmGhostNodeAccessor.h:127
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
static bool isGhostNode(int nodeIndex)
Returns true if the given index is a ghost node index, false if not.
Definition gmMesh.h:136
static int clearGhostFlag(int nodeIndex)
Returns the given index with the ghost node bit cleared.
Definition gmMesh.h:142
int toLocalGhostIndex(int nodeIndex) const
Given a global ghost index (a value >= numNodes() and < totalNumNodes()), returns a zero based versio...
Definition gmMesh.h:153
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
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
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 Unit unit() const =0
Returns the unit in which data returned/received by the accessor is expressed.
const double * value(int index) const
Similar to valueAt(), passing NULL as coordinates.
Definition gmValueAccessor.h:160
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 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 bool setValueFromVariant(int index, const QVariant &v, bool acceptMissingDimension, QString &err)=0
Sets a value with data read from a QVariant.
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 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.
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...
virtual GmValueInfo * info() const =0
Returns the information object describing the values returned by this accessor.
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.
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
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
Declaration of the GmMesh interface class.
Declaration of the GmValueAccessor interface and GmValueAccessorBase class.
Declaration of the GmValueSetEvalContext class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34