G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsVisitorThermo.h
Go to the documentation of this file.
1 
16 #pragma once
17 
19 #include <gsCore/gsFuncData.h>
20 
21 namespace gismo
22 {
23 
24 template <class T>
25 class gsVisitorThermo
26 {
27 public:
28  gsVisitorThermo(const gsFunctionSet<T> & temperatureField_)
29  : dim(0), lambda(0), mu(0), thermalExpCoef(0), N_D(0), patch(0),
30  temperatureField(temperatureField_), paramTemp(0) {}
31 
32  void initialize(const gsBasisRefs<T> & basisRefs,
33  const index_t patchIndex,
34  const gsOptionList & options,
35  gsQuadRule<T> & rule)
36  {
37  // parametric dimension of the first displacement component
38  dim = basisRefs.front().dim();
39  // a quadrature rule is defined by the basis for the first displacement component.
40  rule = gsQuadrature::get(basisRefs.front(), options);
41  // saving necessary info
42  patch = patchIndex;
43  paramTemp = options.getSwitch("ParamTemp");
44  thermalExpCoef = options.getReal("ThExpCoef");
45  T E = options.getReal("YoungsModulus");
46  T pr = options.getReal("PoissonsRatio");
47  lambda = E * pr / ( ( 1. + pr ) * ( 1. - 2. * pr ) );
48  mu = E / ( 2. * ( 1. + pr ) );
49  // resize containers for global indices
50  globalIndices.resize(dim);
51  blockNumbers.resize(dim);
52  }
53 
54  inline void evaluate(const gsBasisRefs<T> & basisRefs,
55  const gsGeometry<T> & geo,
56  const gsMatrix<T> & quNodes)
57  {
58  // store quadrature points of the element for geometry evaluation
59  md.points = quNodes;
60  // NEED_VALUE to get points in the physical domain for evaluation of the temperature gradients
61  // NEED_MEASURE to get the Jacobian determinant values for integration
62  // NEED_GRAD_TRANSFORM to get the Jacobian matrix to transform temperature gradient from the parametric to physical domain
63  if (paramTemp)
64  md.flags = NEED_MEASURE | NEED_GRAD_TRANSFORM;
65  else
66  md.flags = NEED_VALUE | NEED_MEASURE;
67  // Compute image of the quadrature points plus gradient, jacobian and other necessary data
68  geo.computeMap(md);
69  // Compute temperature gradients
70  if (paramTemp) // evaluate gradients in the parametric domain
71  temperatureField.piece(patch).deriv_into(quNodes,tempGrads);
72  else // evaluate gradients in the physical domain
73  temperatureField.piece(patch).deriv_into(md.values[0],tempGrads);
74  // find local indices of the displacement basis functions active on the element
75  basisRefs.front().active_into(quNodes.col(0),localIndicesDisp);
76  N_D = localIndicesDisp.rows();
77  // Evaluate displacement basis functions on the element
78  basisRefs.front().eval_into(quNodes,basisValuesDisp);
79  }
80 
81  inline void assemble(gsDomainIterator<T> & element,
82  const gsVector<T> & quWeights)
83  {
84  // Initialize local matrix/rhs
85  localRhs.setZero(dim*N_D, 1);
86  // Loop over the quadrature nodes
87  for (index_t q = 0; q < quWeights.rows(); ++q)
88  {
89  // Multiply quadrature weight by the geometry measure
90  const T weight = thermalExpCoef*(2*mu+dim*lambda)*quWeights[q]*md.measure(q);
91 
92  if (paramTemp) // transform temperature gradients to the physical domain
93  {
94  // temperature gradient at one point in the physical domain, dim x 1
95  transformGradients(md,q,tempGrads,physGrad);
96  for (index_t d = 0; d < dim; ++d)
97  localRhs.middleRows(d*N_D,N_D).noalias() -= weight * physGrad(d,0) * basisValuesDisp.col(q);
98  }
99  else // use temperature gradients as they are
100  for (index_t d = 0; d < dim; ++d)
101  localRhs.middleRows(d*N_D,N_D).noalias() -= weight * tempGrads(d,q) * basisValuesDisp.col(q);
102  }
103  }
104 
105  inline void localToGlobal(const int patchIndex,
106  const std::vector<gsMatrix<T> > & eliminatedDofs,
107  gsSparseSystem<T> & system)
108  {
109  // computes global indices for displacement components
110  for (short_t d = 0; d < dim; ++d)
111  {
112  system.mapColIndices(localIndicesDisp, patchIndex, globalIndices[d], d);
113  blockNumbers.at(d) = d;
114  }
115  // push to global system
116  system.pushToRhs(localRhs,globalIndices,blockNumbers);
117  }
118 
119 protected:
120  // problem info
121  short_t dim;
122  // Lame and thermal expansion coefficients
123  T lambda, mu, thermalExpCoef;
124  // geometry mapping
125  gsMapData<T> md;
126  // local components of the global linear system
127  gsMatrix<T> localRhs;
128  // local indices (at the current patch) of the displacement basis functions active at the current element
129  gsMatrix<index_t> localIndicesDisp;
130  // number of displacement basis functions active at the current element
131  index_t N_D;
132  // values of displacement basis functions at quadrature points at the current element stored as a N_D x numQuadPoints matrix;
133  gsMatrix<T> basisValuesDisp;
134  // Temperature info
135  index_t patch;
136  const gsFunctionSet<T> & temperatureField;
137  // true if temperature field is defined in the parametric domain; false if in the physical
138  bool paramTemp;
139  // temperature gradient evaluated at the quadrature points or at their images in the physical domain;
140  // stored as a dim x numQuadPoints matrix
141  gsMatrix<T> tempGrads;
142 
143  // all temporary matrices defined here for efficiency
144  gsMatrix<T> physGrad;
145  // containers for global indices
146  std::vector< gsMatrix<index_t> > globalIndices;
147  gsVector<index_t> blockNumbers;
148 
149 }; //class definition ends
150 
151 } // namespace ends
#define short_t
Definition: gsConfig.h:35
#define index_t
Definition: gsConfig.h:32
static gsQuadRule< T > get(const gsBasis< T > &basis, const gsOptionList &options, short_t fixDir=-1)
Constructs a quadrature rule based on input options.
Definition: gsQuadrature.h:48
Creates a variety of quadrature rules.
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
Value of the object.
Definition: gsForwardDeclarations.h:72
Gradient transformation matrix.
Definition: gsForwardDeclarations.h:77
This object is a cache for computed values from an evaluator.