MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
pressure_load.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_pressure_load_h__
21 #define __mast_pressure_load_h__
22 
23 // MAST includes
25 #include <mast/base/exceptions.hpp>
26 
27 namespace MAST {
28 namespace Physics {
29 namespace Elasticity {
30 
31 template <typename FEVarType,
32  typename PressureFieldType,
33  typename SectionAreaType,
34  uint_t Dim,
35  typename ContextType>
37 
38 public:
39 
40  using scalar_t = typename FEVarType::scalar_t;
41  using basis_scalar_t = typename FEVarType::fe_shape_deriv_t::scalar_t;
42  using vector_t = typename Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>;
43  using matrix_t = typename Eigen::Matrix<scalar_t, Eigen::Dynamic, Eigen::Dynamic>;
44 
46  _section (nullptr),
47  _pressure (nullptr),
48  _fe_var_data (nullptr)
49  { }
50 
51  virtual ~SurfacePressureLoad() { }
52 
53  inline void set_section_area(const SectionAreaType& s) { _section = &s;}
54 
55  inline void set_pressure(const PressureFieldType& p) { _pressure = &p;}
56 
57  inline void set_fe_var_data(const FEVarType& fe) { _fe_var_data = &fe;}
58 
59  inline uint_t n_dofs() const {
60 
61  Assert0(_fe_var_data, "FE data not initialized.");
62 
63  return Dim*_fe_var_data->get_fe_shape_data().n_basis();
64  }
65 
66  inline void compute(ContextType& c,
67  vector_t& res,
68  matrix_t* jac = nullptr) const {
69 
70  Assert0(_fe_var_data, "FE data not initialized.");
71  Assert0(_section, "Section property not initialized");
72  Assert0(_pressure, "Pressure not initialized");
73 
74  const typename FEVarType::fe_shape_deriv_t
75  &fe = _fe_var_data->get_fe_shape_data();
76 
77  for (uint_t i=0; i<fe.n_q_points(); i++) {
78 
79  c.qp = i;
80  scalar_t p = _pressure->value(c) * _section->value(c);
81 
82  for (uint_t j=0; j<Dim; j++) {
83 
84  // j-th component of normal vector at ith quadrature point
85  scalar_t nj = fe.normal(i, j);
86 
87  if (nj != 0.) {
88  for (uint_t k=0; k<fe.n_basis(); k++)
89  res(j*fe.n_basis() + k) -= fe.detJxW(i) * fe.phi(i, k) * p * nj;
90  }
91  }
92  }
93  }
94 
95 
96  template <typename ScalarFieldType>
97  inline void derivative(ContextType& c,
98  const ScalarFieldType& f,
99  vector_t& res,
100  matrix_t* jac = nullptr) const {
101 
102  Assert0(_fe_var_data, "FE data not initialized.");
103  Assert0(_section, "Section property not initialized");
104  Assert0(_pressure, "Pressure not initialized");
105 
106  const typename FEVarType::fe_shape_deriv_t
107  &fe = _fe_var_data->get_fe_shape_data();
108 
109  for (uint_t i=0; i<fe.n_q_points(); i++) {
110 
111  c.qp = i;
112  scalar_t p = (_pressure->value(c) * _section->derivative(c, f) +
113  _pressure->derivative(c, f) * _section->value(c)) ;
114 
115  for (uint_t j=0; j<Dim; j++) {
116 
117  // j-th component of normal vector at ith quadrature point
118  scalar_t nj = fe.normal(i, j);
119 
120  if (nj != 0.) {
121  for (uint_t k=0; k<fe.n_basis(); k++)
122  res(j*fe.n_basis() + k) -= fe.detJxW(i) * fe.phi(i, k) * p * nj;
123  }
124  }
125  }
126  }
127 
128 private:
129 
130  const SectionAreaType *_section;
131  const PressureFieldType *_pressure;
132  const FEVarType *_fe_var_data;
133 };
134 
135 
136 } // namespace Elasticity
137 } // namespace Physics
138 } // namespace MAST
139 
140 
141 #endif // __mast_pressure_load_h__
void set_section_area(const SectionAreaType &s)
void compute(ContextType &c, vector_t &res, matrix_t *jac=nullptr) const
void derivative(ContextType &c, const ScalarFieldType &f, vector_t &res, matrix_t *jac=nullptr) const
void set_pressure(const PressureFieldType &p)
typename FEVarType::fe_shape_deriv_t::scalar_t basis_scalar_t
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > vector_t
unsigned int uint_t
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, Eigen::Dynamic > matrix_t