19#ifndef _GIMLI_ELEMENTMATRIX__H
20#define _GIMLI_ELEMENTMATRIX__H
36 this->_newStyle =
false;
38 this->_dofPerCoeff = 0;
44 inline const Vector< ValueType > & operator[](Index row)
const {
47 void resize(Index rows, Index cols=0) {
48 if (cols == 0) cols = rows;
52 mat_.resize(rows, cols);
55 ElementMatrix < ValueType > & operator += (
const ElementMatrix < ValueType > & E){
56 for (uint i = 0; i < size(); i ++){ mat_[i] += E.row(i); }
60 #define DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__(OP) \
61 ElementMatrix < ValueType > & operator OP##= (ValueType val) { \
62 if (this->_newStyle){ \
63 if (this->_integrated){ \
64 for (Index i = 0; i < size(); i ++) mat_[i] OP##= val; \
66 for (auto & m: _matX){ \
71 for (Index i = 0; i < size(); i ++) mat_[i] OP##= val; \
75 DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__(+)
76 DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__(-)
77 DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__(/)
78 DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__(*)
80 #undef DEFINE_ELEMENTMATRIX_UNARY_MOD_OPERATOR__
82 inline Index size()
const {
return mat_.rows(); }
83 inline Index rows()
const {
return mat_.rows(); }
84 inline Index cols()
const {
return mat_.cols(); }
86 inline const ValueType & getVal(Index i, Index j)
const {
88 inline void setVal(Index i, Index j,
const ValueType & v) {
90 inline void addVal(Index i, Index j,
const ValueType & v) {
94 inline void setMat(
const Matrix < ValueType > & m) { mat_ = m; }
96 inline Matrix < ValueType > *
pMat() {
return & mat_; }
98 inline const Matrix < ValueType > &
mat()
const {
return mat_; }
100 inline const Vector < ValueType > &
row(Index i)
const {
return mat_[i]; }
102 inline Vector < ValueType >
col(Index i)
const {
103 Vector < ValueType > ret(this->rows());
104 for (Index j = 0; j < ret.size(); j ++){ ret[j] = mat_[j][i];}
115 inline void setIds(
const IndexArray & idsR,
const IndexArray & idsC) {
116 _idsR = idsR; _idsC = idsC; _ids = idsR;
124 inline const IndexArray &
ids()
const {
return _ids; }
126 inline const IndexArray &
rowIDs()
const {
return _idsR; }
128 inline const IndexArray &
colIDs()
const {
return _idsC; }
130 inline const Index
idx(Index i)
const {
145 const RVector * &
w,
const PosVector * &
x,
int order);
151 const RVector &
u,
bool voigtNotation=
false);
154 const Matrix < ValueType > &
gradientBase()
const {
return this->_grad;}
166 bool voigtNotation=
false);
173 bool voigtNotation=
false);
186 bool voigtNotation=
false);
189 ElementMatrix < ValueType > &
gradU2(
const Cell & cell, ValueType c){
190 Matrix < ValueType > C(1, 1);
192 return this->
gradU2(cell, C,
false);
200 bool voigtNotation=
false);
202 ElementMatrix < ValueType > & ux2uy2uz2(
const Cell & cell,
203 bool useCache=
false);
205 ElementMatrix < ValueType > &
u(
const MeshEntity & ent,
209 ElementMatrix < ValueType > &
u2(
const MeshEntity & ent,
213 ElementMatrix < ValueType > & ux2(
const MeshEntity & ent,
217 ElementMatrix < ValueType > & ux2uy2(
const MeshEntity & ent,
221 ElementMatrix < ValueType > & ux2uy2uz2(
const MeshEntity & ent,
226 ElementMatrix < double > & dudi(
const MeshEntity & ent,
229 Index i,
bool verbose=
false);
231 ElementMatrix < double > & ux(
const MeshEntity & ent,
235 return dudi(ent,
w,
x, 0, verbose);
237 ElementMatrix < double > & uy(
const MeshEntity & ent,
241 return dudi(ent, w,
x, 1, verbose);
243 ElementMatrix < double > & uz(
const MeshEntity & ent,
247 return dudi(ent, w, x, 2, verbose);
250 Vector < ValueType > mult(
const Vector < ValueType > & v){
251 Vector < ValueType > ret(this->size());
257 void mult(
const Vector < ValueType > & a, Vector < ValueType > & ret){
258 ASSERT_EQUAL(size(), ret.size())
259 for (Index i = 0; i < size(); i ++) {
260 for (Index j = 0; j < size(); j ++) {
261 ret[i] += mat_[i][j] * a[_ids[j]];
266 ValueType
mult(
const Vector < ValueType > & a,
267 const Vector < ValueType > & b){
269 for (Index i = 0; i < size(); i ++) {
271 for (Index j = 0; j < size(); j ++) {
272 t += mat_[i][j] * a[_ids[j]];
274 ret += t * b[_ids[i]];
280 template <
class Val > Val
mult_(
const Vector < Val > & a,
281 const Vector < Val > & b,
282 const Vector < Val > & m,
283 const Vector < Val > & n){
285 for (Index i = 0; i < size(); i ++) {
287 for (Index j = 0; j < size(); j ++) {
288 t += mat_[i][j] * (a[_ids[j]]-b[_ids[j]]);
290 ret += t * (m[_ids[i]]-n[_ids[i]]);
295 double mult(
const RVector & a,
const RVector & b,
296 const RVector & m,
const RVector & n){
297 return mult_(a, b, m, n);
299 Complex mult(
const CVector & a,
const CVector & b,
300 const CVector & m,
const CVector & n){
301 return mult_(a, b, m, n);
305 ElementMatrix(Index nCoeff, Index dofPerCoeff, Index dofOffset);
307 ElementMatrix(
const ElementMatrix < ValueType > & E);
309 void copyFrom(
const ElementMatrix < ValueType > & E,
bool withMat=
true);
311 void init(Index nCoeff, Index dofPerCoeff, Index dofOffset);
316 Index nCoeff, Index dof, Index dofOffset);
324 bool elastic,
bool sum,
bool div,
325 Index nCoeff, Index dof, Index dofOffset,
bool kelvin=
false
330 bool elastic=
false,
bool sum=
false,
331 bool div=
false,
bool kelvin=
false);
337 const std::vector < Matrix < ValueType > > &
matX()
const {
return _matX; }
339 std::vector < Matrix < ValueType > > * pMatX() {
return &_matX; }
345 const PosVector &
x()
const { ASSERT_PTR(_x);
return *_x; }
348 const RVector &
w()
const { ASSERT_PTR(_w);
return *_w; }
350 Index order()
const {
return _order; }
351 Index nCoeff()
const {
return _nCoeff; }
352 Index dofPerCoeff()
const {
return _dofPerCoeff; }
353 Index dofOffset()
const {
return _dofOffset; }
355 void setDiv(
bool div){ _div =
true;}
356 bool isDiv()
const {
return _div;}
358 bool isIntegrated()
const {
return _integrated; }
359 void integrated(
bool i) { _integrated = i; }
361 bool valid()
const {
return _valid; }
362 void setValid(
bool v) { _valid = v; }
364 bool elastic()
const {
return _elastic;}
366 bool oldStyle()
const {
return !this->_newStyle; }
368 mutable Matrix < ValueType > mat_;
373 std::map< uint, RVector > uCache_;
374 std::map< uint, Matrix < ValueType > > u2Cache_;
376 std::vector< Matrix < ValueType > > _B;
377 Matrix < ValueType > _grad;
401 const MeshEntity * _ent;
403 const PosVector * _x;
405 std::vector < Matrix < ValueType > > _matX;
411 mutable bool _integrated;
417 ElementMatrix < ValueType > & operator = (
const ElementMatrix < ValueType > & E) {
418 std::cout <<
"ElementMatrix::operator = (" << std::endl;
428template < > DLLEXPORT
429void ElementMatrix < double >::copyFrom(
const ElementMatrix < double > & E,
432template < > DLLEXPORT
433void ElementMatrix < double >::init(Index nCoeff, Index dofPerCoeff,
436DLLEXPORT
void dot(
const ElementMatrix < double > & A,
437 const ElementMatrix < double > & B,
438 double c, ElementMatrix < double > & ret);
440DLLEXPORT
void dot(
const ElementMatrix < double > & A,
441 const ElementMatrix < double > & B,
442 const Pos & c, ElementMatrix < double > & ret);
444DLLEXPORT
void dot(
const ElementMatrix < double > & A,
445 const ElementMatrix < double > & B,
446 const RMatrix & c, ElementMatrix < double > & ret);
448DLLEXPORT
void dot(
const ElementMatrix < double > & A,
449 const ElementMatrix < double > & B,
450 const FEAFunction & c, ElementMatrix < double > & ret);
456#define DEFINE_DOT_MULT(A_TYPE) \
457DLLEXPORT const ElementMatrix < double > dot( \
458 const ElementMatrix < double > & A, \
459 const ElementMatrix < double > & B, \
461DLLEXPORT void mult(const ElementMatrix < double > & A, A_TYPE b, \
462 ElementMatrix < double > & C); \
463DLLEXPORT const ElementMatrix < double > mult( \
464 const ElementMatrix < double > & A, A_TYPE b); \
466DEFINE_DOT_MULT(
double)
467DEFINE_DOT_MULT(
const Pos &)
468DEFINE_DOT_MULT(
const RMatrix &)
471#undef DEFINE_DOT_MULT
473DLLEXPORT
const ElementMatrix < double > dot(
474 const ElementMatrix < double > & A,
475 const ElementMatrix < double > & B);
478DLLEXPORT
void dot(
const ElementMatrix < double > & A,
479 const ElementMatrix < double > & B,
480 ElementMatrix < double > & ret);
486DLLEXPORT
void mult(
const ElementMatrix < double > & A,
const RVector & b,
487 ElementMatrix < double > & C);
489DLLEXPORT
void mult(
const ElementMatrix < double > & A,
const PosVector & b,
490 ElementMatrix < double > & C);
492DLLEXPORT
void mult(
const ElementMatrix < double > & A,
493 const std::vector < RMatrix > & b,
494 ElementMatrix < double > & C);
497DLLEXPORT
void evaluateQuadraturePoints(
const MeshEntity & ent,
501DLLEXPORT
void evaluateQuadraturePoints(
const MeshEntity & ent,
505DLLEXPORT
void evaluateQuadraturePoints(
const MeshEntity & ent,
508 std::vector < RMatrix > & ret);
510DLLEXPORT
void evaluateQuadraturePoints(
const Mesh & mesh, Index order,
512 std::vector< RVector > & ret);
514DLLEXPORT
void evaluateQuadraturePoints(
const Mesh & mesh, Index order,
516 std::vector< PosVector > & ret);
518DLLEXPORT
void evaluateQuadraturePoints(
const Mesh & mesh, Index order,
520 std::vector< std::vector< RMatrix > > & ret);
523#define DEFINE_CREATE_FORCE_VECTOR(A_TYPE) \
524DLLEXPORT void createForceVector(const Mesh & mesh, Index order, \
525 RVector & ret, A_TYPE a, \
526 Index nCoeff, Index dofOffset); \
527DLLEXPORT void createMassMatrix(const Mesh & mesh, Index order, \
528 RSparseMapMatrix & ret, A_TYPE a, \
529 Index nCoeff, Index dofOffset); \
530DLLEXPORT void createStiffnessMatrix(const Mesh & mesh, Index order, \
531 RSparseMapMatrix & ret, A_TYPE a, \
532 Index nCoeff, Index dofOffset, \
533 bool elastic=false, bool kelvin=false); \
535DEFINE_CREATE_FORCE_VECTOR(
double)
536DEFINE_CREATE_FORCE_VECTOR(
const Pos &)
537DEFINE_CREATE_FORCE_VECTOR(
const RVector &)
538DEFINE_CREATE_FORCE_VECTOR(
const PosVector &)
539DEFINE_CREATE_FORCE_VECTOR(
const RMatrix &)
541DEFINE_CREATE_FORCE_VECTOR(
const std::vector< RVector > &)
543DEFINE_CREATE_FORCE_VECTOR(
const std::vector< PosVector > &)
545DEFINE_CREATE_FORCE_VECTOR(
const std::vector < RMatrix > &)
547DEFINE_CREATE_FORCE_VECTOR(
const std::vector< std::vector < RMatrix > > &)
551#undef DEFINE_CREATE_FORCE_VECTOR
555class DLLEXPORT FEAFunction {
557 FEAFunction(Index valueSize): _valueSize(valueSize){ }
559 virtual ~FEAFunction() { }
561 virtual double evalR1(
const Pos & arg,
const MeshEntity * ent=0)
const{
562 log(Warning,
"FEAFunction.eval should be overloaded.");
566 log(Warning,
"FEAFunction.eval should be overloaded.");
567 return Pos(0.0, 0.0, 0.0);
569 virtual RMatrix evalRM(
const Pos & arg,
const MeshEntity * ent=0)
const{
570 log(Warning,
"FEAFunction.eval should be overloaded.");
571 return RMatrix(0, 0);
574 Index valueSize()
const {
return _valueSize; }
583 void add(Index row,
const ElementMatrix < double > & Ai);
586 RVector mult(
const RVector & a,
const RVector & b,
587 const RVector & m,
const RVector & n)
const;
590 RVector mult(
const RVector & a,
const RVector & b)
const;
592 Index rows()
const {
return rows_; }
594 Index cols()
const {
return cols_; }
598 std::vector< RMatrix > mat_;
599 std::vector< IndexArray > _ids;
600 std::vector< Index > row_;
606template <
class ValueType > std::ostream & operator << (std::ostream & str,
609template < > DLLEXPORT std::ostream & operator << (std::ostream & str,
A abstract cell.
Definition meshentities.h:261
Definition elementmatrix.h:580
Definition elementmatrix.h:30
void fillIds(const MeshEntity &ent, Index nC=1)
Definition elementmatrix.cpp:1125
Vector< ValueType > col(Index i) const
Definition elementmatrix.h:102
ElementMatrix< ValueType > & gradU(const MeshEntity &ent, const RVector &w, const PosVector &x, Index nC, bool voigtNotation=false)
void setMat(const Matrix< ValueType > &m)
Definition elementmatrix.h:94
const Vector< ValueType > & row(Index i) const
Definition elementmatrix.h:100
const IndexArray & rowIDs() const
Definition elementmatrix.h:126
void setIds(const IndexArray &idsR, const IndexArray &idsC)
Definition elementmatrix.h:115
Matrix< ValueType > * pMat()
Definition elementmatrix.h:96
ElementMatrix< ValueType > & gradU2(const Cell &cell, ValueType c)
Definition elementmatrix.h:189
void getWeightsAndPoints(const MeshEntity &ent, const RVector *&w, const PosVector *&x, int order)
Definition elementmatrix.cpp:357
ElementMatrix< ValueType > & gradU2(const MeshEntity &ent, const Matrix< ValueType > &C, const RVector &w, const PosVector &x, bool voigtNotation=false)
const Index idx(Index i) const
Definition elementmatrix.h:130
const std::vector< Matrix< ValueType > > & matX() const
Definition elementmatrix.h:337
void fillGradientBase(const MeshEntity &ent, const RVector &w, const PosVector &x, Index nC, bool voigtNotation)
void setIds(const IndexArray &ids)
Definition elementmatrix.h:120
ElementMatrix< ValueType > & u2(const MeshEntity &ent)
ElementMatrix< ValueType > & u(const MeshEntity &ent)
const IndexArray & colIDs() const
Definition elementmatrix.h:128
const IndexArray & ids() const
Definition elementmatrix.h:124
ElementMatrix< ValueType > & grad(const MeshEntity &ent, Index order, bool elastic, bool sum, bool div, Index nCoeff, Index dof, Index dofOffset, bool kelvin=false)
ElementMatrix(Index dof=0)
Definition elementmatrix.h:34
const PosVector & x() const
Definition elementmatrix.h:345
ElementMatrix< ValueType > & grad(const MeshEntity &ent, Index order, bool elastic=false, bool sum=false, bool div=false, bool kelvin=false)
ValueType mult(const Vector< ValueType > &a, const Vector< ValueType > &b)
Definition elementmatrix.h:266
const Matrix< ValueType > & gradientBase() const
Definition elementmatrix.h:154
void mult(const Vector< ValueType > &a, Vector< ValueType > &ret)
Definition elementmatrix.h:257
const MeshEntity & entity() const
Definition elementmatrix.h:342
ElementMatrix< ValueType > & gradU2(const Cell &cell, const Matrix< ValueType > &C, bool voigtNotation=false)
const Matrix< ValueType > & mat() const
Definition elementmatrix.h:98
const RVector & w() const
Definition elementmatrix.h:348
ElementMatrix< ValueType > & pot(const MeshEntity &ent, Index order, bool sum, Index nCoeff, Index dof, Index dofOffset)
Vector< ValueType > stress(const MeshEntity &ent, const Matrix< ValueType > &C, const RVector &u, bool voigtNotation=false)
ElementMatrix< ValueType > & gradU(const Cell &cell, Index nC, bool voigtNotation=false)
Val mult_(const Vector< Val > &a, const Vector< Val > &b, const Vector< Val > &m, const Vector< Val > &n)
Definition elementmatrix.h:280
ElementMatrix< ValueType > & pot(const MeshEntity &ent, Index order, bool sum=false)
Definition elementmatrix.h:555
Simple row-based dense matrix based on Vector.
Definition matrix.h:324
Definition meshentities.h:103
3 dimensional vector
Definition pos.h:73
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
RVector x(const R3Vector &rv)
Definition pos.cpp:107