20 #ifndef __mast_traction_load_h__ 21 #define __mast_traction_load_h__ 29 namespace Elasticity {
31 template <
typename TractionType, u
int_t Dim,
typename ContextType>
33 typename std::enable_if<Dim == 1, void>::type
35 const TractionType &t,
36 typename TractionType::value_t &v) {
38 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
40 v(0) = t.get_scalar_for_dim(0).value(c);
44 template <
typename TractionType, u
int_t Dim,
typename ContextType>
46 typename std::enable_if<Dim == 2, void>::type
48 const TractionType &t,
49 typename TractionType::value_t &v) {
51 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
53 v(0) = t.get_scalar_for_dim(0).value(c);
54 v(1) = t.get_scalar_for_dim(1).value(c);
58 template <
typename TractionType, u
int_t Dim,
typename ContextType>
60 typename std::enable_if<Dim == 3, void>::type
62 const TractionType &t,
63 typename TractionType::value_t &v) {
65 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
67 v(0) = t.get_scalar_for_dim(0).value(c);
68 v(1) = t.get_scalar_for_dim(1).value(c);
69 v(2) = t.get_scalar_for_dim(2).value(c);
73 template <
typename TractionType,
76 typename ScalarFieldType>
78 typename std::enable_if<Dim == 1, void>::type
81 const TractionType &t,
82 typename TractionType::value_t &v) {
84 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
86 v(0) = t.get_scalar_for_dim(0).derivative(c, f);
90 template <
typename TractionType,
93 typename ScalarFieldType>
95 typename std::enable_if<Dim == 2, void>::type
98 const TractionType &t,
99 typename TractionType::value_t &v) {
101 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
103 v(0) = t.get_scalar_for_dim(0).derivative(c, f);
104 v(1) = t.get_scalar_for_dim(1).derivative(c, f);
108 template <
typename TractionType,
110 typename ContextType,
111 typename ScalarFieldType>
113 typename std::enable_if<Dim == 3, void>::type
116 const TractionType &t,
117 typename TractionType::value_t &v) {
119 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
121 v(0) = t.get_scalar_for_dim(0).derivative(c, f);
122 v(1) = t.get_scalar_for_dim(1).derivative(c, f);
123 v(2) = t.get_scalar_for_dim(2).derivative(c, f);
133 template <
typename TractionScalarType, u
int_t Dim,
typename ContextType>
138 using scalar_t =
typename TractionScalarType::scalar_t;
139 using value_t = Eigen::Matrix<scalar_t, Dim, 1>;
143 const TractionScalarType *t1 =
nullptr,
144 const TractionScalarType *t2 =
nullptr):
147 Assert1(Dim>1 || t1 ==
nullptr,
148 Dim,
"t1 should be nullptr for 1D traction");
149 Assert1(Dim>2 || t2 ==
nullptr,
150 Dim,
"t2 should be nullptr for 2D traction");
155 Assert2(i < Dim, i, Dim,
"Invalid dimension index");
162 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
164 traction_value<traction_t, Dim, ContextType>(c, *
this, v);
167 template <
typename ScalarFieldType>
171 Assert2(v.size() == Dim, v.size(), Dim,
"Incorrect size");
173 traction_derivative<traction_t, Dim, ContextType, ScalarFieldType>
180 std::vector<const TractionScalarType*>
_t;
199 template <
typename FEVarType,
200 typename TractionFieldType,
201 typename SectionAreaType,
203 typename ContextType>
210 using vector_t =
typename Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>;
211 using matrix_t =
typename Eigen::Matrix<scalar_t, Eigen::Dynamic, Eigen::Dynamic>;
216 _fe_var_data (nullptr)
223 inline void set_traction(
const TractionFieldType& t) { _traction = &t;}
229 Assert0(_fe_var_data,
"FE data not initialized.");
231 return Dim*_fe_var_data->get_fe_shape_data().n_basis();
245 Assert0(_fe_var_data,
"FE data not initialized.");
246 Assert0(_section,
"Section property not initialized");
247 Assert0(_traction,
"Traction not initialized");
249 const typename FEVarType::fe_shape_deriv_t
250 &fe = _fe_var_data->get_fe_shape_data();
252 typename TractionFieldType::value_t
255 for (
uint_t i=0; i<fe.n_q_points(); i++) {
259 _traction->value(c, trac);
261 trac *= _section->value(c);
263 for (
uint_t j=0; j<Dim; j++) {
269 for (
uint_t k=0; k<fe.n_basis(); k++)
270 res(j*fe.n_basis() + k) -= fe.detJxW(i) * fe.phi(i, k) * trac(j) * nj;
285 template <
typename ScalarFieldType>
287 const ScalarFieldType& f,
291 Assert0(_fe_var_data,
"FE data not initialized.");
292 Assert0(_section,
"Section property not initialized");
293 Assert0(_traction,
"Traction not initialized");
295 const typename FEVarType::fe_shape_deriv_t
296 &fe = _fe_var_data->get_fe_shape_data();
298 typename TractionFieldType::value_t
302 for (
uint_t i=0; i<fe.n_q_points(); i++) {
306 _traction->value(c, trac);
307 _traction->derivative(f, c, dtrac);
309 dtrac *= _section->value(c);
310 trac *= _section->derivative(c, f);
313 for (
uint_t j=0; j<Dim; j++) {
319 for (
uint_t k=0; k<fe.n_basis(); k++)
320 res(j*fe.n_basis() + k) -= fe.detJxW(i) * fe.phi(i, k) * trac(j) * nj;
339 #endif // __mast_traction_load_h__ void set_fe_var_data(const FEVarType &fe)
void value(ContextType &c, value_t &v) const
const FEVarType * _fe_var_data
typename FEVarType::scalar_t scalar_t
const SectionAreaType * _section
const TractionScalarType & get_scalar_for_dim(uint_t i) const
const TractionFieldType * _traction
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > vector_t
#define Assert1(cond, v1, msg)
std::enable_if< Dim==1, void >::type traction_derivative(const ScalarFieldType &f, ContextType &c, const TractionType &t, typename TractionType::value_t &v)
Traction(const TractionScalarType *t0, const TractionScalarType *t1=nullptr, const TractionScalarType *t2=nullptr)
void set_section_area(const SectionAreaType &s)
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...
typename FEVarType::fe_shape_deriv_t::scalar_t basis_scalar_t
std::enable_if< Dim==1, void >::type traction_value(ContextType &c, const TractionType &t, typename TractionType::value_t &v)
void compute(ContextType &c, vector_t &res, matrix_t *jac=nullptr) const
Computes the residual of variational term and returns it in res.
Eigen::Matrix< scalar_t, Dim, 1 > value_t
typename TractionScalarType::scalar_t scalar_t
#define Assert0(cond, msg)
#define Assert2(cond, v1, v2, msg)
void set_traction(const TractionFieldType &t)
typename Eigen::Matrix< scalar_t, Eigen::Dynamic, Eigen::Dynamic > matrix_t
This class implements the discrete evaluation of the surface traction kernel defined as where...
virtual ~SurfaceTractionLoad()
std::vector< const TractionScalarType * > _t
void derivative(const ScalarFieldType &f, ContextType &c, value_t &v) const
This class defines a data structure that can be used to define a parameterized surface traction vecto...