FemProcess
The GeMA Fem Process Plugin
gmpFemPhysicsCommonLuaMaterial.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_PLUGIN_FEM_PHYSICS_COMMON_LUA_MATERIAL_H_
25 #define _GEMA_PLUGIN_FEM_PHYSICS_COMMON_LUA_MATERIAL_H_
26 
28 #include "gmpFemPhysicsCommon.h"
29 
30 #include <luaTable.h>
31 
32 class GmPluginData;
33 
34 
36 class GMP_FEM_PROCESS_API_EXPORT GmpFemPhysicsCommonLuaMaterialImp
37 {
38 public:
43  : _pdata(pdata), _mat(mat), _map(NULL)
44  {
45  assert(_pdata);
46  }
47 
49 
50  // GmpFemPhysicsCommonMaterial methods
51  // ----------------------------------------
52  const QVariantMap* materialMetaDataMap();
53 
54  bool checkLoadedData(const GmElement* e) const;
55 
56  // Lua function calling methods and aux classes
57  // ------------------------------------------------
58 
63  typedef QVariant (*GetFieldDataT)(QString field, const void* context, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
64 
66  typedef bool (*SetFieldDataT)(QString field, const void* context, const GmElement* e, int ip, const QVariant& v);
67 
70  {
76  // ---- NO ADDS BELLOW -----
77  CDT_NUMTYPES
78  };
79 
80  // The set of geometry fields
82  {
92  GF_N,
93  };
94 
97  {
98  CallDataFunctions() : _subTableName(NULL), _getF(NULL), _setF(NULL), _context(NULL) {}
99 
100  const char* _subTableName;
101  GetFieldDataT _getF;
102  SetFieldDataT _setF;
103  const void* _context;
104  };
105 
107  class GMP_FEM_PROCESS_API_EXPORT CallData
108  {
109  public:
110  CallData();
111 
112  LuaTable& inputTable() { assert(_inTable.isValid()); return _inTable; }
113  LuaTable& outputTable() { assert(_outTable.isValid()); return _outTable; }
114  bool call();
115  void cleanup();
116  static int indexMM(lua_State* L);
117 
118  private:
120 
125  const GmElement* _e;
126  int _ip;
127  const GmVector* _coord;
129 
131 
133  const CallDataFunctions* _subTabF[CDT_NUMTYPES]; //<! Pointers to the get/set data functions for each possible sub-table data types. NULL if the type is not available for this call
134  };
135 
136  CallData* prepareUserMethodCall(QString fname, const GmElement* e, int ip, const GmVector* coord,
137  const char* userSubTable = NULL, GetFieldDataT userGetF = NULL,
138  SetFieldDataT userSetF = NULL, const void* userContext = NULL) const;
139 
141  const GmPluginData* pluginData() const { return _pdata; }
142 
143  // Aux methods to make the life of derived classes easier
144  // ------------------------------------------------
145  static QVariant propertyAccessorValueToVariant (GmCellAccessor* ac, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
146  static QVariant nodeAccessorValueToVariant (GmValueAccessor* ac, GmValueAccessor* coordAc, const GmElement* e, int ip, const GmVector* coord, GmInterpolatorType interpType, QVariant interpParam, const GmLogCategory& logger);
147  static QVariant gaussAccessorValueToVariant (GmGaussAccessor* ac, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
148  static void setGaussAccessorValueFromVariant(GmGaussAccessor* ac, const GmElement* e, int ip, const QVariant& v);
149  static bool fillMatrixFromVariant (GmMatrix& mat, int nlin, int ncol, const QVariant& v, QString& err);
150 
151 private:
152  void loadTableData(QString field, QMap<QString, int>& fieldMap, QVector<QPair<GmInterpolatorType, QVariant>>* interpData = NULL, bool savedGaussAttr = false);
153  void loadEntryData(int index, const QVariantMap& data, GmpFemPhysicsCommon::ValueList& list, QMap<QString, int>& map);
154 
155  static QVariant getPropertyValue (QString field, const void* context, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
156  static QVariant getNodeAttrValue (QString field, const void* context, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
157  static QVariant getGaussAttrValue(QString field, const void* context, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
158  static bool setGaussAttrValue(QString field, const void* context, const GmElement* e, int ip, const QVariant& v);
159  static QVariant getGeometryValue (QString field, const void* context, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger);
160 
161  static QVariant variantListToOnStackLuaTable(LuaEnv* env, const QVariantList& v);
162 
165 
168 
169  QVariantMap* _map;
173 
174  QVector<QPair<GmInterpolatorType, QVariant>> _nodeAttrInterpMode;
175 
180 
183 
185 };
186 
187 
188 
200 template <class Base>
202 {
203 public:
207  GmpFemPhysicsCommonLuaMaterial(const GmPluginData* pdata, int typeIndex, QString typeName, const GmLogCategory& logger)
208  : Base(typeIndex, typeName, logger), _d(new GmpFemPhysicsCommonLuaMaterialImp(pdata, this)) {}
209 
211  virtual ~GmpFemPhysicsCommonLuaMaterial() { delete _d; }
212 
213  virtual const QVariantMap* materialMetaDataMap() { return _d->materialMetaDataMap(); }
214 
215  virtual bool checkLoadedData(const GmElement* e) const { return _d->checkLoadedData(e); }
216 
219 
220  CallData* prepareUserMethodCall(QString fname, const GmElement* e, int ip, const GmVector* coord,
221  const char* userSubTable = NULL,
224  const void* userContext = NULL) const
225  {
226  return _d->prepareUserMethodCall(fname, e, ip, coord, userSubTable, userGetF, userSetF, userContext);
227  }
228 
229  // Aux methods to make the life of derived classes easier
230  // ------------------------------------------------
231  static QVariant propertyAccessorValueToVariant(GmCellAccessor* ac, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger)
232  {
234  }
235 
236  static QVariant nodeAccessorValueToVariant(GmValueAccessor* ac, GmValueAccessor* coordAc, const GmElement* e, int ip, const GmVector* coord, GmInterpolatorType interpType, QVariant interpParam, const GmLogCategory& logger)
237  {
238  return GmpFemPhysicsCommonLuaMaterialImp::nodeAccessorValueToVariant(ac, coordAc, e, ip, coord, interpType, interpParam, logger);
239  }
240 
241  static QVariant gaussAccessorValueToVariant(GmGaussAccessor* ac, const GmElement* e, int ip, const GmVector* coord, const GmLogCategory& logger)
242  {
244  }
245 
246  static void setGaussAccessorValueFromVariant(GmGaussAccessor* ac, const GmElement* e, int ip, const QVariant& v)
247  {
249  }
250 
251  static bool fillMatrixFromVariant(GmMatrix& mat, int nlin, int ncol, const QVariant& v, QString& err)
252  {
253  return GmpFemPhysicsCommonLuaMaterialImp::fillMatrixFromVariant(mat, nlin, ncol, v, err);
254  }
255 
256 protected:
257  const GmPluginData* pluginData() const { return _d->pluginData(); }
258 
260 };
261 
262 #endif
263 
A structure used to define if a value is required or not, being able to specify conditional situation...
Definition: gmpFemPhysicsCommon.h:45
int _ip
The current integration point.
Definition: gmpFemPhysicsCommonLuaMaterial.h:126
static QVariant nodeAccessorValueToVariant(GmValueAccessor *ac, GmValueAccessor *coordAc, const GmElement *e, int ip, const GmVector *coord, GmInterpolatorType interpType, QVariant interpParam, const GmLogCategory &logger)
Retrieves the element node values from the given accessor, interpolates the value at the given point ...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:501
GmpFemPhysicsCommon::RequiredIf parseRequiredField(const QVariant &v) const
Parses a require field for loadEntryData()
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:278
The data is a cell property.
Definition: gmpFemPhysicsCommonLuaMaterial.h:71
GmpFemPhysicsCommonMaterial * _mat
The material that is implemented by this object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:167
static QVariant getGeometryValue(QString field, const void *context, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Returns the geometry value associated with the given field, at the given coordinate,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:668
Field N - the shape function vector N evaluated at the integration point coordinate.
Definition: gmpFemPhysicsCommonLuaMaterial.h:92
The real implementation of the GmpFemPhysicsCommonLuaMaterial class methods. See comments on that cla...
Definition: gmpFemPhysicsCommonLuaMaterial.h:36
CallDataType
Stored data type for input data sub-tables.
Definition: gmpFemPhysicsCommonLuaMaterial.h:69
GmpFemPhysicsCommonLuaMaterialImp::CallData CallData
Duplicate Imp typedef as our own.
Definition: gmpFemPhysicsCommonLuaMaterial.h:218
GmpFemPhysicsCommonLuaMaterialImp(const GmPluginData *pdata, GmpFemPhysicsCommonMaterial *mat)
Common Lua material constructor. Receives the PluginData object with the material especification plus...
Definition: gmpFemPhysicsCommonLuaMaterial.h:42
GmTLS< CallData, true > _callData
The per thread set of CallData objects.
Definition: gmpFemPhysicsCommonLuaMaterial.h:181
LuaTable _outTable
The output data lua table function call parameter.
Definition: gmpFemPhysicsCommonLuaMaterial.h:124
static bool setGaussAttrValue(QString field, const void *context, const GmElement *e, int ip, const QVariant &v)
Updates the gauss attribute value associeated with the given field, at the given ip....
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:654
CallDataFunctions _nodeAttrCallFunctions
The set of functions for getting node attribute values. Will have a NULL name if _nodeAttrIndexMap is...
Definition: gmpFemPhysicsCommonLuaMaterial.h:177
Field nodeAccessor - the node coordinate accessor.
Definition: gmpFemPhysicsCommonLuaMaterial.h:90
const char * _subTableName
The sub-table name. A NULL value if there is NO DATA for this type.
Definition: gmpFemPhysicsCommonLuaMaterial.h:100
LuaFunction * _f
The callable function.
Definition: gmpFemPhysicsCommonLuaMaterial.h:122
bool(* SetFieldDataT)(QString field, const void *context, const GmElement *e, int ip, const QVariant &v)
Type for the function used to set derived class values imported from an output data sub-table....
Definition: gmpFemPhysicsCommonLuaMaterial.h:66
CallDataFunctions _userF
The user sub-table (if any) get/set data functions.
Definition: gmpFemPhysicsCommonLuaMaterial.h:132
static QVariant getPropertyValue(QString field, const void *context, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Returns the property value associated with the given field, at the given coordinate,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:610
QMap< QString, int > _propertyIndexMap
Map associating property names in _map with their accessor indices.
Definition: gmpFemPhysicsCommonLuaMaterial.h:170
A wrapper over a QList<T> that knows how to convert itself into a QVariant, provided that the resulti...
Definition: gmpFemPhysicsCommon.h:345
SetFieldDataT _setF
The setter function for the sub-table. Optional.
Definition: gmpFemPhysicsCommonLuaMaterial.h:102
Declaration of the GmpFemPhysicsCommonMaterial and GmpFemPhysicsCommonMaterialFactory classes.
QVariant(* GetFieldDataT)(QString field, const void *context, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Type for the function used to get derived class values exported to an input data sub-table....
Definition: gmpFemPhysicsCommonLuaMaterial.h:63
Field elem - the element (cell) object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:84
QMap< QString, int > _gaussAttrIndexMap
Map associating Gauss attribute names in _map with their accessor indices.
Definition: gmpFemPhysicsCommonLuaMaterial.h:172
virtual ~GmpFemPhysicsCommonLuaMaterial()
Destructor.
Definition: gmpFemPhysicsCommonLuaMaterial.h:211
int _luaStackTop
The Lua stack top before the method call was prepared.
Definition: gmpFemPhysicsCommonLuaMaterial.h:128
GmInterpolatorType
GetFieldDataT _getF
The getter function for the sub table. Optional.
Definition: gmpFemPhysicsCommonLuaMaterial.h:101
const GmPluginData * pluginData() const
Returns the associated plugin data object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:141
QList< GmpFemPhysicsCommon::ValueType > parseDimField(const QVariant &v) const
Parses a dimension field for loadEntryData()
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:224
The data is a node attribute.
Definition: gmpFemPhysicsCommonLuaMaterial.h:72
static QMap< QString, int > _geometryFieldsMap
Map translating geometry field names into the GeometryFields enum.
Definition: gmpFemPhysicsCommonLuaMaterial.h:184
static QVariant getNodeAttrValue(QString field, const void *context, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Returns the interpolated node attribute value associated with the given field, at the given coordinat...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:625
Declaration of the GmpFemPhysicsCommon class.
Field coord - the evaluated integration point natural coordinate.
Definition: gmpFemPhysicsCommonLuaMaterial.h:87
static bool fillMatrixFromVariant(GmMatrix &mat, int nlin, int ncol, const QVariant &v, QString &err)
Fills the given matrix contents with the value of the GmLuaMatrix stored in the given variant value....
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:588
GmpFemPhysicsCommonLuaMaterialImp * _d
The implementation object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:259
QString _fname
The function name.
Definition: gmpFemPhysicsCommonLuaMaterial.h:121
QMap< QString, int > _nodeAttrIndexMap
Map associating node attribute names in _map with their accessor indices.
Definition: gmpFemPhysicsCommonLuaMaterial.h:171
static QVariant propertyAccessorValueToVariant(GmCellAccessor *ac, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Retrieves the given accessor value at the given point and converts it to a QVariant,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:481
static void setGaussAccessorValueFromVariant(GmGaussAccessor *ac, const GmElement *e, int ip, const QVariant &v)
Given a QVariant value that can be either a scalar or a pointer to a GmLuaMatrix object,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:563
Field ip - the evaluated integration point index.
Definition: gmpFemPhysicsCommonLuaMaterial.h:86
An aux structure storing how to get / set data for input data sub-tables.
Definition: gmpFemPhysicsCommonLuaMaterial.h:96
void loadEntryData(int index, const QVariantMap &data, GmpFemPhysicsCommon::ValueList &list, QMap< QString, int > &map)
Loads a single data entry into list, also filling map with its name x index maping.
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:178
void loadTableData(QString field, QMap< QString, int > &fieldMap, QVector< QPair< GmInterpolatorType, QVariant >> *interpData=NULL, bool savedGaussAttr=false)
Loads the data from the given plugin data field (properties, nodeAttributes or gaussAttributes) into ...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:120
Field clength - the element characteristic length.
Definition: gmpFemPhysicsCommonLuaMaterial.h:88
A class that implements a common behaviour for physics materials.
Definition: gmpFemPhysicsCommonMaterial.h:44
GeometryFields
Definition: gmpFemPhysicsCommonLuaMaterial.h:81
Field cdim - the element characteristic dimension.
Definition: gmpFemPhysicsCommonLuaMaterial.h:89
const GmVector * _coord
The current natural coordinate of the integration point.
Definition: gmpFemPhysicsCommonLuaMaterial.h:127
static QVariant variantListToOnStackLuaTable(LuaEnv *env, const QVariantList &v)
Transforms the received QVariant List on a Lua table, stored on the top of the stack....
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:716
Field nodeMatrix - the matrix with element node coordinates.
Definition: gmpFemPhysicsCommonLuaMaterial.h:91
LuaTable _inTable
The input data lua table function call parameter.
Definition: gmpFemPhysicsCommonLuaMaterial.h:123
Field elemId - the element id.
Definition: gmpFemPhysicsCommonLuaMaterial.h:83
QVariantMap * _map
The metadata map built based on _pdata.
Definition: gmpFemPhysicsCommonLuaMaterial.h:169
GmTLS< QSet< QString >, true > _fieldCacheData[CDT_NUMTYPES]
The per thread cache info on referenced input data sub-table fields, per sub-table type.
Definition: gmpFemPhysicsCommonLuaMaterial.h:182
static QVariant getGaussAttrValue(QString field, const void *context, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Returns the gauss attribute value associated with the given field, at the given coordinate,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:641
const QVariantMap * materialMetaDataMap()
Builds the metadata map returned by every GmpFemPhysicsCommonMaterial object based on the plugin data...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:69
The number of entries in this enum.
Definition: gmpFemPhysicsCommonLuaMaterial.h:77
CallDataFunctions _geometryCallFunctions
The set of functions for getting geometry values.
Definition: gmpFemPhysicsCommonLuaMaterial.h:179
The auxiliar class used to store prepared user method call data.
Definition: gmpFemPhysicsCommonLuaMaterial.h:107
A class that implements the common behaviour for physics Lua materials. The template parameter provid...
Definition: gmpFemPhysicsCommonLuaMaterial.h:201
CallData * prepareUserMethodCall(QString fname, const GmElement *e, int ip, const GmVector *coord, const char *userSubTable=NULL, GetFieldDataT userGetF=NULL, SetFieldDataT userSetF=NULL, const void *userContext=NULL) const
Prepares the CallData object for a later call to the given user method, for the given set of element ...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:355
const GmElement * _e
The current element.
Definition: gmpFemPhysicsCommonLuaMaterial.h:125
arma::vec GmVector
const GmPluginData * _pdata
The associated plugin data object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:166
const void * _context
The additional context sent to the getter and setter functions.
Definition: gmpFemPhysicsCommonLuaMaterial.h:103
The data is a Gauss attribute.
Definition: gmpFemPhysicsCommonLuaMaterial.h:73
arma::mat GmMatrix
Field type - the element type string.
Definition: gmpFemPhysicsCommonLuaMaterial.h:85
The data is a a derivade class data.
Definition: gmpFemPhysicsCommonLuaMaterial.h:75
CallDataFunctions _propertyCallFunctions
A vector with the interpolation options for each attribute stored in _nodeAttrIndexMap,...
Definition: gmpFemPhysicsCommonLuaMaterial.h:176
const GmpFemPhysicsCommonLuaMaterialImp * _mat
The associated LuaMaterialImp object.
Definition: gmpFemPhysicsCommonLuaMaterial.h:130
GmpFemPhysicsCommonLuaMaterial(const GmPluginData *pdata, int typeIndex, QString typeName, const GmLogCategory &logger)
Common Lua material constructor. Receives the PluginData object with the material especification plus...
Definition: gmpFemPhysicsCommonLuaMaterial.h:207
TH edata is the geometry table.
Definition: gmpFemPhysicsCommonLuaMaterial.h:74
static QVariant gaussAccessorValueToVariant(GmGaussAccessor *ac, const GmElement *e, int ip, const GmVector *coord, const GmLogCategory &logger)
Retrieves the given accessor value at the given point and converts it to a QVariant,...
Definition: gmpFemPhysicsCommonLuaMaterial.cpp:545
CallDataFunctions _gaussAttrCallFunctions
The set of functions for getting/setting gauss attribute values. Will have a NULL name if _gaussAttrI...
Definition: gmpFemPhysicsCommonLuaMaterial.h:178