GemaCoreLib
The GeMA Core library
gmInterpolatorInputBindings.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_INTERPOLATOR_INPUT_BINDINGS_H_
25 #define _GEMA_INTERPOLATOR_INPUT_BINDINGS_H_
26 
27 #include "gmCoreConfig.h"
28 
29 #include "gmGaussAccessor.h"
30 
42 {
43 public:
45  virtual int numSrcs() = 0;
46 
48  virtual int size() const = 0;
49 
51  virtual int valueSize(int srcIndex) const = 0;
52 
57  virtual void reset() = 0;
58 
62  virtual bool next() = 0;
63 
67  virtual const double* value(int srcIndex) = 0;
68 
74  virtual void coordinate(GmCRVector& coord) = 0;
75 };
76 
81 {
82 public:
83 
87  virtual void setValue(int srcIndex, const double* value) = 0;
88 };
89 
90 // --------------------------------------------------
91 // Values provided by a node accessor
92 // --------------------------------------------------
93 
99 template <class Base, class Ac>
100 class GmInterpolatorNodeDataBinding : public Base
101 {
102 public:
107  : _pointSet(pointSet), _valueAc(nodeAc), _currIndex(-1) { assert(pointSet && nodeAc); }
108 
109  // See comments on the base class
110  virtual int numSrcs() { return 1; }
111 
112  // See comments on the base class
113  virtual int size() const { return _pointSet->size(); }
114 
115  // See comments on the base class
116  virtual int valueSize(int srcIndex) const { Q_UNUSED(srcIndex); assert(srcIndex == 0); return _valueAc->valueSize(); }
117 
118  // See comments on the base class
119  virtual void reset() { _pointSet->reset(); _pointSet->next(_currCoord, &_currIndex); }
120 
121  // See comments on the base class
122  virtual bool next() { assert(_currIndex >= 0); return _pointSet->next(_currCoord, &_currIndex); }
123 
124  // See comments on the base class
125  virtual const double* value(int srcIndex) { Q_UNUSED(srcIndex); assert(srcIndex == 0); assert(_currIndex >= 0); return _valueAc->value(_currIndex); }
126 
127  // See comments on the base class
128  virtual void coordinate(GmCRVector& coord) { coord.setMemory(_currCoord.memptr(), _currCoord.n_rows); };
129 
130 protected:
132  Ac _valueAc;
135 };
136 
139 
141 class GmInterpolatorNodeInOutDataBinding : public GmInterpolatorNodeDataBinding<GmInterpolatorInOutDataBinding, GmValueAccessor*>
142 {
143 public:
146 
147  // See comments on the base class
148  virtual void setValue(int srcIndex, const double* value)
149  {
150  Q_UNUSED(srcIndex); assert(srcIndex == 0); assert(_currIndex >= 0);
151  _valueAc->setValue(_currIndex, value);
152  }
153 };
154 
161 template <class Base, class Ac>
163 {
164 public:
169  : _pointSet(pointSet), _valueAcList(nodeAccessors), _currIndex(-1) { assert(pointSet && !nodeAccessors.isEmpty()); }
170 
171  // See comments on the base class
172  virtual int numSrcs() { return _valueAcList.size(); }
173 
174  // See comments on the base class
175  virtual int size() const { return _pointSet->size(); }
176 
177  // See comments on the base class
178  virtual int valueSize(int srcIndex) const { assert(srcIndex >= 0 && srcIndex < _valueAcList.size()); return _valueAcList.at(srcIndex)->valueSize(); }
179 
180  // See comments on the base class
181  virtual void reset() { _pointSet->reset(); _pointSet->next(_currCoord, &_currIndex); }
182 
183  // See comments on the base class
184  virtual bool next() { assert(_currIndex >= 0); return _pointSet->next(_currCoord, &_currIndex); }
185 
186  // See comments on the base class
187  virtual const double* value(int srcIndex) { assert(srcIndex >= 0 && srcIndex < _valueAcList.size()); assert(_currIndex >= 0); return _valueAcList.at(srcIndex)->value(_currIndex); }
188 
189  // See comments on the base class
190  virtual void coordinate(GmCRVector& coord) { coord.setMemory(_currCoord.memptr(), _currCoord.n_rows); };
191 
192 protected:
197 };
198 
201 
203 class GmInterpolatorMNodeInOutDataBinding : public GmInterpolatorMNodeDataBinding<GmInterpolatorInOutDataBinding, GmValueAccessor*>
204 {
205 public:
208 
209  // See comments on the base class
210  virtual void setValue(int srcIndex, const double* value)
211  {
212  assert(srcIndex >= 0 && srcIndex < _valueAcList.size()); assert(_currIndex >= 0);
213  _valueAcList.at(srcIndex)->setValue(_currIndex, value);
214  }
215 };
216 
217 // --------------------------------------------------
218 // Values provided by a Gauss accessor
219 // --------------------------------------------------
220 
226 template <class Base, class Ac>
228 {
229 public:
234  : _pointSet(pointSet), _valueAc(gaussAc), _currElem(NULL), _currIp(-1) { assert(pointSet && gaussAc); }
235 
236  // See comments on the base class
237  virtual int numSrcs() { return 1; }
238 
239  // See comments on the base class
240  virtual int size() const { return _pointSet->size(); }
241 
242  // See comments on the base class
243  virtual int valueSize(int srcIndex) const { Q_UNUSED(srcIndex); assert(srcIndex == 0); return _valueAc->valueSize(); }
244 
245  // See comments on the base class
246  virtual void reset() { _pointSet->reset(); _pointSet->next(_currCoord, &_currElem, &_currIp); }
247 
248  // See comments on the base class
249  virtual bool next() { assert(_currElem); return _pointSet->next(_currCoord, &_currElem, &_currIp); }
250 
251  // See comments on the base class
252  virtual const double* value(int srcIndex)
253  {
254  Q_UNUSED(srcIndex);
255  assert(srcIndex == 0);
256  assert(_currElem);
257  if(_valueAc->info()->canStoreFunctions())
258  {
259  GmVector ipCoord;
261  return _valueAc->valueAt(_currElem, _currIp, &ipCoord);
262  }
263  else
264  return _valueAc->valueAt(_currElem, _currIp, NULL);
265  }
266 
267  // See comments on the base class
268  virtual void coordinate(GmCRVector& coord) { coord.setMemory(_currCoord.memptr(), _currCoord.n_rows); };
269 
270 protected:
272  Ac _valueAc;
274  int _currIp;
276 };
277 
280 
282 class GmInterpolatorGaussInOutDataBinding : public GmInterpolatorGaussDataBinding<GmInterpolatorInOutDataBinding, GmGaussAccessor*>
283 {
284 public:
287 
288  // See comments on the base class
289  virtual void setValue(int srcIndex, const double* value)
290  {
291  Q_UNUSED(srcIndex); assert(srcIndex == 0); assert(_currElem);
292  _valueAc->setValue(_currElem, _currIp, value);
293  }
294 };
295 
301 template <class Base, class Ac>
303 {
304 public:
309  : _pointSet(pointSet), _valueAcList(gaussAccessors), _currElem(NULL), _currIp(-1) { assert(pointSet && !gaussAccessors.isEmpty()); }
310 
311  // See comments on the base class
312  virtual int numSrcs() { return _valueAcList.size(); }
313 
314  // See comments on the base class
315  virtual int size() const { return _pointSet->size(); }
316 
317  // See comments on the base class
318  virtual int valueSize(int srcIndex) const { assert(srcIndex >= 0 && srcIndex < _valueAcList.size()); return _valueAcList.at(srcIndex)->valueSize(); }
319 
320  // See comments on the base class
321  virtual void reset() { _pointSet->reset(); _pointSet->next(_currCoord, &_currElem, &_currIp); }
322 
323  // See comments on the base class
324  virtual bool next() { assert(_currElem); return _pointSet->next(_currCoord, &_currElem, &_currIp); }
325 
326  // See comments on the base class
327  virtual const double* value(int srcIndex)
328  {
329  assert(srcIndex >= 0 && srcIndex < _valueAcList.size());
330  assert(_currElem);
331  if(_valueAcList.at(srcIndex)->info()->canStoreFunctions())
332  {
333  GmVector ipCoord;
335  return _valueAcList.at(srcIndex)->valueAt(_currElem, _currIp, &ipCoord);
336  }
337  else
338  return _valueAcList.at(srcIndex)->valueAt(_currElem, _currIp, NULL);
339  }
340 
341  // See comments on the base class
342  virtual void coordinate(GmCRVector& coord) { coord.setMemory(_currCoord.memptr(), _currCoord.n_rows); };
343 
344 protected:
348  int _currIp;
350 };
351 
354 
356 class GmInterpolatorMGaussInOutDataBinding : public GmInterpolatorMGaussDataBinding<GmInterpolatorInOutDataBinding, GmGaussAccessor*>
357 {
358 public:
361 
362  // See comments on the base class
363  virtual void setValue(int srcIndex, const double* value)
364  {
365  assert(srcIndex >= 0 && srcIndex < _valueAcList.size()); assert(_currElem);
366  _valueAcList.at(srcIndex)->setValue(_currElem, _currIp, value);
367  }
368 };
369 
370 
371 // --------------------------------------------------
372 // Values provided by a matrix
373 // --------------------------------------------------
374 
377 {
378 public:
386  GmInterpolatorMatrixInputDataBinding(const GmMatrix& data) : _data(data), _currIndex(-1) { assert(data.n_elem); }
387 
388  // See comments on the base class
389  virtual int numSrcs() { return 1; }
390 
391  // See comments on the base class
392  virtual int size() const { return _data.n_cols; }
393 
394  // See comments on the base class
395  virtual int valueSize(int srcIndex) const { Q_UNUSED(srcIndex); assert(srcIndex == 0); return _data.n_rows; }
396 
397  // See comments on the base class
398  virtual void reset() { _currIndex = 0; }
399 
400  // See comments on the base class
401  virtual bool next() { assert(_currIndex >= 0); _currIndex++; return _currIndex < size(); }
402 
403  // See comments on the base class
404  virtual const double* value(int srcIndex) { Q_UNUSED(srcIndex); assert(srcIndex == 0); assert(_currIndex >= 0); return _data.colptr(_currIndex); }
405 
406  // See comments on the base class
407  virtual void coordinate(GmCRVector& coord) { Q_UNUSED(coord); }
408 
409 private:
410  const GmMatrix& _data;
412 };
413 
416 {
417 public:
424  GmInterpolatorMMatrixInputDataBinding(const QList<GmMatrix>& data) : _data(data), _currIndex(-1) { assert(!data.isEmpty()); }
425 
426  // See comments on the base class
427  virtual int numSrcs() { return _data.size(); }
428 
429  // See comments on the base class
430  virtual int size() const { return _data.first().n_cols; }
431 
432  // See comments on the base class
433  virtual int valueSize(int srcIndex) const { assert(srcIndex >= 0 && srcIndex < _data.size()); return _data.at(srcIndex).n_rows; }
434 
435  // See comments on the base class
436  virtual void reset() { _currIndex = 0; }
437 
438  // See comments on the base class
439  virtual bool next() { assert(_currIndex >= 0); _currIndex++; return _currIndex < size(); }
440 
441  // See comments on the base class
442  virtual const double* value(int srcIndex) { assert(srcIndex >= 0 && srcIndex < _data.size()); assert(_currIndex >= 0); return _data.at(srcIndex).colptr(_currIndex); }
443 
444  // See comments on the base class
445  virtual void coordinate(GmCRVector& coord) { Q_UNUSED(coord); }
446 
447 private:
450 };
451 
452 
453 #endif
Base interface for FEM (finite element) mesh elements.
Definition: gmElement.h:37
A GmInterpolatorInputDataBinding implementation returning values provided by a list of Gauss value ac...
Definition: gmInterpolatorInputBindings.h:302
virtual bool next()
Advances the iterator to the next value. Returns false if we already visited the last value and there...
Definition: gmInterpolatorInputBindings.h:401
GmInterpolatorGaussCoordinateSetBinding * _pointSet
The point set providing the indices used to access values.
Definition: gmInterpolatorInputBindings.h:268
const unsigned int n_rows
number of rows in the vector (read-only)
Definition: gmVector.h:87
int _currIndex
The current index.
Definition: gmInterpolatorInputBindings.h:411
GmInterpolatorMMatrixInputDataBinding(const QList< GmMatrix > &data)
Constructor, receiving the list of matrices for which this binding will return values.
Definition: gmInterpolatorInputBindings.h:424
virtual bool next(GmCRVector &coord, int *index)=0
Similar to nextCoordinate(), returns both the next coordinate and node index. Same caveats apply....
virtual void setValue(int srcIndex, const double *value)
Updates the value pointed to by the current iterator position, for the given data source index (betwe...
Definition: gmInterpolatorInputBindings.h:148
GmInterpolatorMNodeDataBinding< GmInterpolatorInputDataBinding, const GmValueAccessor * > GmInterpolatorMNodeInputDataBinding
GmInterpolatorInputDataBinding implementation returning values provided by a list of node value acces...
Definition: gmInterpolatorInputBindings.h:200
virtual int size() const =0
Returns the number of values stored by this object for each data src.
QList< Ac > _valueAcList
The list of accessors for the interpolated node values.
Definition: gmInterpolatorInputBindings.h:194
The GmGaussAccessor class is a proxy object to a value accesor implementing a more convenient interfa...
Definition: gmGaussAccessor.h:38
Declaration of usefull configuration definitions for the Core library.
const T & at(int i) const const
GmInterpolatorInputDataBinding implementation returning values provided by a list of matrices.
Definition: gmInterpolatorInputBindings.h:415
GmInterpolatorMNodeDataBinding(GmInterpolatorNodeCoordinateSetBinding *pointSet, const QList< Ac > &nodeAccessors)
Constructor, receiving the point set for which this binding will return values and the list of access...
Definition: gmInterpolatorInputBindings.h:168
virtual int valueSize(int srcIndex) const
Returns the value dimension for the given data src.
Definition: gmInterpolatorInputBindings.h:395
virtual void ipNaturalCoord(const GmElement *elem, int ip, GmVector &ipCoord) const =0
Given an element and its integration point index, fills ipCoord with its natural coordinate.
virtual bool next()=0
Advances the iterator to the next value. Returns false if we already visited the last value and there...
virtual void setValue(int srcIndex, const double *value)
Updates the value pointed to by the current iterator position, for the given data source index (betwe...
Definition: gmInterpolatorInputBindings.h:210
virtual void coordinate(GmCRVector &coord)
Returns the coordinate of the current iterator position. Does nothing if the input src has no coordin...
Definition: gmInterpolatorInputBindings.h:407
GmInterpolatorInputDataBinding implementation returning values provided by a matrix.
Definition: gmInterpolatorInputBindings.h:376
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:100
int _currIndex
The current index.
Definition: gmInterpolatorInputBindings.h:195
int size() const const
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
virtual void setValue(int srcIndex, const double *value)
Updates the value pointed to by the current iterator position, for the given data source index (betwe...
Definition: gmInterpolatorInputBindings.h:289
int _currIp
The current integration point index.
Definition: gmInterpolatorInputBindings.h:274
virtual const double * value(int srcIndex)
Returns a vector with the value pointed to by the current iterator position, for the given data sourc...
Definition: gmInterpolatorInputBindings.h:404
GmInterpolatorMatrixInputDataBinding(const GmMatrix &data)
Constructor, receiving the matrix for which this binding will return values. Each matrix column shoul...
Definition: gmInterpolatorInputBindings.h:386
Interface for a coordinate set that stores node coordinates. Besides returning coordinates,...
Definition: gmInterpolatorCoordinateBindings.h:143
virtual int size() const =0
Returns the number of coordinates stored by this set.
GmCRVector _currCoord
The current coordinate.
Definition: gmInterpolatorInputBindings.h:134
const QList< GmMatrix > & _data
The list with matrices for the interpolated values.
Definition: gmInterpolatorInputBindings.h:448
int _currIp
The current integration point index.
Definition: gmInterpolatorInputBindings.h:348
A GmInterpolatorInputDataBinding implementation returning values provided by a Gauss value accessor....
Definition: gmInterpolatorInputBindings.h:227
virtual int valueSize(int srcIndex) const =0
Returns the value dimension for the given data src.
bool isEmpty() const const
GmInterpolatorInOutDataBinding implementation working with values provided by a list of node value ac...
Definition: gmInterpolatorInputBindings.h:203
virtual int numSrcs()=0
Returns the number o data srcs (accessors) stored by this object.
Ac _valueAc
The accessor for the interpolated node values.
Definition: gmInterpolatorInputBindings.h:132
Implementation of the GmGaussAccessor proxy class.
GmInterpolatorGaussCoordinateSetBinding * _pointSet
The point set providing the indices used to access values.
Definition: gmInterpolatorInputBindings.h:342
T & first()
GmInterpolatorMGaussDataBinding(GmInterpolatorGaussCoordinateSetBinding *pointSet, const QList< Ac > &gaussAccessors)
Constructor, receiving the point set for which this binding will return values and the list of access...
Definition: gmInterpolatorInputBindings.h:308
virtual void reset()=0
Resets the iterator. The following call to value() will return the first value in the set....
virtual void reset()
Resets the iterator. The following call to value() will return the first value in the set....
Definition: gmInterpolatorInputBindings.h:398
virtual void coordinate(GmCRVector &coord)
Returns the coordinate of the current iterator position. Does nothing if the input src has no coordin...
Definition: gmInterpolatorInputBindings.h:445
virtual int size() const
Returns the number of values stored by this object for each data src.
Definition: gmInterpolatorInputBindings.h:430
virtual int numSrcs()
Returns the number o data srcs (accessors) stored by this object.
Definition: gmInterpolatorInputBindings.h:427
Ac _valueAc
The accessor for the interpolated Gauss values.
Definition: gmInterpolatorInputBindings.h:272
virtual bool next()
Advances the iterator to the next value. Returns false if we already visited the last value and there...
Definition: gmInterpolatorInputBindings.h:439
virtual void setValue(int srcIndex, const double *value)
Updates the value pointed to by the current iterator position, for the given data source index (betwe...
Definition: gmInterpolatorInputBindings.h:363
GmInterpolatorGaussDataBinding< GmInterpolatorInputDataBinding, const GmGaussAccessor * > GmInterpolatorGaussInputDataBinding
GmInterpolatorInputDataBinding implementation returning values provided by a Gauss value accessor.
Definition: gmInterpolatorInputBindings.h:279
virtual void reset()
Resets the iterator. The following call to value() will return the first value in the set....
Definition: gmInterpolatorInputBindings.h:436
GmInterpolatorMGaussDataBinding< GmInterpolatorInputDataBinding, const GmGaussAccessor * > GmInterpolatorMGaussInputDataBinding
GmInterpolatorInOutDataBinding implementation returning values provided by a list of Gauss value acce...
Definition: gmInterpolatorInputBindings.h:353
virtual const double * value(int srcIndex)=0
Returns a vector with the value pointed to by the current iterator position, for the given data sourc...
virtual int valueSize(int srcIndex) const
Returns the value dimension for the given data src.
Definition: gmInterpolatorInputBindings.h:433
virtual int numSrcs()
Returns the number o data srcs (accessors) stored by this object.
Definition: gmInterpolatorInputBindings.h:389
GmInterpolatorNodeDataBinding(GmInterpolatorNodeCoordinateSetBinding *pointSet, Ac nodeAc)
Constructor, receiving the point set for which this binding will return values and the accessor used ...
Definition: gmInterpolatorInputBindings.h:106
GmInterpolatorInOutDataBinding implementation working with values provided by a list of Gauss value a...
Definition: gmInterpolatorInputBindings.h:356
GmInterpolatorInOutDataBinding implementation working with values provided by a node value accessor.
Definition: gmInterpolatorInputBindings.h:141
An auxiliary vector WRAPPER that binds the vector to a CONST memory area with data already initialize...
Definition: gmVector.h:69
QList< Ac > _valueAcList
The list of accessors for the interpolated Gauss values.
Definition: gmInterpolatorInputBindings.h:346
Binding class used to store the set of known values associated with the points used in the interpolat...
Definition: gmInterpolatorInputBindings.h:41
GmCRVector _currCoord
The current coordinate.
Definition: gmInterpolatorInputBindings.h:275
GmInterpolatorNodeCoordinateSetBinding * _pointSet
The point set providing the indices used to access values.
Definition: gmInterpolatorInputBindings.h:190
virtual void reset()=0
Resets the coordinate iterator. The following call to nextCoordinate() will return the first coordina...
int _currIndex
The current index.
Definition: gmInterpolatorInputBindings.h:449
const GmElement * _currElem
The current element.
Definition: gmInterpolatorInputBindings.h:273
virtual void setValue(int srcIndex, const double *value)=0
Updates the value pointed to by the current iterator position, for the given data source index (betwe...
Interface for a coordinate set that stores Gauss point coordinates. Besides returning coordinates,...
Definition: gmInterpolatorCoordinateBindings.h:166
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...
GmCRVector _currCoord
The current coordinate.
Definition: gmInterpolatorInputBindings.h:349
GmInterpolatorNodeDataBinding< GmInterpolatorInputDataBinding, const GmValueAccessor * > GmInterpolatorNodeInputDataBinding
GmInterpolatorInputDataBinding implementation returning values provided by a node value accessor.
Definition: gmInterpolatorInputBindings.h:138
const GmElement * _currElem
The current element.
Definition: gmInterpolatorInputBindings.h:347
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
GmInterpolatorNodeCoordinateSetBinding * _pointSet
The point set providing the indices used to access values.
Definition: gmInterpolatorInputBindings.h:128
GmInterpolatorGaussDataBinding(GmInterpolatorGaussCoordinateSetBinding *pointSet, Ac gaussAc)
Constructor, receiving the point set for which this binding will return values and the accessor used ...
Definition: gmInterpolatorInputBindings.h:233
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition: gmMatrix.h:38
int _currIndex
The current index.
Definition: gmInterpolatorInputBindings.h:133
GmInterpolatorInOutDataBinding implementation working with values provided by a Gauss value accessor.
Definition: gmInterpolatorInputBindings.h:282
virtual const double * value(int srcIndex)
Returns a vector with the value pointed to by the current iterator position, for the given data sourc...
Definition: gmInterpolatorInputBindings.h:442
virtual void coordinate(GmCRVector &coord)=0
Returns the coordinate of the current iterator position. Does nothing if the input src has no coordin...
virtual bool next(GmCRVector &coord, const GmElement **elem, int *ip)=0
Similar to nextCoordinate(), returns both the next coordinate and Gauss point index....
GmCRVector _currCoord
The current coordinate.
Definition: gmInterpolatorInputBindings.h:196
A GmInterpolatorInputDataBinding implementation returning values provided by a list of node value acc...
Definition: gmInterpolatorInputBindings.h:162
A version of GmInterpolatorInputDataBinding that lets us to also update the stored data.
Definition: gmInterpolatorInputBindings.h:80
const GmMatrix & _data
The matrix for the interpolated values.
Definition: gmInterpolatorInputBindings.h:410
A GmInterpolatorInputDataBinding implementation returning values provided by a node value accessor....
Definition: gmInterpolatorInputBindings.h:100
virtual int size() const
Returns the number of values stored by this object for each data src.
Definition: gmInterpolatorInputBindings.h:392