GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmShape.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_SHAPE_H_
25#define _GEMA_SHAPE_H_
26
27#include "gmCell.h"
28
29class GmSpinLock;
31
38{
39public:
40
42 virtual GmCellType elemType() const = 0;
43
45 virtual int numFunctions() const = 0;
46
48 virtual int numNaturalCoord() const = 0;
49
51 virtual int numCartesianCoord() const = 0;
52
54 virtual void naturalCoordLimits(int coord, double* min, double* max) const = 0;
55
64 virtual void nodeNaturalCoord(int node, GmVector& coord) const = 0;
65
71 virtual void naturalCenter(GmVector& coord) const = 0;
72
73 void fillNaturalCoordinates(GmMatrix& coord, bool transposed = false) const;
74
87 virtual bool translateEdgePoint(int edge, const GmVector& srcEdgeCoord, GmVector& elementCoord) const = 0;
88
102 virtual bool translateFacePoint(int face, const GmVector& srcFaceCoord, GmVector& elementCoord) const = 0;
103
130 virtual bool cartesianToNatural(const GmVector& coord, const GmMatrix& X, GmVector& ncoord, bool* inside) const
131 {
132 return cartesianToNatural(coord, X, _preferGeometricConfig, _gradTolConfig, _maxGradIterConfig,
133 _outsideNatTolConfig, ncoord, inside);
134 }
135
169 virtual bool cartesianToNatural(const GmVector& coord, const GmMatrix& X, bool preferGeometric, double gradTol,
170 int maxGradIter, double outsideNatTol, GmVector& ncoord, bool* inside) const
171 {
172 if(preferGeometric && hasGeometryBasedCartesianToNatural())
173 return geometryBasedCartesianToNatural(coord, X, outsideNatTol, ncoord, inside);
174 else
175 return gradientBasedCartesianToNatural(coord, X, gradTol, maxGradIter, outsideNatTol, ncoord, inside);
176 }
177
178 virtual void naturalToCartesian(const GmVector& ncoord, const GmMatrix& X, GmVector& coord) const;
179
193 virtual void shapeValues(const GmVector& ncoord, GmVector& N) const = 0;
194
223 virtual void shapePartials(const GmVector& ncoord, GmMatrix& dN, bool transposed = false) const = 0;
224
225 virtual double shapeCartesianPartialsFromCoord (const GmVector& ncoord, const GmMatrix& X, GmMatrix& dN, bool transposed = false) const;
226 virtual double shapeCartesianPartialsFromJacobian(const GmVector& ncoord, const GmMatrix& J, GmMatrix& dN, bool transposed = false) const;
227
246 virtual double shapeCartesianPartialsFromPJ(const GmMatrix& P, const GmMatrix& J, GmMatrix& dN, bool transposed = false) const = 0;
247
275 virtual void jacobian(const GmVector& ncoord, const GmMatrix& X, GmMatrix& J, bool transposed = false) const
276 {
277 GmMatrix P;
278 jacobianAndPartials(ncoord, X, J, P, transposed);
279 }
280
288 virtual double scaledJacobianDet(const GmMatrix& J) const = 0;
289
298 virtual void jacobianAndPartials(const GmVector& ncoord, const GmMatrix& X, GmMatrix& J, GmMatrix& P, bool transposed = false) const = 0;
299
321 virtual double borderScalingFactor(int border, const GmVector& borderCoord, const GmVector& elementCoord,
322 const GmMatrix& X, bool transposed = false) const = 0;
323
343 virtual double edgeScalingFactor(int border, const GmVector& borderCoord, const GmVector& elementCoord,
344 const GmMatrix& X, bool transposed = false) const = 0;
345
365 virtual double faceScalingFactor(int border, const GmVector& borderCoord, const GmVector& elementCoord,
366 const GmMatrix& X, bool transposed = false) const = 0;
367
387 virtual void jacobianRotation(const GmMatrix& J, GmMatrix& R) const = 0;
388 virtual const GmMatrix& gaussExtrapolationMatrix(const GmIntegrationRule* ir) const;
389 virtual bool pointExtrapolationMatrix(const GmMatrix& points, GmMatrix& em) const;
390
391 double interpolate(const GmVector& nodeValues, const GmVector& ncoord) const;
392
393 static bool initShapeFunctions();
394 static void setConfigOptions(const GmSimulationData* simData);
395 static const GmShape* shapeFromElementType (GmCellType etype, int P, int Q);
396 static const GmShape* linearShapeFromElementType(GmCellType etype, int P, int Q);
397
398protected:
399 virtual void jacIndependentNatCoord(const GmVector& ncoord, const GmMatrix& X, GmMatrix& J, GmMatrix& P, bool transposed) const;
400 virtual void jacDependentNatCoord (const GmVector& ncoord, const GmMatrix& X, GmMatrix& J, GmMatrix& P, bool transposed) const;
401
402 bool ginv(const GmMatrix& A, GmMatrix& inv) const;
403
404 static void jacRotation2D(const GmMatrix&J, GmMatrix& R);
405 static void jacRotation3D(const GmMatrix&J, GmMatrix& R);
406
407#if defined ENABLE_TESTS
408 friend void shapeMappingTests();
409#endif
410 virtual bool gradientBasedCartesianToNatural(const GmVector& coord, const GmMatrix& X, double tol,
411 int maxIter, double natTol, GmVector& ncoord, bool* inside) const = 0;
412
413 bool gradientBasedCartesianToNaturalQuadHex(const GmVector& coord, const GmMatrix& X, double tol,
414 int maxIter, double natTol, GmVector& ncoord, bool* inside, double alpha = _newtonAlpha) const;
415 bool gradientBasedCartesianToNaturalTriTet (const GmVector& coord, const GmMatrix& X, double tol,
416 int maxIter, double natTol, GmVector& ncoord, bool* inside, double alpha = _newtonAlpha) const;
417 bool gradientBasedCartesianToNaturalBar (const GmVector& coord, const GmMatrix& X, double tol,
418 int maxIter, double natTol, GmVector& ncoord, bool* inside, double alpha = _newtonAlpha) const;
419 bool gradientBasedCartesianToNaturalWedge (const GmVector& coord, const GmMatrix& X, double tol,
420 int maxIter, double natTol, GmVector& ncoord, bool* inside, double alpha = _newtonAlpha) const;
421
427 virtual bool hasGeometryBasedCartesianToNatural() const { return false; }
428
433 virtual bool geometryBasedCartesianToNatural(const GmVector& coord, const GmMatrix& X, double natTol,
434 GmVector& ncoord, bool* inside) const
435 {
436 Q_UNUSED(coord); Q_UNUSED(X); Q_UNUSED(natTol); Q_UNUSED(ncoord); Q_UNUSED(inside);
437 return false;
438 }
439
440 bool checkAndClampNaturalCoordinate(double& ncoord, double min, double max, double natTol) const;
441 bool checkAndClampBarycentricNaturalCoordinates(GmVector& ncoord, double natTol) const;
442
443private:
444 static const void* _shapePointersList[GM_NUM_CELL_TYPES];
446
448 static double _gradTolConfig;
450 static double _outsideNatTolConfig;
451 static double _newtonAlpha;
452
455};
456
457
458#endif
459
Integration rule base classe.
Definition gmIntegrationRule.h:89
Shape function handling base classe.
Definition gmShape.h:38
virtual void naturalCoordLimits(int coord, double *min, double *max) const =0
Fills min and max with the domain limits for the given natural coordinate (between 0 and numNaturalCo...
virtual bool cartesianToNatural(const GmVector &coord, const GmMatrix &X, GmVector &ncoord, bool *inside) const
Given a set of cartesian coordinates 'coord' and a matrix with node coordinates 'X',...
Definition gmShape.h:130
static double _newtonAlpha
The default value for alpha used in newton method for cartesianToNatural()
Definition gmShape.h:451
virtual double shapeCartesianPartialsFromPJ(const GmMatrix &P, const GmMatrix &J, GmMatrix &dN, bool transposed=false) const =0
Alternative version of shapeCartesianPartialsXxxx() to calculate shape function partial derivatives w...
static double _gradTolConfig
The convergence tolerance used by gradient based calls to cartesianToNatural.
Definition gmShape.h:448
virtual GmCellType elemType() const =0
Returns the type of this element.
virtual void nodeNaturalCoord(int node, GmVector &coord) const =0
Fills the coord vector with the set of natural coordinates for the reference shape function node....
static QMutex _emCacheMutex
The mutex protecting _emCache.
Definition gmShape.h:454
virtual double edgeScalingFactor(int border, const GmVector &borderCoord, const GmVector &elementCoord, const GmMatrix &X, bool transposed=false) const =0
Returns the scaling factor needed when calculating integrals over element edges. This has the same ef...
virtual void jacobianRotation(const GmMatrix &J, GmMatrix &R) const =0
Computes the rotation matrix from the jacobian axis. Useful for interface elements.
virtual bool cartesianToNatural(const GmVector &coord, const GmMatrix &X, bool preferGeometric, double gradTol, int maxGradIter, double outsideNatTol, GmVector &ncoord, bool *inside) const
Given a set of cartesian coordinates 'coord' and a matrix with node coordinates 'X',...
Definition gmShape.h:169
virtual double scaledJacobianDet(const GmMatrix &J) const =0
Returns the Jacobian determinant multiplied by the scaling factor needed for transforming the differe...
virtual bool geometryBasedCartesianToNatural(const GmVector &coord, const GmMatrix &X, double natTol, GmVector &ncoord, bool *inside) const
Virtual function that should be implemented if a shape can provide a geometric algorithm for converti...
Definition gmShape.h:433
virtual void shapePartials(const GmVector &ncoord, GmMatrix &dN, bool transposed=false) const =0
Function used to calculate shape function partial derivatives with respect to its natural coordinates...
virtual int numFunctions() const =0
Returns the number of shape functions of this element type (equal to the number of nodes)
virtual void jacobianAndPartials(const GmVector &ncoord, const GmMatrix &X, GmMatrix &J, GmMatrix &P, bool transposed=false) const =0
This function does the same calculations as the jacobian() call, but also filling the extra parameter...
virtual int numCartesianCoord() const =0
Returns the number of cartesian coordinates expected by this element type.
static QMap< QPair< GmCellType, int >, GmMatrix > _emCache
A global cache, keyed by cell type + cacheKey(), storing extrapolation matrices.
Definition gmShape.h:453
virtual double borderScalingFactor(int border, const GmVector &borderCoord, const GmVector &elementCoord, const GmMatrix &X, bool transposed=false) const =0
Returns the scaling factor needed when calculating integrals over borders (edges or faces)....
static GmSpinLock _hElementsLock
The spin-lock protecting the access/creation of shape pointers for hierarchical elements.
Definition gmShape.h:445
virtual bool translateEdgePoint(int edge, const GmVector &srcEdgeCoord, GmVector &elementCoord) const =0
Given a "bar like" edge coordinate (from -1 to 1), at the given edge, fills elementCoord with the equ...
static double _outsideNatTolConfig
The "snap" tolerance used by cartesianToNatural to consider a point outside the element.
Definition gmShape.h:450
virtual void shapeValues(const GmVector &ncoord, GmVector &N) const =0
Function used to evaluate the set of shape functions over a point defined by its natural coordinates.
virtual bool translateFacePoint(int face, const GmVector &srcFaceCoord, GmVector &elementCoord) const =0
Given a "quad like" or "tri like" face coordinate (-1 to 1 pair for quad faces and 0 to 1 barycentric...
virtual double faceScalingFactor(int border, const GmVector &borderCoord, const GmVector &elementCoord, const GmMatrix &X, bool transposed=false) const =0
Returns the scaling factor needed when calculating integrals over element faces. This has the same ef...
static bool _preferGeometricConfig
Should calls to cartesianToNatural prefer geometric algorithms (if available) over the gradient based...
Definition gmShape.h:447
virtual bool hasGeometryBasedCartesianToNatural() const
A virtual function that should be replaced to return true if the shape implements a geometry based al...
Definition gmShape.h:427
virtual void naturalCenter(GmVector &coord) const =0
Fills the coord vector with the set of natural coordinates for the element center.
virtual void jacobian(const GmVector &ncoord, const GmMatrix &X, GmMatrix &J, bool transposed=false) const
Calculates the jacobian matrix, relating cartesian coordinates to natural coordinates.
Definition gmShape.h:275
static int _maxGradIterConfig
The maximum number of iterations used by gradient based calls to cartesianToNatural.
Definition gmShape.h:449
virtual int numNaturalCoord() const =0
Returns the number of natural coordinates used by this element type.
Auxiliar class used to store the complete set of simulation data.
Definition gmSimulationData.h:55
A simple spin lock implementation based on a loop using test and set over an atomic int to change its...
Definition gmSpinLock.h:37
Declaration of the GmCell class.
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition gmCellType.h:31
@ GM_NUM_CELL_TYPES
NOT a cell type. Stores the number of available types.
Definition gmCellType.h:77
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34