MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
continuum_stress.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_linear_continuum_stress_h__
21 #define __mast_linear_continuum_stress_h__
22 
23 // MAST includes
25 
26 namespace MAST {
27 namespace Physics {
28 namespace Elasticity {
29 namespace LinearContinuum {
30 
31 
32 template <typename FEVarType,
33  typename MaterialPropertyType,
34  uint_t Dim,
35  typename ContextType>
36 class Stress {
37 
38 public:
39 
40  using scalar_t = typename FEVarType::scalar_t;
41  using nodal_scalar_t = typename FEVarType::fe_shape_deriv_t::scalar_t;
42  using var_scalar_t = typename FEVarType::scalar_t;
43  static const uint_t
45 
46  Stress():
47  _property (nullptr),
48  _fe_var_data (nullptr),
49  _sens_fe_var_data (nullptr)
50  { }
51 
52 
53  inline void
54  set_section_property(const MaterialPropertyType& p) {
55 
56  Assert0(!_property, "Property already initialized.");
57 
58  _property = &p;
59  }
60 
61 
65  inline void set_fe_var_data(const FEVarType &fe_data) {
66 
67  Assert0(!_fe_var_data, "FE data already initialized.");
68  _fe_var_data = &fe_data;
69  }
70 
74  inline void set_fe_var_sensitivity_data(const FEVarType &sens_fe_data) {
75 
76  Assert0(!_sens_fe_var_data, "FE data already initialized.");
77  _sens_fe_var_data = &sens_fe_data;
78  }
79 
80 
81  inline uint_t n_dofs() const {
82 
83  Assert0(_fe_var_data, "FE data not initialized.");
84 
85  return Dim*_fe_var_data->get_fe_shape_data().n_basis();
86  }
87 
88 
89  template <typename AccessorType>
90  inline void
91  compute(ContextType &c,
92  AccessorType &stress) const {
93 
94  Assert0(_fe_var_data, "FE data not initialized.");
95  Assert0(_property, "Section property not initialized");
96 
97  Assert2(stress.size() == n_strain,
98  stress.size(), n_strain,
99  "Incorrect stress vector dimension");
100 
101  const typename FEVarType::fe_shape_deriv_t
102  &fe = _fe_var_data->get_fe_shape_data();
103 
104  Assert2(c.qp < fe.n_q_points(),
105  c.qp, fe.n_q_points(),
106  "Invalid quadrature point index");
107 
108  typename Eigen::Matrix<scalar_t, n_strain, 1>
109  epsilon;
110 
111  typename MaterialPropertyType::value_t
112  m;
113 
115  Bmat;
116  Bmat.reinit(n_strain, Dim, _fe_var_data->get_fe_shape_data().n_basis());
117 
118  _property->value(c, m);
119 
121  <nodal_scalar_t, var_scalar_t, FEVarType, Dim>
122  (*_fe_var_data, c.qp, epsilon, Bmat);
123 
124  // set value for ith quadrature point
125  stress = m * epsilon;
126  }
127 
128 
129  template <typename AccessorType, typename ScalarFieldType>
130  inline void derivative(ContextType &c,
131  const ScalarFieldType &f,
132  AccessorType &dstress) const {
133 
134  Assert0(_fe_var_data, "FE data not initialized.");
135  Assert0(_sens_fe_var_data, "FE data not initialized.");
136  Assert0(_property, "Section property not initialized");
137 
138  Assert2(dstress.size() == n_strain,
139  dstress.size(), n_strain,
140  "Incorrect stress vector dimension");
141 
142  const typename FEVarType::fe_shape_deriv_t
143  &fe = _fe_var_data->get_fe_shape_data();
144 
145  Assert2(c.qp < fe.n_q_points(),
146  c.qp, fe.n_q_points(),
147  "Invalid quadrature point index");
148 
149  typename Eigen::Matrix<scalar_t, n_strain, 1>
150  epsilon,
151  depsilon;
152 
153  typename MaterialPropertyType::value_t
154  m,
155  dm;
156 
158  Bmat;
159  Bmat.reinit(n_strain, Dim, _fe_var_data->get_fe_shape_data().n_basis());
160 
161  _property->value(c, m);
162  _property->derivative(c, f, dm);
163 
165  <nodal_scalar_t, var_scalar_t, FEVarType, Dim>
166  (*_fe_var_data, c.qp, epsilon, Bmat);
167 
169  <nodal_scalar_t, var_scalar_t, FEVarType, Dim>
170  (*_sens_fe_var_data, c.qp, depsilon, Bmat);
171 
172  // set value for ith quadrature point
173  dstress = dm * epsilon + m * depsilon;
174  }
175 
176 
177  template <typename AccessorType>
178  inline void adjoint_derivative(ContextType &c,
179  AccessorType &stress_adj) const {
180 
181  Assert0(_fe_var_data, "FE data not initialized.");
182  Assert0(_property, "Section property not initialized");
183 
184  const typename FEVarType::fe_shape_deriv_t
185  &fe = _fe_var_data->get_fe_shape_data();
186 
187  Assert2(c.qp < fe.n_q_points(),
188  c.qp, fe.n_q_points(),
189  "Invalid quadrature point index");
190 
191  Assert2(stress_adj.rows() == n_strain,
192  stress_adj.rows(), n_strain,
193  "Incorrect stress adjoint accessor rows");
194 
195  Assert2(stress_adj.cols() == 2*fe.n_basis(),
196  stress_adj.cols(), 2*fe.n_basis(),
197  "Incorrect stress adjoint accessor rows");
198 
199 
200  typename Eigen::Matrix<scalar_t, n_strain, 1>
201  epsilon;
202 
203  typename MaterialPropertyType::value_t
204  m;
205 
207  Bmat;
208  Bmat.reinit(n_strain, Dim, _fe_var_data->get_fe_shape_data().n_basis());
209 
210  _property->value(c, m);
211 
213  <nodal_scalar_t, var_scalar_t, FEVarType, Dim>
214  (*_fe_var_data, c.qp, epsilon, Bmat);
215 
216  Bmat.left_multiply(stress_adj, m);
217  }
218 
219 
220 private:
221 
222  const MaterialPropertyType *_property;
223  const FEVarType *_fe_var_data;
224  const FEVarType *_sens_fe_var_data;
225 
226 };
227 } // namespace LinearContinuum
228 } // namespace Elasticity
229 } // namespace Physics
230 } // namespace MAST
231 
232 #endif // __mast_linear_continuum_stress_h__
void derivative(ContextType &c, const ScalarFieldType &f, AccessorType &dstress) const
typename FEVarType::fe_shape_deriv_t::scalar_t nodal_scalar_t
void set_section_property(const MaterialPropertyType &p)
void left_multiply(T1 &r, const T2 &m) const
[R] = [M] * [this]
std::enable_if< Dim==2, void >::type strain(const FEVarType &fe_var, const uint_t qp, typename Eigen::Matrix< VarScalarType, 3, 1 > &epsilon, MAST::Numerics::FEMOperatorMatrix< NodalScalarType > &Bmat)
void set_fe_var_data(const FEVarType &fe_data)
sens_fe_data provides the solution
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
unsigned int uint_t
#define Assert2(cond, v1, v2, msg)
Definition: exceptions.hpp:152
void set_fe_var_sensitivity_data(const FEVarType &sens_fe_data)
sens_fe_data provides the sensitivity of solution
void adjoint_derivative(ContextType &c, AccessorType &stress_adj) const
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...
void compute(ContextType &c, AccessorType &stress) const