Xfem
The Xfem Plugin
xfemGaussAccessor.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_XFEM_GAUSS_ACCESSOR_H_
25 #define _GEMA_XFEM_GAUSS_ACCESSOR_H_
26 
27 #include <gmGaussAccessor.h>
28 
29 class XfemMGaussValueSet;
30 
31 #include "xfemElement.h"
32 #include "xfemGaussValueSet.h"
33 
41 {
42  Q_OBJECT
43 
44 public:
45 
48  : GmGaussAccessor(ac, gvs)
49  {
50  assert(!ac->info()->canStoreFunctions()); // Functions are not supported in this particular implementation
51  assert(snum >= 0 && snum < gvs->numSets());
52  _snum = snum;
53  _si = gvs->stateIndex(snum);
54  }
55 
57  virtual int numPoints(const GmCell* c) const
58  {
59  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
60  assert(e);
61  if(!e->enriched())
63  else
64  return ((XfemGaussValueSet*)_gvs)->numEnrichedPoints(c->cellId());
65  }
66 
67  // Wrapped functions. For descriptions, see GmValueAccessor documentation
68  virtual const double* valueAt(const GmCell* c, int ip, const GmVector* coord) const
69  {
70  const XfemElement* e = saveElemInContext(c, ip);
71  if(!e->enriched())
72  return _ac->valueAt(queryIndex(c, ip), coord);
73  else
74  return convertToAccessorUnit(((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si));
75  }
76 
77  virtual double scalarValueAt(const GmCell* c, int ip, const GmVector* coord) const
78  {
79  const XfemElement* e = saveElemInContext(c, ip);
80  if(!e->enriched())
81  return _ac->scalarValueAt(queryIndex(c, ip), coord);
82  else
83  return convertToAccessorUnit(*((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si));
84  }
85 
86  virtual void matrixValueAt(const GmCell* c, int ip, const GmVector* coord, GmCRMatrix& mat) const
87  {
88  mat.setMemory(valueAt(c, ip, coord), _ac->info()->nlin(), _ac->info()->ncol());
89  }
90 
91  virtual void vectorValueAt(const GmCell* c, int ip, const GmVector* coord, GmCRVector& vec) const
92  {
93  vec.setMemory(valueAt(c, ip, coord), _ac->info()->size());
94  }
95 
96  virtual bool setValue(const GmCell* c, int ip, const double* value)
97  {
98  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
99  assert(e);
100  if(!e->enriched())
101  return _ac->setValue(queryIndex(c, ip), value);
102  else
103  return convertFromAccessorUnit(value, ((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si)), true;
104  }
105 
106  virtual bool setScalarValue(const GmCell* c, int ip, double value)
107  {
108  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
109  assert(e);
110  if(!e->enriched())
111  return _ac->setScalarValue(queryIndex(c, ip), value);
112  else
113  return convertFromAccessorUnit(value, ((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si)), true;
114  }
115 
116  virtual bool setScalarValueAtDim(const GmCell* c, int ip, int dim, double value)
117  {
118  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
119  assert(e);
120  if(!e->enriched())
121  return _ac->setScalarValueAtDim(queryIndex(c, ip), dim, value);
122  else
123  {
124  int n = valueSize();
125  assert(dim >= 0 && dim < n);
126  QVarLengthArray<double, 128> data(n); // If size < 128, allocated on the stack
127  memcpy(data.data(), valueAt(c, ip, NULL), n * sizeof(double));
128  data[dim] = value;
129  return setValue(c, ip, data.data());
130  }
131  }
132 
133  virtual bool setValueAsDef(const GmCell* c, int ip)
134  {
135  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
136  assert(e);
137  if(!e->enriched())
138  return _ac->setValueAsDef(queryIndex(c, ip));
139  else
140  return memcpy(((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si), info()->defValue(), info()->size() * sizeof(double)), true;
141  }
142 
143  virtual bool setFunctionValue(const GmCell* c, int ip, GmUserFunction* functionDef) { Q_UNUSED(c); Q_UNUSED(ip); Q_UNUSED(functionDef); return false; }
144  virtual bool setFunctionValue(const GmCell* c, int ip, GmUserFunctionEvaluator* functionEval) { Q_UNUSED(c); Q_UNUSED(ip); Q_UNUSED(functionEval); return false; }
145 
146  virtual QString valueStr(const GmCell* c, int ip, bool evalFunctions, bool printDefAsNil,
147  int fieldWidth = 0, char format = 'g', int precision = -1, const GmVector* coord = NULL) const;
148 
149  virtual bool setFunctionFromName(const GmCell* c, int ip, QString userFunctionId, QString& err)
150  {
151  Q_UNUSED(c); Q_UNUSED(ip); Q_UNUSED(userFunctionId);
152  err = QObject::tr("Function values are currently unsuported by Xfem Gauss accessors.");
153  return false;
154  }
155 
156  virtual bool setValueFromVariant(const GmCell* c, int ip, const QVariant& v, bool acceptMissingDimension, QString& err);
157 
158  virtual bool isDefValue(const GmCell* c, int ip) const
159  {
160  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
161  assert(e);
162  if(!e->enriched())
163  return _ac->isDefValue(queryIndex(c, ip));
164  else
165  return !memcmp(((XfemGaussValueSet*)_gvs)->dataPointer(e, ip, _si), info()->defValue(), info()->size() * sizeof(double));
166  }
167 
168  virtual bool isFunction(const GmCell* c, int ip) const { Q_UNUSED(c); Q_UNUSED(ip); return false; }
169  virtual QString functionId(const GmCell* c, int ip) const { Q_UNUSED(c); Q_UNUSED(ip); return ""; }
170 
171 private slots :
173  void setDataChanged(const GmValueSet* mvs)
174  {
175  const XfemGaussValueSet* gvs = dynamic_cast<const XfemGaussValueSet*>(mvs);
176  assert(gvs);
177  _si = gvs->stateIndex(_snum);
178  }
179 
180 private:
182  const XfemElement* saveElemInContext(const GmCell* c, int ip) const
183  {
184  const XfemElement* e = dynamic_cast<const XfemElement*>(c);
185  assert(e);
186  saveCellInContext(c, ip);
187  return e;
188  }
189 
190  int _snum;
191  int _si;
192 };
193 
194 #endif
195 
The XfemGaussAccessor class is a proxy object to a value accesor implementing a more convenient inter...
Definition: xfemGaussAccessor.h:40
virtual int numPoints(const GmCell *c) const
Returns the number of Gauss / integration points for the given cell.
Definition: xfemGaussAccessor.h:57
XfemGaussAccessor(GmValueAccessor *ac, XfemGaussValueSet *gvs, int snum)
Constructor. Takes ownership of the accessor.
Definition: xfemGaussAccessor.h:47
void setMemory(const double *data, int nlin)
QString tr(const char *sourceText, const char *disambiguation, int n)
void convertFromAccessorUnit(double val, double *dst) const
Basic interface for an XFEM element.
Definition: xfemElement.h:43
virtual int cellId() const=0
void saveCellInContext(const GmCell *c, int ip) const
int stateIndex(int snum) const
Translates a state number into the index needed by dataPointer()
Definition: xfemGaussValueSet.h:53
int _snum
The state number that this accessor is tied to.
Definition: xfemGaussAccessor.h:190
virtual bool setValueFromVariant(const GmCell *c, int ip, const QVariant &v, bool acceptMissingDimension, QString &err)
Missing a better solution, this is a striped down copy of the GmValueAccessor::setValueFromVariant() ...
Definition: xfemGaussAccessor.cpp:115
virtual int numPoints(const GmCell *c) const
virtual bool enriched() const =0
Returns true if this element has been enriched, false when not.
int _si
State index for defining which (history) state from the value set should be accessed.
Definition: xfemGaussAccessor.h:191
const XfemElement * saveElemInContext(const GmCell *c, int ip) const
Auxiliary function to check that c is a xfem element and to save the element in the context.
Definition: xfemGaussAccessor.h:182
Operating in colaboration with the XfemGaussAccessor class this value set extends the normal Gauss va...
Definition: xfemGaussValueSet.h:35
double convertToAccessorUnit(double val) const
virtual GmValueInfo * info() const=0
Declaration of the XfemElement class.
arma::vec GmVector
void setDataChanged(const GmValueSet *mvs)
Slot called when a state has been added to the value set, changing the index for locked accessors.
Definition: xfemGaussAccessor.h:173
virtual QString valueStr(const GmCell *c, int ip, bool evalFunctions, bool printDefAsNil, int fieldWidth=0, char format='g', int precision=-1, const GmVector *coord=NULL) const
Missing a better solution, this is a striped down copy of the GmValueAccessor::valueStr() implementat...
Definition: xfemGaussAccessor.cpp:43
const GmGaussValueSet * _gvs
void setMemory(const double *data, int nlin, int ncol)
bool canStoreFunctions() const
Declaration of the XfemGaussValueSet class.