MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
plate_linear_acceleration.hpp
Go to the documentation of this file.
1 /*
2 * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3 * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #ifndef __mast_elasticity_plate_linear_acceleration_kernel_h__
21 #define __mast_elasticity_plate_linear_acceleration_kernel_h__
22 
23 // MAST includes
25 #include <mast/base/exceptions.hpp>
27 
28 
29 namespace MAST {
30 namespace Physics {
31 namespace Elasticity {
32 namespace Plate {
33 
34 
35 template <typename NodalScalarType,
36  typename VarScalarType,
37  typename FEVarType>
38 inline void
39 displacement(const FEVarType& fe_var,
40  const uint_t qp,
41  typename Eigen::Matrix<VarScalarType, 3, 1>& u,
43 
44  u.setZero();
45 
46  const typename FEVarType::fe_shape_deriv_t
47  &fe = fe_var.get_fe_shape_data();
48 
49  // make sure all matrices are the right size
50  Assert1(Bmat.m() == 3,
51  Bmat.m(),
52  "Incompatible operator size");
53  Assert2(Bmat.n() == 3*fe.n_basis(),
54  Bmat.n(), 3*fe.n_basis(),
55  "Incompatible Operator size.");
56 
57 
58  // set the strain displacement relation
59  for (uint_t i=0; i<3; i++) {
60  Bmat.set_shape_function(i, i, fe.phi(qp));
61  u(i) = fe_var.u(qp, i);
62  }
63 }
64 
78 template <typename FEVarType,
79  typename SectionPropertyType,
80  typename ContextType>
82 
83 public:
84 
85  using scalar_t = typename FEVarType::scalar_t;
86  using basis_scalar_t = typename FEVarType::fe_shape_deriv_t::scalar_t;
87  using vector_t = typename Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>;
88  using matrix_t = typename Eigen::Matrix<scalar_t, Eigen::Dynamic, Eigen::Dynamic>;
89 
91  _property (nullptr),
92  _fe_var_data (nullptr)
93  { }
94 
95  virtual ~LinearAcceleration() { }
96 
97  inline void
98  set_section_property(const SectionPropertyType& p) {
99 
100  Assert0(!_property, "Property already initialized.");
101 
102  _property = &p;
103  }
104 
105  inline void set_fe_var_data(const FEVarType& fe) { _fe_var_data = &fe;}
106 
107  inline uint_t n_dofs() const {
108 
109  Assert0(_fe_var_data, "FE data not initialized.");
110 
111  return 3*_fe_var_data->get_fe_shape_data().n_basis();
112  }
113 
121  inline void compute(ContextType& c,
122  vector_t& res,
123  matrix_t* jac = nullptr) const {
124 
125  Assert0(_fe_var_data, "FE data not initialized.");
126  Assert0(_property, "Section property not initialized");
127 
128  const typename FEVarType::fe_shape_deriv_t
129  &fe = _fe_var_data->get_fe_shape_data();
130 
131  const uint_t
132  n_basis = fe.n_basis();
133 
134  typename Eigen::Matrix<scalar_t, 3, 1>
135  u;
136 
137  vector_t
138  vec = vector_t::Zero(3*n_basis);
139 
140  scalar_t
141  w_factor = 0.,
142  theta_factor = 0.;
143 
144  matrix_t
145  mat = matrix_t::Zero(3*n_basis, 3*n_basis);
146 
148  Bmat;
149  Bmat.reinit(3, 3, n_basis);
150 
151  for (uint_t i=0; i<fe.n_q_points(); i++) {
152 
153  c.qp = i;
154 
155  _property->translation_inertia(c, w_factor);
156  _property->rotation_inertia(c, theta_factor);
157 
159  <scalar_t, scalar_t, FEVarType>(*_fe_var_data, i, u, Bmat);
160 
161  u(0) *= w_factor;
162  u(1) *= theta_factor;
163  u(2) *= theta_factor;
164 
165  Bmat.vector_mult_transpose(vec, u);
166  res += fe.detJxW(i) * vec;
167 
168  if (jac) {
169 
170  Bmat.right_multiply_transpose(mat, Bmat);
171 
172  mat.topLeftCorner(n_basis, n_basis) *= w_factor;
173  mat.block(n_basis, n_basis, n_basis, n_basis) *= theta_factor;
174  mat.bottomRightCorner(n_basis, n_basis) *= theta_factor;
175 
176  (*jac) += fe.detJxW(i) * mat;
177  }
178  }
179  }
180 
181 
189  template <typename ScalarFieldType>
190  inline void derivative(ContextType& c,
191  const ScalarFieldType& f,
192  vector_t& res,
193  matrix_t* jac = nullptr) const {
194 
195  Assert0(_fe_var_data, "FE data not initialized.");
196  Assert0(_property, "Section property not initialized");
197 
198  const typename FEVarType::fe_shape_deriv_t
199  &fe = _fe_var_data->get_fe_shape_data();
200 
201  const uint_t
202  n_basis = fe.n_basis();
203 
204  typename Eigen::Matrix<scalar_t, 3, 1>
205  u;
206 
207  vector_t
208  vec = vector_t::Zero(3*n_basis);
209 
210  scalar_t
211  dw_factor = 0.,
212  dtheta_factor = 0.;
213 
214  matrix_t
215  mat = matrix_t::Zero(3*n_basis, 3*n_basis);
216 
218  Bmat;
219  Bmat.reinit(3, 3, n_basis);
220 
221  for (uint_t i=0; i<fe.n_q_points(); i++) {
222 
223  c.qp = i;
224 
225  _property->translation_inertia_derivative(c, f, dw_factor);
226  _property->rotation_inertia_derivative(c, f, dtheta_factor);
227 
229  <scalar_t, scalar_t, FEVarType>(*_fe_var_data, i, u, Bmat);
230 
231  u(0) *= dw_factor;
232  u(1) *= dtheta_factor;
233  u(2) *= dtheta_factor;
234 
235  Bmat.vector_mult_transpose(vec, u);
236  res += fe.detJxW(i) * vec;
237 
238  if (jac) {
239 
240  Bmat.right_multiply_transpose(mat, Bmat);
241 
242  mat.topLeftCorner(n_basis, n_basis) *= dw_factor;
243  mat.block(n_basis, n_basis, n_basis, n_basis) *= dtheta_factor;
244  mat.bottomRightCorner(n_basis, n_basis) *= dtheta_factor;
245 
246  (*jac) += fe.detJxW(i) * mat;
247  }
248  }
249  }
250 
251 private:
252 
253  const SectionPropertyType *_property;
254  const FEVarType *_fe_var_data;
255 };
256 
257 
258 } // namespace Plate
259 } // namespace Elasticity
260 } // namespace Physics
261 } // namespace MAST
262 
263 
264 #endif // __mast_elasticity_plate_linear_acceleration_kernel_h__
This class implements the discrete evaluation of the acceleration kernel defined as where...
void vector_mult_transpose(T1 &res, const T2 &v) const
res = v^T * [this]
typename FEVarType::fe_shape_deriv_t::scalar_t basis_scalar_t
#define Assert1(cond, v1, msg)
Definition: exceptions.hpp:143
void right_multiply_transpose(T &r, const T &m) const
[R] = [this]^T * [M]
void displacement(const FEVarType &fe_var, const uint_t qp, typename Eigen::Matrix< VarScalarType, 3, 1 > &u, MAST::Numerics::FEMOperatorMatrix< NodalScalarType > &Bmat)
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, Eigen::Dynamic > matrix_t
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
void set_shape_function(uint_t interpolated_var, uint_t discrete_var, const VecType &shape_func)
sets the shape function values for the block corresponding to interpolated_var and discrete_var...
void derivative(ContextType &c, const ScalarFieldType &f, vector_t &res, matrix_t *jac=nullptr) const
Computes the derivative of residual of variational term with respect to parameter and returns it in...
unsigned int uint_t
#define Assert2(cond, v1, v2, msg)
Definition: exceptions.hpp:152
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > vector_t
void compute(ContextType &c, vector_t &res, matrix_t *jac=nullptr) const
Computes the residual of variational term and returns it in res.
void reinit(uint_t n_interpolated_vars, uint_t n_discrete_vars, uint_t n_discrete_dofs_per_var)
this initializes the operator for number of rows and variables, assuming that all variables has the s...